Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't render Nepali text using fallback font, "Bad font family" #1132

Closed
whitmer opened this issue Oct 29, 2019 · 2 comments
Closed

Can't render Nepali text using fallback font, "Bad font family" #1132

whitmer opened this issue Oct 29, 2019 · 2 comments

Comments

@whitmer
Copy link

whitmer commented Oct 29, 2019

Hi, I'm running into some issues trying to get Prawn to render Nepali text, and I'm not sure where the issue might be, any help would be appreciated.

Using Prawn 2.2.2

pdf = Prawn::Document.new
pdf.font "lib/TimesNewRoman.ttf"
pdf.font_families.update({'MiedingerBook' => {
  normal: "lib/MiedingerBook.ttf" # https://github.com/CoughDrop/obf/blob/master/lib/MiedingerBook.ttf
}})
pdf.fallback_fonts = ['MiedingerBook']
pdf.text_box "भन्नुहोस्"
pdf.render_file("out/prawn.pdf")

When I run this I get:

Traceback (most recent call last):
       16: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/box.rb:134:in `render'
       15: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/box.rb:212:in `render'
       14: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/font.rb:215:in `save_font'
       13: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/box.rb:213:in `block in render'
       12: from /Users/me/.rvm/gems/ruby-2.6.1/gems/pdf-core-0.7.0/lib/pdf/core/text.rb:214:in `character_spacing'
       11: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/box.rb:214:in `block (2 levels) in render'
       10: from /Users/me/.rvm/gems/ruby-2.6.1/gems/pdf-core-0.7.0/lib/pdf/core/text.rb:190:in `text_rendering_mode'
        9: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/box.rb:219:in `block (3 levels) in render'
        8: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/font.rb:101:in `font_size'
        7: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/box.rb:226:in `block (4 levels) in render'
        6: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/wrap.rb:53:in `wrap'
        5: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/line_wrap.rb:47:in `wrap_line'
        4: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/line_wrap.rb:77:in `apply_font_settings_and_add_fragment_to_line'
        3: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/arranger.rb:166:in `apply_font_settings'
        2: from /Users/me/.rvm/gems/ruby-2.6.1/gems/pdf-core-0.7.0/lib/pdf/core/text.rb:214:in `character_spacing'
        1: from /Users/me/.rvm/gems/ruby-2.6.1/gems/prawn-2.2.2/lib/prawn/text/formatted/arranger.rb:168:in `block in apply_font_settings'
RuntimeError (Bad font family)

However if I set the font explicitly instead of using the fallback then the error goes away. I have tested this with multiple Nepali fonts and gotten the same result. However, the issue doesn't come up when using a Thai font as a fallback for Thai strings.

@ameuret
Copy link
Contributor

ameuret commented Jan 4, 2024

I'd say it's because the font family name (declared in the ttf file) is actually 'Miedinger Book'.

Try changing your update call to:

pdf.font_families.update({'Miedinger Book' => {

Note the additional SPACE.

@pointlessone
Copy link
Member

@ameuret Prawn doesn't use PostScript font names to resolve fonts. You can name fonts anything you want and refer to them by that name. PostScript font names are used internally for different things to follow the PDF spec but those are unrelated to how Prawn resolves fonts.

@whitmer I can't reproduce the failure on master branch. It might've been already fixed. However, Prawn still doesn't support complex scripts such as Nepali. See #1295.

I'm closing this but feel free to reopen if you have more details and the issue is not resolved for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants