Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update how svg image file is being read #8893

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/uwp/SharedRenderer/dll/CppWinRTIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace winrt
// using namespace winrt::Windows::Web::Http
using HttpProgress = ::winrt::Windows::Web::Http::HttpProgress;
using HttpClient = ::winrt::Windows::Web::Http::HttpClient;
using HttpResponseMessage = ::winrt::Windows::Web::Http::HttpResponseMessage;

// using namespace winrt::Windows::Web::Http::HttpFilters
using HttpBaseProtocolFilter = ::winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter;
Expand Down
53 changes: 31 additions & 22 deletions source/uwp/SharedRenderer/lib/AdaptiveImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,36 +414,45 @@ namespace AdaptiveCards::Rendering::Xaml_Rendering

if (imgProperties.isImageSvg)
{
// If we have an SVG, we need to try to parse for the image size before setting the image source
auto svgDocumentLoadOperation = winrt::XmlDocument::LoadFromUriAsync(imageUrl);
winrt::HttpClient httpClient;
auto getOperation = httpClient.GetAsync(imageUrl);

svgDocumentLoadOperation.Completed(
[weakThis = this->get_weak(),
weakImageSource = winrt::make_weak(image.as<winrt::SvgImageSource>()),
imageUrl](auto const& operation, auto status) -> void
getOperation.Completed([weakThis = this->get_weak(),
weakImageSource = winrt::make_weak(image.as<winrt::SvgImageSource>()),
imageUrl](auto const& operation, auto status)
{
if (status == winrt::AsyncStatus::Completed)
{
auto strongThis = weakThis.get();
auto strongImageSource = weakImageSource.get();
winrt::HttpResponseMessage response = operation.GetResults();

if (strongThis && strongImageSource)
if (response.IsSuccessStatusCode())
{
if (status == winrt::AsyncStatus::Completed)
{
auto success = strongThis->ParseXmlForHeightAndWidth(operation.GetResults(), strongImageSource);
auto readOperation = response.Content().ReadAsStringAsync();

if (success)
readOperation.Completed([weakThis, weakImageSource, imageUrl](auto const& operation, auto status)
beervoley marked this conversation as resolved.
Show resolved Hide resolved
{
// Now that we've parsed the height and width successfully, we can set the image source
strongThis->SetSvgUriSource(strongImageSource, imageUrl);
auto strongThis = weakThis.get();
auto strongImageSource = weakImageSource.get();

if (strongThis && strongImageSource)
{
if (status == winrt::AsyncStatus::Completed)
{
// Read SVG xml
winrt::XmlDocument xmlDoc;
xmlDoc.LoadXml(operation.GetResults());
auto success = strongThis->ParseXmlForHeightAndWidth(xmlDoc, strongImageSource);
if (success)
{
// Now that we've parsed the height and width successfully, we can set the image source
strongThis->SetSvgUriSource(strongImageSource, imageUrl);
}
}
}
}
else if (status == winrt::AsyncStatus::Error)
anna-dingler marked this conversation as resolved.
Show resolved Hide resolved
{
// Handle error
winrt::hresult error = operation.ErrorCode();
}
});
}
});
}
});
}
else
{
Expand Down
Loading