The Apache FOP Project

The Apache™ Batik Project

SVG Font Converter

The TrueType Font to SVG (ttf2svg) application lets you convert a range of characters from a TrueType Font into the SVG font format.

Running the font converter

If you are using the Batik binary distribution, type the following at the command line:

java -jar batik-ttf2svg.jar OPTIONS

If you are using the Batik source distribution, type the following at the command line:

build ttf2svg OPTIONS

In both cases, the options are the same:

ttf-path[-lrange-begin] [-hrange-end] [-autorange] [-ascii] [-idid] [-ooutput-path] [-testcard]

where:

ttf-path : specifies the TrueType Font file containing the characters to be converted,

-l range-begin -h range-end : specifies the range of characters (by codepoint, in decimal) to be converted,

-autorange : automatically determines the available character range, instead of using the default, ASCII printable characters (ranging from 32 to 126),

-ascii : forces usage of the ASCII character map in the font, instead of the Unicode character map,

-id id : specifies the value for the id attribute of the generated font element,

-o output-path : specifies the pathname of the output SVG document containing the generated SVG font, and

-testcard : specifies that a sequence of SVG text elements should be appended to the output SVG file to test the characters in the SVG font, providing an easy way to validate that generated SVG font visually.

For example:

java -jar batik-ttf2svg.jar /usr/home/myFont.ttf -l 48 -h 57 -id MySVGFont -o mySVGFont.svg -testcard

will convert characters 48 to 57, i.e., '0' to '9', in the myFont.ttf file into their SVG equivalent in the mySVGFont.svg file, appending a test card so that the font can be visualized.

Use cases

The TrueType Font converter application is helpful to be able to embed font definitions in SVG files. This will ensure that the SVG document will look exactly the same on all platform by not relying on system fonts.

Note that users of the tool should make sure that they have the right to embed the font before embedding it in an SVG file and should refer to the font license for information. Note that TrueType Font files contain a flag that defines the “embeddability” of a font and there are tools for checking that flag.