Forrestのメモ
注意
Version 0.7に即して記述しています. Forrestはまだメジャーリリース1.0に達して いません.
0.8以前はjava 1.6に対応していないようです.1.4 1.5で使わないとbuidできません.
皿井さまのサイトの情報が役立ちました.
cocoon2による日本語PDF作成の情報も役に立ちました.
私的なメモの域をでません. この情報にしたがって損害等を生じた場合で も責任は持ちません.
インストール
- Download the tar.gz file from the official site.
- Extract the files and the place folder in the suitable place. (この例では [FBASE] で記述)
- Create an empty directory for xml source files. (この例では [HTML_SRC] で記述)
- In the [HTML_SRC] directory, run [FBASE]/bin/forrest seed in order to create a minimum set and examples of xml source files.
- Modify [HTML_SRC]/src/documentation/content/xdocs/*.xml and create your own site.
Tips
- 日本語を扱うときはUTF-8でエンコード emacs 用には mule-ucs
- Unix系で使うときは 以下のファイルを[HTML_SRC]/updateとして用意しておくと便利
#/bin/tcsh
setenv FORREST_HOME [FBASE]
setenv PATH ${PATH}:${FORREST_HOME}/bin
limit stacksize unlimited
forrest -Dforrest.jvmargs=-Djava.awt.headless=true site
0.6からの移住時の注意
- .xml以外のファイルのデフォルトの置場所が変更になっている.
- [HTML_SRC]/src/documentation/skinconf.xml を0.7にあわせて変更する(大きな変更点はないが0.7設定ファイルから 差分を設定しておくほうが安心).
- 必要ならfavion.ico,その他logoの図を所定の位置にコピー
%cp favion.ico logo.gif [FBASE]/main/webapp/skins/commons/images
PDFの日本語化
デフォルトでは作成されるpdfにおいて 日本語フォントが扱えないので, 扱えるようにします.
オリジナルの fop-0.20.5.jar は変更する必要なし
フォントメトリクスファイルの作成は必須
userconf.xml の作成も必須
メトリクスファイルの作成に fonttool 1.1.3を援用
- 日本語フォントメトリクスファイルの作成
- Download fonttool 1.1.3 from 横浜ベイキット
- Extract the files and the place folder in the suitable place. (この例では [FTBASE] で記述)
- copy [FBASE]/core/fop-0.20.5.jar [FTBASE]/lib/fop.jar
- copy [FBASE]/core/batik-all-1.5.1.jar [FTBASE]/lib/batik.jar
- copy [FBASE]/core/avalon-framework*.jar [FTBASE]/lib/
- [FTBASE]/samples/fonttool.xm か fonttool-kochi.xm を選択し,中身を 必要に応じて編集
- %cd [FTBASE]/samples/
- % ../bin/fonttool -def fonttool.xml [FONTFILEDIR] ../fonts
../lib/fop.jar
ここで[FONTFILEDIR]はフォントファイルのあるディ レクトリ - [FTBASE]/fonts/下にできたフォントメトリクスファイルとフォントファ イルを適切なディレクトリ下に配備. このディレクトリを [FONTFILEDIR]とす る.
- フォント情報ファイルの作成
- [FONTFILEDIR]/userconfig.xmlを作成する.
- シリアライザの変更
- [FBASE]/plugins/org.apache.forrest.plugin.output.pdf/output.xmapを 変更します.
- [FBASE]/build/plugins/org.apache.forrest.plugin.output.pdf/output.xmapも
同様に変更します.
後者のディレクトリは forrestの初回の実行時にできます. [FBASE]/plugins/org.apache.forrest.plugin.output.pdf/output.xmap の内容はなぜか反映されません. 作成されたことを確認後, 改めて上書しないといけません. - トランスレーションファイルの変更
- [FBASE]/main/webapp/skins/common/xslt/fo/document2fo.xslを変更しま す.
- この変更により日本語の改行をうまくコントロールする様にできるようです.
userconfig.xml
ここで[FONTFILEDIR]はサイトの構成にあわせた上, 絶対パスで記述する.
<?xml version='1.0'?>
<configuration>
<entry>
<key>version</key>
<value>FOP 0.20.5</value>
</entry>
<entry>
<key>quiet</key>
<value>false</value>
</entry>
<entry>
<key>debugMode</key>
<value>false</value>
</entry>
<entry>
<key>dumpConfiguration</key>
<value>false</value>
</entry>
<entry>
<key>baseDir</key>
<value>[FONTFILEDIR]</value>
</entry>
<entry role="pdf">
<key>stream-filter-list</key>
<list>
<value>flate</value>
<value>ascii-85</value>
</list>
</entry>
<fonts>
<font embed-file="msmincho.ttc" kerning="yes" metrics-file="msmincho.xml">
<font-triplet name="Mincho" style="normal" weight="normal"/>
<font-triplet name="Mincho" style="normal" weight="bold"/>
<font-triplet name="Mincho" style="italic" weight="normal"/>
<font-triplet name="Mincho" style="italic" weight="bold"/>
</font>
<font embed-file="msmincho.ttc" kerning="yes" metrics-file="mspmincho.xml">
<font-triplet name="PMincho" style="normal" weight="normal"/>
<font-triplet name="PMincho" style="normal" weight="bold"/>
<font-triplet name="PMincho" style="italic" weight="normal"/>
<font-triplet name="PMincho" style="italic" weight="bold"/>
<font-triplet name="serif" style="normal" weight="normal"/>
<font-triplet name="serif" style="normal" weight="bold"/>
<font-triplet name="serif" style="italic" weight="normal"/>
<font-triplet name="serif" style="italic" weight="bold"/>
</font>
<font embed-file="msgothic.ttc" kerning="yes" metrics-file="msgothic.xml">
<font-triplet name="Osaka" style="normal" weight="normal"/>
<font-triplet name="Osaka" style="normal" weight="bold"/>
<font-triplet name="Osaka" style="italic" weight="normal"/>
<font-triplet name="Osaka" style="italic" weight="bold"/>
<font-triplet name="Gothic" style="normal" weight="normal"/>
<font-triplet name="Gothic" style="normal" weight="bold"/>
<font-triplet name="Gothic" style="italic" weight="normal"/>
<font-triplet name="Gothic" style="italic" weight="bold"/>
</font>
<font embed-file="msgothic.ttc" kerning="yes" metrics-file="mspgothic.xml">
<font-triplet name="PGothic" style="normal" weight="normal"/>
<font-triplet name="PGothic" style="normal" weight="bold"/>
<font-triplet name="PGothic" style="italic" weight="normal"/>
<font-triplet name="PGothic" style="italic" weight="bold"/>
<font-triplet name="sans-serif" style="normal" weight="normal"/>
<font-triplet name="sans-serif" style="normal" weight="bold"/>
<font-triplet name="sans-serif" style="italic" weight="normal"/>
<font-triplet name="sans-serif" style="italic" weight="bold"/>
<font-triplet name="sans" style="normal" weight="normal"/>
<font-triplet name="sans" style="normal" weight="bold"/>
<font-triplet name="sans" style="italic" weight="normal"/>
<font-triplet name="sans" style="italic" weight="bold"/>
</font>
</fonts>
</configuration>
output.xmap
<map:serializer name="fo2pdf" src="org.apache.cocoon.serialization.FOPSerializer" mime-type="application/pdf" />
を以下で置き換えます. [FONTFILEDIR]はサイトの構成にあわせた上, 絶対パスで記述する.
<map:serializer name="fo2pdf" src="org.apache.cocoon.serialization.FOPSerializer" mime-type="application/pdf" > <user-config>[FONTFILEDIR]/userconfig.xml</user-config> </map:serializer>
document2fo.xsl
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
を
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" language="ja">
に変えます.
PDFに図表示
PNGファイルをPDFに図表示するにはJiniが必要です. 以下, 公式サイトのFAQより
To get PNGs working in PDFs with Jimi:
- Download Jimi from http://java.sun.com/products/jimi/
- Unpack the Jimi distribution and copy JimiProClasses.zip to [FBASE]/lib/optional/jimi-1.0.jar.
jpg,gifがPDFに図表示されない場合は以下を確認.
- 図が大きすぎないか?
- 図の置場所は? 原則もとのxmlファイルから相対指定できる位置に図ファイ ルがある必要があるようです.
pdfファイルの 英語 日本語 切り替え
上記の設定では英語のテキストにも日本語フォントが組み込まれ以下の欠 点が生じます.
- ファイルサイズが大きくなり, 生成, 通信, 表示に時間がかかる.
- 日本語フォントの英字フォントはあまりきれいでない.
上記の欠点を解消するために, 元ソースの タグに xml:lang属性で"ja"指定があれば, 日本語フォントを組み込んだPDFファ イルを生成し, そうでなければデフォルトの処置をする対策を施しました.
変更対象ファイルは次の2つです.
- [FONTFILEDIR]/userconfig.xml
- [FBASE]/main/webapp/skins/common/xslt/fo/document2fo.xsl
- userconfig.xmlから, serif, sans-serif, sansの情報を削除します.
- document2fo.xsl の font-family指定を xml:lang属性の値によって切り替えるようにします.
力業で以下のようなコード断片をfont-family指定をする10数ヵ所におよぶ 複数個所で記述しています. もう少しましな解決ほうがあるように思います.
<xsl:variable name="fontfamily">
<xsl:choose>
<xsl:when test='lang("ja")'>PMincho</xsl:when>
<xsl:otherwise>serif</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fo:block
font-family="{$fontfamily}"
font-size="70%"
text-align="start"
font-style="italic">
<xsl:value-of select="header/title"/>
</fo:block>

