How can we force Webview to use TrueType (ttf) font only instead of SVG

We are using Custom Arabic font in our Android App. We have used @font-face to specify the font using SVG and TrueType font files. By default the WebView loads the SVG font and we have noticed that the SVG version of the font is missing some characters. Is there any way that we can force Webview to use TrueType (ttf) font only instead of SVG.


试试这个代码:

webSettings.setFixedFontFamily("file:///android_asset/myfont.ttf");

就像这样,它完美的作品。

1 //load the fontType
private String getHtmlData(String bodyHTML) {
     String head = "<head>" +
                "<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> " +
                "<style type="text/css">@font-face {font-family: MyFont;src: url("file:///android_asset/fonts/myfont.TTF")}body {font-family: MyFont;font-size: medium;text-align: justify;}</style>"+
        "</head>";
     return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
}

2 // load the webview content
webView.loadDataWithBaseURL(null, getHtmlData(content), "text/html", "utf-8", null);

3 // end.
链接地址: http://www.djcxy.com/p/34822.html

上一篇: Android上自定义字体的自定义样式

下一篇: 我们如何强制Webview仅使用TrueType(ttf)字体而不是SVG