Closed tandibar closed 8 years ago
@tandibar - Thanks for filing an issue!
Any chance you can provide me a link to the .ttf
files that you're using?
I've noticed this issue before, and I believe the issue lies in the code for Prawn::Table
(see my comment in #7). With the proper font files, I should be able to replicate the issue and further investigate.
I found the necessary font files on Google fonts. Here's some initial observations:
Prawn::Errors::CannotFit
exception is thrown because there is not enough width in the table's TextBox
to render the icon. This is tested and appropriate behaviour in Prawn.Prawn::Table
the minimum cell width is not being calculated properly, but I'm not quite sure yet.For the time being, you can simply force the table cell to have a certain width when dealing with custom fonts:
font 'Monda'
data = [
[table_icon('fa-birthday-cake', width: 24), 'Cake'],
['is', 'Great!']
]
table(data)
The real question is:
Why is Prawn::Table
not determining an appropriate minimum width for the cell that includes the icon? Perhaps the font change is not being handled properly - I'll need to dig deeper.
I can confirm that this is caused by a defect in the Prawn::Table
codebase.
Please see Prawn::Table #42. Prawn::Table
appears to not consider the cell's specified font when calculating the minimum width requirements for a table cell.
Furthermore, this code reveals that Prawn::Table
naively uses the M
character as the widest individual character in a font. Clearly this behaviour is incompatible with icon fonts.
@tandibar - I'm going to keep this issue open for a few days as reminder to myself, but there is not very much that can be done for this issue from Prawn::Icon
's perspective (other than specifying the cell's width).
Hi, thx for taking care so your quickly. I just tried with manually setting width and it works. I need to set at least 19 as width. But there is much white space in the cells.
I will see what Prawn::Table
does to take care of this. For me it's totally okay to close this issue.
Perfect thanks!
Also note that the valign
and align
settings may be useful for moving the icons around in the cell:
data = [
[table_icon('fa-birthday-cake', width: 24, valign: :center, align: :center), 'Cake'],
['is', 'Great!']
]
table(data)
I am using a special font like this:
if i run your simple example after that
it crashes with
Prawn::Errors::CannotFit
exception. Any idea?