You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Bruce Robertson <br...@mta.ca> on 2003/02/24 06:57:08 UTC

SVG Font Embedder for Cocoon

[This is an abridged version of a HOWTO posted at the Cocoon Wiki: 
http://wiki.cocoondev.org/Wiki.jsp?page=Embedding_SVG_Fonts] 

*Introduction*

Using server-generated SVG in a multi-lingual or with complex layout 
inevitably leads to frustration over fonts. A map with multi-lingual text 
carefully layed out using the Bitstream Cyberbit font will be riddled 
with 'missing character' squares when rendered on a client's machine 
that lacks Cyberbit. 

The SVG specification does offer a solution to this problem: scalable 
font glyphs can be described within an svg:font element. With these, 
the client renders text using the appropriate SVG glyphs, not relying 
on font descriptions from the client's operating environment. But it 
would be completely impractical to render the entire, e.g., Cyberbit 
font as an SVG font and expect the client machine to upload this with 
each view. What is needed is a mechanism that appends to an SVG document 
only those glyphs necessary for it to be rendered. As it turns out, the 
marvellous Batik SVG Graphics2D environment has just this ability. I've 
tapped into it to make an xslt transformation (extended with xalan/java) 
which takes any SVG document and adds to it the glyphs necessary for 
its viewing. The result is a somewhat heavier document, but one that is 
completely portable. An example: 
http://heml.mta.ca/heml-cocoon/map.svgz?
url=docs/source/heml/newton.xml&mapName=britain&fontName=Melmo 


*Use* 

To use the SVGFontEmbedder, you'll need to ensure that: 

   1. Your Cocoon environment has the Batik jar file. Check WEB-INF/libs 
   for a file called something like batik-all.jar. (I've tested 
   this with Cocoon 2.0.4, which comes with the 1.5b2 Batik code.) 

   2. You can process an xslt file with Xalan. Xalan is the default 
   xslt processor in Cocoon, but some people have patched in support 
   for Saxon because of its superior speed. (It should be noted that, 
   at present, its speed comes at the cost of being able to pass off 
   its elements to java processes as DOM objects, a deal-breaker for me.) 

You'll also need to download two files: 

   1. heml-cocoon.jar from any Heml release v.0_5.4 or greater, found at 
   http://heml.mta.ca/releases 
   2. svgEmbedFonts.xsl, the latest version 
   of which is easiest to aquire at its view cvs page 

Install heml-cocoon.jar in your $COCOON_HOME/WEB-INF/libs directory, and 
put 
svgEmbedFonts.xsl wherever your xsl files usually reside. Emend your 
sitemap to transform your SVG files just before they are serialized as 
svg+xml. (Incidentally, there is no point in using this transformation 
before rasterizing SVG to jpg or png, since your server will have access 
to its own fonts when rasterizing.) For instance, an appropriate part 
of my sitemap looks like this: 

<map:transform src="xslt/util/svgEmbedFonts.xsl"/> 

Once Cocoon is duly restarted, etc., your SVG should now have the 
necessary svg:glyph elements automagically added. 

*Caveats* 

   1. This code will only recognize fonts specified with 
   the font-family="MY_FONT" attribute notation. You can't use 
   style="font-family: MY_FONT" and expect this process to assign the 
   right font to your text. On the positive side, the font-family can 
   be specified on the svg:text element or any of its ancestors, just 
   like in any honest SVG document.   


-- 
Bruce Robertson, 
Dept. of Classics, Mount Allison University
http://heml.mta.ca

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org