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

[CP] [Impeller] Make text glyph offsets respect the current transform #39140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/tiled_texture_contents.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/geometry_unittests.h"
#include "impeller/geometry/matrix.h"
#include "impeller/geometry/path_builder.h"
Expand Down Expand Up @@ -1178,6 +1179,20 @@ TEST_P(AiksTest, CanRenderTextOutsideBoundaries) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, TextRotated) {
Canvas canvas;
canvas.Transform(Matrix(0.5, -0.3, 0, -0.002, //
0, 1, 0, 0, //
0, 0, 0.3, 0, //
100, 100, 0, 1.3));

ASSERT_TRUE(RenderTextInCanvas(
GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?",
"Roboto-Regular.ttf"));

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanDrawPaint) {
Paint paint;
paint.color = Color::MediumTurquoise();
Expand Down
17 changes: 9 additions & 8 deletions impeller/compiler/shader_lib/impeller/transform.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ vec2 IPVec2TransformPosition(mat4 matrix, vec2 point) {
// atlas.
vec4 IPPositionForGlyphPosition(mat4 mvp,
vec2 unit_position,
vec2 glyph_position,
vec2 glyph_size) {
vec4 translate =
mvp[0] * glyph_position.x + mvp[1] * glyph_position.y + mvp[3];
mat4 translated_mvp =
mat4(mvp[0], mvp[1], mvp[2], vec4(translate.xyz, mvp[3].w));
return translated_mvp * vec4(unit_position.x * glyph_size.x,
unit_position.y * glyph_size.y, 0.0, 1.0);
vec2 destination_position,
vec2 destination_size) {
mat4 translation = mat4(1, 0, 0, 0, //
0, 1, 0, 0, //
0, 0, 1, 0, //
destination_position.xy, 0, 1);
return mvp * translation *
vec4(unit_position.x * destination_size.x,
unit_position.y * destination_size.y, 0.0, 1.0);
}

#endif