7 kwietnia 2011

FOP i fonty

Aby użyć dodatkowych fontów w Apache FOP, w pliku konfiguracyjnym w sekcji <fonts>, należy umieścić odpowiednie wpisy. Poniżej zamieszczam prosty skrypt, który generuje nam te wpisy. Używam czcionki DejaVu ponieważ jest "otwarta" i zawiera znaki Unicode.
#!/bin/bash

FOP="/home/tools/fop/"
INCLUD="${FOP}build/fop.jar:${FOP}lib/avalon-framework.jar:${FOP}lib/commons-logging.jar:${FOP}lib/commons-io.jar:${FOP}lib/xmlgraphics-commons.jar"

for font in `find /home/tools/fonts -name "*.ttf"`;do
    NAME=${font%%.*}
    java -cp "${INCLUD}" org.apache.fop.fonts.apps.TTFReader "${font}" "${NAME}.xml"
done

for FONT in `find /home/tools/fonts -name "*.ttf" | sort`;do
    NAME=${FONT%%.*}
    FILE=`basename ${FONT}`

    NAME2=${FILE%%.*}

    echo "<font metrics-url=\"${NAME}.xml\" kerning=\"yes\" embed-url=\"${FONT}\">"

    STYLE="normal"
    WEIGHT="normal"

    if echo ${NAME2} | grep -qi oblique;then
        NAME2=`echo ${NAME2} | sed -re 's/\-?oblique//i'`
        STYLE="oblique"
    fi

    if echo ${NAME2} | grep -qi italic;then
        NAME2=`echo ${NAME2} | sed -re 's/\-?italic//i'`
        STYLE="italic"
    fi


    if echo ${NAME2} | grep -qi bold;then
        NAME2=`echo ${NAME2} | sed -re 's/\-?bold//i'`
        WEIGHT="bold"
    fi

    echo "      <font-triplet name=\"${NAME2}\" style=\"${STYLE}\" weight=\"${WEIGHT}\"/>"
    echo "</font>"

done
Zawartość katalogu /home/tools/fonts przed uruchomieniem skryptu:
DejaVuSans-Bold.ttf
DejaVuSans-BoldOblique.ttf
DejaVuSans-ExtraLight.ttf
DejaVuSans-Oblique.ttf
DejaVuSans.ttf
DejaVuSansCondensed-Bold.ttf
DejaVuSansCondensed-BoldOblique.ttf
DejaVuSansCondensed-Oblique.ttf
DejaVuSansCondensed.ttf
DejaVuSansMono-Bold.ttf
DejaVuSansMono-BoldOblique.ttf
DejaVuSansMono-Oblique.ttf
DejaVuSansMono.ttf
DejaVuSerif-Bold.ttf
DejaVuSerif-BoldItalic.ttf
DejaVuSerif-Italic.ttf
DejaVuSerif.ttf
DejaVuSerifCondensed-Bold.ttf
DejaVuSerifCondensed-BoldItalic.ttf
DejaVuSerifCondensed-Italic.ttf
DejaVuSerifCondensed.ttf
Poniżej rezultat uruchomienia skryptu:
<font metrics-url="/home/tools/fonts/DejaVuSans-Bold.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSans-Bold.ttf">
        <font-triplet name="DejaVuSans" style="normal" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSans-BoldOblique.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSans-BoldOblique.ttf">
        <font-triplet name="DejaVuSans" style="oblique" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSans-ExtraLight.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSans-ExtraLight.ttf">
        <font-triplet name="DejaVuSans-ExtraLight" style="normal" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSans-Oblique.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSans-Oblique.ttf">
        <font-triplet name="DejaVuSans" style="oblique" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSans.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSans.ttf">
        <font-triplet name="DejaVuSans" style="normal" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansCondensed-Bold.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansCondensed-Bold.ttf">
        <font-triplet name="DejaVuSansCondensed" style="normal" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansCondensed-BoldOblique.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansCondensed-BoldOblique.ttf">
        <font-triplet name="DejaVuSansCondensed" style="oblique" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansCondensed-Oblique.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansCondensed-Oblique.ttf">
        <font-triplet name="DejaVuSansCondensed" style="oblique" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansCondensed.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansCondensed.ttf">
        <font-triplet name="DejaVuSansCondensed" style="normal" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansMono-Bold.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansMono-Bold.ttf">
        <font-triplet name="DejaVuSansMono" style="normal" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansMono-BoldOblique.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansMono-BoldOblique.ttf">
        <font-triplet name="DejaVuSansMono" style="oblique" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansMono-Oblique.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansMono-Oblique.ttf">
        <font-triplet name="DejaVuSansMono" style="oblique" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSansMono.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSansMono.ttf">
        <font-triplet name="DejaVuSansMono" style="normal" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerif-Bold.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerif-Bold.ttf">
        <font-triplet name="DejaVuSerif" style="normal" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerif-BoldItalic.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerif-BoldItalic.ttf">
        <font-triplet name="DejaVuSerif" style="italic" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerif-Italic.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerif-Italic.ttf">
        <font-triplet name="DejaVuSerif" style="italic" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerif.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerif.ttf">
        <font-triplet name="DejaVuSerif" style="normal" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerifCondensed-Bold.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerifCondensed-Bold.ttf">
        <font-triplet name="DejaVuSerifCondensed" style="normal" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerifCondensed-BoldItalic.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerifCondensed-BoldItalic.ttf">
        <font-triplet name="DejaVuSerifCondensed" style="italic" weight="bold"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerifCondensed-Italic.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerifCondensed-Italic.ttf">
        <font-triplet name="DejaVuSerifCondensed" style="italic" weight="normal"/>
</font>
<font metrics-url="/home/tools/fonts/DejaVuSerifCondensed.xml" kerning="yes" embed-url="/home/tools/fonts/DejaVuSerifCondensed.ttf">
        <font-triplet name="DejaVuSerifCondensed" style="normal" weight="normal"/>
</font>

Brak komentarzy: