Skip to content

SkParagraph doesn't account for applyHeightToFirstAscent applyHeightToLastDescent on empty paragraphs with strut enabled #112123

@LongCatIsLooong

Description

@LongCatIsLooong

Steps to Reproduce

const style = TextStyle(height: 11, fontSize: 7);
const simple = TextSpan(text: 'x', style: style);
const emptyString = TextSpan(text: '', style: style);
const emptyParagraph = TextSpan(style: style);

final painter = TextPainter(
  textDirection: TextDirection.ltr,
  strutStyle: StrutStyle.fromTextStyle(style),
  textHeightBehavior: const TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false),
);

for (final span in [simple, emptyString, emptyParagraph]) {
  painter.text = span;
  painter.layout();
  final realHeight = painter.height;
  final preferredHeight = painter.preferredLineHeight;
  print('${span.text} > real height: $realHeight, preferred height: $preferredHeight');
}

"real height" should always be the same as "preferred height" (8 px) in all 3 cases. However right now for both "emptyString" and "emptyParagraph" the reported "real height" is 77.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsa: typographyText rendering, possibly libtxtdependency: skiaSkia team may need to help usf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions