FontSerialiser

It’ll only serialise those glyphs that have been loaded (i.e. used), so you might need to write some dummy text containing the chars you need before serialising it?

yes this is exactly what we’ve done at work to embed the font we need.
We generate a long string with all unicode characters, that’s really brute force but it works.

BTW any chance to see freetype support anytime in the future?
I’ve seen it’s already used on linux.

[quote]BTW any chance to see freetype support anytime in the future?
I’ve seen it’s already used on linux.[/quote]

How would that be useful on win32/mac?

for loadding TrueType fonts from disk/resources for example… does that make sense?

see that old post for reference:
http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=2678&highlight=freetype

I needed to embed some LCD fonts (again) and the new JUCE has new Typeface classes so the font serializer utility does not work. I wrote my own, with some command line switches and using the new JUCE classes (some more options and error checking).

code (svn)
win32 binary

Hey Atom,
Would you mind sharing a bit more info on how this works. I tried running it in the console and I do not see any generated file. ??? Also, there isn’t much for documentation in your class either. I’m just trying to serialize some fonts for embedding in JUCE 1.5. I’ve read all the posts, used Niall’s serialize (which does generate a file), but you mentioned things changed in newer versions of JUCE (a little more explanation on this would help too), so I am not sure what to do at this point to get it to work.

Thanks,
VK

this is how i serialize a font installed on Windows (Arial)

C:\devel>Fserialize.exe
Fserialize::initialise -f (font file name) -F (font name) [-n (glyph count)]


C:\devel>Fserialize.exe -f arial_serialized.bin -F "Arial" -n 255
Fserialize::serializeFont looking for font in system list [Arial]
Fserialize::serializeFont font found, attempt to create typeface
Fserialize::serializeFont copying glyphs to CustomTypeface
Fserialize::serializeFont typeface created, attempt to write to file, glyphs=255

Fserialize::serializeFont typeface written to file
Fserialize::serializeFont finished

C:\devel>dir arial_serialized.bin
 Volume in drive C is A-DATA SSD
 Volume Serial Number is 02A1-CECD

 Directory of C:\devel

11/29/2009  04:13 AM            23,978 arial_serialized.bin
               1 File(s)         23,978 bytes
               0 Dir(s)  45,172,559,872 bytes free

C:\devel>

a .bin file is created that you can import to Jucer and create a resource from it and create a CustomTypeface from this data later. It’s very simple.

The class itself

  1. reads command line -f -F -n parameters
  2. checks if it can write to the file given at the -f parameter
  3. checks if the font name is not empty (should be quoted in " cause fonts have spaces in the, the same applies to filenames)
  4. then the serializeFont() method kicks in and checks if the given font name exists in the system
  5. If it finds one it takes the number of glyphs specified with the n parameter from the Typeface and writes them to the file.

and that’s it. the previous version posted here did the same thing, it’s just JUCE classes changed and new calls have to be made to serialize a font

Thanks Atom, that makes sense now. Also thanks for the updated serializer. A very helpful tool.

well don’t thank me yet, apparently this is not all. i’ll update that asap. but you need to create all possible variations of each font (italic, bold, italic+bold, plain) and serialize them each, and thhen join them in your app. i’ll try to write something to make this automagic.

i think it’s the perfect job for the Jucer !!

My thoughts exactly. Would also be nice to be able to use it in the Jucer as a Typface once it’s been imported as a resource. Not sure how that would work since the current font selection is based on system fonts.

@ Atom - Thanks for the updated info, that’s good know. I’d like to see what you come up with for it. What’s involved in joining them?

you need to create 4 streams and join them later, i guess a special class/macro/static-function is needed in your application to use all the possible styles of a font. i’ll write that soon and re-write the fserializer, i’ll be needing that anyway.

You can control the font->typeface mapping by overriding LookAndFeel::getTypefaceForFont()

well i re-wrote the font seiralizer and it serializes bold italic bold+italic and plain typefaces into one resource file, however you need to extract those typefaces later, i wrote a small class that does this
http://edoapp.googlecode.com/svn/trunk/Tools/Fserialize/

once created with the binary resource as the parameter you can easily get each typeface, i do this in LookAndFeel class like so:

GekonLookAndFeel::GekonLookAndFeel
{
       sonyTypeface = new FSerializedTypeface (sony_bin, sony_binSize);
}
const Typeface::Ptr GekonLookAndFeel::getTypefaceForFont (const Font &font)
{
	return (sonyTypeface->getTypefaceForFlags (font.getStyleFlags()));
}

i guess i missed the underline typeface, but i never used that.

Hey Atom,
Thanks for the updated info. However, none of the links in these last posts are working any longer. Did you move the files? I’d like to check it out.

Thanks,
vk

sorry fot that, fserialize is here:

http://edoapp.googlecode.com/svn/trunk/Tools/Fserialize/