When special characters like arrows, delta-signs etc. are used that are
not part of the ISO Latin 1 Charater set (see http://www.htmlhelp.com/
reference/charset/latin1.gif), then the FOP engine only shows the #
character instead of the correct character. If the symbol is marked
using the <fo:inline font-family="Symbol">yourchar</fo:inline> FO-
tag, it works, but by default a font like Arial or Helvetica is used and
this font does not contain the special characters not part of the Latin 1
set.
How would it be possible to search for all non-Latin1 characters and
use the above FO-tag to mark them? This way a correct FO-document
could be produced containing all special symbols/characters within a
fo:inline tag...
More information about this:
From the Apache FOP FAQ (http://xmlgraphics.apache.org/fop/
faq.html#pdf-characters):
6.2. Some characters are not displayed, or displayed incorrectly, or
displayed as “#”.
^
This usually means the selected font doesn't have a glyph for the
character.
The standard text fonts supplied with Acrobat Reader have mostly
glyphs for characters from the ISO Latin 1 character set. For a variety of
reasons, even those are not completely guaranteed to work, for
example you can't use the fi ligature from the standard serif font.
Check the overview for the default PDF fonts.
If you use your own fonts, the font must have a glyph for the desired
character. Furthermore the font must be available on the machine
where the PDF is viewed or it must have been embedded in the PDF
file. See embedding fonts.
For most symbols, it is better to select the symbol font explicitely, for
example in order to get the symbol for the mathematical empty set,
write:
<fo:inline font-family="Symbol">∅</fo:inline>
The "#" shows up if the selected font does not define a glyph for the
required character, for example if you try:
<fo:inline font-family="Helvetica">∅</fo:inline>
Hier wäre eine Beschreibung von Marc Vorreiter:
Anfang der weitergeleiteten E-Mail:
Hallo Joel,
wie versprochen hier eine kleine Anleitung zum Einbinden von Schriften in FOP
1. zu jeder Schrift-Datei ein Font-Metric-File erstellen
2. FOP-Config anpassen
3. beim PDF-Erzeugen die Config-Datei mit einbinden
Beispiel für die Schrift CAMBRIA (eine der neuen Schriften aus Windows Vista)
Die Schriften die bei Windows Vista neu dabei sind haben wirklich einen sehr großen Zeichenumfang und das auch in bold und italic (keineswegs selbstverständlich bei UTF8 Schriften).
Um ohne Vista an diese Schriften zu kommen kann man sich einfach den kostenlosen Microsoft Powerpoint Viewer 2007 runterladen und installieren.
1. Erzeugen eines Font-Metric-File
Die Beschreibung auf der FOP-Webseite (http://xmlgraphics.apache.org/fop/0.95/fonts.html) funktionierte bei mir nicht auf Anhieb weil ein paar libraries fehlten.
Ich bin schließlich bei folgendem Aufruf gelandet:
java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar;lib\xercesImpl-2.7.1.jar;lib\xml-apis-1.3.02.jar;lib\xalan-2.7.0.jar;lib\batik-all-1.7.jar;lib\xmlgraphics-commons-1.3.1.jar;lib\serializer-2.7.0.jar org.apache.fop.fonts.apps.TTFReader c:\windows\fonts\CAMBRIAB.ttf CAMBRIAB.xml
Eventuell muss man da je nach FOP-Version die Versionsnummern der libraries anpassen.
Ein kleine Besonderheit gibt es, wenn man keine ttf sondern eine ttc (Font-Collection) hat. Dann muss man beim Erstellen des Metric-Files folgenden Parameter hinzufügen: -ttcname "Cambria". Dieser gibt an welche Schrift der Schriftsammlung gemeint ist. Das ist aber auf der oben genannten Webseite ganz gut beschrieben.
2. Anpassen der FOP-Config
Eintragen der Schriften in der FOP-Config (fop/conf/fop.xconf)
<fonts>
<font metrics-url="CAMBRIA.xml" kerning="yes" embed-url="CAMBRIA.ttc">
<font-triplet name="Cambria" style="normal" weight="normal" />
</font>
<font metrics-url="CAMBRIAB.xml" kerning="yes" embed-url="CAMBRIAB.ttf">
<font-triplet name="Cambria" style="normal" weight="bold" />
</font>
<font metrics-url="CAMBRIAI.xml" kerning="yes" embed-url="CAMBRIAI.ttf">
<font-triplet name="Cambria" style="italic" weight="normal" />
</font>
<font metrics-url="CAMBRIAZ.xml" kerning="yes" embed-url="CAMBRIAZ.ttf">
<font-triplet name="Cambria" style="italic" weight="bold" />
</font>
</fonts>
hier die Dateien ohne weitere Pfadangaben da ich die Dateien direkt in den FOP-Ordner gepackt habe
Benutzen der Schrift in xml-fo
<fo:block font-family="Cambria">
3. Aufruf von FOP mit config
beim Aufruf von FOP die Config-Datei einbinden
fop -c conf/fop.xconf test.fo test.pdf
Bei mir kam es dabei zunächst zu einem Fehler weil Java nicht genügend Speicher zur Verfügung stand.
Deshalb musste ich bei mir eine kleine Erweiterung in der Datei fop.bat beim java-Aufruf vornehmen:
"%JAVACMD%" -Xmx1024m %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%