Skip to content

Commit 55dca70

Browse files
bderozanderso
authored andcommitted
[Impeller] Make text glyph offsets respect the current transform (flutter#39119)
1 parent b24591e commit 55dca70

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "impeller/entity/contents/filters/inputs/filter_input.h"
1616
#include "impeller/entity/contents/tiled_texture_contents.h"
1717
#include "impeller/geometry/color.h"
18+
#include "impeller/geometry/constants.h"
1819
#include "impeller/geometry/geometry_unittests.h"
1920
#include "impeller/geometry/matrix.h"
2021
#include "impeller/geometry/path_builder.h"
@@ -1178,6 +1179,20 @@ TEST_P(AiksTest, CanRenderTextOutsideBoundaries) {
11781179
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
11791180
}
11801181

1182+
TEST_P(AiksTest, TextRotated) {
1183+
Canvas canvas;
1184+
canvas.Transform(Matrix(0.5, -0.3, 0, -0.002, //
1185+
0, 1, 0, 0, //
1186+
0, 0, 0.3, 0, //
1187+
100, 100, 0, 1.3));
1188+
1189+
ASSERT_TRUE(RenderTextInCanvas(
1190+
GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?",
1191+
"Roboto-Regular.ttf"));
1192+
1193+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1194+
}
1195+
11811196
TEST_P(AiksTest, CanDrawPaint) {
11821197
Paint paint;
11831198
paint.color = Color::MediumTurquoise();

impeller/compiler/shader_lib/impeller/transform.glsl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ vec2 IPVec2TransformPosition(mat4 matrix, vec2 point) {
1515
// atlas.
1616
vec4 IPPositionForGlyphPosition(mat4 mvp,
1717
vec2 unit_position,
18-
vec2 glyph_position,
19-
vec2 glyph_size) {
20-
vec4 translate =
21-
mvp[0] * glyph_position.x + mvp[1] * glyph_position.y + mvp[3];
22-
mat4 translated_mvp =
23-
mat4(mvp[0], mvp[1], mvp[2], vec4(translate.xyz, mvp[3].w));
24-
return translated_mvp * vec4(unit_position.x * glyph_size.x,
25-
unit_position.y * glyph_size.y, 0.0, 1.0);
18+
vec2 destination_position,
19+
vec2 destination_size) {
20+
mat4 translation = mat4(1, 0, 0, 0, //
21+
0, 1, 0, 0, //
22+
0, 0, 1, 0, //
23+
destination_position.xy, 0, 1);
24+
return mvp * translation *
25+
vec4(unit_position.x * destination_size.x,
26+
unit_position.y * destination_size.y, 0.0, 1.0);
2627
}
2728

2829
#endif

0 commit comments

Comments
 (0)