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

No fallback_fonts support? #80

Open
luiges90 opened this issue Mar 29, 2017 · 6 comments
Open

No fallback_fonts support? #80

luiges90 opened this issue Mar 29, 2017 · 6 comments

Comments

@luiges90
Copy link

luiges90 commented Mar 29, 2017

It seems that fallback_fonts are unsupported in tables. That means if I want to put text of multiple languages in one table while having suitable font for each languages I am out of luck 😞

pdf = Prawn::Document.new
pdf.font_families["zh"] = {
  :normal => { :file => "#{data_path}/bsmi00lp.ttf", :font => "zh" }
}
pdf.fallback_fonts ['Helvetica', 'zh']

table = [
  ['', '總覽SUMMARY', ''],
  ['...', '東西something', '...']
]

pdf.table(table, width: pdf.bounds.width, cell_style: {fallback_fonts: ['Helvetica', 'zh']})

Gives me this error

Your document includes text that''s not compatible with the Windows-1252 character set.
If you need full UTF-8 support, use TTF fonts instead of PDF''s built-in fonts.
@hC4stillo
Copy link

Having the same problem here, can't get fallback fonts inside table cells

@oshanz
Copy link

oshanz commented Mar 13, 2018

prawnpdf/prawn#1054
seems that issue also is also about the same problem

@fbukevin
Copy link

fbukevin commented May 18, 2018

With collecting some information, here is a workaround works for me:

  1. Check #{Prawn::DATADIR}/fonts/ if the TrueType font file you want exists. If not, download it and put it into the folder. I have no idea why gkai00mp.ttf (font for simplified Hant letters) was not installed when I use bundle to install prawn. But you can find it here.

  2. In the prawn pdf file

prawn_document do |pdf|	
  pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
  pdf.text "你好,世界!"
end

Should works fine.

@urkle
Copy link

urkle commented Feb 21, 2022

@pointlessone So, I ran across this issue while researching if Prawn + Prawn-Table is a viable option for building out reports.

It seems the issue is centered around the Table::Cell::Text class calling width_of on the font text (and other related methods) but the "text" does not get checked for fallback fonts before calling that method.

In the core Prawn this happens because all text rendering ends up going through a Formatted::Box before doing any work, and that Box class has a series of functions to process the text ( #process_fallback_fonts ).

So the question is how can we fix this issue cleanly in Prawn-Table?

  1. I can "hack away" and copy portions of box into Cell::Text to have it implement the fallback_font functionality?
  2. I can rework Cell::Text to utilize the Box class instead (hopefully).

@pointlessone
Copy link
Member

@urkle I'm a bit rusty on the prawn-table internals. Option 2 sound like a cleaner approach. I take it's easier to copy code over but if we change how text boxes work in Prawn we will end up with a diverging implementation again.

@urkle
Copy link

urkle commented Mar 14, 2022

@pointlessone I have a working set of PRs. It required making some slight changes to Prawn core (adding a new method to the Fomatted::Box to request it calculate the width)

prawnpdf/prawn#1259 - Core changes to prawn needed
#145 - Changes to prawn-table needed

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

6 participants