Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text_box with shrink_to_fit sometimes crops end of sentence #1292

Open
unterkoefler opened this issue Feb 16, 2023 · 0 comments · May be fixed by #1293
Open

text_box with shrink_to_fit sometimes crops end of sentence #1292

unterkoefler opened this issue Feb 16, 2023 · 0 comments · May be fixed by #1293

Comments

@unterkoefler
Copy link

In rare cases, Text#text_box (https://www.rubydoc.info/gems/prawn/Prawn/Text#text_box-instance_method) with the overflow: :shrink_to_fit option causes part of the text to be cropped out. This is unexpected because if the text doesn't fix the box, it should be shrunk until it does, not cropped.

This occurs specifically when the width of the box is just big enough to fit the text and two float precisions errors occur. Say, for example, we want to put "Two words" in a text box of width 50.0. First, when shrink_to_fit runs to determine the font size, the width of "Two words" is computed as 49.999999.shrink_to_fit says, cool, this will fit, no need to reduce the font size or wrap the line. Then the line is actually printed and this time the width is computed as 50.00000001. This causes the line to be split and "words" is put on the second line, but if there isn't enough height, it will be cropped.

I have a commit with a spec that manually introduces these precision errors and has a failing spec here: unterkoefler@aca0044

Happy to put up a pr to fix :)

@unterkoefler unterkoefler linked a pull request Feb 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant