Fixed glyph positions flipping by one pixel when atlas slot assignments changed.#1508
Merged
Conversation
… positions land on integer pixels.
Hparty
requested review from
domchen,
richardshan0614 and
shlzxjp
as code owners
July 22, 2026 05:17
shlzxjp
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题:字形图集渲染的像素对齐直接对平移分量做 std::round。平移量 = 真实设备位置 - 图集槽位坐标,当真实位置为半整数时,std::round 半值远离零的特性会使取整方向随槽位正负翻转,导致同一个字形仅因被分配到图集不同槽位(取决于渲染历史)而偏移 1px。
修改:ComputeGlyphRenderMatrix 改为先对槽位无关的设备锚点坐标(matrix * atlasLocation)取整,再减去精确的矩阵线性项回写到平移分量,渲染时与矩阵自身的缩放项精确抵消,锚点精确落在整数像素上。非复杂分支的 y 方向同样消除了对 atlasLocation.y 的取整依赖,并保留整行共享基线加逐字形偏移分别取整的原有设计;复杂与非复杂两个分支的数学形式已统一。
基准:6 个截图测试的基准版本已在 version.json 中更新(TextAlignTest x3、TextRenderTest、LayerTest、VectorLayerTest)。