0
votes

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.

2

2 Answers

0
votes

Try this code:

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

Just like this and it works perfectly.

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.