Android Question LoadHTML with Custom Font

bocker77

Active Member
Licensed User
Longtime User
I tested a free font with Chrome and it works but cannot get it to work in a WebView view. I converted it to a woff file and still am having the problem. The string that holds the HTML was checked to make sure that the code in both matched with the exception of how the custom font was brought in. The background file loaded just fine.

HTML:
<html>
<head>
<style type='text/css'>
@font-face {
font-family: MyFont;
src: url('OldNewspaperTypes.ttf')
}
body {
font-family: MyFont;
}
</style>
</head>
<body background='ViewArmy.png'>
Hello all
</body>
</html>

My code
B4X:
sbHTML.Append("<html>").Append(CRLF)
sbHTML.Append("<head>").Append(CRLF)
sbHTML.Append("<style type='text/css'>").Append(CRLF)
sbHTML.Append("@font-face {").Append(CRLF)
sbHTML.Append("font-family: MyFont;").append(CRLF)
sbHTML.Append("src: url('" & WebViewAssetFile("OldNewspaperTypes.ttf") & "'").Append(CRLF)
sbHTML.Append("}").Append(CRLF)
sbHTML.Append("body {").Append(CRLF)
sbHTML.Append("font-family: MyFont;").Append(CRLF)
sbHTML.Append("}").Append(CRLF)
sbHTML.Append("</style>").Append(CRLF)
sbHTML.Append("</head>").Append(CRLF)
sbHTML.Append("<body background='" & WebViewAssetFile("ViewArmy.png") & "'>").Append(CRLF)
...
sbHTMLUnion.Append("Hello all").Append(CRLF)
sbHTMLUnion.Insert(0, sbHTML)
sbHTMLUnion.Append("</body>").Append(CRLF)
sbHTMLUnion.Append("</html>")
strHTMLUnion = sbHTMLUnion.ToString
wbvViewArmy.LoadHtml(strHTMLUnion)

Can anyone see what I am doing wrong or is it that that font just won't work with b4a Webview?
 

bocker77

Active Member
Licensed User
Longtime User
So you feel the issue is how the font file is getting loaded. I am not sure about the smart string literal but I can definitely do your other suggestion. Also then I presume no need for the WebViewAssetFile and use the syntax from the HTML example.

Thanks Erel
 
Upvote 0
Top