prawnpdf / prawn-table

Provides support for tables in Prawn
Other
206 stars 101 forks source link

Change movement depending on vertical table alignment #128

Open rsynnest opened 3 years ago

rsynnest commented 3 years ago

This is a potential fix for #127

It's a cheeky fix, but I think the end result is much better.

Before: image

After: image

Test PDF was generated using this code:

Prawn::Document.generate('result.pdf') do

data = [ ["TOP", "", ""], ]
table data, :cell_style => { :valign => :top}
move_down 20

data = [ ["CENTER", "", ""], ]
table data, :cell_style => { :valign => :center}
move_down 20

data = [ ["BOTTOM", "", ""], ]
table data, :cell_style => { :valign => :bottom}
move_down 20

end
rsynnest commented 3 years ago

Here is a PDF showing the results rendered for the 15 built-in Prawn fonts: result.pdf

The only ones that have a problem are Symbol and ZapfDingbats, but those would also blow up with the pre-PR code, because the bottom-alignment code is unchanged.

rsynnest commented 3 years ago

Someone let me know that TTF fonts might have negative results after this change. I went ahead and generated a PDF using 310 TTF fonts available in Windows 10.

Before this PR: before.pdf

After this PR: after.pdf

Most TTF fonts appear to benefit from this PR, and at the worst, they remain the same broken result as before the PR (usually Top and Center are just too low). I given that valign seems to be broken currently for ALL fonts, including the builtin ones, this fix at least fixes built in fonts, and seems to also benefit most TTF fonts in testing.