Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4784512

Browse files
committed
Handle non-trivial transforms
1 parent 1bfd501 commit 4784512

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

impeller/entity/contents/text_contents.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static bool CommonRender(
154154
Point{static_cast<Scalar>(atlas->GetTexture()->GetSize().width),
155155
static_cast<Scalar>(atlas->GetTexture()->GetSize().height)};
156156

157-
Vector2 screen_offset = (entity.GetTransformation().Basis() * offset).Round();
157+
Vector2 screen_offset = (entity.GetTransformation() * offset).Round();
158158

159159
for (const auto& run : frame.GetRuns()) {
160160
auto font = run.GetFont();
@@ -170,21 +170,34 @@ static bool CommonRender(
170170
// For each glyph, we compute two rectangles. One for the vertex positions
171171
// and one for the texture coordinates (UVs).
172172

173-
auto screen_space_glyph_origin =
174-
(entity.GetTransformation() *
175-
(glyph_position.position + glyph_position.glyph.bounds.origin))
176-
.Floor() +
177-
screen_offset;
178-
179173
auto uv_origin =
180174
(atlas_glyph_bounds->origin - Point(0.5, 0.5)) / atlas_size;
181175
auto uv_size = (atlas_glyph_bounds->size + Size(1, 1)) / atlas_size;
182176

177+
// Rounding here prevents most jitter between glyphs in the run when
178+
// nearest sampling.
179+
auto screen_glyph_position =
180+
screen_offset +
181+
(entity.GetTransformation().Basis() *
182+
(glyph_position.position + glyph_position.glyph.bounds.origin))
183+
.Round();
184+
183185
for (const auto& point : unit_points) {
184186
typename VS::PerVertexData vtx;
185187

186-
vtx.position =
187-
screen_space_glyph_origin + (point * atlas_glyph_bounds->size);
188+
if (entity.GetTransformation().IsTranslationScaleOnly()) {
189+
// Rouding up here prevents the bounds from becoming 1 pixel too small
190+
// when nearest sampling. This path breaks down for projections.
191+
vtx.position =
192+
screen_glyph_position + (entity.GetTransformation().Basis() *
193+
point * glyph_position.glyph.bounds.size)
194+
.Ceil();
195+
} else {
196+
vtx.position = entity.GetTransformation() *
197+
(offset + glyph_position.position +
198+
glyph_position.glyph.bounds.origin +
199+
point * glyph_position.glyph.bounds.size);
200+
}
188201
vtx.uv = uv_origin + point * uv_size;
189202

190203
if constexpr (std::is_same_v<TPipeline, GlyphAtlasPipeline>) {

0 commit comments

Comments
 (0)