LoginSignup
10
15

More than 5 years have passed since last update.

asciidoctor-pdfで日本語を含むSVG画像を扱う

Posted at

asciidoctor-pdfで日本語を含むSVGを扱うには

asciidoctor-pdfでSVGを含む画像を出力する際、SVGに日本語が含まれていると"¬"になってしまう問題の対策となります。
原因はPDF出力する際にPrawnがWin1252のCharsetに対応したフォントを使用しないことになります。
asciidoctor-pdfのGithubに対策は書いてあったのですが備忘録としてまとめておきます。

ここではasciidoctor, asciidoctor-pdfは既に導入済みとします。

asciidocotor-pdf-cjk-kai_gen_gothicをインストールする

インストール手順はGithub参照

Prawn-SVGに日本語フォントを指定するコードを追加する

asciidoctor-pdfのGithubでCJK環境の問題点として議論されていた中に解決策として提示されていました。
フォント指定を追加するコードを別途作成して、実行時にロードする形となります。

config.rb
Prawn::Svg::Font::GENERIC_CSS_FONT_MAPPING.merge!(
  'sans-serif' => 'KaiGen Gothic JP'
)

asciidoctor-pdf実行時に上記コードを記述したファイルを指定する

ここでは変換元ファイルと同じ階層にconfig.rbを配置した形としてあります。

$ asciidoctor-pdf -r asciidoctor-diagram -r ./config.rb -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicJP test.adoc

動作確認環境

10
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
15