thinreports / thinreports-generator

A Ruby library for Thinreports
https://github.com/thinreports/thinreports
MIT License
297 stars 48 forks source link

Prawn::Errors::UnknownFont error occured: "is not a known font" #89

Closed hidakatsuya closed 6 years ago

hidakatsuya commented 6 years ago

Steps to reproduce

Schema (example.tlf)

    :
  "items": [
    {
      "id": "text",
      "type": "text-block",
        :
      "style": {
        "font-family": [
          "Helvetica"
        ],
    }
  ],
    :

Code

page.item(:text).style(:bold, true).value('aaaaあ')
page.item(:text).style(:italic, true).value('aaaaあ')

Error

8: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/text/formatted/line_wrap.rb:77:in `apply_font_settings_and_add_fragment_to_line'
7: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/text/formatted/arranger.rb:166:in `apply_font_settings'
6: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/pdf-core-0.7.0/lib/pdf/core/text.rb:214:in `character_spacing'
5: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/text/formatted/arranger.rb:169:in `block in apply_font_settings'
4: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/font.rb:57:in `font'
3: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/font.rb:253:in `find_font'
2: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/font.rb:301:in `load'
1: from /Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/font.rb:301:in `new'
/Users/--/.anyenv/envs/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/prawn-2.2.2/lib/prawn/font/afm.rb:53:in `initialize':  is not a known font. (Prawn::Errors::UnknownFont)

Environments

Cause

  1. Helvetica (AFM) does not support "あ" character
  2. Prawn will apply fallback font
  3. IPAMincho has applied as fallback font
  4. IPAMincho supports "あ" character, but does not have .ttf for bold style
  5. Prawn can't find font, and raises Prawn::Errors::UnknownFont

How to Fix

Known Issue

In the above case, specified bold/italic are NOT applied.