Need a text to image function

Monkey Archive Forums/Digital Discussion/Need a text to image function

Lindsay(Posted 2014) [#1]
Edit: never mind, I've figured out a much easier compromise!

I've been beating my head against this problem for weeks now, figured it was time to see if anybody else has an idea.

I don't care if this is done in Monkey,Xcode,VisualC,Cocos,'s a standalone tool to build the data files for my game, not part of the game itself.

- Function takes "text" and "filename" as parameters
- Creates a new text object with a given font and size containing "text". It's automatically sized to be just large enough to hold "text" in that font, but no larger.
- Retrieves the canvas of that object and saves it to disk as a transparent PNG file ("filename".PNG)

Before anybody says "use bitmap fonts", here's why that won't work: some of the words I need to convert to graphics are in languages like Arabic which have very complex rendering rules, not straightforward letter->glyph substitution.

Up to now I've been doing a variation of this, 100 words at a time, using a graphics program (and my game then uses DrawImageRect to pull out just the word it needs). This works, but there are literally thousands of words I need to convert ... Not impossible, but highly tedious.

So if anybody can see a way to do this, please let me know!

TeaBoy(Posted 2014) [#2]
Hi Lindsay,

Not sure if this could help, but I've been using the GD Library with PHP lately, perhaps you could see if that is a possible solution, perhaps call PHP via CLI
to create the required PNG?

[Edit]: Hmm... just looked into it abit more, have you looked at

DruggedBunny(Posted 2014) [#3]
I think 297chrisc's Truetype font module would help you do this.

Lindsay(Posted 2014) [#4]
Thanks guys - overnight I've realised that if I drop support for the two most problematic languages, every other language I want to support will work with a bitmap font, so I'm going to do that as it's a heck of a lot less work!