1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

thinreportsで中国語(韓国語)のPDFを表示したい

Posted at

カスタムフォントが選択できない

Screen Shot 2020-10-26 at 11.12.08.png

現状フォントは固定で、持ち込みのフォントは指定できない様子。
このまま中国語(韓国語でも)を入れようとすると、PDFの状態で文字化けを起こす。

解決方法

韓国語や中国語のテキストをPDFで表示できない

Railsであれば、ここにあるようにinitializerをつくってやる。

config/initializers/thinreports.rb
Thinreports.configure do |config|
  config.fallback_fonts <<
    Rails.root.join("app/thinreports/NotoSansCJKsc-Regular.ttf").to_s
end

ここで重要なのはttfフォントで、NOTOフォントを使う必要がある。
(□表示は英語圏ではTOFUと呼ばれ、もう豆腐表示はうんざり - no more tofu - NOTO らしい 、ついでにtofulearn.com

最初は「CJK」なんだからフォントファイル一個でChineseJapaneseKorean全部表示できるんでしょ?って思ってたけど、どうやら違う。適当にダウンロードしてきたNotoCJKファイルは日本語バージョンだったため引き続き中国語の表示ができなかった(□になる部分がPDFでは空白表示だった)。

よくよく調べるとCJKでも各地域ごとのフォントバージョンがあるらしい。

  • Simplified Chinese (SC)
  • Traditional Chinese (TC)
  • Japanese (JP)
  • Korean (KR)

最初に使ってたファイルはよくよく見るとNotoSansCJKjp-Regular.ttfだった。なので、NotoSansCJKsc-Regular.ttfを適当に探してみて、当ててみたらバッチリだった。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?