iOS Question The custom Font in WebView1 does not work

AlfaizDev

Well-Known Member
Licensed User
I use this code in B4A
It works well
When I used it in B4I
The coordination works except the custom Font
It shows me to write default Font for mobile

B4X:
    File.Copy(File.DirAssets, "uthmantn1ver10.otf",File.DirLibrary,"uthmantn1ver10.otf")

B4X:
    Dim Deel As String =Content
        Dim pish As String = "<html><head><style type='text/css'>@font-face {font-family: MyFont;src: url('" _
    & File.DirLibrary &"/uthmantn1ver10.otf')}body {font-family: MyFont;font-size: "&20&"pt}</style></head><body> "
        Dim pas As String = "</body></html>"
        Dim  myHtmlString As String = pish & Deel &pas
        WebView1.LoadHtml(myHtmlString)
 
Last edited:

AlfaizDev

Well-Known Member
Licensed User
Code works

But this code below and found the same work
B4X:
LContant.TextAlignment=3

I remained a small problem I want to align be justified and right
The problem you get in the last line where it is back to the left

He did this code and did not work
B4X:
LContant.TextAlignment=Bit.Or(2,3)

See the image at the bottom
 

Attachments

  • 566.png
    439.3 KB · Views: 244
Last edited:
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Thanks
The justification in Label has worked for me
But can I find a solution to the line in WebView

3. Save the html in a file in File.DirLibrary and load it with LoadURL. Try it without the full path to the font file, only the file name.

I can't save the data as an html file
Because I am importing data from databases into a WebView
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
If to come back to https://www.b4x.com/android/forum/t...-in-webview1-does-not-work.132282/post-835048

1) If to use #AppFont, IOS sees a custom font like any other IOS fonts. So, I don't see a reason to File.Copy

2) font-family: MyFont ???
Your font belongs to KFGQPC Uthman Taha Naskh
url - guess, not needed

3) Add something like <meta name=viewport content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'> to header. Otherwise it will be troubles with scale.

4) I don't see text-align: justify (for example in styles) and dir=rtl (for example in <html>)
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
1) If to use #AppFont, IOS sees a custom font like any other IOS fonts. So, I don't see a reason to File.Copy

Thanks, I didn't notice that
The situation is different from b4a

2) font-family: MyFont ???
Your font belongs to KFGQPC Uthman Taha Naskh
url - guess, not needed
What will the path of the line be in the html code?
instead of this

B4X:
 Dim Deel As String =Content
        Dim pish As String = "<html><head><style type='text/css'>@font-face {font-family: MyFont;src: url('" _
   [B] & File.DirLibrary &"/uthmantn1ver10.otf')[/B]}body {font-family: MyFont;font-size: "&20&"pt}</style></head><body> "

Format codes are in the database
The text is stored in the database as html
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I placed UthmanTN1Ver10.otf into Special subfolder and added #AppFont : UthmanTN1Ver10.otf

In Application_Start I did Log (Font.CreateNew2 ("KFGQPC Uthman Taha Naskh", 20dip)).
Result: <B4IFontWrapper: <UICTFont: 0x7fd768641970> font-family: "KFGQPC Uthman Taha Naskh"; font-weight: normal; font-style: normal; font-size: 20.00pt>. Means IOS sees a font family.

HTML ... It's hard to test, because I don't know how a font looks. Guess, inside <style type=text/css> it's neccessary to do something like body { font-family: KFGQPC Uthman Taha Naskh; font-size: 20pt }
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
HTML ... It's hard to test, because I don't know how a font looks. Guess, inside <style type=text/css> it's neccessary to do something like body { font-family: KFGQPC Uthman Taha Naskh; font-size: 20pt }
Well I will try on it
Thanks
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
HTML ... It's hard to test, because I don't know how a font looks. Guess, inside <style type=text/css> it's neccessary to do something like body { font-family: KFGQPC Uthman Taha Naskh; font-size: 20pt }


It looks like the one in the picture
I tried with the code and it didn't work
B4X:
Dim pish As String = "<html><head><style type=text/css>body" _
    & " { font-family:'KFGQPC Uthman Taha Naskh;'; font-size: 80pt;text-align: center; color: #E2341D; }</style></head> "
Dim Deel As String = txt
    Dim pas As String = "</body></html>"
    Dim  myHtmlString As String = pish & Deel &pas
    WebView1.LoadHtml(myHtmlString)
text:
من أسباب الاصابة بمرض تكون العظم الناقص. إن اضطراب العظام الخلقية تترافق مع عيب في النسيج الضام، مما يؤدي إلى عدم القدرة على بناء العظم أو تكوينه ويؤدي إلى سهولة كسر العظام، وغالبا ما يكون سبب تلك الكسور غير ظاهر.
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I did some experiments,

1) It looks that B4I WebView.LoadHtml does not set baseurl. So I replaced it to OBJC,
2) Fonts are really should be described in CSS, because WKWebView (probably) works in another process.
3) About your font I am not sure. But Latin fonts are correct.

 

Attachments

  • s23.zip
    473.1 KB · Views: 263
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…