PDA

View Full Version : Bitmap Font Generator



Nitrogen
02-01-2007, 01:34 PM
I've just released version 3.0 of my bitmap font generator: Font Studio.
(http://www.nitrogen.za.org/projectinfo.asp?id=12)

<center>http://www.nitrogen.za.org/gallery/thumbs/FontStudio.jpg (http://www.nitrogen.za.org/viewimage.asp?id=7)</center>

One of the minor irritations when making games or graphics apps, is that if you need quick text you have to either dig up some huge library or write one yourself. Well, I've taken the hassle out of making and displaying fonts. Font Studio is easy to use and saves font information into one convenient file using jpeg compression. This file can be loaded into Delphi (http://www.nitrogen.za.org/projectinfo.asp?id=12) or C++ (http://www.nitrogen.za.org/projectinfo.asp?id=28) and integrates with your OpenGL projects.

Features:

* New Interface

* Much faster processing times

* Drop Shadows!

* Delphi and C++ support

* Full control over character placement

* Coloured fonts and masks

JSoftware
02-01-2007, 02:19 PM
Looks great. I'm going to try that

WILL
02-01-2007, 04:39 PM
Very nice...

I remember the last such tool was bundled with XCESS, but it had saved in it's own format only. Plus you had to get the whole suite to just use it.

This is great stuff. I may have a use for it myself. ;)

jdarling
02-01-2007, 04:41 PM
Any chance that you could implement using PNG instead of JPEG since in PNG you have full alpha transparency and wouldn't have to record a mask? This would also allow for smoother edges. I know that FPC supports PNG and I believe that there is support in the newer versions of Delphi (though I haven't tried them).

Nitrogen
02-01-2007, 06:38 PM
Yea, I was thinking about using TGA files because I can decode TGA's easily..

But it saves a 24bit JPEG and an 8bit grayscale jpeg inside a single file which is very easy on your file size.. And I've set the quality to very high, I've never seen any jpeg artefacts on it...

jdarling
02-01-2007, 07:00 PM
PNG gives you everything that TGA and JPG give you. Alpha Transparency, Compressed Size, and on top of it its lossless. Of course, JPG or TGA are also valid options, my concern would be with JPG's lossly compression if you did manage to get a pattern that would allow for artifacts.

Also, looking at your code, you save the image to a standard file and then save/load it accordingly. You don't have to do this, and can simply load/save directly to your main buffer. This will save on some overhead and fix any problems associated with drive size and writes issues.

One final thing, I wrote a quick version of your loader in FPC (extracts all info and the image file) and the JPG's don't load properly with the standard FPC libs. They are fine when I extract them to a file, but not fine when loaded within the TJPGImage object. So TGA or PNG would be better if you want support through native libraries in FPC.

Nitrogen
02-01-2007, 08:48 PM
Yea, I'll have a look into PNGs.. I wrote the whole JPG saving thing a long time ago.

Strange that those jpg objects dont work in FPC, any good Delphi PNG loaders you can suggest?

WILL
02-01-2007, 09:05 PM
Wasn't able to find much, but here are a few links that'll help you get started. ;)

Portable Network Graphics (PNG) Specification and Extensions (http://www.libpng.org/pub/png/spec/)
libpng Homepage (http://www.libpng.org/pub/png/libpng.html)

Texture Loader (http://www.coolgroups.com/alpha/) (It's in C++ though :P)


Oh and also sdl_images supports PNG through libpng I believe. So maybe you can get some use out of JEDI-SDL for this?

Legolas
02-01-2007, 10:23 PM
http://pngdelphi.sourceforge.net/
http://freeimage.sourceforge.net/
http://www.delphi-gems.com/GraphicEx.php

:)

Nitrogen
02-01-2007, 10:53 PM
Thanks guys, I'll go through those!

jdarling
03-01-2007, 01:57 PM
http://pngdelphi.sourceforge.net/
http://freeimage.sourceforge.net/
http://www.delphi-gems.com/GraphicEx.php
Its worth noting that GraphicEx is read only on PNG. Still, its one of the best graphic reading libraries out there for Delphi. Now if only the conversion for FPC/Lazarus was complete :(

PNGImage (pngdelphi.sourceforge.net) is one of the most stable that I've found.

Nitrogen
03-01-2007, 09:07 PM
Yea, that's the one I've downloaded.

I hope I can integrate this with the font loader unit without bloating it too much...

Chebmaster
05-01-2007, 02:47 AM
1. A nice thing, but useless for us, Russians.
2. Clicking the "Characters" button raises an Access Violation

Nitrogen
05-01-2007, 09:13 AM
Yea, because there's no Unicode support..

Might be why the character setup is messing up too.

Chebmaster
05-01-2007, 03:44 PM
Well, on my machine it obviously *does* use the Cyrillic character set (at least the exotic part of it are visible, corresponding to Serbian, AFAIK), so if it just allowed to choose which characters of the ANSI set to use, that would do.

But what the crashy button "Characters" should normally do?

Nitrogen
05-01-2007, 05:20 PM
It opens up a window which shows all the characters nicely in a list so you can choose the starting and ending characters. But you can still type in the manual numbers if you want.

I've fixed the bug, but I'm busy adding TGA support before I release it again. PNGs carry too much extra baggage that needs to be installed before you can use them, and TGA files are very easy to load.

JSoftware
05-01-2007, 08:26 PM
I like it. I'm writing a wrapper though as your code doesn't really fit well into resolution indepent positioning and scaling wise.

The tool is polished and it just works smoothly(except for the Characters button). TGA format output in your own fileformat could be fine though to eliminate the need for the jpeg unit(and all the rtl graphics units)

Don't you forget to set the length of the F array to 0 when your TFontObj object is getting freed?

Nitrogen
05-01-2007, 11:32 PM
Possibly, but then F is a defined member of the TFontObj class, surely the class destructor knows enough to free all it's member variables?

If F was a pointer to a dynamically allocated array, then yes, it would create a memory leak.

Chesso
07-01-2007, 05:45 AM
Hi, I'm going to try this out soon, so I'm not entirely sure how much use it is to me, but would the output be fine for use in UnDelphiX's TPowerFont?

I was going to make my own from scratch but it sounds like this tool will make the job easier (and it does JPEG, as UnDelphiX doesn't support PNG's yet).

Nitrogen
07-01-2007, 11:29 AM
I've never used UnDelphiX, so I really cant say.

All this program does is give you a texture and list of characters with their Left,Top,Right,Bottom coordinates, and some spacing information, how you use it is up to you. You can have a look at the Font2.pas unit in the Font Test project to see how to load the files..

I'm busy with an update to the program.. Adding Unicode support is looking to be a huge pain in the ass, but I have got proper character spacings now, and not relying on the Canvas.TextWidth() function. The Characters button has been redone, and now shows all 65000 unicode characters, but I'm not happy with the way it does this. The main window is able to render unicode now, but the font rendering technique still has to become multibyte-character-aware.

Chesso
07-01-2007, 12:39 PM
Ok, well from what I have seen so far, is that TPowerFont with UnDelphiX, has the characters in a specific order in the image, and you basically tell it the bounding box (just like with images and the TImageList).

so each character might have a space of 22x22 or some such and then of course they will have a specific row and column set and order the characters go in (so the components knows exactly what is what).

Zampoteh
27-01-2007, 02:19 AM
1. A nice thing, but useless for us, Russians.
That supports russian: http://font2pic.narod.ru/

Sly
29-01-2007, 11:19 AM
Have you seen AngelCode's BMFont (http://www.angelcode.com/products/bmfont/)? It supports Unicode very well, and I've yet to find another font bitmap maker that packs so many characters onto a bitmap.
http://www.angelcode.com/products/bmfont/images/bmfont_thumb.gif (http://www.angelcode.com/products/bmfont/images/bmfont_thumb.gif) http://www.angelcode.com/products/bmfont/images/settings_thumb.gif (http://www.angelcode.com/products/bmfont/images/settings_thumb.gif) http://www.angelcode.com/products/bmfont/images/font_thumb.gif (http://www.angelcode.com/products/bmfont/images/font_thumb.gif)

Nitrogen
06-02-2007, 10:41 AM
Thats kind of what Fontstudio 4 will look like.

Well, I've been busy with FontStudio and it's taken a surprising amount of time. I still havent got halfway to implementing a full product yet, but I have built a better Character Map than the one included with windows..

http://www.nitrogen.za.org/gallery/FontCharMap.jpg

You can switch between the entire unicode range (up to 65532 characters) or just the characters that are supported by this font. And each one is selectable for use in the bitmap font, and colour coded by codepage.

I've written a binary 2d-space partitioning tree algorithm to pack the characters into the texture, so we'll soon see how effective it is... And I hope to take advantage of todays processors by getting the drawing of the font and the generating of the mask happening in another thread..

It's surprisingly hard to design a system like this one where the user needs to quickly preview the current settings, but generating the preview takes time.. You have to find a way around having to recalculate everything every time something changes..

Unfortunately the next version of Font Studio will not be fully backwards compatible, and you wont be able to load fs3 files using the (to be written) Font4.pas unit..

Sly
06-02-2007, 12:38 PM
A very useful feature of AngelCode's BMFont, the font creator that Microsoft provides with the Xbox 360 development kit, and bmfontgen (for use with XNA) is that the user can supply a text file containing all the text that the game will use. The font creator will then only include the characters in the text file. This means that every character included in the font is used at least once and not wasting space on the texture.

Nitrogen
06-02-2007, 12:50 PM
Simple enough to implement, I'll add it in when Microsoft uses FontStudio for it's XBox dev kit :)

LP
06-02-2007, 05:29 PM
I don't get it, what is the use of Unicode in bitmap font renderer? Are you going to render >10000 characters like in Chinese and put all of them on textures? I mean, if specific ANSI charset has 256 characters, this is still "okay" (with larger letters you get 1024x1024 texture or 4+ 256x256 textures), but using Unicode implies you get >256 characters in your bitmap font, which implies that using pre-rendered letters at start is a bad approach anyway. You may get better results rendering the required letters in real-time on some sort of cache - perhaps something similar to what D3DXFont does.

By the way, before releasing first Asphyre 4 snapshot I had thoughts on using your font studio but after making few tests and getting the same pixel and edge artifacts I've had in FontRender back in PowerDraw days, I've had no choice but to work on updated Asphyre FontTool.

Edit: I suggest you test your tool with different font sizes (smaller ones, especially) and different settings first and fix all existing bugs before working on additional features.

For instance, you can start by fixing this:
http://img401.imageshack.us/img401/3079/fontstudiosk1.th.jpg (http://img401.imageshack.us/my.php?image=fontstudiosk1.jpg)

Sly
07-02-2007, 10:29 AM
In my current Xbox 360 project, which is likely to be released in 18 different languages, all user-visible text is stored as UTF-8. We will have at least 3000 Asian characters (Japanese, Chinese at a minimum) pre-rendered on textures. We will be using the feature I mentioned before of only including the charactres that are actually used in the text.

Rendering characters on demand into a cache does not allow very good anti-aliasing, outlining and shadow effects, or special graphic filters to be applied to the bitmap. These effects all take time to render, which is better done as a pre-processing step before it gets into the game.

savage
07-02-2007, 11:12 AM
In my current Xbox 360 project,

Krome's coming soon section hasn't listed any Next Gen games yet. Without risk of losing your job, what is your opinion of which console ( Wii, XB360 or PS3 ) is easiest to develop for?

Nitrogen
07-02-2007, 11:39 AM
I suggest you test your tool with different font sizes (smaller ones, especially) and different settings first and fix all existing bugs before working on additional features.

Agreed. It's actually very simple to fix that, and I should have thought of making it fix it automatically, but I was working on the assumption that the user would like to tweak the font him/herself. Thats what you get when you playtest your own programs! *doh*

Instead of adding new features on top of old code, I'm actually going for a whole rewrite of the entire thing, which will fix and remove all of those types of glitches.


I don't get it, what is the use of Unicode in bitmap font renderer?

If you have an international game you HAVE to use unicode. The one example that really stands out as a good unicode compatible game is Track Mania Nations. People from all round the world play and it can handle Russian, Chinese, Korean chat text ingame. Using, you guessed it, bitmap fonts.

Sly
09-02-2007, 12:37 AM
In my current Xbox 360 project,

Krome's coming soon section hasn't listed any Next Gen games yet. Without risk of losing your job, what is your opinion of which console ( Wii, XB360 or PS3 ) is easiest to develop for?

In order of ease of development:
- Xbox 360. The toolset provided by Microsoft is absolutely brilliant. It's just like debugging on a remote PC.
- Wii. If you have developed for Gamecube, then Wii is pretty much the same. It's an overclocked Gamecube. Same development tools, very similar hardware.
- PS3. If I say what I really think, Sony might sue me for defamation.

Nitrogen
17-02-2007, 04:06 PM
I've been busy with Font Studio...

http://www.nitrogen.za.org/gallery/fontstudio1.jpg

This shot shows the custom-drawn font combobox, which looks just like the professional one seen in applications such as MS Word or Photoshop. It also shows the binary space partitioning algorithm which packs the characters into the texture, and finally it indirectly shows the multithreaded nature of the program. It uses a separate rendering thread to generate the font texture.

LP
17-02-2007, 04:51 PM
Nitrogen, that's a nice job! Does it save the rectangle information for individual letters? Any way to put this information in an XML file?

Nitrogen
17-02-2007, 06:55 PM
Yes. it generates a set of texture coordinates for each character as well as their ABC widths (A being leading space, B being total width, C being trailing space) as defined inside the font file, so you can render them *exactly* how windows renders it!

With the file formats, I'm going to be flexible.. offering JPG and TGA at first with embedded font info, then adding XML and PNG support later.

vgo
17-02-2007, 07:30 PM
I'm using your font generator/library in my engine. It's so good that there's no point to even try to make one myself! :)

Thanks a lot!

Nitrogen
17-02-2007, 07:44 PM
Cool! thats the idea..

But dont get too comfortable with v3, when this version is done you'll have to re-create your fonts but everything else should work mostly the same...

fireton
18-02-2007, 01:49 PM
I've just released version 3.0 of my bitmap font generator: Font Studio.
(http://www.nitrogen.za.org/projectinfo.asp?id=12)

Please take a look at HGE font editor (http://hge.relishgames.com).

Robert Kosek
18-02-2007, 07:39 PM
Please take a look at HGE font editor (http://hge.relishgames.com).Look at what? No screenshots, standalone distribution of the editor, or anything. Nitrogen's work has been around for a long time here, so I don't know what you're getting at. From what little I did manage to find, I saw that Nitrogen's work is better.

Nitrogen
18-02-2007, 09:22 PM
I did take a look at it.. It's got quite a nice custom interface (though I did have some trouble clicking the scrollbars), and seems to be at the same stage of development as my Font Studio v3..

One thing I like is the antialiasing.. I've still got to get that down on my Font Studio...

chronozphere
12-07-2007, 02:45 PM
@Nitrogen. I have a question about the format you save your data in.

In the font4.pas unit i found this datastructure??


type FontInfo = record
A, C: integer;
Wid, Hgt: cardinal;
char: WideChar;
x1,y1,x2,y2: double;
end;


Can you explain what the different fields mean??
I get the (x1,y1,x2,y2) Rectangle on the texture but e.g i can't figure out what A and C contain?
Can you explain that please??

Thanx!

paul_nicholls
13-07-2007, 04:33 AM
@Nitrogen. I have a question about the format you save your data in.

In the font4.pas unit i found this datastructure??


type FontInfo = record
A, C: integer;
Wid, Hgt: cardinal;
char: WideChar;
x1,y1,x2,y2: double;
end;


Can you explain what the different fields mean??
I get the (x1,y1,x2,y2) Rectangle on the texture but e.g i can't figure out what A and C contain?
Can you explain that please??

Thanx!

From one of Nitrogen's posts above:

"Yes. it generates a set of texture coordinates for each character as well as their ABC widths (A being leading space, B being total width, C being trailing space) as defined inside the font file, so you can render them *exactly* how windows renders it!"

cheers,
Paul.

Chebmaster
14-07-2007, 06:22 AM
But how about the kerning?
Does anybody calculate it or retrieve it from the text rendering function?

Because I now make what could be called a built-in analog of this stuff for my engine, developing also the kerning calculation algorithm. It's raw and untested yet, but once it's done I'll post the code.

P.S. I did it before, for my now dead manga scanlation tool.

P.P.S. Kerning is the inter-character distance that considers the shape of characters. Each character have one value for each other character, so generally, kerning is a N * N numeric array. Being the smartass I am, my prog caches it in the grayscale PNGs to avoid repeating the lenghty re-calculation each time program starts up.

P.P.P.S. For anyone interested, the algorithm is this: the text as a single line, with wide spaces between characters, created in GIMP or Photoshop, resulting in an grayscale bitmap, usually somewhere around 6000x20. Al the characters are stored parallelly as a single-line text file (which is also used in GIMP to render the text consistently). When the program starts, it checks if one of these files is newer than the texture file, in this case rebuilding the texture and kerning data by automatically bisecting the single strip source image according the charset text file. The first two characters are always "0"s, for the calibration purpose.

Allows you to use the hand-drawn and hand-retouched fonts (I, actually, have one, I drew it back in 2000).

arthurprs
18-08-2007, 09:51 PM
Nice tool

arthurprs
19-08-2007, 01:03 AM
Nice tool

only too hard to use inside my app ;/

wagenheimer
15-05-2008, 02:55 AM
Is there any example of how to use fonts generated by FontTool 4?

chronozphere
15-05-2008, 06:00 AM
http://www.nitrogen.za.org/projectinfo.asp?id=13

Should work with version 3.0. I assume it also works with 4.0 and up but not sure. You should try that. ;)