Open luiges90 opened 7 years ago
Having the same problem here, can't get fallback fonts inside table cells
https://github.com/prawnpdf/prawn/issues/1054 seems that issue also is also about the same problem
With collecting some information, here is a workaround works for me:
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.
In the prawn pdf file
prawn_document do |pdf|
pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
pdf.text "你好,世界!"
end
Should works fine.
@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).
@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.
@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 prawnpdf/prawn-table#145 - Changes to prawn-table needed
It seems that
fallback_fonts
are unsupported intable
s. 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 😞Gives me this error