Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Flutter 3]TextPainter does not respect the height factor of text style #104153

@WeiCongcong

Description

@WeiCongcong

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. The computed line height will not respect the height of text style

Expected results:
If the font size is 16, height is 20 / 16 and the textScaleFactor is 1.0, the computed line height should be 20.

Actual results:
The font size is 16, height is 20 / 16 and the textScaleFactor is 1.0, the computed line height is 19.

Code sample
  double _computeLineHeight() {
    TextSpan text = const TextSpan(
      text: 'This is a Sample',
      style: TextStyle(
        fontSize: 16,
        height: 20 / 16,
      ),
    );
    TextPainter painter = TextPainter(text: text, textDirection: TextDirection.ltr, textScaleFactor: 1.0);
    painter.layout(maxWidth: 200);
    return painter.computeLineMetrics()[0].height;
  }

You can get the code here.

Logs
[✓] Flutter (Channel stable, 3.0.0, on macOS 11.3.1 20E241 darwin-x64, locale en-CN)
    • Flutter version 3.0.0 at /path/to/libs/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee4e09cce0 (9 days ago), 2022-05-09 16:45:18 -0700
    • Engine revision d1b9a6938a
    • Dart version 2.17.0
    • DevTools version 2.12.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /path/to/Android/android-sdk-macosx
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /path/to/Android/android-sdk-macosx
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Community Edition (version 2021.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.67.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (3 available)
    • iPhone 11 (mobile) • 3033A4F1-03F1-465E-BEEC-E21D869D19CD • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-7 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 11.3.1 20E241 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 101.0.4951.64

[!] HTTP Host Availability
    ✗ HTTP host "https://cocoapods.org/" is not reachable. Reason: An error occurred while checking the HTTP host: Connection reset by peer

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: typographyText rendering, possibly libtxtc: regressionIt was better in the past than it is nowengineflutter/engine related. See also e: labels.found in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions