Repository: flutter
Issue: When using `TextPainter` to measure the width of `RichText`, setting `textWidthBasis` to `TextWidthBasis.longestLine` does not take effect.
Labels: framework,engine,a: typography,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.22,found in release: 3.23

### Steps to reproduce

Refer to [repo](https://github.com/kjxbyz/flutter_rich_text_text_painter)

### Expected results

When measuring the width of a `RichText` using a `TextPainter`, setting the `textWidthBasis` in the `TextPainter` to `TextWidthBasis.longestLine` works properly.

### Actual results

When using `TextPainter` to measure the width of `RichText`, setting `textWidthBasis` in `TextPainter` to `TextWidthBasis.longestLine` does not take effect.

### Code sample

Refer to [repo](https://github.com/kjxbyz/flutter_rich_text_text_painter)

### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-x64, locale zh-Hans-CN)
    • Flutter version 3.22.2 on channel stable at /Users/ying/fvm/versions/3.22.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (4 周前), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/ying/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/ying/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • 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 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.91.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.92.0

[!] Proxy Configuration
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[✓] Connected device (4 available)
    • Kimmy's iPhone (mobile)             • 00008020-000A1D110A32002E            • ios            • iOS 17.5.1 21F90
    • iPhone SE (3rd generation) (mobile) • 74C71045-56B8-4CF6-8B58-2ADC4713A917 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                     • macos                                • darwin-x64     • macOS 14.5 23F79 darwin-x64
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 126.0.6478.127

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>