Drawing text in languages other than English

Monkey Forums/Monkey Programming/Drawing text in languages other than English

Lindsay(Posted 2014) [#1]
I'm looking at how to make my app in several languages. I've quickly found that DrawText doesn't like it! I've looked at some of the modules but it's unclear which (if any) work with foreign characters.

Can someone point the way?

Thanks,
Lindsay


therevills(Posted 2014) [#2]
DrawText uses the mojo_font.png which doesn't contain any foreign characters, I'd suggest using either FontMachine, AngelFont or Chris's new TrueType Font module:
http://www.monkey-x.com/Community/posts.php?topic=8470


Lindsay(Posted 2014) [#3]
I will definitely need support for Asian characters, and right-to-left languages like Arabic too. I know, not asking for much!


therevills(Posted 2014) [#4]
I would say you are going to have to create your own system for Arabic... I don't think any of the current font modules support right to left.


nikoniko(Posted 2014) [#5]
Lindsay wrote:
Can someone point the way?


It's a bit hard to implement than using ansi chars only.

therevills wrote:
DrawText uses the mojo_font.png


Bitmap font is a simplest way. Create font image for every supported language and switch it in run-time. I am not sure about DrawText() works correct with international chars by default.

therevills wrote:
Chris's new TrueType Font


This module doesn't support chars with code over 255 yet.

AngelFont creates bitmap font for foreign languages. I don't know about FontMachine. I haven't license to use it.


ziggy(Posted 2014) [#6]
Adding right-to-left to fontmachine should be a piece of cake and the module is open source. also, the editor allows to export arabic characters (and asian characters too). In fact, you can just pass the arabic text and align to the right which is supported in all drawing commands, including wordwrapp etc.


Goodlookinguy(Posted 2014) [#7]
FontMachine supports foreign characters. I don't think it has right-to-left handling though.

Edit: Ninja'd


Playniax(Posted 2014) [#8]
Maybe this helps. Ignition X comes with a tool to convert TTF files so Ignition X can render them. Here is a screenshot


vmakar85(Posted 2014) [#9]
Hi Lindsay, i use fantom engine and online bmf http://kvazars.com/littera/


Midimaster(Posted 2014) [#10]
I use a modyfied version of AngleFont, which now accepts big sized fonts with high Unicode numbers.The regular AngleFont stopps at ASCIIs>255. My modification allows numbers upto 40,000. In this context I modyfied the function LoadFont(), which now loads thousand of font images within 200msec.
I prepare the image fonts I need with the tool from Beaker (AngleFont author). The images are often very big (1000x1000pix).
I use it for german, russian and other european languages. I never tested arabic or chinese...

Search for "Nobuyuki" here in forum. He is very experiences wit foreign language fonts a did a lot of modifications.


Lindsay(Posted 2014) [#11]
Thanks everyone -- in the end I've "solved" the problem by using image files - not as fonts, but as pre-rendered files of the text I actually need. Obviously this makes the app bigger, but I can live with that.


nikoniko(Posted 2014) [#12]
Playniax wrote:
Maybe this helps. Ignition X comes with a tool to convert TTF files so Ignition X can render them. Here is a screenshot

It shows ascii only. Do screenshot with unicode chars (Russian, Arabic, Chinese, etc)


vmakar85 wrote:


Well. No found chinese and arabic in presset of charsets.


Midimaster wrote:
I use a modyfied version of AngleFont,


Do you publish your solution yet?


vmakar85(Posted 2014) [#13]
nikoniko



Midimaster(Posted 2014) [#14]
As I remember it were only a few changes necessary. Beaker inserted a check for ASCIIs over 255. I replaced this with the constant MAX_CHARS and set MAX_CHARS to the maximum unicode number need in my font:

modul anglefont.monkey:
Class AngelFont
	Private
	
	Global _list:StringMap<AngelFont> = New StringMap<AngelFont>
	Const MAX_CHARS%=8500
	Field image:Image[] = New Image[1]	
	Field chars:Char[MAX_CHARS+1]
....
	Method DrawText:Void(txt:String, x:Int, y:Int)
		Local prevChar:Int = 0
		xOffset = 0
		
		For Local i:= 0 Until txt.Length
			Local asc:Int = txt[i]
			If asc>MAX_CHARS Then
				Print asc + " " + MAX_CHARS
				 asc= "*"[0]
				 Error ""
			Endif

Now you already can create image fonts with more characters. You need not more!



I also changed the loading function, because it was too slow for more than 255 characters. The original function loads a text with the character descriptions. My new function loads a DataBuffer which contain the character values as Shorts:

	Method LoadFontFast:Void(url:String, FontImage:Image=NULL)
		
		Local Bank:DataBuffer = DataBuffer.Load("monkey://data/" + url  + ".bin")	
		Local id%,Nr%
		For  Nr=0 To (Bank.Length()/16-4)
			Local x%,y%,w%,h%,xoff%,yoff%,adv%
			Local da%
			da=Nr*2*8
			id=Bank.PeekShort(da)
			x=Bank.PeekShort(da+2)
			y=Bank.PeekShort(da+4)
			w=Bank.PeekShort(da+6)
			h=Bank.PeekShort(da+8)
			
			xoff=Bank.PeekShort(da+10)
			yoff=Bank.PeekShort(da+12)
			adv=Bank.PeekShort(da+14)
			chars[id] = New Char(x, y, w, h, xoff, yoff, adv)
			If h > Self.height Self.height = h
			If yoff < Self.heightOffset Self.heightOffset = yoff
		Next
	
		If FontImage<>Null
			image[0] =FontImage
		Else
			image[0] = LoadImage(url+".png")
		Endif 
	End Method



nikoniko(Posted 2014) [#15]
vmakar85

Ok. My Firefox was crashed on that preset.

Midimaster

thx!