PiSupply / PaPiRus

Resources for PaPiRus ePaper eInk displays
https://www.pi-supply.com/product/papirus-epaper-eink-screen-hat-for-raspberry-pi/
Other
346 stars 88 forks source link

Text incorrectly wraps with custom font... #130

Closed eat-sleep-code closed 7 years ago

eat-sleep-code commented 7 years ago

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

shawaj commented 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?

eat-sleep-code commented 7 years ago

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

tvoverbeek commented 7 years ago

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 .

eat-sleep-code commented 7 years ago

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

tvoverbeek commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@tvoverbeek Had any chance to review this yet?

tvoverbeek commented 7 years ago

@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 .

tvoverbeek commented 7 years ago

See my PR #142. Should solve your problem.

eat-sleep-code commented 7 years ago

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

eat-sleep-code commented 7 years ago

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

tvoverbeek commented 7 years ago

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 .

eat-sleep-code commented 7 years ago

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 commented 7 years ago

PR #144 has been merged. Closing issue.