-
-
Notifications
You must be signed in to change notification settings - Fork 80
Draw text #384
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
Draw text #384
Conversation
dlech
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code looks fine. Some high-level discussion though...
I'm wondering if a fixed width font would be a better choice for a first font since that is what people will be used to on EV3 and NXT. It makes it easier to line things up nicely on the screen and be able to print over existing text with a new value and know that it will be the same size so it won't leave extra artifacts on the screen.
lib/pbio/tools/fontconvert.py
Outdated
| """Convert a font to format used by pbio.""" | ||
|
|
||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2025 Nicolas Schodet | ||
| # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Convert a font to format used by pbio.""" | |
| # | |
| # SPDX-License-Identifier: MIT | |
| # Copyright (c) 2025 Nicolas Schodet | |
| # | |
| # | |
| # SPDX-License-Identifier: MIT | |
| # Copyright (c) 2025 Nicolas Schodet | |
| # | |
| """Convert a font to format used by pbio.""" | |
Makes it a little easier for license auditing tools to have the license as close to the top of the file as we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
I changed to Terminus Font 8x16 pixels. I kept Liberation Sans for the future GUI. |
8f5d3fd to
d8a305e
Compare
This is needed for building fonts.
Use only one font for the moment, Terminus Font, 8x16 pixels size. A script is included to generate the font source using freetype-py. Only handle ASCII characters as discussed. Antialiasing is not that great with the limited number of gray levels on the EV3, so use only monochrome font, which works great thanks to hinting. Refs: pybricks/support#2154
There is no need to load image from a string, and there is a more pythonic way to get the screen Image object from the hub object. Refs: pybricks/support#2154
d8a305e to
219c19b
Compare
|
Merged, thank you! |
|
I noticed most shapes like boxes are drawn down from the top, so a box of 10 height shows as 10 pixels. For text, it seems inverted. So text displayed at (0, 0) gets partially chopped off. Is that intentional? I would have expected text to work like other shapes, but I don't remember 100% what our old API did. I was drawing a box to put text in, but the text is always outside the box if you set the same |
|
The coordinate is the one of the text baseline, see the Freetype doc for explanation. However, the python API use the top-left corner to match the EV3 API: pbio_image_draw_text(&self->image, font, x, y + font->top_max, text, text_len, text_color);It adds I would like to add some API to access font metrics from python, it will be useful for non-monospace fonts. |
|
Thank you. If it is intentional, I am all for it! 😄 |
Include only one font for the moment, Liberation Sans Regular, 14 pixels em size.
A script is included to generate the font source using freetype-py.
Only handle ASCII characters as discussed.
Antialiasing is not that great with the limited number of gray levels on the EV3, so use only monochrome font, which works great thanks to hinting.
Also remove string Image parameter as discussed.