[Impeller] Ignore the Z basis when scaling text (flutter/engine#41995)

Fixes https://github.com/flutter/flutter/issues/126510.

`GetMaxBasisLength()` includes the Z basis vector, which happens to not
be getting scaled down along with the X and Y for this reproduction
case. And so given the 2D nature of text and the intent of this scale
parameter, it's returning a value that's too large here.
This commit is contained in:
Brandon DeRosier
2023-05-12 15:28:19 -07:00
committed by GitHub
parent b46ff342f3
commit 54d5c489c2
4 changed files with 26 additions and 1 deletions

View File

@@ -1103,7 +1103,7 @@ void DlDispatcher::drawDisplayList(
void DlDispatcher::drawTextBlob(const sk_sp<SkTextBlob> blob,
SkScalar x,
SkScalar y) {
Scalar scale = canvas_.GetCurrentTransformation().GetMaxBasisLength();
Scalar scale = canvas_.GetCurrentTransformation().GetMaxBasisLengthXY();
canvas_.DrawTextFrame(TextFrameFromTextBlob(blob, scale), //
impeller::Point{x, y}, //
paint_ //

View File

@@ -336,6 +336,21 @@ TEST(GeometryTest, MatrixGetMaxBasisLength) {
}
}
TEST(GeometryTest, MatrixGetMaxBasisLengthXY) {
{
auto m = Matrix::MakeScale({3, 1, 1});
ASSERT_EQ(m.GetMaxBasisLengthXY(), 3);
m = m * Matrix::MakeSkew(0, 4);
ASSERT_EQ(m.GetMaxBasisLengthXY(), 5);
}
{
auto m = Matrix::MakeScale({-3, 4, 7});
ASSERT_EQ(m.GetMaxBasisLengthXY(), 4);
}
}
TEST(GeometryTest, MatrixMakeOrthographic) {
{
auto m = Matrix::MakeOrthographic(Size(100, 200));

View File

@@ -202,6 +202,14 @@ Scalar Matrix::GetMaxBasisLength() const {
return std::sqrt(max);
}
Scalar Matrix::GetMaxBasisLengthXY() const {
Scalar max = 0;
for (int i = 0; i < 3; i++) {
max = std::max(max, e[i][0] * e[i][0] + e[i][1] * e[i][1]);
}
return std::sqrt(max);
}
/*
* Adapted for Impeller from Graphics Gems:
* http://www.realtimerendering.com/resources/GraphicsGems/gemsii/unmatrix.c

View File

@@ -290,6 +290,8 @@ struct Matrix {
Scalar GetMaxBasisLength() const;
Scalar GetMaxBasisLengthXY() const;
constexpr Vector3 GetBasisX() const { return Vector3(m[0], m[1], m[2]); }
constexpr Vector3 GetBasisY() const { return Vector3(m[4], m[5], m[6]); }