-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix icon text fit #8741
Fix icon text fit #8741
Conversation
This PR changes the way icons are aligned with text when the and with this PR applied: As you can see, the previous code essentially ignored the This makes me believe that we should better define how
/cc @mapbox/design @mapbox/studio |
I don't think there are valid use cases for that. @kkaefer My 2c would be this: When |
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 is quite a big difference in test/integration/render-tests/text-variable-anchor/all-anchors-icon-text-fit/expected.png is it caused by incorrect icon collision boxes?
@asheemmamoowala it didn't initially, but I changed the behavior so that the text-fitting happens earlier in the process and is now respected in the collision boxes it generates. @tristen I made an example page that allows playing with the various values and how they're affecting positioning: I increased the size so that it's easier to see. In Firefox and Chrome, antialiasing for the resized canvas is disabled (Safari doesn't have support for that). A few other things that are fixed:
There are also some changes that I'm not sure about:
Using |
49f27a0
to
cb7c306
Compare
Oh awesome @kkaefer "Fixed/new version" is 👨🍳 💋 |
This seems like reasonable behavior to me, and provides decent outcomes, but I wonder if there is enough of a use-case to add support and documentation for this nuance.
👍 to disabling |
cb7c306
to
878e018
Compare
For the sake of getting this merged let's defer dealing with the |
878e018
to
035598a
Compare
035598a
to
fb1a4ef
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.
looks great!
One question, not directly related to changes in this PR. In some of the tests, for instance, both-text-anchor-1x-image-2x-screen, text is not center-aligned to the anchor, is it a bug?
Can you say more? I believe that this test image is correct. |
897129a
to
9908423
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.
There are ~9 rendered tests added here with the same geojson source data. Could those be moved into a separate fixture?
Could you also update the style spec doc for text-icon-fit
to indicate that it disables icon-size
and icon-anchor
.
I decided to move this to the next release since we'll have a few other fixes and behavior changes for |
This PR sizes and positions the collision boxes correctly, except when using |
9908423
to
f1f31ce
Compare
I pushed two commits to Both commits fail the icon-text-fit/text-variable-anchor render tests. I haven't investigated whether this are good or bad differences. |
We're adding a 1 pixel border around all icons when adding them to the image atlas texture to avoid having neighboring icons bleed into the current image when using linear texture interpolation. When stretching icons to fit the text's dimensions with `icon-text-fit`, however, we didn't account for this correctly: We didn't add the border in this case, resulting in stretched icons that didn't quite cover the whole text. When the difference between the icon's original size and the stretched size was small, this wasn't really noticeable, especially in cases where we were using nearest neighbor texture interpolation instead of linear interpolation. When accounting for the 1 pixel border, have to to take into account that there's no longer a 1:1 mapping between vertex units and pixel units, and expand the vertices adequately.
also add a lot more unit and render tests
23d3dda
to
95c918b
Compare
Thanks @ansis! I only picked the first commit because this puts us at par with GL Native. Let's land the second patch in a separate PR. |
@kkaefer is there a ticket or PR for the second patch mentioned here? |
Yes, it's at #8803 |
We're adding a 1 pixel border around all icons when adding them to the image atlas texture to avoid having neighboring icons bleed into the current image when using linear texture interpolation. When stretching icons to fit the text's dimensions with
icon-text-fit
, however, we didn't account for this correctly: We didn't add the border in this case, resulting in stretched icons that didn't quite cover the whole text. When the difference between the icon's original size and the stretched size was small, this wasn't really noticeable, especially in cases where we were using nearest neighbor texture interpolation instead of linear interpolation. When accounting for the 1 pixel border, have to to take into account that there's no longer a 1:1 mapping between vertex units and pixel units, and expand the vertices adequately.Here's an example:
This example uses a really small icon so that the discrepancy between the true size and the scaled size is big, which leads to a large error.
Native patch is forthcoming.