-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Conversation
Why the intermediate png? |
{ | ||
public partial class FontImageSource : ImageSource | ||
{ | ||
private static BindableProperty CreateBindableProperty<T>( |
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.
I'd avoid trying to be smart here. it makes the code harder to understand in the big picture. this code is basically boilerplate. And I agree we could make this boilerplate thinner, but not here, ideally...
|
||
namespace Xamarin.Forms | ||
{ | ||
public partial class FontImageSource : ImageSource |
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.
ImageSourceConverter needs to be extended with a new format to create a FontImageSource easily from XAML. please propose something
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.
weren't we discussing an UWP approach too ?
* [UWP] font image source * address comment * [UWP] performance optimization of the rendering of icons font - the minimum Dpi of the icon is 300
To allow emoji to be used everywhere an |
If we cache the image somehow, then this really is an optimization - in a sense - because we don't have to redraw the emoji each time. |
return null; | ||
|
||
var device = CanvasDevice.GetSharedDevice(); | ||
var dpi = Math.Max(_minimumDpi, Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi); |
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.
Just a note about DPI on UWP: it can change during the lifetime of an app and even the control. The density can be changed via settings, but also by just dragging the app to a new monitor. I have a 200% surface and a 150% externbal display.
This might also change if accessibility is used - possibly on iOS and Android as well.
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.
Truth! But should fixing that use case block the PR? Kinda sounds like a corner case on a corner platform, no? Otherwise, we'll have to detect that the DPI changed and then run around and update glyphs? Sounds icky (or is it simple)? Do we think this is the only place we have that issue? Which is to say, if there are other places we cache DPI specific resources then how about we open an enhancement, subject it to prioritization, and fix 'em all at once.
I'm outta chaff.
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.
we'll have to detect that the DPI changed and then run around and update glyphs?
it simple.
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.
I agree this is not a blocking issue at this time, but just wanted to make sure we all knew about this possibility. And, as you mention, we possibly have the same issue in other areas - maybe we need another issue...
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.
Nice. So we'll open a separate "Fix multimon DPI change on UAP" and fixing FontImageSource
can be task one?
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.
Yeah. We probably can actually make this a public concept - the app may want to adjust to things like this. I was doing this for macOS for Xamarin.Essentials - a way to track when the resolution/scale changes. If the OS does not support it, then the event just never fires.
macOS
NSNotificationCenter.DefaultCenter.AddObserver(NSApplication.DidChangeScreenParametersNotification, OnDidChangeScreenParameters);
UWP:
var di = DisplayInformation.GetForCurrentView();
di.DpiChanged += OnDisplayInformationChanged;
else | ||
{ | ||
throw new InvalidCastException($"\"{Control.Source.GetType().FullName}\" is not supported."); | ||
} |
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.
I would move this into an extension method because it probably needs to be used on other image-bearing controls - such as image buttons or page icons.
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.
More Truth! But if we're gonna go on a de-duplication jihad, how about we start with BP definition boilerplate (see above...).
Caching the images would be a win, but how about we wait for a customer to complain first. Not trying to be facetious, but caches also have their problems... They take up memory, they need to be flushed, they need to be invalidated (if we ever do the DPI stuff). If anything, I'd expose the png so the user can cache and own the policy. Or do we already have an image cache? |
Failing tests are unrelated to this PR |
* min viable fontImageSource * [UWP] Min viable FontImageSource (#4817) * [UWP] font image source * address comment * [UWP] performance optimization of the rendering of icons font - the minimum Dpi of the icon is 300 * char -> string; CR feedback
* min viable fontImageSource * [UWP] Min viable FontImageSource (xamarin#4817) * [UWP] font image source * address comment * [UWP] performance optimization of the rendering of icons font - the minimum Dpi of the icon is 300 * char -> string; CR feedback
Nice feature but I think it will be better if you have a helper class like that as no one will memorize all this Glyph https://github.com/neilkennedy/FontAwesome.Xamarin/blob/master/FontAwesome.Xamarin/FontAwesome.cs |
Is it really necessary to keep an array in memory, even if it's just 4 items, having to iterate over it using a loop with temporary variables? Also having |
Description of Change
FontImageSource
derives fromImageSource
and accepts a glyph (character) from a font plus a size and color which it'll use to create a.png
which can then be displayed as an image. Unfortunately, many places where you'd like to use this currently accept aFileImageSource
but that'll be a separate work item.Issues Resolved
API Changes
Added:
FontImageSource
see https://github.com/xamarin/Xamarin.Forms/compare/font-image-source?expand=1#diff-6e54598e403bbd75200d983f2182df8fR564
Before/After Screenshots
Testing Procedure
Run
Font ImageSource - Legacy