Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Arabic Letters Alignment — Gideros Forum

Arabic Letters Alignment

mertocanmertocan Member
edited November 2016 in General questions
Hi,

All arabic letters are in same position but It shows them in different places. How Can I align them?

Thanks.
Mert

Comments

  • n1cken1cke Maintainer
    edited November 2016
    @mertocan: try TextField.new(font, letter, sample) where sample is a string with highest and lowest character in your font e.g. "Fg" sample is often enough for English texts. Or do you need to put each letter right in the center?
  • Yes, I need to put letters right in the center. I will try sample suggestion.
  • Also, I am not able to write arabic words with system font.


    this doesnt display anything. How Can I display it with system font? I tried to change language of device but it didnt work.
    TextField.new(nil,"طحزوهدجبا")
  • n1cken1cke Maintainer
    Accepted Answer
    @mertocan: built-in Gideros font has only ASCII characters. You need to add your own font for this, but Gideros cannot display arabic words properly because currently Gideros doesn't support placing chars from right to left. However, you can display any chars one by one and use bitmaps with prerendered arabic text.

    This solution places a char right into the center of a cell:
    -- parameters
    local width, height = 150, 150
    local font = TTFont.new("Charis SIL Bold.ttf", height)
    local letter = "-"
     
    -- background
    local pixel = Pixel.new(0x00BBFF, 0.5, width, height)
    stage:addChild(pixel)
     
    -- letter
    local text = TextField.new(font, letter)
    local x, y, w, h = font:getBounds(letter)
    text:setPosition(0.5 * (width - w) - x, 0.5 * (height - h) - y)
    stage:addChild(text)
  • hgy29hgy29 Maintainer
    Accepted Answer
    Here is a lua adaptation of some C code I wrote years ago to display arabic text. It does ligatures and finally reverse unicode chars to simulate right to left writing. The result looks good but I don't know arabic so I can't tell if it is correct or not.
    function arabicProcessing(text)
    	local Achar={0x002,0x024,0x062,0x084,0x0C4,0x104,0x144,0x184,0x1C2,0x1E2,0x202,0x222,
                                   0x244,0x284,0x2C4,0x304,0x344,0x384,0x3C4,0x404,0x440,0x440,0x440,0x440,0x440,0x440,
                                   0x444,0x484,0x4C4,0x504,0x544,0x584,0x5C4,0x602,0x622,0x644}
    	local last=0	
    	local rtext=""
    	for p, cur in utf8.codes(text) do 
    		if ((last>=0x627) and (last<=0x64A)) then
    			local A=Achar[last-0x626]
    			local unibase=0xFE8D+(A>>4)
    			local of=0 --0=iso,1=fin,2=ini,3=med
    			if ((cur>=0x627) and (cur<=0x64A)) then
    				of=2+state
    			else
    				of=state
    			end
    			state=1
    			if (of>=(A&0xF)) then of=0 end
    			of=of+unibase
    			rtext=rtext..utf8.char(of)
    		else
    			if last>0 then
    				rtext=rtext..utf8.char(last)
    			end
    		state=0
    		end
    		last=cur
    	end
    	if last>0 then
    		rtext=rtext..utf8.char(last)
    	end
    	text=""
    	for p, cur in utf8.codes(rtext) do 
    		text=utf8.char(cur)..text
    	end
    	return text
    end
     
     
     
    local font=TTFont.new("DejaVuSans.ttf",20)
     
    local text="ينتحر و اختفى عن الانظار ليكمل بقية حياته ..."
    --text="TEST"
     
    print(text)
    text=arabicProcessing(text)
    print(text)
     
    local tf=TextField.new(font,text)
     
    tf:setY(50)
    stage:addChild(tf)

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • It seems like it is working. Thanks.
  • SinisterSoftSinisterSoft Maintainer
    edited December 2017
    Alter the last bit to this and it will sort out brackets...
    <pre>	for p, cur in utf8.codes(rtext) do
    		if cur==0x28 or cur==0x29 then cur=cur~1 end   -- this will swap brackets
    		text=utf8.char(cur)..text
    	end
    To add things like square brackets and curly brackets just add their ascii codes to the check. This works by toggling the last bit of the ascii code to swap from one bracket type to the other.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.