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

feat: Font manifest #17118

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"fonts": [
{
"font_style": "italic",
"font_weight": 400,
"font_stretch": "Condensed",
"family_name": "ms-appx:///Assets/Fonts/OpenSans/OpenSans_Condensed-MediumItalic.ttf"
},
{
"font_style": "normal",
"font_weight": 400,
"font_stretch": "SemiCondensed",
"family_name": "ms-appx:///Assets/Fonts/OpenSans/OpenSans_SemiCondensed-Regular.ttf"
},
{
"font_style": "normal",
"font_weight": 600,
"font_stretch": "SemiCondensed",
"family_name": "ms-appx:///Assets/Fonts/OpenSans/OpenSans_SemiCondensed-SemiBold.ttf"
},
{
"font_style": "normal",
"font_weight": 700,
"font_stretch": "Normal",
"family_name": "ms-appx:///Assets/Fonts/OpenSans/OpenSans-Bold.ttf"
},
{
"font_style": "normal",
"font_weight": 400,
"font_stretch": "Normal",
"family_name": "ms-appx:///Assets/Fonts/OpenSans/OpenSans-Regular.ttf"
},
]
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -9574,6 +9574,8 @@
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\Even Badder Mofo.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\FamilyGuy-4grW.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\Nillambari-K7y1W.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\OpenSans\*.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\OpenSans\OpenSans.ttf.manifest" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\Renaiss-Italic.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\RoteFlora.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Formats\animated.gif" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,70 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[RunsOnUIThread]
public class Given_TextBlock
{
[TestMethod]
[DataRow((ushort)400, FontStyle.Italic, FontStretch.Condensed, "ms-appx:///Assets/Fonts/OpenSans/OpenSans_Condensed-MediumItalic.ttf")]
[DataRow((ushort)400, FontStyle.Normal, FontStretch.SemiCondensed, "ms-appx:///Assets/Fonts/OpenSans/OpenSans_SemiCondensed-Regular.ttf")]
[DataRow((ushort)600, FontStyle.Normal, FontStretch.SemiCondensed, "ms-appx:///Assets/Fonts/OpenSans/OpenSans_SemiCondensed-SemiBold.ttf")]
[DataRow((ushort)700, FontStyle.Normal, FontStretch.Normal, "ms-appx:///Assets/Fonts/OpenSans/OpenSans-Bold.ttf")]
[DataRow((ushort)400, FontStyle.Normal, FontStretch.Normal, "ms-appx:///Assets/Fonts/OpenSans/OpenSans-Regular.ttf")]
public async Task When_Font_Has_Manifest(ushort weight, FontStyle style, FontStretch stretch, string ttfFile)
{
var SUT = new TextBlock
{
Text = "Hello World!",
FontSize = 18,
FontStyle = style,
FontStretch = stretch,
FontWeight = new FontWeight(weight),
FontFamily = new FontFamily("ms-appx:///Assets/Fonts/OpenSans/OpenSans.ttf"),
};

var expectedTB = new TextBlock
{
Text = "Hello World!",
FontSize = 18,
FontFamily = new FontFamily(ttfFile)
};

var differentTtf = "ms-appx:///Assets/Fonts/OpenSans/OpenSans-Bold.ttf";
if (ttfFile == differentTtf)
{
differentTtf = "ms-appx:///Assets/Fonts/OpenSans/OpenSans-Regular.ttf";
}

var differentTB = new TextBlock
{
Text = "Hello World!",
FontSize = 18,
FontFamily = new FontFamily(differentTtf),
};

var sp = new StackPanel()
{
Children =
{
SUT,
expectedTB,
differentTB,
},
};

await UITestHelper.Load(sp);
var actual = await UITestHelper.ScreenShot(SUT);
var expected = await UITestHelper.ScreenShot(expectedTB);
var different = await UITestHelper.ScreenShot(differentTB);
await ImageAssert.AreEqualAsync(actual, expected);
await ImageAssert.AreNotEqualAsync(actual, different);
}

#if __SKIA__
[TestMethod]
// It looks like CI might not have any installed fonts with Chinese characters which could cause the test to fail
[Ignore("Fails on CI")]
public async Task Check_FontFallback()
{
var SUT = new TextBlock { Text = "示例文本", FontSize = 24 };
var skFont = FontDetailsCache.GetFont(SUT.FontFamily?.Source, (float)SUT.FontSize, SUT.FontWeight, SUT.FontStyle).SKFont;
var skFont = FontDetailsCache.GetFont(SUT.FontFamily?.Source, (float)SUT.FontSize, SUT.FontWeight, SUT.FontStretch, SUT.FontStyle).SKFont;
Assert.IsFalse(skFont.ContainsGlyph(SUT.Text[0]));

var fallbackFont = SKFontManager.Default.MatchCharacter(SUT.Text[0]);
Expand Down
22 changes: 12 additions & 10 deletions src/Uno.UI.Toolkit/Storage/StorageFileHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#nullable enable
using System.Threading;
using System;
using System.Threading.Tasks;
using Uno;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Uno;

namespace Uno.UI.Toolkit;

Expand All @@ -16,14 +16,16 @@ public partial class StorageFileHelper
/// </summary>
/// <param name="fileName">relative file path</param>
/// <returns>A task that will complete with a result of true if file exists, otherwise with a result of false.</returns>
public static async Task<bool> ExistsInPackage(string fileName) => await FileExistsInPackage(fileName);

#if IS_UNIT_TESTS || __NETSTD_REFERENCE__
private static Task<bool> FileExistsInPackage(string fileName)
=> throw new NotImplementedException();
public static async Task<bool> ExistsInPackage(string fileName)
{
#if HAS_UNO
return await Windows.Storage.Helpers.StorageFileHelper.ExistsInPackage(fileName);
#else
return await FileExistsInPackage(fileName);
#endif
}

#if __SKIA__ || WINDOWS || WINAPPSDK || WINDOWS_UWP || WINUI
#if !HAS_UNO
private static Task<bool> FileExistsInPackage(string fileName)
{
var executingPath = Assembly.GetExecutingAssembly().Location;
Expand Down
25 changes: 0 additions & 25 deletions src/Uno.UI.Toolkit/Storage/StorageFileHelper.iOSmacOS.cs

This file was deleted.

17 changes: 9 additions & 8 deletions src/Uno.UI/Controls/PaintPool.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class TextPaintPool
private record Entry(
FontWeight FontWeight,
FontStyle FontStyle,
FontStretch FontStretch,
FontFamily FontFamily,
double FontSize,
double CharacterSpacing,
Expand All @@ -38,6 +39,7 @@ private class EntryComparer : IEqualityComparer<Entry>
public bool Equals(Entry x, Entry y) =>
x.FontWeight == y.FontWeight
&& x.FontStyle == y.FontStyle
&& x.FontStretch == y.FontStretch
&& x.FontFamily == y.FontFamily
&& x.Foreground == y.Foreground
&& x.FontSize == y.FontSize
Expand All @@ -48,6 +50,7 @@ private class EntryComparer : IEqualityComparer<Entry>
public int GetHashCode(Entry entry) =>
entry.FontWeight.GetHashCode()
^ entry.FontStyle.GetHashCode()
^ entry.FontStretch.GetHashCode()
^ entry.FontFamily?.GetHashCode() ?? 0
^ entry.Foreground.GetHashCode()
^ entry.FontSize.GetHashCode()
Expand All @@ -74,19 +77,19 @@ private class EntryComparer : IEqualityComparer<Entry>
/// can be tricky to place properly.
/// </remarks>
/// <returns>A <see cref="TextPaint"/> instance.</returns>
public static TextPaint GetPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
public static TextPaint GetPaint(FontWeight fontWeight, FontStyle fontStyle, FontStretch fontStretch, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
{
if (shader != null)
{
// The "Shader" native object can't be use as a cache key
return InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations);
return InnerBuildPaint(fontWeight, fontStyle, fontStretch, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations);
}

var key = new Entry(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, baselineAlignment, textDecorations);
var key = new Entry(fontWeight, fontStyle, fontStretch, fontFamily, fontSize, characterSpacing, foreground, baselineAlignment, textDecorations);

if (!_entries.TryGetValue(key, out var paint))
{
_entries.Add(key, paint = InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations));
_entries.Add(key, paint = InnerBuildPaint(fontWeight, fontStyle, fontStretch, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations));
_entriesList.Add(key);

TryScavenge();
Expand Down Expand Up @@ -123,17 +126,15 @@ private static void TryScavenge()
}
}

private static TextPaint InnerBuildPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
private static TextPaint InnerBuildPaint(FontWeight fontWeight, FontStyle fontStyle, FontStretch fontStretch, FontFamily fontFamily, double fontSize, double characterSpacing, Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
{
var paintSpecs = BuildPaintValueSpecs(fontSize, characterSpacing);

var typefaceStyle = TypefaceStyleHelper.GetTypefaceStyle(fontStyle, fontWeight);

return TextPaintPoolNative.BuildPaint(
paintSpecs.density,
paintSpecs.textSize,
paintSpecs.letterSpacing,
FontHelper.FontFamilyToTypeFace(fontFamily, fontWeight, typefaceStyle),
FontHelper.FontFamilyToTypeFace(fontFamily, fontWeight, fontStyle, fontStretch),
(int)((Android.Graphics.Color)foreground),
(textDecorations & TextDecorations.Underline) == TextDecorations.Underline,
(textDecorations & TextDecorations.Strikethrough) == TextDecorations.Strikethrough,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,7 @@ public bool IsTextScaleFactorEnabled
// Skipping already declared property Foreground
// Skipping already declared property FontWeight
// Skipping already declared property FontStyle
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Text.FontStretch FontStretch
{
get
{
return (global::Windows.UI.Text.FontStretch)this.GetValue(FontStretchProperty);
}
set
{
this.SetValue(FontStretchProperty, value);
}
}
#endif
// Skipping already declared property FontStretch
// Skipping already declared property FontSize
// Skipping already declared property FontFamily
// Skipping already declared property CornerRadius
Expand Down Expand Up @@ -158,14 +145,7 @@ public int CharacterSpacing
// Skipping already declared property CornerRadiusProperty
// Skipping already declared property FontFamilyProperty
// Skipping already declared property FontSizeProperty
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Microsoft.UI.Xaml.DependencyProperty FontStretchProperty { get; } =
Microsoft.UI.Xaml.DependencyProperty.Register(
nameof(FontStretch), typeof(global::Windows.UI.Text.FontStretch),
typeof(global::Microsoft.UI.Xaml.Controls.ContentPresenter),
new Microsoft.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Text.FontStretch)));
#endif
// Skipping already declared property FontStretchProperty
// Skipping already declared property FontStyleProperty
// Skipping already declared property FontWeightProperty
// Skipping already declared property ForegroundProperty
Expand Down
24 changes: 2 additions & 22 deletions src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,7 @@ public bool IsTextScaleFactorEnabled
// Skipping already declared property Foreground
// Skipping already declared property FontWeight
// Skipping already declared property FontStyle
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Text.FontStretch FontStretch
{
get
{
return (global::Windows.UI.Text.FontStretch)this.GetValue(FontStretchProperty);
}
set
{
this.SetValue(FontStretchProperty, value);
}
}
#endif
// Skipping already declared property FontStretch
// Skipping already declared property FontSize
// Skipping already declared property FontFamily
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
Expand Down Expand Up @@ -150,14 +137,7 @@ public int CharacterSpacing
#endif
// Skipping already declared property FontFamilyProperty
// Skipping already declared property FontSizeProperty
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Microsoft.UI.Xaml.DependencyProperty FontStretchProperty { get; } =
Microsoft.UI.Xaml.DependencyProperty.Register(
nameof(FontStretch), typeof(global::Windows.UI.Text.FontStretch),
typeof(global::Microsoft.UI.Xaml.Controls.Control),
new Microsoft.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Text.FontStretch)));
#endif
// Skipping already declared property FontStretchProperty
// Skipping already declared property FontStyleProperty
// Skipping already declared property FontWeightProperty
// Skipping already declared property ForegroundProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,7 @@ public bool IsColorFontEnabled
// Skipping already declared property Foreground
// Skipping already declared property FontWeight
// Skipping already declared property FontStyle
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Text.FontStretch FontStretch
{
get
{
return (global::Windows.UI.Text.FontStretch)this.GetValue(FontStretchProperty);
}
set
{
this.SetValue(FontStretchProperty, value);
}
}
#endif
// Skipping already declared property FontStretch
// Skipping already declared property FontSize
// Skipping already declared property FontFamily
// Skipping already declared property IsTextSelectionEnabled
Expand Down Expand Up @@ -212,14 +199,7 @@ public double BaselineOffset
// Skipping already declared property CharacterSpacingProperty
// Skipping already declared property FontFamilyProperty
// Skipping already declared property FontSizeProperty
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Microsoft.UI.Xaml.DependencyProperty FontStretchProperty { get; } =
Microsoft.UI.Xaml.DependencyProperty.Register(
nameof(FontStretch), typeof(global::Windows.UI.Text.FontStretch),
typeof(global::Microsoft.UI.Xaml.Controls.TextBlock),
new Microsoft.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Text.FontStretch)));
#endif
// Skipping already declared property FontStretchProperty
// Skipping already declared property FontStyleProperty
// Skipping already declared property FontWeightProperty
// Skipping already declared property ForegroundProperty
Expand Down
Loading
Loading