How to display Arabic word using print method?

Description: 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
Topic author
Posts: 1
With us: 6 months 23 days

#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?


Posts: 461
With us: 9 years
Location: Paris France

#2by jogad » 27.03.2017, 13:15


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.
(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:


Posts: 2
With us: 7 months 23 days

#3by carton » 27.03.2017, 19:33

Just had the same problem. Thank you for sharing.

Posts: 461
With us: 9 years
Location: Paris France

#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.
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
      if b<128 then
         car = string.char(b);
      elseif b<224 then
         car = string.sub(s,i,i+1)
      elseif b<240 then
         car = string.sub(s,i,i+2)
         car = string.sub(s,i,i+3)
      inverse = car..inverse
   return inverse

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:
(13.05 KiB) Downloaded 32 times

Posts: 1
With us: 6 months 9 days

More Arabic fonts

#5by beyond23 » 09.04.2017, 07:06

Hi, if you are looking for some more Arabic fonts or want to create Arabic fonts for design purpose i will recommend go to cool letters, it has fonts like aladdin and lot of other fonts; you can also adjust them, hope this helps

Return to “Help Central”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest