Papervision3D: Dynamic TrueType Font Loading

Posted by on December 28, 2008


[View Source Code]

Papervisoin3D’s 3D text is nice, but the font choices are limited unless you want to take the time to implement your own Font3D files. I’ve been working with font parsing for the last month for another project and thought why not create a font parser for Papervision3D?

The TrueType font parsing library came from Alessandro Crugnola. It is part of an ActionScript port of the Java applications typecast. I’m in the process of writing a much leaner font parser that will have support for both TrueType and OpenType fonts.

I did make a small change to the Papervision3D library. Some of the font files do not have a complete character set. This can cause VectorLetter3D to choke.

In org.papervision3d.typography.VectorLetter3D, around line 40 I added:

40
41
42
if (_font.motifs.hasOwnProperty(_char)) {
	createVertices(_font.motifs[_char]);
}

To load a TrueType font simply pass the font data as a ByteArray to the static class Font3DLoader and you get a Font3D object back.

1
var font3D:Font3D = Font3DLoader.load(trueTypeByteArray);

If the font file contains more than one font, the first font is loaded.

10 Comments on Papervision3D: Dynamic TrueType Font Loading

Respond | Trackback

  1. wormik says:

    very cool – thanks for sharing :)

  2. This is wonderful. Thank you!

  3. John Dyer says:

    Great work. This will be very useful!

  4. [...] code that allows you to use truetype fonts without the need of creating Font3D files. Check it out here on James’ [...]

  5. Felipe Lima says:

    Hi! Do you know if there is already any way to do this process for OpenType fonts? I’ve noticed the majority of my fonts are OpenType, so I would appreciate a tool to generate a Font3d from an OpenType font file!
    Thanks!
    Felipe

  6. james says:

    Hi Felipe,

    I currently do not have a way of generating a Font3D file without first converting the font to TrueType.

    FontForge can convert OpenType to TrueType.
    It is a free, open source, font editing tool that runs on Linux, OS X, and Windows.
    Just open the font in FontForge and save it as TrueType.

    http://fontforge.sourceforge.net/

    You can find instructions for batch converting fonts at: http://www.stuermer.ch/blog/convert-otf-to-ttf-font-on-ubuntu.html

    James

  7. ken says:

    during publish in cs3 when use chinese font (size 3MB)truetype font has error ” over time 15 seconds”

  8. [...] think so? Learn how to load TrueType fonts and use them in the Papervision library by reading this tutorial. The article includes demo and the source [...]

  9. Sam says:

    thanks, very nice.
    But how to use it with embed font?

Respond

Comments

Comments: