prawn
prawn copied to clipboard
Can't render Nepali text using fallback font, "Bad font family"
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.