Nathaniel Chen
Nathaniel Chen

Reputation: 82

Some font type can't apply in UWP

I found some font type not able to using in UWP.

For example: Noto Sans CJK TC, or Noto Sans(both are Google opensource font)

Even this font already installed in system, or put into app project and using "ms-appx:" or relative path to setting this font.

(Like this question's answer:UWP - Font only applied in Designer, which provide a example, able to using custom font)

When I applied some font, only seen effect in designer but not in run-time.

And there have guideline but which didn't tell how to know which font type isn't able to using in UWP. https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/fonts?f=255&MSPPError=-2147217396

Is there have any font type limit in UWP?

Thanks!

Upvotes: 3

Views: 1810

Answers (1)

Jay Zuo
Jay Zuo

Reputation: 15758

I found the problem cause I put page inside folder, but why?

In you code, you are using following code to set FontFamily:

FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC"

The URI you've used is a relative URI, It will access files relative to the current XAML page. In your case, while using this in BlankPage1, it will try to access Assets/fonts/NotoSansCJKtc-Thin.otf file in current folder which is the "UI" folder. As there is no such file in "UI" folder, the FontFamily property will use its default value.

To access files relative to the root of the package, from a XAML page, you can use an absolute path URIs (those that begin with a "/") like following:

<TextBlock Margin="0,80,0,0"
               HorizontalAlignment="Center"
               FontFamily="/Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC"
               FontSize="80"
               Foreground="#878787">
    微abc012
</TextBlock>

Or using ms-appx: scheme like following:

<TextBlock Margin="0,80,0,0"
           HorizontalAlignment="Center"
           FontFamily="ms-appx:///Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC"
           FontSize="80"
           Foreground="#878787">
    微abc012
</TextBlock>

And FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC" can work, but FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC Thin" won't.

I have the same issue in my side. Form the otf file, its font name should be "Noto Sans CJK TC Thin".
enter image description here However using this font name won't work both in XAML Designer and run-time. I think this issue may related to the otf file as I tested with some other fonts, they all worked as expected.

I also try to reference other project font resource in same solution.

To reference other project font resource in same solution, you can refer to my previous answer in UWP - Font only applied in Designer.

Upvotes: 6

Related Questions