@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?
@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:
-- parameterslocal width, height =150, 150local font = TTFont.new("Charis SIL Bold.ttf", height)local letter ="-"-- backgroundlocal pixel = Pixel.new(0x00BBFF, 0.5, width, height)
stage:addChild(pixel)-- letterlocal 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)
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=0local rtext=""for p, cur in utf8.codes(text)doif((last>=0x627)and(last<=0x64A))thenlocal A=Achar[last-0x626]local unibase=0xFE8D+(A>>4)local of=0--0=iso,1=fin,2=ini,3=medif((cur>=0x627)and(cur<=0x64A))then
of=2+state
else
of=state
end
state=1if(of>=(A&0xF))then of=0end
of=of+unibase
rtext=rtext..utf8.char(of)elseif last>0then
rtext=rtext..utf8.char(last)end
state=0end
last=cur
endif last>0then
rtext=rtext..utf8.char(last)end
text=""for p, cur in utf8.codes(rtext)do
text=utf8.char(cur)..text
endreturn text
endlocal 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)
Alter the last bit to this and it will sort out brackets...
<pre>for p, cur in utf8.codes(rtext)doif cur==0x28 or cur==0x29 then cur=cur~1end-- 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
Comments
this doesnt display anything. How Can I display it with system font? I tried to change language of device but it didnt work.
This solution places a char right into the center of a cell:
Likes: pie
https://deluxepixel.com