Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Handle default size better.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Brown committed Mar 13, 2020
1 parent e106e68 commit 8d674bb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
54 changes: 54 additions & 0 deletions Xamarin.Forms.Controls/GalleryPages/FontImageSourceGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,60 @@ public FontImageSourceGallery()
}, i % 10, i / 10);
i++;

grid.Children.Add(new Image
{
Source = new LayeredFontImageSource
{
Size = 30,
Layers = new List<FontImageSource> {
new FontImageSource
{
Glyph = '\uf2d1'.ToString(),
FontFamily = fontFamily,
Size = 20
},
new FontImageSource
{
Glyph = '\uf100'.ToString(),
FontFamily = fontFamily,
Color = Color.Yellow,
Size = 20
},
},
},
BackgroundColor = Color.Black,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
}, i % 10, i / 10);
i++;

grid.Children.Add(new Image
{
Source = new LayeredFontImageSource
{
Size = 20,
Layers = new List<FontImageSource> {
new FontImageSource
{
Glyph = '\uf2d1'.ToString(),
FontFamily = fontFamily,
Size = 30
},
new FontImageSource
{
Glyph = '\uf100'.ToString(),
FontFamily = fontFamily,
Color = Color.Yellow,
Size = 30
},
},
},
BackgroundColor = Color.Black,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
}, i % 10, i / 10);
i++;

grid.Children.Add(new Image
{
Source = new LayeredFontImageSource
Expand Down
7 changes: 2 additions & 5 deletions Xamarin.Forms.Platform.iOS/Renderers/ImageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ public sealed class FontImageSourceHandler : IImageSourceHandler
//should this be the default color on the BP for iOS?
readonly Color _defaultColor = Color.White;

static readonly double _defaultFontSize = 30;

[Preserve(Conditional = true)]
public FontImageSourceHandler()
{
Expand All @@ -271,22 +269,21 @@ private class LayerProperties
float scale = 1f)
{
UIImage image;
float baseSize = 0;
var layerPropertiesList = new List<LayerProperties>();
var maxImageSize = CGSize.Empty;
var renderingModeAlwaysOriginal = false;

if (imageSource is LayeredFontImageSource layeredFontImageSource)
{
baseSize = (float)layeredFontImageSource.Size;
var baseSize = (float)layeredFontImageSource.Size;
var baseFont = UIFont.FromName(layeredFontImageSource.FontFamily ?? string.Empty, baseSize) ?? UIFont.SystemFontOfSize(baseSize);
var baseIconColor = layeredFontImageSource.Color.IsDefault ? _defaultColor : layeredFontImageSource.Color;
var baseAttString = layeredFontImageSource.Glyph == null ? null : new NSAttributedString(layeredFontImageSource.Glyph, font: baseFont, foregroundColor: baseIconColor.ToUIColor());
maxImageSize = layeredFontImageSource.Glyph == null ? CGSize.Empty : ((NSString)layeredFontImageSource.Glyph).GetSizeUsingAttributes(baseAttString.GetUIKitAttributes(0, out _));

foreach (var layer in layeredFontImageSource.Layers)
{
var size = layer.Size == _defaultFontSize ? baseSize : (float)layer.Size;
var size = layer.IsSet(LayeredFontImageSource.SizeProperty) ? (float)layer.Size : baseSize;
var font = layer.FontFamily == null ? baseFont : UIFont.FromName(layer.FontFamily ?? string.Empty, size) ??
UIFont.SystemFontOfSize(size);
var iconcolor = layer.Color.IsDefault ? baseIconColor : layer.Color;
Expand Down

0 comments on commit 8d674bb

Please sign in to comment.