简体   繁体   English

自定义字体在 Uno.WASM 中有效,但在 Uno.UWP 中无效

[英]Custom Font working in Uno.WASM, but not working in Uno.UWP

Since i have not seen something helpful after searching for a while, i decided to ask here:由于搜索了一段时间后我没有看到有用的东西,所以我决定在这里问:

I have a small testing Project, just to import a custom Icon Font from the interwebs.我有一个小型测试项目,只是为了从互联网导入自定义图标字体。 Current Proedure is the following: my MainApp.xaml consists of a single Textblock, which is referencing a Style-element in Styles.xaml, which in turn references a FontFamily where i load the ttf file per platform.当前程序如下:我的 MainApp.xaml 由一个文本块组成,它引用 Styles.xaml 中的样式元素,而后者又引用了每个平台的加载文件。

In WASM it works great (base64 URI), but in UWP i just cant get the font-icon to display at all.在 WASM 中效果很好(base64 URI),但在 UWP 中,我根本无法显示字体图标。 The Style.xaml gets imported perfectly by the App.xaml, the Size gets applied, but it seems there is something wrong with the FontFamily-Tags. Style.xaml 由 App.xaml 完美导入,尺寸被应用,但字体家族标签似乎有问题。

I tried:我试过了:

  1. Installing my font by hand => Worked like a charm.手动安装我的字体 => 工作就像一个魅力。 So its probably not the font file?所以它可能不是字体文件?
  2. https://platform.uno/docs/articles/features/custom-fonts.html , but it didn't help. https://platform.uno/docs/articles/features/custom-fonts.html ,但它没有帮助。
  3. https://blog.mzikmund.com/2020/01/custom-fonts-in-uno-platform/ which in turn, didn't change much. https://blog.mzikmund.com/2020/01/custom-fonts-in-uno-platform/又没有太大变化。
  4. https://github.com/MartinZikmund/blog-2020/tree/master/Uno.CustomFonts even after cross-referencing here, i couldn't get it to work. https://github.com/MartinZikmund/blog-2020/tree/master/Uno.CustomFonts即使在这里交叉引用之后,我也无法让它工作。
  5. https://github.com/unoplatform/calculator/blob/uno/src/Calculator.Shared/Styles.xaml i also cross-checked with the official calculator-port, but even after setting things up like they did, nothing changed. https://github.com/unoplatform/calculator/blob/uno/src/Calculator.Shared/Styles.xaml我也与官方的计算器端口进行了交叉检查,但即使像他们一样设置好,也没有任何改变。
  6. Reinstall VS (i use the Community Version).重新安装 VS(我使用社区版)。 Here's my Code:这是我的代码:

MainApp.xaml: MainApp.xaml:

<Page
    x:Class="Testing.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Testing"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock Text="L"  Style="{ThemeResource IconTextStyle}" />
    </Grid>
</Page>

Styles.xaml: Styles.xaml:

<ResourceDictionary
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:xamarin="http://uno.ui/xamarin"
            xmlns:macos="http://uno.ui/macos"
            xmlns:wasm="http://uno.ui/wasm"
            xmlns:skia="http://uno.ui/skia"
            xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            mc:Ignorable="xamarin wasm macos skia"
    >


    <win:FontFamily x:Key="IconScratchedFontFamily">ms-appx:///Assets/PWSmallIcons.ttf#Small-Icons-Scratched</win:FontFamily>
    <macos:FontFamily x:Key="IconScratchedFontFamily">ms-appx:///Assets/PWSmallIcons.ttf#Small-Icons-Scratched</macos:FontFamily>
    <wasm:FontFamily x:Key="IconScratchedFontFamily">Small-Icons-Scratched</wasm:FontFamily>
    <skia:FontFamily x:Key="IconScratchedFontFamily">ms-appx:///Assets/PWSmallIcons.ttf#Small-Icons-Scratched</skia:FontFamily>

    <win:FontFamily x:Key="IconClearFontFamily">ms-appx:///Assets/PWSmallIconsFree.ttf#Small-Icons-Free</win:FontFamily>
    <macos:FontFamily x:Key="IconClearFontFamily">ms-appx:///Assets/PWSmallIconsFree.ttf#Small-Icons-Free</macos:FontFamily>
    <wasm:FontFamily x:Key="IconClearFontFamily">Small-Icons-Free</wasm:FontFamily>
    <skia:FontFamily x:Key="IconClearFontFamily">ms-appx:///Assets/PWSmallIconsFree.ttf#Small-Icons-Free</skia:FontFamily>

    <Style TargetType="TextBlock" x:Key="IconTextStyle">
        <Setter Property="FontFamily"
            Value="{StaticResource IconScratchedFontFamily}" />
        <Setter Property="FontWeight"
            Value="Normal" />
        <Setter Property="FontSize"
            Value="116" />
    </Style>
</ResourceDictionary>

App.xaml: App.xaml:

<Application
    x:Class="Testing.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Testing">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ms-appx:///Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

</Application>

Found the solution:找到了解决方案:

    <win:FontFamily x:Key="IconScratchedFontFamily">ms-appx:///Assets/PWSmallIcons.ttf#PWSmallIcons</win:FontFamily>
    <macos:FontFamily x:Key="IconScratchedFontFamily">ms-appx:///Assets/PWSmallIcons.ttf#PWSmallIcons</macos:FontFamily>

Background: The part after the # indicates the name of the font, as it is written in the.ttf File , not name of the Font as I want to reference it , which is pretty obvious if you think about it.背景:#后面的部分表示字体的名称,因为它写在.ttf文件中,而不是我要引用的字体名称,如果您考虑一下,这很明显。

It was nearly impossible to figure out with my provided code, so I decided to update my question for anyone else running into this problem.用我提供的代码几乎不可能弄清楚,所以我决定为遇到这个问题的其他人更新我的问题。

For Win and macOS the way to define the FontFamily in the Resources is by using just the FontName that in your case it would be something like:对于WinmacOS ,在Resources中定义FontFamily的方法是仅使用FontName ,在您的情况下,它类似于:

<win:FontFamily x:Key="IconScratchedFontFamily">Small-Icons-Scratched</win:FontFamily>
<macos:FontFamily x:Key="IconScratchedFontFamily">Small-Icons-Scratched</macos:FontFamily>

and

<win:FontFamily x:Key="IconClearFontFamily">Small-Icons-Free</win:FontFamily>
<macos:FontFamily x:Key="IconClearFontFamily">Small-Icons-Free</macos:FontFamily>

With this, you should be able to use your FontFamily definitions in any of your Styles.有了这个,您应该能够在您的任何 Styles 中使用您的FontFamily定义。

Hope this helps.-希望这可以帮助。-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM