Page 1 of 2

Importing TTF Fonts

Posted: Mon Mar 16, 2009 4:22 pm
by ian_scho
Hi, been importing a font, with success, as it's just like a bmp import:

Code: Select all

gfx["flamespitter"] = dsb_get_bitmap("./GFX/flamespitter")
gfx["DMJAVASCROLLFONT"] = dsb_get_font("scrollfont")
However it falls over if I place the file in a subdirectory ./fonts/scrollfont.ttf

Code: Select all

gfx["DMJAVASCROLLFONT"] = dsb_get_font("./fonts/scrollfont")
Not a problem to have it in my Dungeon directory, just not as tidy :P

Re: (fixed) Graphics.dsb and file importing

Posted: Mon Mar 16, 2009 8:51 pm
by Sophia
DSB can't import TTF fonts at all!

Allegro does, however, have a program called TTF2PCX that will convert a TTF to a static PCX bitmap that Allegro (and thus DSB) can use. You're limited to one size, of course, but you generally would only use the font in one or two sizes anyway, so it's not a terrible issue to create bitmaps for the fonts needed.

The reason it appears to work when not in a subdirectory is that there is an entry in graphics.dat called SCROLLFONT. This is what is getting loaded-- not your file.

Re: Importing TTF Fonts

Posted: Tue Mar 17, 2009 9:00 am
by ian_scho
lol. Thanks again Sophia.

Will take a look at TTF2PCX, but the site is under maintenance at the time of writing.

Re: Importing TTF Fonts

Posted: Tue Mar 17, 2009 9:37 am
by ian_scho
Works a treat :)

Re: Importing TTF Fonts

Posted: Wed Dec 08, 2010 12:39 am
by Gambit37
Just found this thread. The linked TTF tool loks interesting. Also:
the program can output antialiased fonts, which are generated by rendering the TrueType characters at eight times the requested size and then scaling down (an 8x8 supersampling grid provides 64 intensity levels). Fonts in this format can be drawn in Allegro by passing -1 as the color to textout(), but this will obviously only work if you have a suitable gradient in your palette.
Does this in any way shape or form help with the issue of creating anti-aliased fonts that can be recoloured in DSB? I soooooooo want to move away from pixel fonts, that's way too old school now.... :)

Re: Importing TTF Fonts

Posted: Wed Dec 08, 2010 2:27 am
by Sophia
Gambit37 wrote:Does this in any way shape or form help with the issue of creating anti-aliased fonts that can be recoloured in DSB?
Not directly, because the bit about "pass -1 as the color" means that it's presumably just using the font as a colored font, and not tinting it at all-- meaning no recoloring by Allegro proper. However, I think that I can use some of the blender functions offered by Allegro to do a decent job of recoloring the font myself. It'll take a fair bit of hacking around in the DSB core, but I think it's doable. :mrgreen:

Re: Importing TTF Fonts

Posted: Tue Apr 26, 2011 6:32 pm
by Gambit37
Found the following for doing TTF fonts in Lua using the Freetype library. Any good for DSB?
http://lua-gd.luaforge.net/manual.html#api.text

Re: Importing TTF Fonts

Posted: Tue Apr 26, 2011 8:23 pm
by Sophia
No, because that's designed for drawing on gd images, which have little or nothing in common with Allegro bitmaps.
There is an Allegro utility called TTF2PCX that will convert a TTF font to a static Allegro font. Knowing this, do you still need TTF support?

Re: Importing TTF Fonts

Posted: Tue Apr 26, 2011 8:27 pm
by Gambit37
I'm just looking for solutions for anti-aliased type... don't really mind how it works :-)

Re: Importing TTF Fonts

Posted: Fri Dec 02, 2011 4:42 pm
by Gambit37
Any of the stuff on these pages useful in getting anti-aliased fonts into DSB? ;-)

http://www.allegro.cc/forums/thread/431118
http://www.mattsmith.allegronetwork.com/fonts/attf2pcx/

On another note, if I wanted to create a font from scratch, what are the rules for

1) Number of rows and columns in the font grid ?
2) Character order ?
3) Colours used to define the divisions between letters ?

Looking at the fonts in the default DSB graphics, they don't seem to follow a pattern....?

Re: Importing TTF Fonts

Posted: Sat Dec 03, 2011 11:43 pm
by Sophia
1) There are no rules on the number of rows and columns as far as I can tell.
2) Character order is ASCII.
3) For a 256-color font, the background is color index 0 and the separator is color index 255.
For a truecolor font, the background is {255, 0, 255} (power pink) and the separator is {255, 255, 0} (yellow).

The issue with an anti-aliased font is that Allegro doesn't know how to draw it. I looked at the allegro source code and fonts are hardcoded to not care about alpha channels etc., so it's even messier than I thought. :(

Re: Importing TTF Fonts

Posted: Wed Dec 07, 2011 3:45 am
by Gambit37
Thanks for the spec :-) Can I use extended Ascii, (from 128 -> 255), or is it just the regular 32 -> 127 range?

I assume all fonts are considered mono spaced and every grid box has to be the same size? Or can we have different sized boxes for characters (narrow for "I", wide for "W") to do proportional fonts?

Re: Importing TTF Fonts

Posted: Wed Dec 07, 2011 4:37 am
by Sophia
Yes, you can use ASCII values 128-255. You can even use Unicode provided you convert everything to UTF-8 so the underlying C engine can store it in a standard char array, if you're feeling more ambitious. However much of a character set you want to define, DSB can use. (Actually, I should say, Lua and Allegro can use. DSB is just good at obliviously handling the bytes so the middleware can work its magic)

No, actually, I'm pretty sure it allows differently sized boxes, which is the whole reason behind having the separator-color and the somewhat openended way of defining the font.

Re: Importing TTF Fonts

Posted: Wed Dec 07, 2011 5:37 pm
by Gambit37
Awesome! I've found a way of simulating anti-aliasing for some specific font situations (where they don't need to be re-coloured by the engine). And with the proportional ability, that opens up possibilities for some prettier interface work :-) I'm getting pretty stoked to use DSB now :-)

Re: Importing TTF Fonts

Posted: Mon May 07, 2012 1:26 am
by Gambit37
Right, so I've finally got around to trying out a custom font and I simply cannot get it to work. I'm pretty sure the format is OK as I followed your instructions and also compared mine against the examples that come with http://www.allegro.cc/depot/AllegroFontEditor/

I had problems originally even loading the font, but cleared up all those issues. The font now seems to load OK, but when I call it in dsb_bitmap_textout, DSB bombs out saying it's not a font:
My code:

Code: Select all

dsb_bitmap_textout(bmp, font_test, champions[champions_roster[s]].shortname, 582, 90+(100*(s-1)), CENTER, {97,179,179})
Error Message:

Code: Select all

FATAL LUA ERROR: Lua Function fullscreen_draw: /select-champions.lua:125: dsb_bitmap_textout requires Font in param 2
@@@ LUA STACK @@@
[S:storming_nira_prime/select-champions.lua:125: dsb_bitmap_textout requires Font in param 2]
@@@@@@
This is my font: http://matthill.co/f/dsb/font_test.pcx

Pulling my hair out...! Any help please?

Re: Importing TTF Fonts

Posted: Mon May 07, 2012 1:31 am
by Gambit37
Argh, never mind, I realised i missed the "gfx." prefix off the font name *facepalm*

Re: Importing TTF Fonts

Posted: Mon May 07, 2012 1:57 pm
by Gambit37
Another one: How do I change the main sys_font? I can't seem override it: updating a new fontgrid.pcx at the root of my dungeon folder makes no difference.

Re: Importing TTF Fonts

Posted: Mon May 07, 2012 6:20 pm
by Sophia

Code: Select all

sys_font = dsb_get_font("MYNEWFONT")
:mrgreen:

Re: Importing TTF Fonts

Posted: Mon May 07, 2012 6:36 pm
by Gambit37
Doh! Thanks :-)

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 10:58 am
by Joramun
I have a problem loading a pcx font from a directory, using dsb_get_font(name,path)
Dsb doesn't seem to like it.

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 6:17 pm
by Sophia
Make sure it's a 256-color PCX, not a 16-color one, which Allegro doesn't understand for some reason.
Otherwise, I'm not sure. What do you mean by "doesn't seem to like"?

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 9:28 pm
by Gambit37
Yeah, I've had constant problems with PCXs. Its largely because I use PhotoShop and that reverses the palette when you save as PCX. Why are you using PCX anyway? Can't you use a modern format like PNG for this stuff, PCX is bloody ancient! ;-)

Also, fonts must be setup EXACTLY right. You can only have ONE pixel dividers between each row, if not, DSB doesn't recognise it as a font. Here's one I set up the other day which works:
http://matthill.co/f/dsb/font_test.pcx

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 9:44 pm
by Sophia
Gambit37 wrote:Also, fonts must be setup EXACTLY right. You can only have ONE pixel dividers between each row, if not, DSB doesn't recognise it as a font.
No, it doesn't have to only be one pixel. The default font grid as well as the wall font both use wider dividers. I will agree that Allegro can be a finicky when it comes to what it'll accept as a font, though.

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 9:49 pm
by Gambit37
Hmmm, I couldn't get it to work if there was more than 1 pixel between each row. Tore my hair out for ages trying to get it work. Why can't you use PNGs?

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 10:36 pm
by Sophia
Mostly because invariably then someone would create a font with an alpha channel and wonder why it didn't work.

If you want to use a halfway modern format, you could always use BMP, too. DSB supports that.

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 11:21 pm
by Gambit37
Ah, cool, I thought for some arcane reason you could only use PCXs for these weird incidental graphics. I mean, I never understood why I could use PNGs nearly everywhere, then had to use PCXs for other things like fonts and hero icons, it didn't really make any sense.

The thing is though, one can create a paletted 8-bit PNG that would work just as well here, so I still don't understand why you won't make the formats consistent? It's just really strange and annoying having to remember that certain graphics have to be in a different format and this sort of "unknown unknown" weirdness doesn't make learning DSB any easier.

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 11:30 pm
by Sophia
It really isn't so bad!
For 256 color images, use BMP or PCX.
For truecolor images, use PNG or TGA.
That's all you have to remember. :)

I won't include support for 256 color PNGs because there is no support now and that's code I'd have to write, when two other perfectly good 256 color image formats are already supported-- and I'd honestly rather work on other things!

Re: Importing TTF Fonts

Posted: Tue May 08, 2012 11:37 pm
by Gambit37
Fair enough, at least I can use BMPs now, I did not realise this. This will solve all the crappy palette reversing shenanigans I've had to do on PCXs that come from PhotoShop... that was all highly annoying.

Re: Importing TTF Fonts

Posted: Thu May 10, 2012 10:00 pm
by Joramun
Sophia wrote:Otherwise, I'm not sure. What do you mean by "doesn't seem to like"?
:oops: It just doesn't detect it. I'm gonna try changing the color depth.

Re: Importing TTF Fonts

Posted: Thu May 10, 2012 10:12 pm
by Gambit37
Show me your font and I can probably fix it :-)