1

我正在开发用于在 Windows 手机中学习webBrowser概念的简单应用程序。我的目标是在我的 WP7 中显示泰卢固语(印度语)的内容。该 Web 应用程序仅显示泰卢固语内容

我的 MainPage.xaml.cs 代码是:

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        webBrowser1.Navigate(new Uri("http://www.eenadu.net", UriKind.Absolute));
    }

在 MainPage.xaml 文件中

<phone:WebBrowser HorizontalAlignment="Left" Margin="0,92,0,0" Name="webBrowser1"
 VerticalAlignment="Top" Height="575" Width="468" FontFamily="Fonts/eenadu.ttf#Eenadu"  />

我已将该 .ttf 文件包含在我的项目中 Fonts 文件夹下,并分配了 Build Action = 'Content'

我能够调用 URL,但它显示不可读的字符。

有没有其他方法可以将自定义字体应用于 Web 浏览器控件?

提前致谢

4

2 回答 2

2

Windows 手机支持网络字体。但是,它们不能嵌入到 XAP 中。建议的解决方法是将字体托管在远程服务器上,并可能使用 AppCache 将字体文件保存在设备本地。

于 2013-01-23T21:52:10.643 回答
0

无需从远程服务器托管,您可以使用本地字体嵌入 CSS 并注入到浏览器控制。

(1.) 创建嵌入字体的 CSS

body, a, p, span, div, textarea {
        font-family: MyCustomFont;
}

@font-face {
    font-family: MyCustomFont;
    src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAXXXXXXXXXXX......) format('woff');
    font-weight: normal;
    font-style: normal;
} 

(2.) 在 WebView_NavigationCompleted 方法中注入 jQuery 和 CSS

 private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
 {
    // Inject jQuery file which located at local
    StorageFile jquery = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///JavaScripts\\jquery-1.10.2.min.js"));
        string jquery_string = await FileIO.ReadTextAsync(jquery);
        await MyWebView.InvokeScriptAsync("eval", new string[] { jquery_string });


    // Inject custom font embedded CSS 
    StorageFile myfontcss = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///CSS\\mycustomfont.css"));
            string myfontcss_string = await FileIO.ReadTextAsync(myfontcss);

            myfontcss_string = myfontcss_string.Replace("\n", "").Replace("\t", ""); //.Replace("'", "&#39;").Replace("\"", "&#34;");
            string cssRef = "$(\"<style id='myfont' type='text/css'>" + myfontcss_string + "</style>\").appendTo('head');";

            await MyWebView.InvokeScriptAsync("eval", new string[] { cssRef });

 }
于 2016-10-21T13:42:04.490 回答