Skip to content

With TextBaseline.ideographic text gets cut off below the baseline.  #94680

Description

@SShayashi

What is the difference between TextBaseline.alphabetic and TextBaseline.ideographic?

Overview

Just by reading the TextBaseline documentation, I could not understand the difference in appearance between TextBaseline.alphabetic and TextBaseline.ideographic. So, to check out the visual difference, I try the sample code below. Although the baseline of the characters aligned, there was no visual difference. What is the difference TextBaseline.alphabetic and TextBaseline.ideographic?

Reference

The same question in the Stack Over Flow was answered about the difference between the two properties. But the sample code did not show the difference.

flutter doctor -v
$ flutter doctor -v
[✓] Flutter (Channel stable, 2.5.1, on macOS 11.5.2 20G95 darwin-x64, locale ja)
    • Flutter version 2.5.1 at /Users/sshayashi/fvm/versions/2.5.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffb2ecea52 (2 months ago), 2021-09-17 15:26:33 -0400
    • Engine revision b3af521a05
    • Dart version 2.14.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/sshayashi/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode13beta5.app/Contents/Developer
    • Xcode 13.0, Build version 13A5212g
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 51.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

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

[✓] Connected device (2 available)
    • iPod touch (7th generation) (mobile) • C830390E-B470-4EC4-9F15-23477CACF678 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-2 (simulator)
    • Chrome (web)                         • chrome                               • web-javascript • Google Chrome 96.0.4664.55

• No issues found!
sshayashi@MacBook-Pro:~/Programs/baseline_reprodution »
sample code
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              crossAxisAlignment: CrossAxisAlignment.baseline,
              textBaseline: TextBaseline
                  .ideographic, // TextBaseline.alphabetic show the same result
              children: const [
                Text(
                  'ABCDefgh 漢字漢字漢字',
                ),
                Text(
                  'ABCDefg 漢字',
                  style: TextStyle(
                    fontSize: 20,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

sample code screenshots
no baseline properties TextBaseline.alphabetic TextBaseline.ideographic

Activity

  1. added
    in triagePresently being triaged by the triage team
    a: typographyText rendering, possibly libtxt
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Dec 6, 2021
  2. changed the title [-]What is the difference between TextBaseline.alphabetic and TextBaseline.ideographic?[/-] [+][Docs] Improve documentation for Textbaseline.alphabetic and TextBaseline.ideographic[/+] on Dec 7, 2021
  3. SShayashi commented on Dec 15, 2021

    @SShayashi
    Author

    @maheshmnj
    Thanks for your triage and labeling. Is this just a documentation issue? If so, could you please provide some sample code that shows the difference between TextBaseline.alphabetic and TextBaseline.ideographic?

  4. maheshj01 commented on Dec 20, 2021

    @maheshj01
    Member

    @SShayashi thanks for pointing out. This looks like a bug to me I see no difference in text baseline alignment when using either TextBaseline.alphabetic or Texbaseline.ideographic.

    Ideally with Textbaseline.alphabetic English text should sit on the line but when using non-English characters, it would pass slightly below the baseline. To prevent this Textbaseline.ideographic is available which should keep all characters (english or non-english) above the baseline.

    As per the below output Textbaseline.alphabetic seems to be working as expected. The issue looks related to Textbaseline.ideographic.

    image

    code sample
    import 'package:flutter/material.dart';
    import 'package:shared_preferences/shared_preferences.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({Key? key, required this.title}) : super(key: key);
    
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text(
                  'You have pushed the button this many times: 你好世界',
                  style: TextStyle(
                      backgroundColor: Colors.red,
                      textBaseline: TextBaseline.alphabetic),
                ),
                const SizedBox(
                  height: 5,
                ),
                const Text(
                  'You have pushed the button this many times: 你好世界',
                  style: TextStyle(
                    textBaseline: TextBaseline.ideographic,
                    backgroundColor: Colors.red,
                  ),
                ),
                Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {},
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ),
        );
      }
    }
    
    flutter doctor -v
    [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.8.1 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 77d935af4d (4 days ago), 2021-12-16 08:37:33 -0800
        • Engine revision 890a5fca2e
        • Dart version 2.15.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.2)
        • 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.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 60.1.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.61.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Redmi K20 Pro (mobile) • 192.168.1.3:5555 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)        • macos            • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome           • web-javascript • Google Chrome 96.0.4664.110
    
    • No issues found!
    
    [✓] Flutter (Channel master, 2.9.0-1.0.pre.93, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.9.0-1.0.pre.93 at /Users/mahesh/Documents/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 1be7f1ea56 (5 days ago), 2021-12-14 22:14:07 -0500
        • Engine revision e444009bf4
        • Dart version 2.16.0 (build 2.16.0-109.0.dev)
        • DevTools version 2.9.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.2)
        • 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.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 60.1.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.61.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Redmi K20 Pro (mobile) • 192.168.1.3:5555 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)        • macos            • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome           • web-javascript • Google Chrome 96.0.4664.110
    
    • No issues found!
    
  5. changed the title [-][Docs] Improve documentation for Textbaseline.alphabetic and TextBaseline.ideographic[/-] [+]With `TextBaseline.ideographic` Non-english characters get cut off below the baseline. [/+] on Dec 20, 2021
  6. changed the title [-]With `TextBaseline.ideographic` Non-english characters get cut off below the baseline. [/-] [+]With `TextBaseline.ideographic` text gets cut off below the baseline. [/+] on Dec 20, 2021
  7. maheshj01 commented on Dec 20, 2021

    @maheshj01
    Member

    image

    code sample 2
    import 'package:flutter/material.dart';
    import 'package:shared_preferences/shared_preferences.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({Key? key, required this.title}) : super(key: key);
    
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Stack(
                  alignment: Alignment.bottomCenter,
                  children: const [
                    Text(
                      'You have pushed the button this many times: 你好世界',
                      style: TextStyle(
                          // backgroundColor: Colors.red,
                          textBaseline: TextBaseline.alphabetic),
                    ),
                    Divider()
                  ],
                ),
                const SizedBox(
                  height: 5,
                ),
                Stack(
                  alignment: Alignment.bottomCenter,
                  children: const [
                    Text(
                      'You have pushed the button this many times: 你好世界',
                      style: TextStyle(
                        textBaseline: TextBaseline.ideographic,
                        // backgroundColor: Colors.red,
                      ),
                    ),
                    Divider()
                  ],
                ),
                Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {},
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ),
        );
      }
    }
    
  8. added
    P2Important issues not at the top of the work list
    engineflutter/engine related. See also e: labels.
    on Feb 2, 2022
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

    P2Important issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)a: typographyText rendering, possibly libtxtengineflutter/engine related. See also e: labels.found in release: 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions