B4J Question Problem with Arabic text appearing on WebView

AlfaizDev

Well-Known Member
Licensed User
Problem with Arabic text appearing on WebView
I use WebView
When using it on Android the font appears beautiful
But when applying the same code on b4j the font overlaps, especially the vowels
I also saved the page as an HTML file and it works fine I think. The problem is in WebView b4j.
b4a
1736750621180.png


b4j
1736750662409.png


B4X:
Dim Font_Naskh As String="naskh.ttf"
    Dim Text As String=$"<p class=MsoNormal dir=RTL style='margin-top:6.0pt;margin-right:14.2pt;
margin-bottom:3.0pt;margin-left:0cm;line-height:normal;
page-break-after:avoid'><a name="_Toc97034699"><span lang=AR-SA style='font-family:Font_Naskh'>
الْجُغْرَافِيَّا الطَّبِيعِيَّةِ وهِي الَّتِي تَهْتِمُ بِدِرَاسَةِ طَبِيعَةِ الْأَرَضِ مِن حَيْث الْبِنْيَةِ الْجِيُولُوجِيَّةِ وَالظَّوَاهِرِ الْجَوِّيَّةِ وَالنَّبَاتِ وَالْحَيَوَانِ الطَّبِيعِيِّ أَو
    ومِنهَا أَيْضا الْجُغْرَافِيَا الْفَلَكِيَّةِ وَتَهْتِمُ بِدِرَاسَةِ شَكْلِ الْأرْضِ وَحَجْمِهَا وَحَرَكَتِهَا وَكُرَوِيَّتِهَا وَعَلَاَّقَاتِهَا بِالْكَوَاكِبِ الْأُخْرَى
</span ></a></p>
<p class=MsoNormal dir=RTL><span dir=LTR>&nbsp;</span ></p>
</div>
    
    "$
    Dim myHtmlString,code As String
    
    code  = $"
    <html dir='rtl'>
    <head>
    <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/>
    <style Type='text/css'>
    @font-face {font-family: Font_Naskh;src: url('${ xui.FileUri(File.DirAssets,Font_Naskh) }');}


     body  {
    font-family: 'Font_Naskh',  sans-serif;
    font-size: ${16}pt;
    text-align: justify;
    }
    </style>
    </head>
    <body>  "$

    ''Log(B4XPages.MainPage.TypF_WebView1)

    myHtmlString = code &Text &  "</body></html>"

Log(myHtmlString)
'    myInterface.addJavascriptInterface(WebView1, "B4A")
    WebView1.LoadHtml(myHtmlString)
 

AlfaizDev

Well-Known Member
Licensed User
Try to use a different font. Anyway, this is not something that is controlled by B4J.

You can also try BBCodeView for rich text. It does support Arabic, though you might encounter some edge cases.
I need to use this font only. Any other recommendations about that? Also, because my text is html, I need to use webview.
When I run it on the browser it works fine
See example
 

Attachments

  • test.zip
    90.4 KB · Views: 3
Upvote 0
Top