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 incorrectly wraps with custom font... #130

Closed
eat-sleep-code opened this issue Jun 16, 2017 · 14 comments
Closed

Text incorrectly wraps with custom font... #130

eat-sleep-code opened this issue Jun 16, 2017 · 14 comments
Labels

Comments

@eat-sleep-code
Copy link
Contributor

eat-sleep-code commented Jun 16, 2017

  • display.AddText(text = 'Awaiting player roster', x = 5, y = 5, size = 14, Id = 'Status') results in text wrapping because there is not quite enough room to fit the text with the default font.

  • display.AddText(text = 'Awaiting player roster', x = 5, y = 5, size = 14, Id = 'Status', font_path = '/font/benton-sans-regular.ttf') results in text wrapping, even though the font face should provide plenty of room for the text.

It appears that font geometry is not being properly accounted for.

@shawaj
Copy link
Member

shawaj commented Jun 16, 2017

Thanks, this is a good find! As you say it's not actually taking into account the font geometry.

@tvoverbeek do you know if there is a way to allow it to be aware of the size of the font?

@eat-sleep-code
Copy link
Contributor Author

This is pretty much the last thing standing in the way of my app working perfectly.

@tvoverbeek
Copy link
Contributor

tvoverbeek commented Jul 3, 2017 via email

@eat-sleep-code
Copy link
Contributor Author

@tvoverbeak So that would get me height and width of my text? But what would I do with the height and width?

@tvoverbeek
Copy link
Contributor

Look at the code in textpos.py (https://github.com/PiSupply/PaPiRus/blob/master/papirus/textpos.py).
Function addToImageText (lines 77-157) does the calculations for wrapping the text.
Its calculations are based on a fixed width font (equal width for each character).
This function needs to be modified substantially to support variable width fonts by using ImageFont.ImageFont.getsize(text). You will either have to do this yourself, or wait till I am back home in Europe after my holidays (after July 11) before I can experiment and test this.
Maybe somebody else beats me to it.
Regards from down under.

@eat-sleep-code
Copy link
Contributor Author

I will let you tackle it when you get back. My Python skills are elementary, so would prefer if a pro did it. Have a good holiday.

@eat-sleep-code
Copy link
Contributor Author

@tvoverbeek Had any chance to review this yet?

@tvoverbeek
Copy link
Contributor

tvoverbeek commented Jul 20, 2017 via email

@tvoverbeek
Copy link
Contributor

See my PR #142. Should solve your problem.

@eat-sleep-code
Copy link
Contributor Author

@tvoverbeek see my comment on the PR about an extraneous preceding space.

@eat-sleep-code
Copy link
Contributor Author

eat-sleep-code commented Jul 25, 2017

Also might be nice to have option to limit text to X lines (and truncate any remaining data).

@tvoverbeek
Copy link
Contributor

tvoverbeek commented Jul 25, 2017 via email

@eat-sleep-code
Copy link
Contributor Author

See pull request for text limiting. In the case of my MLB app, sometimes a play description provided by MLB was too long and was colliding with the ball and base display below it. By adding a maxLines feature, I can limit it to 3 lines and prevent the collision. I also resolved the preceding space issue that was causing subsequent lines to be slightly updated.

@tvoverbeek
Copy link
Contributor

PR #144 has been merged. Closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants