【改訂後】DITA-OT1.4.3のPDF出力を日本語化する(RenderX XEP編)

DITA-OT1.4.3のPDF出力を日本語化する(RenderX XEP編)

【重要】

XSLTエンジンをSaxon9Bにすると、以下のようなエラーが発生することがわかりました。

  [java] Error on line 290 of index.xsl:
  [java]   Cannot find a matching 2-argument function named
  [java]   {http://www.idiominc.com/opentopic/exsl/function}getIndexEntry()
  [java] Transformation failed: Run-time errors were reported
  [i18n-preprocess] [Fatal Error] stage2.fo:70:114: XML document structures must start and end within the same entity.
Processing ended.

申し訳ありませんが、原因がわかるまでは、【改訂前】の方法でセットアップしてください。ただし、%DITA-OT%demo\fo\cfg\fo\i18n\ja_JP.xml をカスタマイズする手順については、【改訂前】の手順にありませんのでご注意ください。

DITA-OT1.4.2.1までは、PDF2出力を使うためにFO plug-inをインストールする必要がありましたが、DITA-OT1.4.3からはFO plug-inが最初からDITA-OTに組み込まれています。DITA-OTを実行するときに、出力タイプとしてPDFまたはPDF2を指定すると、従来のFO plug-inのコードが実行されます。

DITA-OT1.4.2.1以前のFO plug-inは、RenderX XEPを使用することを前提に作られていました。このため、%DITA-OT%demo\fo\lib\fo.jarの中に、RenderX XEP起動するためのクラス・オブジェクトが含まれてました。DITA-OT1.4.3では、FO plug-inが標準化されたことに伴い、XSLフォーマッターの選択についてもオープンになりました。デフォルトの設定では、XSLフォーマッターとしてApache FOPが使われるようになっています。

DITA-OT1.4.3のfo.jarには、RenderX XEPを起動するためのクラス・オブジェクトが含まれておらず、代わりJavaのソース・コードが提供されています。もし、RenderX XEPを使用する場合は、Javaのソース・コードをコンパイルして、%DITA-OT%demo\fo\lib\fo.jarをリビルドしなければいけません。

DITA-OT1.4.3で、DITA-OT1.4.2.1以前と同様のPDFを出力するには、出力タイプにlagacypdfを指定します。

前提条件

  • JDK Ver 1.5以降のインストールが完了していること(fo.jarをビルドするため、JREではなくJDKが必要です)
  • DITA OT 1.4.3のインストールが完了していること

RenderX XEPのインストール

1) 以下のURLから、RenderX personal edition(無料)を入手する。
  http://www.renderx.com/download/personal.html

2) 上記ページの"Personal License Download"の、Name, Organization, Emailの各テキスト・ボックスに必要事項を入力し、[Submit]ボタンをクリックする。

3) "Download instructions: RenderX XEP v4 Trial Software"というタイトルのメールが送られてくる。このメールには、"license.xml"というファイルが添付されている。

4) "license.xml"を、%DITA-OT%demo\fo\lib\xep フォルダの下に保存する。

5) メール本文の書かれているURLにアクセスし、"Select your license key"のテキスト・ボックスの右横にある[参照...]ボタンをクリックし、4)で保存したlicense.xmlファイルを選択する。

6) [Update]ボタンをクリックすると、Webブラウザの別ウィンドウにインストール・ファイル(xep-4.14-20081212-personal.zip)のリンクが表示されるので、そのリンクをクリックしてzipファイルをダウンロードする。

7) ダウンロードしたzipファイルを解凍すると、以下のファイルができる。

  • LICENSE-PERSONAL.TXT
  • readme.txt
  • xep-4.14-20081212-personal.zip

8) readme.txt に書かれているインストール手順に従って、コマンド・プロンプトから以下のコマンドを実行する。

java -jar setup-4.14-20081212-personal.jar

9) RenderX license agreementのダイアログ・ボックスが表示されたら、ライセンス条項を読み[Yes, I accept]ボタンをクリックする。

10) RenderX XEP setupのダイアログ・ボックスが表示されたら、2つのテキスト・ボックスにそれぞれ以下のパスを入力し、[Install]ボタンをクリックする。

  • Install XEP to the directory:  %DITA-OT%demo\fo\lib\xep
  • License file:  %DITA-OT%demo\fo\lib\xep\license.xml

11) "Installation successful"のメッセージが表示されたら、[Finish]ボタンをクリックする。

%DITA-OT%demo\fo\lib\fo.jarをリビルドする

DITA-OT1.4.3の %DITA-OT%demo\fo\lib\fo.jar の中に、RenderX XEPを起動するためのクラス・オブジェクトが含まれていないので、%DITA-OT%demo\fo\buildPackage.xmlの内容を修正し、fo.jarをリビルドする。

1) システム環境変数JAVA_HOMEが設定されているか確認し、設定されていない場合はJDKのインストール・パスを設定する。

2) %DITA-OT%demo\fo\buildPackage.xml の中の以下の行を修正する。

【修正前】

<javac srcdir="${src.dir}" destdir="${bin.dir}" classpath="${ant.jar}"
  debug="on" excludes="com/idiominc/ws/opentopic/fo/xep/**">

【修正後】

<javac srcdir="${src.dir}" destdir="${bin.dir}" classpath="${ant.jar}"
  debug="on">

3) %DITA-OT%startcmd.batをダブルクリックしてコマンド・プロンプトを開く。

4) %DITA-OT%demo\foフォルダへ移動し、以下のコマンドを入力する。

cd demo\fo
ant -f buildPackage.xml

※ビルド中に、「警告:この文字は、エンコーディング MS932 にマップできません。」というエラー・メッセージが出るが、無視して構わない(コピーライトの記号が文字化けを起こしているために出力されるエラー・メッセージ)。

ビルドが正常終了すると、C:\DITA-OT1.4.3-PLUS\demo\fo\lib\fo.jar が更新される。

FO FormatterをApache FOPからRenderX XEPに変更する

DITA-OT1.4.3からは、Apache FOPがデフォルトのFO Formatterになっている。
FO FormatterとしてRenderX XEPを使うようにする手順は以下のとおり。

1) %DITA-OT%demo\fo\build.xml の中で、pdf.formatter というプロパティに fop が指定されているので、この値を xep に変更する。

※おまけ
build.xmlのデフォルトの設定では、DITA-OT実行後にXSL-FOのファイルが削除される。
デバッグのためにXSL-FOを残しておきたい場合は、build.xml の中の、transform.topic2pdfターゲットの定義の中の、deleteの部分をコメント・アウトする。

<!--<delete>-->
  <!--Deleting the stage files isn't necessary, since it will be cleaned by
      clean-temp, and is useful for debugging.-->
  <!--<fileset dir="${buildDir}" includes="stage?.*"/>-->
  <!--<fileset dir="${dita.map.output.dir}" includes="topic.fo"/>-->
<!--</delete>-->

日本語対応のための設定

1) %DITA-OT%demo\fo\build.xml の中の、document.locale というプロパティでドキュメントのロケールを設定している。このパラメータに、英語ドキュメントを出力する場合はen_US、日本語ドキュメントを出力する場合はja_JPを指定する。このことについては、DITA Open Toolkit User Guideの"Localizing in PDF2 output target"に書いてある。このlocaleに指定により、自動生成文字や索引の出来方も日本語仕様になる。dost.jarの/ditalocale(Antパラメータのargs.dita.locale)に従ってdocument.localeを設定するように、以下のとおりbuild.xmlを変更する。

<project name="dita.build"  basedir=".">

    <property name="customization.dir" value="${basedir}/Customization"/>
    <property name="ot.dir" value="${basedir}/../.."/>
    <property name="lib.dir" value="${ot.dir}/lib"/>
    <property name="fo.lib.dir" value="${basedir}/lib"/>
    <property name="xep.dir" value="${fo.lib.dir}/xep"/>
    <property name="merged.file" value="${dita.map.filename.root}_MERGED.xml" />
    <!-- <property name="document.locale" value="en_US" /> -->
    <!-- <property name="document.locale" value="ja_JP" /> -->
    <condition property="document.locale" value="ja_JP">
      <and>
        <isset property="args.dita.locale" />
        <or>
          <equals arg1="ja-jp" arg2="${args.dita.locale}" casesensitive="false"/>
          <equals arg1="ja" arg2="${args.dita.locale}"  casesensitive="false"/>
        </or>
      </and>
    </condition>
    <condition property="document.locale" value="en_US">
      <and>
        <isset property="args.dita.locale" />
        <or>
          <equals arg1="en-us" arg2="${args.dita.locale}" casesensitive="false"/>
          <equals arg1="en" arg2="${args.dita.locale}" casesensitive="false"/>
        </or>
      </and>
    </condition>

	<!-- configure FO engines -->

2) %DITA-OT%demo\fo\lib\xep\xep.xmlの定義に、以下のとおり MSGothic と MSMincho の定義を追加する。

<!-- Sample configuration for Windows TrueType fonts.  -->

<font-group xml:base="file:/C:/Windows/Fonts/" label="Windows TrueType" embed="true" subset="true"> 
  <font-family name="Arial">
    <font><font-data ttf="arial.ttf"/></font>
    <font style="oblique"><font-data ttf="ariali.ttf"/></font>
    <font weight="bold"><font-data ttf="arialbd.ttf"/></font>
    <font weight="bold" style="oblique"><font-data ttf="arialbi.ttf"/></font>
  </font-family>

  <font-family name="Times New Roman" ligatures="&#xFB01; &#xFB02;">
    <font><font-data ttf="times.ttf"/></font>
    <font style="italic"><font-data ttf="timesi.ttf"/></font>
    <font weight="bold"><font-data ttf="timesbd.ttf"/></font>
    <font weight="bold" style="italic"><font-data ttf="timesbi.ttf"/></font>
  </font-family>

  <font-family name="Courier New">
    <font><font-data ttf="cour.ttf"/></font>
    <font style="oblique"><font-data ttf="couri.ttf"/></font>
    <font weight="bold"><font-data ttf="courbd.ttf"/></font>
    <font weight="bold" style="oblique"><font-data ttf="courbi.ttf"/></font>
  </font-family>

  <font-family name="Tahoma" embed="true">
    <font><font-data ttf="tahoma.ttf"/></font>
    <font weight="bold"><font-data ttf="tahomabd.ttf"/></font>
  </font-family>

  <font-family name="Verdana" embed="true">
    <font><font-data ttf="verdana.ttf"/></font>
    <font style="oblique"><font-data ttf="verdanai.ttf"/></font>
    <font weight="bold"><font-data ttf="verdanab.ttf"/></font>
    <font weight="bold" style="oblique"><font-data ttf="verdanaz.ttf"/></font>
  </font-family>

  <font-family name="Palatino" embed="true" ligatures="&#xFB00; &#xFB01; &#xFB02; &#xFB03; &#xFB04;">
    <font><font-data ttf="pala.ttf"/></font>
    <font style="italic"><font-data ttf="palai.ttf"/></font>
    <font weight="bold"><font-data ttf="palab.ttf"/></font>
    <font weight="bold" style="italic"><font-data ttf="palabi.ttf"/></font>
  </font-family>

  <!-- Begin Japanese -->
  <font-family name="MSGothic">
    <font><font-data ttf="msgothic.ttc"/></font>
    <font style="oblique"><font-data ttf="msgothic.ttc"/></font>
    <font weight="bold"><font-data ttf="msgothic.ttc"/></font>
    <font weight="bold" style="oblique"><font-data ttf="msgothic.ttc"/></font>
  </font-family>

  <font-family name="MSMincho">
    <font><font-data ttf="msmincho.ttc"/></font>
    <font style="oblique"><font-data ttf="msmincho.ttc"/></font>
    <font weight="bold"><font-data ttf="msmincho.ttc"/></font>
    <font weight="bold" style="oblique"><font-data ttf="msmincho.ttc"/></font>
  </font-family>
  <!-- End Japanese -->

</font-group>

3) フォント・マッピングをカスタマイズするために、%DITA-OT%demo\fo\cfg\fo\font-mappings.xml を %DITA-OT%demo\fo\Customization\fo の下にコピーする。

4) %DITA-OT%\demo\fo\Customization\fo\font-mappings.xml を編集し、日本語フォントの指定箇所を以下のとおり変更する。

<font-mappings>

  <font-table>

    <aliases>
      <alias name="Helvetica">Normal</alias>
    </aliases>
    <aliases>
      <alias name="Courier">Monospaced</alias>
    </aliases>

    <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>KozMinProVI-Regular</font-face-->
        <font-face>MSGothic</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>KozMinProVI-Regular</font-face-->
        <font-face>MSMincho</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>KozMinProVI-Regular</font-face-->
        <font-face>MSGothic</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>
  </font-table>

</font-mappings>

5) 日本語フォントを適用する、Unicode文字コードの範囲を変更するために、%DITA-OT%demo\fo\cfg\fo\i18n\ja_JP.xml を、%DITA-OT%demo\fo\Customization\fo\i18n の下にコピーする。

6) %DITA-OT%demo\fo\Customization\fo\i18n\ja_JP.xml を編集し、日本語のキャラクタ・セットの部分を以下のとおり変更する。

    <alphabet char-set="Japanese">
        <character-set>
            <!-- CJK Unified Ideographs -->
            <character-range>
                <start include="yes">&#x4E00;</start>
                <end include="yes">&#x9FBF;</end>
            </character-range>
            <!-- CJK Unified Ideographs Extension A -->
            <character-range>
                <start include="yes">&#x3400;</start>
                <end include="yes">&#x4DBF;</end>
            </character-range>
            <!-- CJK Compatibility Ideographs (IBM extended for Japanese Windows) -->
            <character-range>
                <start include="yes">&#xFA0E;</start>
                <end include="yes">&#xFA2D;</end>
            </character-range>
            <!-- Kanbun -->
            <character-range>
                <start include="yes">&#x3190;</start>
                <end include="yes">&#x319F;</end>
            </character-range>
            <!-- CJK Symbols and Punctuation -->
            <character-range>
                <start include="yes">&#x3000;</start>
                <end include="yes">&#x303F;</end>
            </character-range>
            <!-- Halfwidth and Fullwidth Forms -->
            <character-range>
                <start include="yes">&#xFF00;</start>
                <end include="yes">&#xFFEF;</end>
            </character-range>
            <!-- Hiragana -->
            <character-range>
                <start include="yes">&#x3040;</start>
                <end include="yes">&#x309F;</end>
            </character-range>
            <!-- Katakana -->
            <character-range>
                <start include="yes">&#x30A0;</start>
                <end include="yes">&#x30FF;</end>
            </character-range>
            <!-- Katakana Phonetic Extensions -->
            <character-range>
                <start include="yes">&#x31F0;</start>
                <end include="yes">&#x31FF;</end>
            </character-range>
            <!-- Arrows -->
            <character-range>
                <start include="yes">&#x2190;</start>
                <end include="yes">&#x21FF;</end>
            </character-range>
        </character-set>
    </alphabet>

7) font-mappings.xml と ja_JP.xml のカスタマイズを有効にするために、%DITA-OT%demo\fo\Customization\catalog.xml を修正する。catalog.xml.orig をコピーして catalog.xml を作り、FontMapperのコメントと、日本語のI18N設定のコメントを解除する。

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

    <!-- I18N configuration override entries.-->
    <!--uri name="cfg:fo/i18n/de_DE.xml" uri="fo/i18n/de_DE.xml"/-->
    <!--uri name="cfg:fo/i18n/en_US.xml" uri="fo/i18n/en_US.xml"/-->
    <!--uri name="cfg:fo/i18n/es_ES.xml" uri="fo/i18n/es_ES.xml"/-->
    <!--uri name="cfg:fo/i18n/fr_FR.xml" uri="fo/i18n/fr_FR.xml"/-->
    <!--uri name="cfg:fo/i18n/it_IT.xml" uri="fo/i18n/it_IT.xml"/-->
    <uri name="cfg:fo/i18n/ja_JP.xml" uri="fo/i18n/ja_JP.xml"/>
    <!--uri name="cfg:fo/i18n/zh_CN.xml" uri="fo/i18n/zh_CN.xml"/-->