Android Question Camobidian (Khmer) characters UTF8

Rusty

Well-Known Member
Licensed User
Longtime User
I have successfully used Gujarati, Chinese,...lots of other character sets successfully as button text.
I am trying to use Khmer characters (range 1780 through 20a3 approx.). For some reason, using the same UTF8 logic for the other languages doesn't seem to work for Khmer. I'm loading the Khmer.ttf font.
Does anyone know what the limitation might be?
Thanks,
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
hmmm.
As a very simple test, I did the following:
B4X:
    Dim B As Button
    B.Initialize("B")
    B.Color = Colors.White
    B.Text = "ឆ៩៧"
    B.TextColor = Colors.Black
    B.TextSize = 36
    Activity.AddView(B, 200dip, 200dip, 200dip, 200dip)
the result is a button that is entirely blank...
can you send your code sample?
Thanks,
Rusty
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You said: "...I'm loading the Khmer.ttf font.", however I don't see that in your code, anyway, I'm attaching my sample for you to take a look.
 

Attachments

  • CambodianFont_Sample.zip
    23.1 KB · Views: 355
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
you are right.
In my haste to simplify my approach for posting on this blog, i failed to set the font...
My code should be:
B4X:
    Dim B As Button
    B.Initialize("B")
    B.Color = Colors.White
    B.Text = "ឆ៩៧"
    B.TextColor = Colors.Black
    B.TextSize = 36
    language = "khm"
    languagenm = "Khmer"
    B.Typeface = Typeface.LoadFromAssets("Khmer.ttf")
    Activity.AddView(B, 200dip, 200dip, 200dip, 200dip)
I appreciate your sample code. However, it is merely using the Khmer font to display English characters.
I'm trying to use the extended characters values Hex: 17e1, 17e7, 20ab as an example (not the characters pictured above, but still the extended values).
If you change your english text for hex values (ret = Bit.ParseInt(hex, 16) and try, it will likely be blank.
This works for other languages like Gujarati, Chinese etc.
Any ideas?
Thanks
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks NJDude,
Did you try it on your machine? Strangely, the LOG displays the Khmer symbols just fine, it's just the buttons that don't.
So I assume the environment supports Khmer, but apparently the runtime doesn't...
Thanks for all your help.
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Erel,
Here it is, I had to rename it from .ttf to .txt to get past the file filters on this blog. you'll have to rename it back to khmer.ttf.
Thanks!
Rusty
 

Attachments

  • khmer.txt
    31.5 KB · Views: 302
Upvote 0

agraham

Expert
Licensed User
Longtime User
I'm afraid that is not a proper Khmer font file but just a fancy font for the normal A to Z alphabet so doesn't contain the real Khmer glyphs that you need.

There is a proper Khmer font on my Windows 7 desktops called KhmerUI.ttf. I don't know if it is part of Windows or was added by Word or some other program. You could try that to see if it works but I don't think you are allowed to distribute it. Maybe you can find something here http://www.cambodia.org/fonts/
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks agraham,
I had originally downloaded the font from the www.cambodia.org/fonts location. Somewhere along the way, I must have grabbed the smaller one thinking they were the same and they are NOT. I re-installed the font and ALL IS WELL.
Thank you very much for pointing this out to me.
Regards,
Rusty

Do you know if there is a way to load the font from Dirrootexternal instead of dirassets?
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks.
I created a sub:
B4X:
Sub LoadFontFromFile(FontName As String) As Typeface
    Dim t As Typeface
    Dim o(1) As Object
    Dim s(1) As String
    Dim r As Reflector
    o(0) = File.DirRootExternal & "/survey/" & FontName
    s(0) = "java.lang.String"
    t = r.RunStaticMethod("android.graphics.Typeface", "createFromFile", o, s)
    Return t
End Sub
where fontname = "khmeros.ttf"
The result is "Native typeface cannot be made"
any thoughts?
One other consideration, the LOG display seems to be able to display ALL fonts I've tried to use without having to load any font files etc.
How does the b4a log handle fonts, maybe I can use this method.
Thanks,
Rusty

OK, I found the error on the external font loading, I'd failed to put the "/" after the foldername survey, it has been corrected above and works GREAT!
Thanks for your insights :)
 
Upvote 0
Top