embedding fonts in PDF output

Here should go questions about transforming XML with XSLT and FOP.
catterall
Posts: 51
Joined: Sat Jan 24, 2004 12:10 am
Location: Oaxaca, Mexico
Contact:

embedding fonts in PDF output

Post by catterall » Thu Jan 26, 2006 11:01 pm

I would like to create PDF output with embedded fonts (specifically Lucida Grande) Is there any way I can do this with FOP (or XEP)?

george
Site Admin
Posts: 2102
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Thu Jan 26, 2006 11:07 pm

Hi Ron,

I think we have an article about how to do that with FOP on the documentation page:
http://www.oxygenxml.com/documentation.html
Check the How to Add a Font to the <oXygen/> Built-in FOP article:
http://www.oxygenxml.com/doc/addFontToFOP.pdf

Best Regards,
George

catterall
Posts: 51
Joined: Sat Jan 24, 2004 12:10 am
Location: Oaxaca, Mexico
Contact:

Post by catterall » Fri Jan 27, 2006 4:17 am

Thanks George, I have a ttf of LucidaGrande in Open Office, I'll have a go tomorrow.

Will this work with XEP as well? (If I have selected XEP in place of FOP in preferences)?

Ron

dnedrow
Posts: 60
Joined: Wed Jan 28, 2004 10:51 pm

Post by dnedrow » Fri Jan 27, 2006 6:22 am

catterall wrote:Will this work with XEP as well? (If I have selected XEP in place of FOP in preferences)?
Ron,

I believe font embedding/subsetting is configured in the xep.xml file. Take a look at section 2.4.1.1 of the XEP 4.x Reference.

-David

catterall
Posts: 51
Joined: Sat Jan 24, 2004 12:10 am
Location: Oaxaca, Mexico
Contact:

Post by catterall » Fri Jan 27, 2006 5:17 pm

David - thanks for the ref to the XEP manal, I'll try that when I get the fop working

George -back to embedding fonts in fop

I tried following the 'How To' you pointed out and get a fail: (see fail message at bottom)

MacOS X 10.3.9 G4

dainzu:/~ ron$ cd /Library/Fonts

dainzu:/Library/Fonts ron$ ls -l
total 26864
-rwxrwxrwx 1 root admin 534828 17 Sep 2003 AmericanTypewriter.dfont
-rwxrwxrwx 1 root admin 333686 17 Sep 2003 Apple Chancery.dfont
-rwxrwxrwx 1 root admin 190500 17 Sep 2003 Apple Symbols.ttf
.
.
-rwxrwxrwx 1 root admin 1145248 25 Jan 2005 LucidaGrande.ttf
-rwxrwxrwx 1 root admin 1139952 25 Jan 2005 LucidaGrandeBold.ttf
.
.
-rwxrwxrwx 1 root admin 524806 17 Sep 2003 Zapfino.dfont
-rwxrwxrwx 1 root admin 10668 12 Nov 2004 fonts.cache-1

dainzu:/~ ron$ cd /Applications/Utilities/oxygen/oxygen\ 7.0

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 root# ls -l Oxygen.app/Contents/Resources
total 1192
-rw-r--r-- 1 ron admin 49151 11 May 2005 Oxygen.icns
-rw-r--r-- 1 ron admin 51451 20 Dec 03:40 OxygenCSS.icns
-rw-r--r-- 1 ron admin 41434 11 May 2005 OxygenDTD.icns
-rw-r--r-- 1 ron admin 53708 24 Aug 06:11 OxygenNRL.icns
-rw-r--r-- 1 ron admin 53845 24 Aug 06:11 OxygenRNC.icns
-rw-r--r-- 1 ron admin 53925 24 Aug 06:11 OxygenRNG.icns
-rw-r--r-- 1 ron admin 53821 24 Aug 06:11 OxygenSCH.icns
-rw-r--r-- 1 ron admin 52124 11 May 2005 OxygenWSDL.icns
-rw-r--r-- 1 ron admin 41625 11 May 2005 OxygenXML.icns
-rw-r--r-- 1 ron admin 41625 24 Aug 06:11 OxygenXQUERY.icns
-rw-r--r-- 1 ron admin 41611 11 May 2005 OxygenXSD.icns
-rw-r--r-- 1 ron admin 41274 11 May 2005 OxygenXSL.icns

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ mkdir Oxygen.app/Contents/Resources/Java

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 root# ls -ld Oxygen.app/Contents/Resources/Java
drwxr-xr-x 2 root ron 68 27 Jan 08:03 Oxygen.app/Contents/Resources/Java

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ which java
/usr/bin/java

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ cat ttfConvert.sh
#!/bin/sh
export LIB=oxygen.app/Contents/Resources/Java
export CMD="java -cp $LIB/fop.jar:$LIB/avalon-framework.jar:$LIB/xml-apis.jar:"
export CMD="$CMD$LIB/xercesImpl.jar:$LIB/xalanOxygen.zip org.apache.fop.fonts.apps.TTFReader"
export FONT_DIR='/Library/Fonts'
$CMD $FONT_DIR/LucidaGrande.ttf LucidaGrande.xml
$CMD $FONT_DIR/LucidaGrandeBold.ttf LucidaGrandeBold.xml

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ cat fopConfiguration.xml
<configuration>
<fonts>
<font metrics-file="LucidaGrande.xml" kerning="yes" embed-file="file:/Library/Fonts/LucidaGrande.ttf">
<font-triplet name="LucidaGrande" style="normal" weight="normal" />
</font>
<font metrics-file="LucidaGrandeBold.xml" kerning="yes" embed-file="file:/Library/Fonts/LucidaGrandeBold.ttf">
<font-triplet name="LucidaGrandeBold" style="normal" weight="bold" />
</font>
</fonts>
</configuration>

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ sh ttfConvert.sh
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fop/fonts/apps/TTFReader
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fop/fonts/apps/TTFReader

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Fri Jan 27, 2006 6:16 pm

Hello Ron,
catterall wrote:dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ mkdir Oxygen.app/Contents/Resources/Java

...

dainzu:/Applications/Utilities/oxygen/oxygen 7.0 ron$ cat ttfConvert.sh
#!/bin/sh
export LIB=oxygen.app/Contents/Resources/Java
export CMD="java -cp $LIB/fop.jar:$LIB/avalon-framework.jar:$LIB/xml-apis.jar:"
export CMD="$CMD:$LIB/xercesImpl.jar:$LIB/xalanOxygen.zip org.apache.fop.fonts.apps.TTFReader"
The LIB variable must contain the path to the directory containing the files fop.jar, avalon-framework.jar, etc, that is the lib folder sibling of oxygen.app. You should not create it yourself with mkdir. Please use in ttfConvert.sh:

Code: Select all

export LIB=lib
just like in the Windows and Linux versions of the file. The lib directory was moved out of oxygen.app in a previous version but the LIB variable remained the same in the article. We will correct it.

Regards,
Sorin

catterall
Posts: 51
Joined: Sat Jan 24, 2004 12:10 am
Location: Oaxaca, Mexico
Contact:

Post by catterall » Fri Jan 27, 2006 11:09 pm

Tried that with ttfConvert.sh -

dainzu:/Applications/Utilities/oxygen/6.2/oxygen ron$ cat ttfConvert.sh
#!/bin/sh
export LIB=lib
export CMD="java -cp $LIB/fop.jar:$LIB/avalon-framework.jar:$LIB/xml-apis.jar:"
export CMD="$CMD$LIB/xercesImpl.jar:$LIB/xalanOxygen.zip org.apache.fop.fonts.apps.TTFReader"
export FONT_DIR='/Library/Fonts'
$CMD $FONT_DIR/LucidaGrande.ttf LucidaGrande.xml
$CMD $FONT_DIR/LucidaGrandeBold.ttf LucidaGrandeBold.xml

dainzu:/Applications/Utilities/oxygen/6.2/oxygen ron$

all I get now is -

dainzu:/Applications/Utilities/oxygen/6.2/oxygen ron$ sh ttfConvert.sh
TTF Reader v1.1.1

Reading /Library/Fonts/LucidaGrande.ttf...

Number of glyphs in font: 2826
Unicode cmap table not present
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at org.apache.fop.fonts.TTFFile.createCMaps(TTFFile.java:449)
at org.apache.fop.fonts.TTFFile.readFont(TTFFile.java:439)
at org.apache.fop.fonts.apps.TTFReader.loadTTF(TTFReader.java:222)
at org.apache.fop.fonts.apps.TTFReader.main(TTFReader.java:184)
TTF Reader v1.1.1

Reading /Library/Fonts/LucidaGrandeBold.ttf...

Number of glyphs in font: 2826
Unicode cmap table not present
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at org.apache.fop.fonts.TTFFile.createCMaps(TTFFile.java:449)
at org.apache.fop.fonts.TTFFile.readFont(TTFFile.java:439)
at org.apache.fop.fonts.apps.TTFReader.loadTTF(TTFReader.java:222)
at org.apache.fop.fonts.apps.TTFReader.main(TTFReader.java:184)
dainzu:/Applications/Utilities/oxygen/6.2/oxygen ron$

and the files LucidaGrande.xml and LucidaGrandeBold.xml are not created

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Mon Jan 30, 2006 7:08 pm

Hello Ron,

I cannot find the files LucidaGrande.ttf and LucidaGrandeBold.ttf in the font directory of Windows or Mac OS. I think they are not standard fonts. In order to try to see what is wrong please send the two .ttf files to support at oxygenxml dot com.

Regards,
Sorin

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Tue Jan 31, 2006 5:38 pm

Hello,

Thank you for the files. As you discovered and told us in an email the TrueType font files that you are trying to configure to Apache FOP for inclusion into a generated PDF document don't include a character map for mapping the characters of the font to Unicode, which the TTF reader embedded in FOP requires. The same script works fine for Unicode enabled TrueType fonts, for example Arial Unicode. There are tools for converting an existing character map table but not for creating such a table. I think you will have to use Unicode enabled fonts with Apache FOP.

I hope that helps,
Sorin

thesaint
Posts: 3
Joined: Thu Mar 01, 2007 8:59 pm
Location: Hannover, Germany

Converting Mac fonts

Post by thesaint » Sun Apr 15, 2007 10:16 am

I found a way to "fix" Mac fonts, that often are bundled in resource or .dfont files or don't have the correct encoding. You need two programs: Fondu and FontForge, both can be installed via Fink (http://fink.sourceforge.net). And this is how it works:

Extract the Font on the command line with fondu (Fonts that are .dfont bundles or resource bundles need extraction, fonts with the .ttf suffix don't need this step):

Code: Select all

fondu path/to/font

Fondu will extract the ttf files from the font

Try extracting the metrics. if you get the following error messages:

Code: Select all

Unicode cmap table not present
Unsupported format: Aborting
you must reencode the font with fontforge:

Start x11 and fontforge. Open the ttf file.
Select "Encoding -> Reencode -> Windows Latin (ANSI)".
Select "File -> Generate Fonts" and save the font as ttf or type1 font.

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Converting Mac fonts

Post by sorin_ristache » Mon Apr 16, 2007 11:14 am

thesaint wrote:Select "Encoding -> Reencode -> Windows Latin (ANSI)".
What happens with the characters that are not included in the Windows Latin (that is CP-1252) encoding if the font contains such characters?


Regards,
Sorin

Post Reply