Skip to content

[web] paragraph incorrectly estimates its paint bounds #97756

@yjbanov

Description

@yjbanov

On the web, in HTML mode, the bounds estimation logic uses Paragraph.width and Paragraph.height to estimate the paint bounds of the paragraph. This is not precise, and leads to two issues:

  • It overestimates the size of the canvas it needs for painting, which is inefficient.
  • When double.infinity is passed as the width constraint it estimates 1000000000 as its paint bounds, which later can lead to NaN results down in the engine compositor math.

Instead, bounds should be estimated based on the line metrics. For example, if text is aligned to be in the center the bounding rectangle would be something smaller than the width and also in the center.

Here's a test case that passes today, but shouldn't (I don't have the expected figures right now without an actual fix; I just know that these are wrong):

    test('infinite width', () {
      final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(
        fontFamily: 'Ahem',
        fontSize: 10,
      ));
      builder.addText('Hello, World!');
      final Paragraph paragraph = builder.build();
      paragraph.layout(const ParagraphConstraints(width: double.infinity));
      underTest.drawParagraph(paragraph, Offset.zero);
      underTest.endRecording();
      expect(underTest.pictureBounds, const Rect.fromLTRB(0, 0, 1000000000, 11));
    });

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: typographyText rendering, possibly libtxtcustomer: sameheree: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webe: web_htmlHTML rendering backend for Webengineflutter/engine related. See also e: labels.platform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions