cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jasha Joachimsthal" <j.joachimst...@hippo.nl>
Subject RE: Font problem using SVG text in PDFs
Date Mon, 05 Mar 2007 15:37:10 GMT
Hi Andrew,

It's a bit a PITA but you can add fonts to your PDF. I hope it works for
your SVG too. The info below came from
http://xmlgraphics.apache.org/fop/0.20.5/fonts.html and
http://cocoon.apache.org/2.1/userdocs/pdf-serializer.html 

 

If you want to use a specific fonts:

    * the font has to be present on the file system of the server;
    * all used variants (normal, bold, italic, bolditalic) are available
as seperate font. They cannot be simulated like in a text editor!

As an example Arial is used (sorry, bit lazy with copy-paste).

First you have to extract the fonts to xml files. You have to repeat
this for every variant. To do this, you need the jars of fop,
xercexImpl, and xml-apis that come with Cocoon (below the standard
Cocoon 2.1.8 is used).

C:\projects\COCOON_2_1_8\lib>java -cp
optional\fop-0.20.5.jar;endorsed\xercesImpl-2.7.1.jar;endorsed\xml-apis-
1.3.02.jar
 org.apache.fop.fonts.apps.TTFReader c:\windows\fonts\arial.ttf
c:\hippo\fop-fonts\arial.ttf.xml TTF Reader v1.1.1

Repeat this for arialbd (bold), arialbi (bolditalics) and ariali
(italics) and be sure to change the destination xml filename. Create a
folder named fop-fonts and move the font xml files into that folder.
Then create a file called fop-fonts.xml with these contents. Note the
difference between the uri's in metrics-file and embed-file.

<configuration>
  <fonts>
    <font metrics-file="file:///C:/fop-fonts/arial.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIAL.TTF">
      <font-triplet name="Arial" style="normal" weight="normal"/>
    </font>
    <font metrics-file="file:///C:/fop-fonts/ariali.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIALI.TTF">
      <font-triplet name="Arial" style="italic" weight="normal"/>
    </font>
    <font metrics-file="file:///C:/fop-fonts/arialbd.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIALBD.TTF">
      <font-triplet name="Arial" style="normal" weight="bold"/>
    </font>
    <font metrics-file="file:///C:/fop-fonts/arialbi.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIALBI.TTF">
      <font-triplet name="Arial" style="italic" weight="bold"/>
    </font>
  </fonts>
</configuration>

The last step is to reference to this file from Cocoon.

<map:serializer name="fo2pdf"
       src="org.apache.cocoon.serialization.FOPSerializer"
       mime-type="application/pdf"
       logger="sitemap.serialization.FOPSerializer">
    <user-config>cocoon:/fop/fop-fonts.xml</user-config>
  </map:serializer>

Although the location of the config file can be referenced using the
cocoon protocol, its contents must contain absolute paths on the
filesystem.

Cocoon is now ready to embed fonts into the PDF.

Regards,

Jasha Joachimsthal

Hippo
Oosteinde 11
1017 WT Amsterdam
The Netherlands
+31 (0)20 5224466 

www.hippo.nl 

> -----Original Message-----
> From: Andrew Stevens [mailto:ats37@hotmail.com] 
> Sent: maandag 5 maart 2007 15:57
> To: users@cocoon.apache.org
> Subject: Font problem using SVG text in PDFs
> 
> Can anyone help with this, or point me to a better place to ask?
> 
> I'm generating some PDFs using the FOP block in Cocoon 2.1.7. 
>  These include a company logo, which is done using an SVG 
> file that is copied into a fo:instream-foreign-object node by 
> the XSL (the SVG file is passed into the XSL as a 
> map:aggregate part).  The graphical part of the logo is fine, 
> but I'm having a few problems getting the text part to 
> display properly.
> 
> The text is in Times, which should be available in any viewer 
> as it's one of the base 14 fonts mandated by the PDF spec.  
> The relevant SVG is <svg:text xml:space="preserve" 
> style="font-size:22px;font-style:normal;font-weight:normal;fil
> l:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-lin
> ecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:T
> imes,serif;" 
> x="0.79575568" y="18.302387" id="text1871">OURNAMEHERE</svg:text>
> Running on a Windows-based server this displays fine, the 
> logo text appears in Times as expected.  However, when 
> deployed to our Solaris-based servers (which will be the 
> production environment) the logo text appears in a sans-serif 
> font - I assume this is Courier, which appears to be the 
> default font according to the Batik docs.  I've tried many 
> variations and combinations of the font-family value, 
> Times/TimesNewRoman/Times New Roman/serif, on the svg:text 
> node and/or a nested tspan element (where Inkscape originally 
> had it), but all to no avail.
> 
> The FOP documentation states "If possible, Batik will use 
> normal PDF text when inserting text. It does this by checking 
> if the text can be drawn normally and the font is supported." 
> But it doesn't really say just what "supported" means; I 
> would have hoped that the base 14 fonts were always 
> supported, but it appears this isn't the case.  We're using 
> the JPA library on the Solaris boxes as they're headless and 
> don't have X windows installed, and
> java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().get
> AvailableFontFamilyNames()
> only returns a handful of fonts (various Lucida variants and 
> a few generic default ones like "Serif"); on the Windows box 
> this also has the various standard Windows fonts, in 
> particular including "Times New Roman".  So I tried embedding 
> the Windows server's times.ttf font in the PDF, according to 
> the instructions in the FOP documentation, but even that 
> makes no difference.
> 
> Before I start trying to convert Times to an SVG font, or the 
> text to a series of paths, I thought I'd ask whether anyone 
> else here has had similar problems, and how they got around 
> them?  Or would I be better off asking on the FOP and/or Batik lists?
> 
> 
> Andrew.
> --
> http://pseudoq.sourceforge.net/  Open source java Sudoku application
> 
> _________________________________________________________________
> Find a local pizza place, movie theater, and more....then map 
> the best route! 
> http://maps.live.com/?icid=hmtag1&FORM=MGAC01
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 

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


Mime
View raw message