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

Commit

Permalink
[Impeller] Make text glyph offsets respect the current transform (#39119
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bdero authored Jan 25, 2023
1 parent 2e7d6fa commit 30c02e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 15 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "impeller/entity/contents/scene_contents.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 @@ -1183,6 +1184,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

0 comments on commit 30c02e4

Please sign in to comment.