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 1 commit
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,7 @@ public bool IsAccessKeyScope
// 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 @@ -226,14 +213,7 @@ public string AccessKey
#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.Documents.TextElement),
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
28 changes: 28 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ public FontStyle FontStyle
);
#endregion

#region FontStretch

public FontStretch FontStretch
{
get => (FontStretch)this.GetValue(FontStretchProperty);
set => this.SetValue(FontStretchProperty, value);
}

public static DependencyProperty FontStretchProperty { get; } =
DependencyProperty.Register(
nameof(FontStretch),
typeof(FontStretch),
typeof(ContentPresenter),
new FrameworkPropertyMetadata(
FontStretch.Normal,
FrameworkPropertyMetadataOptions.Inherits,
(s, e) => ((ContentPresenter)s)?.OnFontStretchChanged((FontStretch)e.OldValue, (FontStretch)e.NewValue)
)
);
Comment on lines +332 to +348
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use generated properties

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeromelaban For readability or perf?

My concern with generated DPs is that they cache the value when it changes. So, it's faster, but increases the object size. So my personal view to it is "speed vs memory"

#endregion

#region TextWrapping Dependency Property

public TextWrapping TextWrapping
Expand Down Expand Up @@ -659,6 +680,13 @@ protected virtual void OnFontStyleChanged(FontStyle oldValue, FontStyle newValue

partial void OnFontStyleChangedPartial(FontStyle oldValue, FontStyle newValue);

private protected virtual void OnFontStretchChanged(FontStretch oldValue, FontStretch newValue)
{
OnFontStretchChangedPartial(oldValue, newValue);
}

partial void OnFontStretchChangedPartial(FontStretch oldValue, FontStretch newValue);

protected virtual void OnContentChanged(object oldValue, object newValue)
{
if (oldValue is View || newValue is View)
Expand Down
28 changes: 28 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,27 @@ public FontStyle FontStyle
);
#endregion

#region FontStretch

public FontStretch FontStretch
{
get => (FontStretch)this.GetValue(FontStretchProperty);
set => this.SetValue(FontStretchProperty, value);
}

public static DependencyProperty FontStretchProperty { get; } =
DependencyProperty.Register(
nameof(FontStretch),
typeof(FontStretch),
typeof(Control),
new FrameworkPropertyMetadata(
FontStretch.Normal,
FrameworkPropertyMetadataOptions.Inherits,
(s, e) => ((Control)s)?.OnFontStretchChanged((FontStretch)e.OldValue, (FontStretch)e.NewValue)
)
);
Comment on lines +719 to +729
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated properties

#endregion

#region Padding DependencyProperty

public Thickness Padding
Expand Down Expand Up @@ -967,6 +988,13 @@ protected virtual void OnFontStyleChanged(FontStyle oldValue, FontStyle newValue

partial void OnFontStyleChangedPartial(FontStyle oldValue, FontStyle newValue);

private protected virtual void OnFontStretchChanged(FontStretch oldValue, FontStretch newValue)
{
OnFontStretchChangedPartial(oldValue, newValue);
}

partial void OnFontStretchChangedPartial(FontStretch oldValue, FontStretch newValue);

protected virtual void OnPaddingChanged(Thickness oldValue, Thickness newValue)
{
OnPaddingChangedPartial(oldValue, newValue);
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private void InitializePartial()
// Invalidate _paint
partial void OnFontWeightChangedPartial() => _paint = null;
partial void OnFontStyleChangedPartial() => _paint = null;
// TODO: FontStretch?
partial void OnFontFamilyChangedPartial() => _paint = null;
partial void OnFontSizeChangedPartial() => _paint = null;
partial void OnCharacterSpacingChangedPartial() => _paint = null;
Expand Down
30 changes: 30 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ private void OnFontStyleChanged()

#endregion

#region FontStretch Dependency Property

public FontStretch FontStretch
{
get => (FontStretch)GetValue(FontStretchProperty);
set => SetValue(FontStretchProperty, value);
}

public static DependencyProperty FontStretchProperty { get; } =
DependencyProperty.Register(
nameof(FontStretch),
typeof(FontStretch),
typeof(TextBlock),
new FrameworkPropertyMetadata(
defaultValue: FontStretch.Normal,
options: FrameworkPropertyMetadataOptions.Inherits,
propertyChangedCallback: (s, e) => ((TextBlock)s).OnFontStretchChanged()
)
);
Comment on lines +196 to +206
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated properties


private void OnFontStretchChanged()
{
OnFontStretchChangedPartial();
InvalidateTextBlock();
}

partial void OnFontStretchChangedPartial();

#endregion

#region TextWrapping Dependency Property

public TextWrapping TextWrapping
Expand Down
Loading
Loading