Windows 8 如何将字体嵌入Windows应用商店应用程序并从WebView NavigateToString方法使用它?

Windows 8 如何将字体嵌入Windows应用商店应用程序并从WebView NavigateToString方法使用它?,windows-8,fonts,windows-runtime,windows-store-apps,Windows 8,Fonts,Windows Runtime,Windows Store Apps,我想在Windows应用商店应用的WebView中使用字体 我指的是这一页。 此页面使用WebView的导航方法。 但我想使用NavigateToString方法。 传递使用font to NavigateToString方法的HTML字符串,并希望显示该HTML。 下面的示例1失败 例1: private async void Button_Click_1(object sender, RoutedEventArgs e) { MyWebView.Naviga

我想在Windows应用商店应用的WebView中使用字体

我指的是这一页。

此页面使用WebView的导航方法。 但我想使用NavigateToString方法。 传递使用font to NavigateToString方法的HTML字符串,并希望显示该HTML。 下面的示例1失败

例1:

    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        MyWebView.NavigateToString("<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta charset=\"utf-8\" /><style type=\"text/css\">  @font-face { font-family: \"ipafont\"; font-style: normal; font-weight: 400; src: url(ipaexm.woff);} .ipa { font-family: \"ipafont\"; font-size: xx-large; }</style></head><body><div class=\"ipa\">Hello, Good morning.</div></body></html>");
    }
private async void按钮\u单击\u 1(对象发送方,RoutedEventArgs e)
{
MyWebView.NavigateToString(@font-face{font-family:\'ipafont\“字体样式:正常;字体重量:400;src:url(ipaexm.woff);}.ipa{font-family:\'ipafont\“字体大小:xx大号;}你好,早上好。”);
}
我试着改变

src:url(ipaexm.woff)

src:url(“ms-appx-web:///ipaexm.woff");

但我失败了。 当然,我在Windows应用商店应用程序的根文件夹中包含了“ipaexm.woff”字体

下面的例子2成功了

例2:

    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
       string style = "@font-face { font-family: 'ipa';  src: url(data:application/x-font-woff;charset=utf-8;base64," + <BASE 64 ENCODED TEXT OF FONT GOES HERE)> + ") format('woff'), url('ipa__-webfont.ttf') format('truetype'); font-style: normal; font-weight: 400; }";

        MyWebView.NavigateToString("<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta charset=\"utf-8\" /><style type=\"text/css\">  @font-face { font-family: 'ipafont'; src: url('ipa__-webfont.eot'); } " +  style + " .ipa { font-family: \"ipafont\"; font-size: xx-large; }</style></head><body><div class=\"ipa\">Hello, Good morning.</div></body></html>");

    }
private async void按钮\u单击\u 1(对象发送方,RoutedEventArgs e)
{
string style=“@font-face{font-family:'ipa';src:url(数据:application/x-font-woff;charset=utf-8;base64,“+”))格式('woff'),url('ipa_u-webfont.ttf')格式('truetype');字体样式:正常;字体重量:400;}”;
MyWebView.NavigateToString(@font-face{font-family:'ipafont';src:url('ipa_uu-webfont.eot');}“+style+”。ipa{font-family:\'ipafont\”;字体大小:xx大号;}你好,早上好。”);
}
我想用一种方式来举例。 我使用的字体大约为5MB,因此字体的Base64编码文本太长。
通过NavigateToString方法使用字体有什么好方法吗?

我自己也问了同样的问题,最后找到了答案

如果您使用
Source
属性将HTML放入WebView中,有几种解决方案是可行的,但是如果您使用
NavigateToString

除了这个

将此代码放入HTML文件的头部。如果在css文件中,这将不起作用

@font-face {
    font-family: 'FontAwesome';
    src: url(data:application/x-font-woff;charset=utf-8;base64,<BASE64 STRING OF fontawesome-webfont.woff>) format('woff'), 
        url('ms-appx-web:///fontawesome-webfont.ttf?v=4.2.0') format('truetype');
    font-weight: normal;
    font-style: normal;
}
@font-face{
字体系列:“FontAwesome”;
src:url(数据:application/x-font-woff;charset=utf-8;base64,)格式('woff'),
url('ms-appx-web:///fontawesome-webfont.ttf?v=4.2.0格式('truetype');
字体大小:正常;
字体风格:普通;
}

您可以使用转换woff文件。如果这个链接不起作用,那么还有很多其他页面也会这样做

关于WebView和嵌入式字体可能会提供一些帮助谢谢你的评论。我指的是上面问题中的页面。哦。。很抱歉,我没有注意到这一点以及NavigateToString的细微差别,从您的帖子中可以看出,ms appx web:///选项似乎适用于CSS,但不适用于woff。。。我会看看能不能找到更多。