org.heml.image.text
Class SvgFontEmbedder

java.lang.Object
  extended by org.heml.image.text.SvgFontEmbedder

public class SvgFontEmbedder
extends Object

Uses the Batik SVGGraphics2D environment to produce an svg:defs element containing the smallest necessary font and glyph definitions. Call registerFont(text, fontName) for each svg:text element in the document, then get the defs with the getEmbeddedFonts() method The web/xslt/util/svgEmbedFonts.xsl file from the Heml project (http://www.heml.org) illustrates how to use this code within a Xalan xslt envrionment to embed fonts in arbitrary SVG documents.

This code has been tested with Batik's 1.5b2 and 1.5b4 releases. Future releases may well place the necessary svg:def element in a different place. This would require a rewrite of this class' registerFont() method.

This class works in the following way. Each call to registerFont() draws a bogus text string on a Batik SVGGraphics2D environment which has been set to use embedded fonts. The getEmbeddedFonts() method copies the svg:def element to which Batik writes its font definitions


Constructor Summary
SvgFontEmbedder()
           
 
Method Summary
 Element getEmbeddedFonts()
           
static void main(String[] args)
          A test of this class.
 void registerFont(String text, String fontName)
          Indicates the use of fontName on the string text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SvgFontEmbedder

public SvgFontEmbedder()
Method Detail

registerFont

public void registerFont(String text,
                         String fontName)
Indicates the use of fontName on the string text

Parameters:
text - the String that will be displayed
fontName - the name of the font that will display the text

getEmbeddedFonts

public Element getEmbeddedFonts()
Returns:
an svg:defs element containing the fonts and glyphs necessary to display the texts which have been specified through sucessive calls to fontName

main

public static void main(String[] args)
A test of this class. Pass in 1) A sample text string, and 2) a font name string. The method will print the corresponding svg:def element to System.out



Copyright © 2003 Bruce Robertson All Rights Reserved.