feat(core): render local CJK glyphs at 2x texture resolution (#4304)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Taku Fukada
2026-07-01 20:52:01 +09:00
committed by GitHub
parent 60f15190c3
commit 887e6021e6
22 changed files with 357 additions and 84 deletions

View File

@@ -71,7 +71,8 @@ void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphD
Glyph GlyphManager::generateLocalSDF(const FontStack& fontStack, GlyphID glyphID) {
Glyph local = localGlyphRasterizer->rasterizeGlyph(fontStack, glyphID);
local.bitmap = util::transformRasterToSDF(local.bitmap, 8, .25);
const double radius = local.metrics.isDoubleResolution ? 16.0 : 8.0;
local.bitmap = util::transformRasterToSDF(local.bitmap, radius, .25);
return local;
}

View File

@@ -11,21 +11,13 @@ namespace mbgl {
the glyph and appropriate metrics. GlyphManager will then use TinySDF to
transform the rasterized bitmap into an SDF.
The JS equivalent of this functionality will only generate glyphs in the
'CJK Unified Ideographs' and 'Hangul Syllables' ranges, for which it can
get away with rendering a fixed 30px square image and GlyphMetrics of:
width: 24,
height: 24,
left: 0,
top: -8,
advance: 24
The JS equivalent also uses heuristic evaluation of the font stack name
to control the font-weight it uses during rasterization.
The shared default codepoint filter is
util::i18n::allowsFixedWidthGlyphGeneration.
Following maplibre-gl-js, platform implementations use 2x bitmaps with
1x metrics via GlyphMetrics::isDoubleResolution.
It is left to platform-specific implementation to decide how best to
map a FontStack to a particular rasterization.
map a FontStack to a particular rasterization (font, weight, style).
The default implementation simply refuses to rasterize any glyphs.
*/

View File

@@ -267,11 +267,15 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
builtInOffset = {0.0f, 0.0f};
}
// rectBuffer is in 1x logical units; only rect.w/h carry the texture
// scale. GL JS keeps 2x glyphs centered by storing fractional
// left/top metrics, so native local glyphs do the same.
const float textureScale = positionedGlyph.metrics.isDoubleResolution ? 2.0f : 1.0f;
const float x1 = (positionedGlyph.metrics.left - rectBuffer) * positionedGlyph.scale - halfAdvance +
builtInOffset.x;
const float y1 = (-positionedGlyph.metrics.top - rectBuffer) * positionedGlyph.scale + builtInOffset.y;
const float x2 = x1 + rect.w * positionedGlyph.scale / pixelRatio;
const float y2 = y1 + rect.h * positionedGlyph.scale / pixelRatio;
const float x2 = x1 + rect.w / textureScale * positionedGlyph.scale / pixelRatio;
const float y2 = y1 + rect.h / textureScale * positionedGlyph.scale / pixelRatio;
Point<float> tl{x1, y1};
Point<float> tr{x2, y1};