DITA-OT1.5.3とApache FOPを使って日本語に対応したPDFを作成する
以前の方法ではDITA-OT1.5.3に対応できないので1.5.3用にまとめ直しました.
事前準備
PDFに埋め込む日本語フォントを用意します.
昨日作成したIPAフォントとそのフォントメトリックスを使用します.
FO pluginのbuild.xmlを修正
%DITA-OT%\demo\fo\build_template.xmlを修正します.
実行時にはbuild_template.xmlがbuild.xmlにコピーされて実行されているようなのでbuild.xmlを直接書き換えてもダメです.
変更箇所は"default.locale"と"default.language"の値です.
<project name="dita.build" basedir="."> <import file="${dita.plugin.org.dita.pdf2.dir}/build_fop.xml"/> <import file="${dita.plugin.org.dita.pdf2.dir}/build_axf.xml"/> <import file="${dita.plugin.org.dita.pdf2.dir}/build_xep.xml"/> <target name="transform.topic2pdf.init"> <property name="customization.dir" value="${dita.plugin.org.dita.pdf2.dir}/Customization"/> <property file="${customization.dir}/build.properties"/> <property name="default.locale" value="ja_JP"/> <property name="default.language" value="ja"/> ...
フォントマッピングの変更
デフォルトのフォントマッピングを変更してIPAフォントを指定するようにします.
- %DITA-OT%\demo\fo\cfg\fo\font-mapping.xmlを%DITA-OT%\demo\fo\Customization\fo\font-mapping.xmlへコピーします.
- char-setがJapaneseの時のfont-faceを以下のようにfont-mapping.xmlを変更します.
<logical-font name="Sans"> <physical-font char-set="default"> <font-face>Helvetica</font-face> </physical-font> <physical-font char-set="Simplified Chinese"> <font-face>AdobeSongStd-Light</font-face> </physical-font> <physical-font char-set="Japanese"> <font-face>IPAGothic</font-face> </physical-font> <physical-font char-set="Korean"> <font-face>AdobeMyungjoStd-Medium</font-face> </physical-font> <physical-font char-set="Symbols"> <font-face>ZapfDingbats</font-face> </physical-font> <physical-font char-set="SubmenuSymbol"> <font-face>ZapfDingbats</font-face> </physical-font> <physical-font char-set="SymbolsSuperscript"> <font-face>Helvetica</font-face> <baseline-shift>20%</baseline-shift> <override-size>smaller</override-size> </physical-font> </logical-font> <logical-font name="Serif"> <physical-font char-set="default"> <font-face>Times</font-face> </physical-font> <physical-font char-set="Simplified Chinese"> <font-face>AdobeSongStd-Light</font-face> </physical-font> <physical-font char-set="Japanese"> <font-face>IPAMincho</font-face> </physical-font> <physical-font char-set="Korean"> <font-face>AdobeMyungjoStd-Medium</font-face> </physical-font> <physical-font char-set="Symbols"> <font-face>ZapfDingbats</font-face> </physical-font> <physical-font char-set="SubmenuSymbol"> <font-face>ZapfDingbats</font-face> </physical-font> <physical-font char-set="SymbolsSuperscript"> <font-face>Times</font-face> <baseline-shift>20%</baseline-shift> <override-size>smaller</override-size> </physical-font> </logical-font> <logical-font name="Monospaced"> <physical-font char-set="default"> <font-face>Courier</font-face> </physical-font> <physical-font char-set="Simplified Chinese"> <font-face>AdobeSongStd-Light</font-face> </physical-font> <physical-font char-set="Japanese"> <font-face>IPAGothic</font-face> </physical-font> <physical-font char-set="Korean"> <font-face>AdobeMyungjoStd-Medium</font-face> </physical-font> <physical-font char-set="Symbols"> <font-face>ZapfDingbats</font-face> </physical-font> <physical-font char-set="SymbolsSuperscript"> <font-face>Courier</font-face> <baseline-shift>20%</baseline-shift> <override-size>smaller</override-size> </physical-font> </logical-font>
- %DITA-OT%\demo\fo\Customization\fo\catalog.xmlを変更します.
上のフォントマッピングを有効にするようにcatalog.xmlを変更します.
<!-- FontMapper configuration override entry.--> <uri name="cfg:fo/font-mappings.xml" uri="fo/font-mappings.xml"/>
fop.xconfの変更
最後に%DITA-OT%\demo\fo\fop\fop.xconfを変更します.
事前に用意したIPAフォントはC:\fop-1.0\fonts\にあるものとします.
PDFを作成するときにIPAフォントを指定するように追加します.
<renderer mime="application/pdf"> <filterList> <!-- provides compression using zlib flate (default is on) --> <value>flate</value> <!-- encodes binary data into printable ascii characters (default off) This provides about a 4:5 expansion of data size --> <!-- <value>ascii-85</value> --> <!-- encodes binary data with hex representation (default off) This filter is not recommended as it doubles the data size --> <!-- <value>ascii-hex</value> --> </filterList> <fonts> <!-- embedded fonts --> <!-- This information must exactly match the font specified in the fo file. Otherwise it will use a default font. For example, <fo:inline font-family="Arial" font-weight="bold" font-style="normal"> Arial-normal-normal font </fo:inline> for the font triplet specified by: <font-triplet name="Arial" style="normal" weight="bold"/> If you do not want to embed the font in the pdf document then do not include the "embed-url" attribute. The font will be needed where the document is viewed for it to be displayed properly. possible styles: normal | italic | oblique | backslant possible weights: normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 (normal = 400, bold = 700) --> <!-- <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf"> <font-triplet name="Arial" style="normal" weight="normal"/> <font-triplet name="ArialMT" style="normal" weight="normal"/> </font> <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf"> <font-triplet name="Arial" style="normal" weight="bold"/> <font-triplet name="ArialMT" style="normal" weight="bold"/> </font> --> <font metrics-url="C:\fop-1.0\fonts\ipamincho.xml" embed-url="C:\fop-1.0\fonts\ipam.ttc" kerning="yes"> <font-triplet name="IPAMincho" style="normal" weight="normal"/> <font-triplet name="IPAMincho" style="normal" weight="bold"/> <font-triplet name="IPAMincho" style="italic" weight="normal"/> <font-triplet name="IPAMincho" style="italic" weight="bold"/> </font> <font metrics-url="C:\fop-1.0\fonts\ipagothic.xml" embed-url="C:\fop-1.0\fonts\ipag.ttc" kerning="yes"> <font-triplet name="IPAGothic" style="normal" weight="normal"/> <font-triplet name="IPAGothic" style="normal" weight="bold"/> <font-triplet name="IPAGothic" style="italic" weight="normal"/> <font-triplet name="IPAGothic" style="italic" weight="bold"/> </font> </fonts> <!-- This option lets you specify additional options on an XML handler --> <!--xml-handler namespace="http://www.w3.org/2000/svg"> <stroke-text>false</stroke-text> </xml-handler--> </renderer>
これで日本語のPDFを作成した時に日本語部分の文字化けが解消されます.
fop.xconfのフルパス指定問題は元に戻ってしまったのでまた考えます.