Closed eat-sleep-code closed 7 years ago
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?
This is pretty much the last thing standing in the way of my app working perfectly.
Look at the PIL ImageFont documentation. I believe the function you need is ImageFont.ImageFont.getsize(text) which returns (width, height).
On 2 July 2017 at 13:29, eat-sleep-code notifications@github.com wrote:
This is pretty much the last thing standing in the way of my app working perfectly.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/issues/130#issuecomment-312468664, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7kOSayutkKrA-Gr9v-nNNneqYctkks5sJw6fgaJpZM4N8uD1 .
@tvoverbeak So that would get me height and width of my text? But what would I do with the height and width?
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.
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.
@tvoverbeek Had any chance to review this yet?
@eat-sleep-code Back home now. Plan to start on it next week.
On Thu, Jul 20, 2017 at 9:49 PM, eat-sleep-code notifications@github.com wrote:
@tvoverbeek https://github.com/tvoverbeek Had any chance to review this yet?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/issues/130#issuecomment-316810884, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7hyGH3F8rOjEQeSkpzHpBdJg7vEoks5sP69IgaJpZM4N8uD1 .
See my PR #142. Should solve your problem.
@tvoverbeek see my comment on the PR about an extraneous preceding space.
Also might be nice to have option to limit text to X lines (and truncate any remaining data).
See reply on the PR. Regarding limiting the text, the code already limits the text to what fits on the screen. Any text going (vertically) off screen is discarded.
On Tue, Jul 25, 2017 at 6:32 AM, eat-sleep-code notifications@github.com wrote:
Also might be nice to have option to limit text to X lines (and truncate any remain data).
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/issues/130#issuecomment-317626266, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7iCjCKa_oQiOaSfvUkgF78NMJrj5ks5sRW_cgaJpZM4N8uD1 .
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.
PR #144 has been merged. Closing issue.
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.