-
Notifications
You must be signed in to change notification settings - Fork 134
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
text: change line ascent and descent to fit font size #123
base: main
Are you sure you want to change the base?
Conversation
Please follow the Go style for changes, and sign off your commits. Example:
Also, can you add a test so this behaviour doesn't regress? I'll let @whereswaldon decide on the change itself. |
368ebe5
to
c8a6e96
Compare
@eliasnaur Sure. Updated. And I have drop the leading around line, like line-height of css did. |
Signed-off-by: Morlay <[email protected]>
c8a6e96
to
52787f2
Compare
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.
Thank you for the patch and test. I've tried to carefully review this change and its implications, and I'm not certain that we want to go this direction.
This change will force a run shaped with size X to have an effective bounds height of X even if the font for that run displays glyphs larger than or smaller than X. We lose information provided by the font designer here by overriding their preferences.
Additionally, even if every run of text on a line is the same size (not guaranteed), I believe this change will not guarantee that the line as a whole has an ascent and descent that sum to X. If varying runs of text have differently-distributed ascents and descents with respect to the baseline, we may take the branch on line 905 for one run, and the branch on 908 for a different run, resulting in the most extreme ascent and descent available on the line being set as the line's overall ascent/descent. This is also the current behavior, but I think is something that the changeset wanted to alter.
When I sanity-check this behavior against CSS, it seems that CSS also does not normalize baseline positions.
I believe that the correct way to achieve what you wanted is to align the stacked text by their respective baselines. Sadly, layout.Stack
does not have a feature for that, but we can at least demonstrate the idea with layout.Flex.
You could write a layout type that allows stacking content aligned by baseline by borrowing relevant portions of code from layout.Flex
and layout.Stack
.
In the general case, I don't think text is safe to align purely by matching the upper-left corner of the bounding box in many GUI software toolkits, so I'm reluctant to make this change within Gio.
@morlay What do you think? Am I missing some important context or use-cases?
The biggest problem isn't the layout, it's in the text input. Chars is dancing when text mixed inputing, because of this problem. |
For css, it could fixed by line height https://codepen.io/morlay/pen/jOXKKrw But css line height model is different. https://iamvdo.me/en/blog/css-font-metrics-line-height-and-vertical-align So I choose the resizing to fix. |
0d543a0
to
1686874
Compare
How do you think? |
@morlay Thank you for your patience. Gio's line height model currently defines the distance between baselines, unlike CSS. This has the consequence of not defining the distance between the first baseline and the logical top of the text. To get a logical top, we're currently using the highest ascender value of any run on the first line. Since varying fonts have varying ascender heights, we get the jumping as we switch between fonts that you describe within the editor. None of Gio's specific text metric behaviors are set in stone. My goal in choosing them has always been to try to learn from other text stacks and choose the (seemingly) best model I could find. Our line height has both
I don't love normalizing the baseline because it discards font information, so I think I'd prefer to explore making our line height definition solve this problem. Can you elaborate on what you would like to change about the line height semantics in order to address this? |
May consider to support this feature https://github.com/jantimon/text-box-trim-examples I think we could define the baseline easier. |
@morlay, what version of EDIT: Actually, the font is from EDIT2: With |
The status of this PR, from my point of view, is:
Though I'm learning, I'm by no means a text layout expert, especially in the spacing/alignment area. I'm open to input on how we should evolve our model to address this. Thus far, I think I've heard a few proposed solutions:
|
It is to resolve line-height issue of css. if we don't want to implement line-height like css. I think we could ignore it.
Yes. But we could do normalizing for align the baseline only (fix offset-y). |
67c77c9
to
46cc311
Compare
f8029f2
to
026d3f9
Compare
037391a
to
4759601
Compare
3d36537
to
74ccc9c
Compare
With this patch, the example will render correct like
with v0.3.0,same font size and line height not stacked.
For
widget.Editor
,baseline will change, when CJK char input after nonCJK ones.
This patch could fix this too.
Example: