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
Fixed an issue where font metrics were incorrect for monospaced fonts. #8886
Conversation
com.dynamo.cr/com.dynamo.cr.bob/src/com/dynamo/bob/font/Fontc.java
Outdated
Show resolved
Hide resolved
hmmm, I was sure that the editor uses |
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.
Editor changes look good! 👍
Thanks. |
} | ||
|
||
glyphBankBuilder.setIsMonospaced(is_monospaced); | ||
glyphBankBuilder.setPadding(padding); |
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.
For non-monospaced fonts, this value taken into account as part of the last glyph width (we add padding*2 to each width). But for monospaced fonts, we need it to add it as part of the text width and also to offset it back when rendering monospaced font.
font-offset {:x (if (:is-monospaced font-map) | ||
(- 0 (* (:padding font-map) 0.5)) | ||
0) | ||
:y 0}] |
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.
We render each glyph starting some point and then draw every next letter at Advance Width (+ tracking) from prev. one.
But width of the glyph already include padding. Which makes width of the text a bit bigger and moves initial rendering point for the padding.
Adding padding the line-widths helps to return real line width and compensate 0.5 of padding for the positioning . But another 0.5 of padding should be compensted by moving the initial point of rendering (we can't just add double padding to the line-width)
@@ -739,6 +749,10 @@ namespace dmRender | |||
float layout_width; | |||
int line_count = Layout(text, width, lines, max_lines, &layout_width, lm, measure_trailing_space); | |||
float x_offset = OffsetX(te.m_Align, te.m_Width); | |||
if (font_map->m_IsMonospaced) | |||
{ | |||
x_offset -= font_map->m_Padding * 0.5f; |
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.
please check the comment for clojure code.
@@ -835,8 +849,8 @@ namespace dmRender | |||
|
|||
for (int line = 0; line < line_count; ++line) { | |||
TextLine& l = lines[line]; | |||
int16_t x = (int16_t)(x_offset - OffsetX(te.m_Align, l.m_Width) + 0.5f); | |||
int16_t y = (int16_t) (y_offset - line * leading + 0.5f); |
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.
Rounded vertex coordinates is the reason of dancing text (#7197)
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.
Checked in the editor, and it works great! Just some minor issues with indentation in the code.
Co-authored-by: Mats Gisselson <[email protected]>
Co-authored-by: Mats Gisselson <[email protected]>
Monospaced fonts should always use the fixed Advance Width for each symbol as its width, instead of the glyph's real width.
Fix #7900
Fix #7197
PR checklist
Example of a well written PR description:
### Technical changes
Technical changes:
Technical notes: