-
-
Notifications
You must be signed in to change notification settings - Fork 670
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
refactor(core): simplify fonts handling #4194
Conversation
|
i think we will drop entire buffers.c/h when we get rid of old rendering, which will hopefully be soon enough. |
00e4847
to
1fce051
Compare
Can the change of order in translation jsons cause some problems moving forward @matejcik ? If so, I can revert it and just define the The reason to start from |
yeah the ids are baked into the translation blobs, this would really mess up the upgrade/downgrade scenario. please revert. aside, I believe that there was a reason for skipping 0 for font index, but perhaps it doesn't apply anymore with this refactor? |
1fce051
to
94db1ee
Compare
I reverted the re-assignment of font IDs. The PR is ready for review.
|
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.
overall comment: why not get rid of font_id_t
and instead use const struct font_info_t*
pervasively? then it's the responsibility of the (first) caller to pass in a valid font_info_t, and everyone else can look at the attributes directly.
then instead of FONT_NORMAL
being an enum value, you would use &FONT_NORMAL
as a pointer to a const struct font_info_t in all places
in Rust you would change pub enum Font
to
pub type FontInfo = ffi::font_info_t;
pub type Font = &'static FontInfo;
impl font to impl fontinfo, modify the self
owning arguments to references because FontInfo is no longer Copy/Clone, adjust the rest...
one thing we'd need to do is keep the mapping to translation blob font ids somewhere. presumably only in Rust? because it's only Rust that interfaces with translation blobs
How are we with this one? @obrusvit |
94db1ee
to
27a9b80
Compare
I rebased the branch on top of |
27a9b80
to
e62b11b
Compare
} | ||
|
||
pub fn text_height(self) -> i16 { | ||
display::text_height(self.into()) | ||
display::get_font_info(self.into()).map_or(i16::MAX, |font| font.height.try_into().unwrap()) |
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'm thinking, just unwrap!()
the whole thing, asking for a text_height on an invalid font id should be an unrecoverable error, no? (dtto below)
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 kept it the same as it is in other equivalent functions in the file. Do you insist on unwrap!()
instead?
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.
yeah, I meant in all of them, not in text_height specifically.
i think unwrap!
is better here, it seems pointless to spend code on returning value for a nonexistent font?
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.
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.
ah but there's still an unwrap()
in there. we don't want to call fn unwrap
basically ever, always use unwrap!
this should be unwrap!(display::get_font_info(self.into())).height as i16
(honestly wouldn't worry about doing a try_into ... speaking of, why is it an int
in the struct and not uint16_t
?)
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 see. unwrap()
removed.
I kept int
as it was before. If you don't mind, as changing it to uint16_t
is a slightly larger change (fonts generator, generated fonts, function headers and callers), I'd postpone it to another PR not to prolong this one.
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.
not stopping the PR on it anymore but you could have avoided the map() if you just unwrap!() the result of get-font-info, which would have given you an infallible non-option struct with the height attribute
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.
yes, removed the map
on rebase
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.
It looks good to me. I've just commented on a few minor issues.
@@ -85,7 +82,7 @@ impl Glyph { | |||
c_data >> 4 | |||
} | |||
|
|||
pub fn bitmap(&self) -> Bitmap<'static> { | |||
pub fn bitmap(&self) -> Bitmap<'a> { |
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.
speaking of: it looks like Bitmap::new
does not check that there's enough data provided here? @cepetr can you comment?
} | ||
|
||
pub fn text_height(self) -> i16 { | ||
display::text_height(self.into()) | ||
display::get_font_info(self.into()).map_or(i16::MAX, |font| font.height.try_into().unwrap()) |
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.
yeah, I meant in all of them, not in text_height specifically.
i think unwrap!
is better here, it seems pointless to spend code on returning value for a nonexistent font?
Introduce a new flag `_NAME` for each font and reduce the usage of `_ENABLE` flag to purely compilation guard. [no changelog]
This commit removes the usage of macros for font data definitions. Instead, it includes data as const structs of newly introduced font_info_t type. [no changelog] refactor(core): use font_id_t instead of plain int [no changelog]
Change to the new structures and preserve manual changes. This commit also removes duplicated definition of nonprintable glyph for _UPPER fonts. [no changelog]
c1f3d3e
to
c09fd18
Compare
@matejcik this check at ensure!(data.len() == size, "Invalid glyph data size"); The problem was that padding to full bytes was applied also if the glyph was already aligned. Then the size of the data read from translation blob and the expected size calculated from "ý": "060807000718ccf3cdf0de00", // wrong
"ý": "060807000718ccf3cdf0de", // fixed Note that the problem was invisible for regular ASCII glyphs (in C arrays) because the last zero byte was simply ignored. However, I fixed it also for these cases. Please, see c09fd18 |
good fix but this also means that this will cause a nasty crash at text render time if you run with an outdated translation blob |
- re-implement some fonts handling functions in Rust and delete them from C - C code only needs to handle ASCII characters [no changelog]
[no changelog]
[no changelog]
c09fd18
to
a3680e6
Compare
This PR aims to further simplify the font handling in
core
.The main objective was to get rid of the numerous macros, which are quite cumbersome to work with. This is achieved by introducing
struct font_info_t
which is filled with needed data for each font during font generation bygen_font.py
. Then there is a functionget_font_info
defined In thecore/embed/gfx/fonts/fonts.c
which is used to access font data.TODO:
_UPPER
fonts seems not effective