Skip to content

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

Closed

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.

Activity

  1. added
    e: impellerImpeller rendering backend issues and features requests
    engineflutter/engine related. See also e: labels.
    on Jan 28, 2025
  2. changed the title [-][impeller] ahem rect's aren't maintaining their shape[/-] [+][impeller] font rect's aren't maintaining their shape with uniform scales[/+] on Jan 28, 2025
  3. added
    in triagePresently being triaged by the triage team
    and removed
    in triagePresently being triaged by the triage team
    on Jan 29, 2025
  4. github-actions commented on Feb 14, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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