-
Notifications
You must be signed in to change notification settings - Fork 542
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
[UWP Render] Add Static SVG Support to ImageRenderer #8107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code works: have you thought about having small classes for SVG and Bitmap image?
and each classes implementing SetImageOnUIElement() so that we don't have to pass in isImageSvg boolean? We are likely going to support more image types. Relying on parameters to branch out to different images types could become a burden on later development.
Within the SetImageOnUIElement methods, we have similar code segments for two different image types, if we organize them into classes, you may find additional opportunities to refactor codes.
@jwoo-msft I can look into doing this. I originally had two separate methods for Update: we synced offline, and I'll work on refactoring after this PR is completed |
Related Issue
Fixes #8124
Description
This PR adds SVG support to the UWP Image Renderer.
Note: Provided SVGs cannot have an explicit height or width set. This will interfere with the provided styles and sizing and can cause rendering issues.
Files Changes
AdaptiveImageRenderer.cpp
SetImageOnUIElement
to add additional logic for SVG handlingSetSourceAsync
handling becauseSvgImageSource
andBitmapImage
handle these responses differentlywinrt::ImageSource XamlBuilder::CreateImageSource(bool isImageSvg)
method returns the correct type of ImageSource for renderingboolean XamlBuilder::IsSvgImage(std::string url)
method determines if the url is an SVGImageLoadTracker.cpp
void TrackImage(winrt::ImageSource const& image)
method that calls the respective tracking method for each image typevoid TrackSvgImage(winrt::SvgImageSource const& svgImage)
for SVG handlingMarkFailedLoadBitmapImage
toMarkFailedLoadImage
and add logic for SVGsUnsubscribeFromEvents
method that handlesTrackedSvgImageDetails
TrackedImage_SvgImageLoaded(winrt::IInspectable const& sender, winrt::SvgImageSourceOpenedEventArgs const& eventArgs)
TrackedImage_SvgImageFailed(winrt::IInspectable const& sender, winrt::SvgImageSourceFailedEventArgs const& eventArgs)
ImageLoadTracker.h
TrackedSvgImageDetails : winrt::implements<TrackedSvgImageDetails, winrt::IInspectable>
to handle Svg loading eventsm_eventRevokers
->m_bitmapEventRevokers
std::unordered_map<winrt::IInspectable, winrt::com_ptr<TrackedSvgImageDetails>> m_svgEventRevokers;
to track SVGTrackedImage_ImageLoaded
->TrackedImage_BitmapImageLoaded
TrackedImage_ImageFailed
->TrackedImage_BitmapImageFailed
XamlBuilder.h
isImageSvg
parameter toSetImageOnUIElement
andPopulateImageFromUrlAsync
methodsboolean IsSvgImage(std::string url)
method.winrt::ImageSource CreateImageSource(bool isImageSvg)
methodXamlHelpers.cpp
SetAutoImageSize
methodImageSource
is Bitmap or SVG to get the height and width.XamlHelpers.h
SetAutoImageSize
method to takeImageSource
instead ofBitmapSource
Visualizer Changes
Sample Cards
How Verified
In Progress
Future Work
Microsoft Reviewers: Open in CodeFlow