DITA-OT1.4.3でPDFを日本語出力させる(Apache FOP)

DITA-OT1.5.3での作業方法についてはこちらに書きました.

id:ditahackさんはRenderX XEPで作業されているけど,こちらはオリジナル(Apache FOP)でやる方法.

FOP0.95のフォントメトリックスを作成する

DITA-OT1.4.3のfull installはFOP0.95が入っているので,これのフォントメトリックスファイルを作成します.
Windowsの場合はこちらのサイトが一番お手軽.

Apache FOP の 無設定 日本語フォント対応 (Windows向け)
http://javaswing.sakura.ne.jp/articles/fop_ja.html

ここで生成されたfontsフォルダをフォルダごと,%DITA-OT%\demo\fo\fopへコピーする.

fop.xconfの修正

上のツールを使うとfop_ja.xconfというファイルが生成されるので,%DITA-OT%\demo\fo\fop\conf\fop.xconfを修正する.
なおfop_ja.xconfではfont-triplet nameが2バイト文字で表記されているがシングルバイトにしておくこと.DITA側の問題でエラーになります.
ちなみにこんな感じ.

...
<!-- NOTE: This is the version of the configuration -->
<fop version="1.0">

  <!-- Base URL for resolving relative URLs -->
  <base>.</base>
  <strict-validation>false</strict-validation>
  
<!-- fop_ja start -->
  <font-base>C:\DITA-OT1.4.3\demo\fo\fop\fonts</font-base>
<!-- fop_ja end   -->

  <!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
...
...
<!-- insert from here -->
        <font metrics-url="msgothic.xml" embed-url="msgothic.ttc" kerning="yes">
          <font-triplet name="MS Mincho" style="normal" weight="normal"/>
          <font-triplet name="MS Mincho" style="normal" weight="bold"/>
          <font-triplet name="MS Mincho" style="italic" weight="normal"/>
          <font-triplet name="MS Mincho" style="italic" weight="bold"/>
        </font>
        <font metrics-url="msgothic.xml" embed-url="msgothic.ttc" kerning="yes">
          <font-triplet name="MS Gothic" style="normal" weight="normal"/>
          <font-triplet name="MS Gothic" style="normal" weight="bold"/>
          <font-triplet name="MS Gothic" style="italic" weight="normal"/>
          <font-triplet name="MS Gothic" style="italic" weight="bold"/>
        </font>
...

ちなみにmsmincho.xmlを指定すると文字化けするので,両方ともmsgothic.xmlを暫定的に使っています.

font-mappings.xmlの変更

font-mappings.xmlをコピーします.

 cp %DITA-OT%\demo\fo\cfg\fo\font-mappings.xml %DITA-OT%\demo\fo\Customization\fo\

font-mappings.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>MS Gothic</font-face>
                        </physical-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>MS Mincho</font-face>
                        </physical-font>

%DITA-OT%\demo\fo\Customization\catalog.xmlの変更

上で設定したカスタマイズの情報が通るように,変更します.

    <!-- FontMapper configuration override entry.-->
    <uri name="cfg:fo/font-mappings.xml" uri="fo/font-mappings.xml"/>

これで,日本語が表示されます.

今のところの問題点は

  • MS明朝を使用すると文字化けが起こる
  • 全角カンマ","や全角ピリオド"."をDITAで使用すると,フォントが埋め込まれない