boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
735 stars 157 forks source link

Text height calculation causing misalignment #122

Closed jheth closed 7 years ago

jheth commented 7 years ago

Have you seen a scenario where stamp_pages mis-aligns text for bottom_left, bottom, bottom_right when using characters that sit below the line? g, j, p, q, y

bottom_left: Introduction bottom: sample.docx bottom_right: 3

It's a noticeable height difference when only one position has one of these characters. It seems like the issue is with the height calculation. It's interesting that the top margin is not as noticeable.

jheth commented 7 years ago

I propose the following change to fonts.rb, dimensions_of:

      height = metrics_array.map { |m| m ? m[:boundingbox][3] : 0 } .max
      height_min = (metrics_array.map { |m| m ? m[:boundingbox][1] : 0 }).min
      height -= height_min if height_min > 0

Only subtract the min height if it's greater than 0.

jheth commented 7 years ago

I take part of this back. This is only an issue when font_size is changing. I think it's font_size andtext_valign causing the problem.

jheth commented 7 years ago

Not an issue.

boazsegev commented 7 years ago

Hi @jheth ,

Thank you for opening this issue. I was without internet access for the last week and apologize for the belated response.

I see you closed the issue, so I assume everything works as expected.

If you find any unexpected behavior, please let me know. I'm happy to help.

Have a wonderful day, Bo.