2012年10月25日木曜日

レポート日本語化 / Using japanese font on report

Apache OFBizは画面や帳票の出力にFOP、FreeMarkerなどいくつかの方法が使われています。現在OFBizで使用されているFOP、FreeMarkerは画面と異なり各国語を切り替えて使用することができません。まず日本語で帳票が作成できる環境を構築します。

1.コマンドラインから下記のコマンドで、FOP用のフォントメトリックスを作成します。

cd c:\ofbiz\framework\base
java -cp ./lib/fop-0.95.jar;./lib/commons/commons-logging-1.1.jar;./lib/commons/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader /windows/fonts/msmincho.ttc -ttcname "MS Mincho" msmincho.xml
java -cp ./lib/fop-0.95.jar;./lib/commons/commons-logging-1.1.jar;./lib/commons/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader /windows/fonts/msmincho.ttc -ttcname "MS PMincho" mspmincho.xml
java -cp ./lib/fop-0.95.jar;./lib/commons/commons-logging-1.1.jar;./lib/commons/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader /windows/fonts/msgothic.ttc -ttcname "MS Gothic" msgothic.xml
java -cp ./lib/fop-0.95.jar;./lib/commons/commons-logging-1.1.jar;./lib/commons/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader /windows/fonts/msgothic.ttc -ttcname "MS PGothic" mspgothic.xml
java -cp ./lib/fop-0.95.jar;./lib/commons/commons-logging-1.1.jar;./lib/commons/commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader /windows/fonts/msgothic.ttc -ttcname "MS UI Gothic" msuigothic.xml

2.作成されたファイルは、ファイル内のフォント名が文字化けしていますので、任意のテキストエディタでフォント名を変更します。












3.作成したファイルをC:\ofbiz\framework\webapp\configに移動します。

4.FOPの設定ファイルに、作成したフォントメトリックスを指定します。任意のテキストエディタを使用して、C:\ofbiz\framework\webapp\config\fop.xconfファイルを編集します。次の行を追加します。

<font metrics-url="msgothic.xml" embed-url="C:\WINDOWS\Fonts\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>
        <font metrics-url="mspgothic.xml" embed-url="C:\WINDOWS\Fonts\MSGOTHIC.TTC" kerning="yes">
            <font-triplet name="MS PGothic" style="normal" weight="normal"/>
            <font-triplet name="MS PGothic" style="normal" weight="bold"/>
            <font-triplet name="MS PGothic" style="italic" weight="normal"/>
            <font-triplet name="MS PGothic" style="italic" weight="bold"/>
        </font>
        <font metrics-url="msuigothic.xml" embed-url="C:\WINDOWS\Fonts\MSGOTHIC.TTC" kerning="yes">
            <font-triplet name="MS UI Gothic" style="normal" weight="normal"/>
            <font-triplet name="MS UI Gothic" style="normal" weight="bold"/>
            <font-triplet name="MS UI Gothic" style="italic" weight="normal"/>
            <font-triplet name="MS UI Gothic" style="italic" weight="bold"/>
        </font>
        <font metrics-url="msmincho.xml" embed-url="C:\WINDOWS\Fonts\MSMINCHO.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="mspmincho.xml" embed-url="C:\WINDOWS\Fonts\MSMINCHO.TTC" kerning="yes">
            <font-triplet name="MS PMincho" style="normal" weight="normal"/>
            <font-triplet name="MS PMincho" style="normal" weight="bold"/>
            <font-triplet name="MS PMincho" style="italic" weight="normal"/>
            <font-triplet name="MS PMincho" style="italic" weight="bold"/>
        </font>
      </fonts>

5.共通で使用されるフォント指定部分を編集します。Arialフォントを指定している箇所が2か所あるので、それぞれMS UI Gothicに変更します。C:\ofbiz\framework\common\widget\CommonScreens.xml

                <!--<set field="defaultFontFamily" value="Arial"/>-->
                <set field="defaultFontFamily" value="MS UI Gothic"/>

6.画面、帳票、メールのテンプレートがそれぞれのアプリケーション内にありますので、フォントを指定している箇所を変更します。

7.では、PDFを表示してみましょう。Apache OFBizを起動して、業務>売掛(AR)>請求書に移動します。




2012/10/27 追記
次のファイルでHelveticaフォントが指定されています

applications\accounting\webapp\accounting\invoice\PrintInvoices.fo.ftl
applications\accounting\webapp\accounting\reports\AcctgTransEntriesSearchResult.fo.ftl
applications\accounting\webapp\accounting\reports\AcctgTransSearchResult.fo.ftl
applications\accounting\webapp\accounting\reports\ChartOfAccount.fo.ftl
applications\manufacturing\webapp\manufacturing\jobshopmgt\CuttingListReport.fo.ftl
applications\manufacturing\webapp\manufacturing\reports\ShipmentLabel.fo.ftl
applications\manufacturing\webapp\manufacturing\reports\ShipmentPlanStockReport.fo.ftl
applications\manufacturing\webapp\manufacturing\reports\ShipmentWorkEffortTasks.fo.ftl
applications\order\webapp\ordermgr\reports\OrderPurchaseReportPayment.fo.ftl
applications\order\webapp\ordermgr\reports\OrderPurchaseReportProduct.fo.ftl
applications\order\webapp\ordermgr\reports\PurchasesByOrganizationReport.fo.ftl
applications\order\webapp\ordermgr\reports\SalesByStoreReport.fo.ftl
applications\product\webapp\catalog\product\ProductBarCode.fo.ftl
applications\product\webapp\facility\facility\NotReadyToPick.fo.ftl
applications\product\webapp\facility\facility\Picklist.fo.ftl
applications\product\webapp\facility\facility\PrintPickSheets.fo.ftl
applications\product\webapp\facility\shipment\ShipmentBarCode.fo.ftl



2 件のコメント:

  1. 5.は、Arialの設定はもともとコメントアウトされていますが、その後に追加すればいいということですか?

    6.の編集箇所について、帳票だけでもいいのでパスを教えてもらえませんか?

    返信削除
  2. 5についてはその通りです。6は本文に追記しました。

    返信削除