Skip to content

[impeller] font rect's aren't maintaining their shape with uniform scales #162348

@gaaclarke

Description

@gaaclarke

reproduction steps

namespace {
double GetAspectRatio(Rect rect) {
  return static_cast<double>(rect.GetWidth()) / rect.GetHeight();
}
}  // namespace

TEST_P(TextContentsTest, MaintainsShape) {
#ifndef FML_OS_MACOSX
  GTEST_SKIP() << "Results aren't stable across linux and macos.";
#endif

  std::shared_ptr<TextFrame> text_frame =
      MakeTextFrame("th", "ahem.ttf", /*font_size=*/50);

  std::shared_ptr<TypographerContext> context = TypographerContextSkia::Make();
  std::shared_ptr<GlyphAtlasContext> atlas_context =
      context->CreateGlyphAtlasContext(GlyphAtlas::Type::kAlphaBitmap);
  std::shared_ptr<HostBuffer> host_buffer = HostBuffer::Create(
      GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter());
  ASSERT_TRUE(context && context->IsValid());
  for (int i = 0; i <= 1000; ++i) {
    Scalar font_scale = 0.440 + (i / 1000.0);
    Rect position_rect[2];
    Rect uv_rect[2];

    {
      GlyphAtlasPipeline::VertexShader::PerVertexData data[12];
      std::shared_ptr<GlyphAtlas> atlas =
          CreateGlyphAtlas(*GetContext(), context.get(), *host_buffer,
                           GlyphAtlas::Type::kAlphaBitmap, font_scale,
                           atlas_context, text_frame);
      ISize texture_size = atlas->GetTexture()->GetSize();

      TextContents::ComputeVertexData(
          data, text_frame, font_scale,
          /*entity_transform=*/Matrix::MakeScale({font_scale, font_scale, 1}),
          /*offset=*/Vector2(0, 0),
          /*glyph_properties=*/std::nullopt, atlas);
      position_rect[0] = PerVertexDataPositionToRect(data);
      uv_rect[0] = PerVertexDataUVToRect(data, texture_size);
      position_rect[1] = PerVertexDataPositionToRect(data + 6);
      uv_rect[1] = PerVertexDataUVToRect(data + 6, texture_size);
    }
    EXPECT_NEAR(GetAspectRatio(position_rect[1]), GetAspectRatio(uv_rect[1]), 0.001) << i;
  }
}

observed result

This fails about 30% of the time.

expected result

I expect the aspect ratio of the uv's to match the position vertices. Otherwise weird glyphs might appear stretched or shrunk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.r: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions