prawnpdf / prawn-table

Provides support for tables in Prawn
Other
205 stars 98 forks source link

Table cell auto width calculated wrong with inline styles #73

Open willjohnson opened 7 years ago

willjohnson commented 7 years ago

I seem to be having the issue that is laid out in this issue:

https://github.com/prawnpdf/prawn/issues/360

The auto width of the table cells seems to calculate by including the characters used in the html tags. In this case <font size='20'> and </font>.

table_data = Array.new

list_items.each do |li|

    table_data << ["<font size='20'>*</font>", li.text]

end

table(table_data, :cell_style => {:border_width => 1, :padding => 2, :inline_format => true})
basvk commented 7 years ago

I've been bitten by this bug today as well (or at least, the issue title fits). Widths of columns in a table that has :inline_format => true are calculated incorrectly, even without any html tags in the strings. I'm using a different font than the default for this table though. By removing the :inline_format => true from the table options I get a correct result.

Looks like Prawn::Table::Cell::Text#styled_width_of is not passing enough style information to Prawn::Document#width_of (for example font information), as a result the arranger uses default document font settings to calculate width.