[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 25, 2023
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 @@ -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