ReportLabの穴
- StyleのwordWrapをCJKにすると、Paragraph中での<br/>が効かない。どうやらバグ。修正パッチ:
--- paragraph.py 2009-01-26 20:59:27.000000000 +0900 +++ /usr/local/lib/python2.5/site-packages/reportlab/platypus/paragraph.py 2009-03-27 14:47:40.000000000 +0900 @@ -714,7 +714,7 @@ lineBreak = hasattr(u.frag,'lineBreak') endLine = (widthUsed>maxWidth + _FUZZ and widthUsed>0) or lineBreak if endLine: - if lineBreak: continue + #if lineBreak: continue extraSpace = maxWidth - widthUsed + w #This is the most important of the Japanese typography rules. #if next character cannot start a line, wrap it up to this line so it hangs最近のsubversion trunkでは直っているようです(2009/7/12)。 - Paragraph中では、全角スペースは半角スペースと同じ扱い。つまり、複数の空白は1個に圧縮、行頭の空白は無くなる。 複数の空白が1個に圧縮というよりは、「空白文字」ではない「単語間の空白」という伸び縮みする物体に変換されます。 wordWrapがCJKかどうかは関係無くそうなる。
- TableStyleの指定は、Table中のセルに入れたParagraphには効かない。TEXTCOLORとかALIGNが効かなくて悩む。 Table中のセルには素直に文字列を指定し、TableStyleで日本語フォントを指定するのがいい。
- 日本語を使用するには、事前におまじないが必要。
さらに、Style、Paragraphの文字列中の「<para font="...">」、TableStyleでいちいちフォント指定する必要がある。
registerFont(UnicodeCIDFont('HeiseiKakuGo-W5')) registerFont(UnicodeCIDFont('HeiseiMin-W3'))
- TrueTypeフォントファイルからフォントを読み込んで使うには:
こんな感じ。
registerFont(TTFont('Meiryo', 'meiryo.ttc')) registerFont(TTFont('Meiryo-Italic', 'meiryo.ttc', subfontIndex=1)) registerFont(TTFont('Meiryo-Bold', 'meiryob.ttc')) registerFont(TTFont('Meiryo-BoldItalic', 'meiryob.ttc', subfontIndex=1)) addMapping('Meiryo', 0, 0, 'Meiryo') addMapping('Meiryo', 1, 0, 'Meiryo-Bold') addMapping('Meiryo', 0, 1, 'Meiryo-Italic') addMapping('Meiryo', 1, 1, 'Meiryo-BoldItalic')
- Imageを縦横比率を保ったままサイズ指定するには、「kind='bound'」引数を指定する。 指定されたwidth、heightの四角に納まり、かつ縦横比率を保ったサイズに変換される。
- Imageが表示されるサイズは、image.drawWidthとimage.drawHeight。
(2009/3/23 - sgk)
