jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.31k stars 777 forks source link

Fix right alignment #244

Closed Anka2310 closed 5 years ago

Anka2310 commented 5 years ago

width has already been reduced by left and right margin, so right margin doesn't need to be subtracted twice

Anka2310 commented 5 years ago

During testing I found out that automatic line breaks occur with this PR. It seems that a little more space needs to be subtracted (e.g. 5mm works), but I'm not sure what value would be best for all cases.

jung-kurt commented 5 years ago

The WriteAligned example works properly without the change, but breaks after the change.

What is the situation where the current logic doesn't work properly?

Anka2310 commented 5 years ago

You can see also in the WriteAligned example that the current logic doesn't work properly; the right margin is taken into account twice, so the space to the right side is too large.

jung-kurt commented 5 years ago

You can see also in the WriteAligned example that the current logic doesn't work properly; the right margin is taken into account twice, so the space to the right side is too large.

Right you are, @Anka2310. It becomes quite evident when you increase the right margin in that example. Thanks for calling this out.

It seems that a little more space needs to be subtracted (e.g. 5mm works), but I'm not sure what value would be best for all cases.

I think we need to figure out where this small discrepancy originates so we can fix it correctly.

jung-kurt commented 5 years ago

Thanks, @Anka2310 -- this was a good catch.

It looks like the cell margins were causing the unexpected automatic line break. This is addressed by subtracting a "smidge" more than twice the cell margin from the string width -- not pretty, but disabling line breaks by some other means seems like it would be even less so. If you find a cleaner solution, let's use it!