How to display Arabic word using print method?

Have a question about using Celestia? Check here first for FAQs and helpful advice.
Forum rules
Please help to make this forum more useful by checking the FAQs before posting! Keep it clean, keep it civil, keep it truthful, stay on topic, be responsible, share your knowledge.
Topic author
ahmedbahgat
Posts: 1
Joined: 25.03.2017
With us: 7 years 8 months

How to display Arabic word using print method?

Post #1by ahmedbahgat » 25.03.2017, 21:09

Hello all

I am trying to display Arabic words, like the Arabic names for the stars but I just don't know how, I know I have to use UTF-8 encoded characters but it is not working when I substitute the Arabic word with its UTF-8 encoded characters


Can you help me please with an example of displaying UTF-8 encoded characters using the print or the flash method?


Cheers

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 2 months
Location: Paris France

Post #2by jogad » 27.03.2017, 13:15

Hi,

It looks like arabic fonts in .txf format are missing in the celestia\fonts directories.
Maybe you can rebuild them following the method described here.
https://en.wikibooks.org/wiki/Celestia/Internationalization
(see "Building .txf font texture files" )
Change the "font_bold.ttf" in the description with a ttf police containing arabic characters.

celestia:print() uses the font "TitleFond" as declared in the celestia.cfg file.

I can't help too much because I am unable to write with this set of characters. (No arabic keyboard and above all zero knowledge of the language itself).

But I can test if you post a utf-8 encoded celx script with a valid celestia:print() statement containing arabic words.
- Please precise the default language of your computer and the language displayed in Celestia when you launch Celestia.

I fear there is also a problem in Celestia concerning the right to left management of the scripting.
In this case maybe you will have to write your text in reverse order :ill:

.

carton
Posts: 2
Joined: 22.02.2017
With us: 7 years 9 months

Post #3by carton » 27.03.2017, 19:33

Just had the same problem. Thank you for sharing.

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 2 months
Location: Paris France

Post #4by jogad » 28.03.2017, 19:51

.
Definitively, the arabic fonts are missing.

Here is a workaround to display arabic words in Celestia.
This is not the only way to do it, but maybe you find it useful. :smile:

1) Building the font for Celestia.

I have built a txf font with arabic characters (and also the latin ones, so you can use it to write any kind of text including special west-europeans letters with accents.

The base font is the simpo.ttf font that I found here.
https://cooltext.com/Fonts-Unicode-Arabic
I choosed this font because the latin characters in it match well withe the usual celestia fonts.
Of course another font is maybe better for arabic characters. Please tell me.

I gave the name simpo24_ar.txf to this font.
I got it withe this command :
ttf2txf -w 1048 -h 1048 -f codepoints_ar.txt -s 24 -o simpo24_ar.txf simpo.ttf

I join this font to this message.

2) copy this font in the fonts directory of Celestia.

3) In the celestia.cfg file, replace the sansbold20.txf with simpo24_ar.txf as TitleFont

Code: Select all

Font       "sans12.txf"
  LabelFont  "sans12.txf"
  # TitleFont  "sansbold20.txf"
  TitleFont  "simpo24_ar.txf"


Now you shoud be able to print arabic text using the celestia:print() or celestia:flash() functions.

But there is still a problem :
As I guessed, these functions don't manage the right to left order of arabic scripture and the text is written in reverse order.

To fix this issue, I have created a little lua function that reverse the order of a utf-8 text.

Here is a minimal script as exemple.

Code: Select all

local function utf8inverse(s)
   local inverse="";
   local i=1
   while (i <= string.len(s)) do
      local car,b
      b=string.byte(s,i)
      if b<128 then
         car = string.char(b);
         i=i+1
      elseif b<224 then
         car = string.sub(s,i,i+1)
         i=i+2
      elseif b<240 then
         car = string.sub(s,i,i+2)
         i=i+3
      else
         car = string.sub(s,i,i+3)
         i=i+4
      end
      inverse = car..inverse
   end
   return inverse
end

celestia:print(utf8inverse("هذا النجم الدبران") , 60,0,0,-12,-3)


And a screen copy of the result.
(click for a bigger view)

2017-03-28 21_22_10-Celestia.png


I Hope it make sense :think: I used google to translate from French to Arab.

Download the font from here:
Attachments
simpo24_ar.zip
(13.05 KiB) Downloaded 278 times


Return to “Help Central”