cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Updated: FOP and Embedding Fonts
Date Mon, 02 Oct 2006 17:13:29 GMT
A document has been updated:

http://cocoon.zones.apache.org/daisy/documentation/1225.html

Document ID: 1225
Branch: main
Language: default
Name: FOP and Embedding Fonts (unchanged)
Document Type: Cocoon Document (unchanged)
Updated on: 10/2/06 3:17:15 PM
Updated by: Philippe Laplanche

A new version has been created, state: draft

Parts
=====

Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name:  (unchanged)
Size: 6675 bytes (previous version: 37 bytes)
Content diff:
--- <html><body><p>TODO</p></body></html>
+++ <html>
+++ <body>
+++ 
+++ <h2>FOP and Embedding Fonts</h2>
+++ 
+++ <p>Dynamically generating a PDF file (with embedded fonts) in Cocoon is
+++ basically 8 steps:</p>
+++ 
+++ <ol>
+++ <li>Create the font(s) metric file(s).</li>
+++ <li>Create a custom configuration file for FOP (Cocoons PDF renderer), which
+++ tells it what fonts are available and where to find them.</li>
+++ <li>Create your xml (left as an exercise for the reader ;)</li>
+++ <li>Create your xslt (again, up to you)</li>
+++ <li>In the sitemap, tell the fo2pdf serializer where your custom configuration
+++ file is located.</li>
+++ <li>Add a match for your PDF (I'm sure you can do the rest...).</li>
+++ <li>Start Cocoon.</li>
+++ <li>Request your PDF.</li>
+++ </ol>
+++ 
+++ <p>Easy yeah? OK. Step-by-step...</p>
+++ 
+++ <h3>Create the font(s) metric file(s).</h3>
+++ 
+++ <p>NoteAll java calls have nothing else in the classpath or ext directory. Also,
+++ instructions which have wrapped should be entered as one single instruction.</p>
+++ 
+++ <p>The instruction to generate a font metric file is:</p>
+++ 
+++ <p>Windows:</p>
+++ 
+++ <pre>$ cd %PATH_TO_COCOON%\lib
+++ $ java -cp optional\fop-0.20.4.jar;core\xercesImpl-2.0.0.jar;core\xml-apis.jar \
+++   org.apache.fop.fonts.apps.TTFReader \
+++   %PATH_TO_FONT% %PATH_TO_METRICS_DIR%\%FONT_NAME%.xml
+++             </pre>
+++ 
+++ <p>Unix:</p>
+++ 
+++ <pre>$ cd $PATH_TO_COCOON/lib
+++ $ java -cp optional/fop-0.20.4.jar;core/xercesImpl-2.0.0.jar;core/xml-apis.jar \
+++   org.apache.fop.fonts.apps.TTFReader \
+++   $PATH_TO_FONT  $PATH_TO_METRICS_DIR/$FONT_NAME.xml
+++             </pre>
+++ 
+++ <h4>Example: Create the Arial metric files.</h4>
+++ 
+++ <p>For the sake of the rest of this tutorial, I'm going to be using Windows NT,
+++ converting the Arial family of fonts and storing the metrics files in the
+++ location <tt>D:\fop-fonts</tt>.</p>
+++ 
+++ <p>My TTF files are located in <tt>C:\WINNT\Fonts</tt>. If you are running
on
+++ Linux/Windows 9x/ME/2000/XP please alter as appropriate.</p>
+++ 
+++ <p>NoteI normally use Cygwin; a Unix shell environment which runs on Windows. If
+++ I slip some Unix into here, please excuse me (although I'd welcome the
+++ feedback...).</p>
+++ 
+++ <p>Start a command session (as appropriate to your env), then change to Cocoon
+++ libs directory.</p>
+++ 
+++ <pre>$ cd %PATH_TO_COCOON%\lib</pre>
+++ 
+++ <p>Create the metrics directory (D:\fop-fonts)</p>
+++ 
+++ <pre>$ mkdir d:\fop-fonts</pre>
+++ 
+++ <p>Create the metrics for arial.ttf, arialb.ttf, arialbi.ttf, ariali.ttf</p>
+++ 
+++ <pre>$ java -cp optional\fop-0.20.4.jar;core\xercesImpl-2.0.0.jar;core\xml-apis.jar
\
+++   org.apache.fop.fonts.apps.TTFReader \
+++   C:\WINNT\Fonts\arial.ttf D:\fop-fonts\arial.ttf.xml
+++ $ java -cp optional\fop-0.20.4.jar;core\xercesImpl-2.0.0.jar;core\xml-apis.jar \
+++   org.apache.fop.fonts.apps.TTFReader \
+++   C:\WINNT\Fonts\arialb.ttf  D:\fop-fonts\arialb.ttf.xml
+++ $ java -cp optional\fop-0.20.4.jar;core\xercesImpl-2.0.0.jar;core\xml-apis.jar \
+++   org.apache.fop.fonts.apps.TTFReader \
+++   C:\WINNT\Fonts\arialbi.ttf D:\fop-fonts\arialbi.ttf.xml
+++ $ java -cp optional\fop-0.20.4.jar;core\xercesImpl-2.0.0.jar;core\xml-apis.jar \
+++   org.apache.fop.fonts.apps.TTFReader \
+++   C:\WINNT\Fonts\ariali.ttf  D:\fop-fonts\ariali.ttf.xml
+++ </pre>
+++ 
+++ <p>If everything went to plan, you should now have the metrics for the Arial
+++ fonts in your fop-fonts directory.</p>
+++ 
+++ <h3>Create a custom configuration file</h3>
+++ 
+++ <p>I normally store this with the metrics file in the fop-fonts directory
+++ (called config.xml (ensure there's not a font called config ;)) although I fully
+++ qualify all the filenames just incase I move it ;)</p>
+++ 
+++ <p>I also find it useful to retain the <tt>.ttf</tt> as it is also possible
to
+++ add other types of fonts (if you want to read the FOP docs) and the
+++ <tt>.ttf</tt> tells me where to locate the font.</p>
+++ 
+++ <pre>&lt;configuration&gt;
+++   &lt;fonts&gt;
+++     &lt;font metrics-file="D:/fop-fonts/arial.ttf.xml" 
+++           kerning="yes" embed-file="C:/WINNT/Fonts/arial.ttf"&gt;
+++       &lt;font-triplet name="Arial" style="normal" weight="normal"/&gt;
+++       &lt;font-triplet name="ArialMT" style="normal" weight="normal"/&gt;
+++     &lt;/font&gt;
+++     &lt;font metrics-file="D:/fop-fonts/arialb.ttf.xml" 
+++           kerning="yes" embed-file="C:/WINNT/Fonts/arialb.ttf"&gt;
+++       &lt;font-triplet name="Arial" style="normal" weight="bold"/&gt;
+++       &lt;font-triplet name="ArialMT" style="normal" weight="bold"/&gt;
+++     &lt;/font&gt;
+++     &lt;font metrics-file="D:/fop-fonts/arialbi.ttf.xml"
+++           kerning="yes" embed-file="C:/WINNT/Fonts/arialbi.ttf"&gt;
+++       &lt;font-triplet name="Arial" style="italic" weight="bold"/&gt;
+++       &lt;font-triplet name="ArialMT" style="italic" weight="bold"/&gt;
+++     &lt;/font&gt;
+++     &lt;font metrics-file="D:/fop-fonts/ariali.ttf.xml"
+++           kerning="yes" embed-file="C:/WINNT/Fonts/ariali.ttf"&gt;
+++       &lt;font-triplet name="Arial" style="italic" weight="normal"/&gt;
+++       &lt;font-triplet name="ArialMT" style="italic" weight="normal"/&gt;
+++     &lt;/font&gt;
+++   &lt;/fonts&gt;
+++ &lt;/configuration&gt;
+++ </pre>
+++ 
+++ <p>There are other things you can add to this file, look at the FOP
+++ documentation for further information.</p>
+++ 
+++ <p>If you are wondering why each font has been added twice, it has to do with
+++ the font lookup. If the font is specified as 'Arial' and the weight is 'bold'
+++ then FOP searches for a matching <tt>&lt;font-triplet/&gt;</tt>, then
uses the
+++ parent <tt>&lt;font/&gt;</tt> tag to get the actual font information.
If the
+++ font is specified as 'ArialMT' (it's proper name) it will still work. Think of
+++ it as an alias capability.</p>
+++ 
+++ <h3>Sitemap and fo2pdf serializer</h3>
+++ 
+++ <p>All that remains is to tell the serializer, where your config file is
+++ located. Find the line in your sitemap which looks like:</p>
+++ 
+++ <pre>&lt;map:serializer name="fo2pdf"
+++                 src="org.apache.cocoon.serialization.FOPSerializer"
+++                 mime-type="application/pdf"/&gt;
+++ </pre>
+++ 
+++ <p>and replace it with:</p>
+++ 
+++ <pre>&lt;map:serializer name="fo2pdf"
+++                 src="org.apache.cocoon.serialization.FOPSerializer"
+++                 mime-type="application/pdf"&gt;
+++   &lt;user-config&gt;D:/fop-fonts/config.xml&lt;/user-config&gt;
+++ &lt;/map:serializer&gt;
+++ </pre>
+++ 
+++ <p>You can use absolute paths like above or relative ones. The relative paths
+++ will be resolved to the sitemap's directory. Furthermore it's possible to use
+++ Cocoon protocols like <tt>cocoon://</tt> or <tt>context://</tt>.</p>
+++ 
+++ <p>NoteIn an older version of Cocoon (2.0.3 and earlier) the config file
+++ location was specified by using an attribute 'src' on &lt;user-config/&gt;. If
+++ you still have this in your sitemap, it's recommended to change it to the above
+++ provided configuration.</p>
+++ 
+++ <p>And that's it. Oh, one final thing to remember: the cache isn't aware of your
+++ config file; <strong>always</strong> delete your cache-dir after modifying
your
+++ config file.</p>
+++ 
+++ </body>
+++ </html>


Mime
View raw message