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
Improve CJK text rendering [#2990] #3006
Conversation
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3006 +/- ##
==========================================
+ Coverage 75.11% 75.22% +0.10%
==========================================
Files 240 241 +1
Lines 19170 19244 +74
Branches 4325 4338 +13
==========================================
+ Hits 14400 14476 +76
+ Misses 4770 4768 -2
☔ View full report in Codecov by Sentry. |
Is it possible to fix the alignment as part of this PR as well (you mentioned changing it)? see #1051. |
I don't believe so. I would intend this PR to make it into a minor version release or even a patch (no API enhancements). If we change those hardcoded alignment numbers, we will almost certainly change the visual appearance of multilingual labels, which would be a "breaking" change for v4 possibly. We're in a bit of a bind from what I understand, because those numbers are hardcoded to be appropriate for the fonts Mapbox provided as part of their API - DIN Pro for latin and Arial Unicode for fallbacks. Because MapLibre users are using whatever fonts they like, we don't have data to support an improvement there. The best we could we do is make recommendations on a fallback font - see maplibre/font-maker#16 - and then make multilingual labels work well for that recommendation. In any case, it's beyond the scope of this PR. |
Ok, thanks for the info! |
@HarelM what's the best way example for the |
Try reading this: |
Testing https://bdon.github.io/maplibre-cjk/ visually on:
|
I think there are a few failing render tests due to this change. |
This looks like a fairly small change, so I think it can go in, I don't see and issues in the code. |
I'm currently experimenting with refactoring the code to move |
I added to my demo what would happen if we quadruple the resolution. Quite fun, it would allow MapLibre GL JS to render some quite large text labels without too much round corners |
I don't want to bring this pull request off track, but it is very appealing what you can do with local glyph generation. Will think about the options |
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've left a small comment, approved otherwise.
THANKS!! |
Can you resolve conflicts for the changelog file please? |
THANKS! |
not sure about this test case - at least locally I can delete the entire code block at
compareByPixelmatch always returns 0 (for all platforms). Can you verify you see the same?
|
Is this
maybe we need to use these? https://github.com/pngjs/pngjs#sync-api |
Maybe the pixel diff threshold of the test is too low to detect the improvement of this pull request ... |
Nope, the CJK map is empty, so nothing is drawn. |
Wait, not sure it is empty, I'll check if I can add a background... |
I'll open a PR shortly with the relevant fixes. Seem like this test is broken for a long time... :-( |
I've opened a PR: #3162. |
I've decided to remove the CJK test there and count on the render tests. |
@HarelM all the render tests may be passing because the test harness disables local ideograph rendering (the exact code path this PR affects) by default: I don't think there are any instances where this code is tested by render tests. If we enable the option in a render test, the exact pixel output will depend on platform. |
Created a new test using the old code at #3166 we can merge first before this PR |
Sure, why not. |
* Port CJK browser test to render test [#3006, #3162] * add platform-specific expected images for local ideographs render test. [#3166] * Ubuntu expected is tofu * github actions ubuntu runner: apt install CJK fonts for render tests [#3166] * Commit expected Ubuntu local ideographs image with noto fonts installed from apt [#3166]
Thanks bringing higher resolution CJK to MapLibre GL JS, @bdon. Can you open an issue in MapLibre Native that we remember to do the same there? |
* Double TinySDF-rendered glyphs with new texScale glyph property * Change topAdjustment/leftAdjustment to make 2x glyphs match 1x positions
Can we push this forward? |
@bdon any chance to fix that last few comments? |
The default allowed diff of 0.00025 is not sensitive enough to catch the difference here: visually it looks like the correct change in one of the 3 platforms (not sure what's going on in the other 2) with a diff of (gif attached) diff.mp4 |
I changed the test to use much larger text sizes over the default, which should make it more sensitive to pixel changes |
@bdon did you open a ticket in MapLibre Native? |
@wipfli I haven't. I can open one when I have a plan to work on it, but I don't right now. |
Addresses proposal in #2990
Double TinySDF-rendered glyphs with new texScale glyph property.
Change topAdjustment/leftAdjustment to make 2x glyphs match 1x positions.
Video clip of before/after:
cjk-pixel-align.mp4
This required adding
0.5
to both topAdjustment and leftAdjustment, otherwise the alignment was slightly off from the old glyphs, potentially being a "breaking" visual change (an extremely small one).Launch Checklist
Document any changes to public APIs- no changes to public APIs.CHANGELOG.md
under the## main
section.