flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.27k stars 27.1k forks source link

Some Custom fonts are not properly displayed #146715

Open bipinkrish opened 4 months ago

bipinkrish commented 4 months ago

Steps to reproduce

An example from signwriting_flutter which uses custom signwriting TTF fonts from https://github.com/sutton-signwriting/font-ttf

Expected results

In Windows it's alright, rendering actual visualization of FSW string

Actual results

But in Android and Web it is just throwing emojis or nothing, maybe because of noto-font ?

Code sample

Code sample ```dart import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:signwriting_flutter/signwriting_flutter.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'SignWriting Image Test', home: Scaffold( appBar: AppBar( title: const Text('SignWriting Image Test'), ), backgroundColor: Colors.black, body: Center( child: FutureBuilder( future: signwritingToImage( 'AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S20544510x500S10019476x475', trustBox: false, lineColor: Colors.deepOrange, fillColor: Colors.white, ), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (snapshot.hasData) { return Image.memory(snapshot.data!); } else { return const Text('Failed to render SignWriting image'); } } else { return const CircularProgressIndicator(); } }, ), ), ), ); } } ```

Screenshots or Video

Screenshots / Video demonstration

Windows:

windows

Android:

android

Web:

web

Logs

Logs ```console Launching lib\main.dart on Chrome in debug mode... This app is linked to the debug service: ws://127.0.0.1:57165/er9FDGf5wwQ=/ws Debug service listening on ws://127.0.0.1:57165/er9FDGf5wwQ=/ws Connecting to VM Service at ws://127.0.0.1:57165/er9FDGf5wwQ=/ws Could not find a set of Noto fonts to display all missing characters. Please add a font asset for the missing characters. See: https://flutter.dev/docs/cookbook/design/fonts ```

Flutter Doctor output

Doctor output ```console [√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.19045.2311], locale en-US) • Flutter version 3.19.5 on channel stable at D:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (2 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\Bipin\AppData\Local\Android\Sdk • Platform android-34, build-tools 34.0.0 • ANDROID_SDK_ROOT = C:\Users\Bipin\AppData\Local\Android\Sdk • Java binary at: D:\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.2) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.7.34018.315 • Windows 10 SDK version 10.0.20348.0 [√] Android Studio (version 2022.3) • Android Studio at D:\Android Studio • 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.6+0-b2043.56-10027231) [√] VS Code (version 1.88.1) • VS Code at C:\Users\Bipin\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.86.0 [√] Connected device (4 available) • RMX3395 (mobile) • 192.168.1.3:43355 • android-arm64 • Android 13 (API 33) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.2311] • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.122 • Edge (web) • edge • web-javascript • Microsoft Edge 122.0.2365.52 [√] Network resources • All expected network resources are available. • No issues found! ```
danagbemava-nc commented 4 months ago

Hi @bipinkrish, did you do any extra setup to get it working on windows?

Also, if you add the noto fonts, does it work for you?

bipinkrish commented 4 months ago

@danagbemava-nc I did not do any extra steps for Windows and since this is a very custom font with weird characters i haven't used noto-font.

danagbemava-nc commented 4 months ago

By extra setup, I meant if you installed the ttf for sign writing on your windows desktop environment before running the app. Or if you already had it installed

bipinkrish commented 4 months ago

I meant if you installed the ttf for sign writing on your windows desktop environment before running the app. Or if you already had it installed

I did, maybe that is why it is working in windows, do you have suggestion for me?

danagbemava-nc commented 4 months ago

I do not unfortunately.

I can reproduce the issue using the code sample shared above and the font files provided, this isn't limited to android or web. It applies to all platforms. For desktop, the fonts will start working when the ttf is installed on the system directly. Looking at the README for the font, it looks like this cannot be installed directly on android. However, with the font files available, I believe it should be loaded on all platforms.

Labeling for further investigation.

flutter doctor -v ``` [!] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB) • Flutter version 3.19.6 on channel stable at /Users/nexus/dev/sdks/flutter ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 54e66469a9 (35 hours ago), 2024-04-17 13:08:03 -0700 • Engine revision c4cd48e186 • Dart version 3.3.4 • DevTools version 2.31.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/nexus/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/nexus/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.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.2.2 • Dart plugin version 232.10286 [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (4 available) • Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 17.4.1 21E236 • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.60 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ``` ``` [✓] Flutter (Channel master, 3.22.0-14.0.pre.32, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB) • Flutter version 3.22.0-14.0.pre.32 on channel master at /Users/nexus/dev/sdks/flutters • Upstream repository https://github.com/flutter/flutter.git • Framework revision d4b42780ba (3 hours ago), 2024-04-19 00:21:25 -0400 • Engine revision b6234dd198 • Dart version 3.5.0 (build 3.5.0-76.0.dev) • DevTools version 2.35.0-dev.8 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/nexus/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/nexus/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.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.2.2 • Dart plugin version 232.10286 [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (5 available) • Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 17.4.1 21E236 • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.60 [✓] Network resources • All expected network resources are available. • No issues found! ```
bipinkrish commented 4 months ago

@danagbemava-nc It works on windows because font is installed on the system but why didn't it work for the web on the same system?

danagbemava-nc commented 4 months ago

It won't work in a windows application on a system that doesn't have the font installed. You'd have to instruct your users to install the font on their devices as well, which I don't is supposed to be the case.

I imagine the browser doesn't have access to your system fonts so that's perhaps why it doesn't work.

bipinkrish commented 4 months ago

@danagbemava-nc One solution is, instead of using the font files in the package use it in the project itself.

bipinkrish commented 4 months ago

Like

flutter:
  fonts:
    - family: SuttonSignWritingFill
      fonts:
        - asset: assets/fonts/SuttonSignWritingFill.ttf

    - family: SuttonSignWritingLine
      fonts:
        - asset: assets/fonts/SuttonSignWritingLine.ttf
ameenvga commented 4 months ago
Screenshot 2024-04-25 at 11 41 52 AM

I'm encountering a similar issue. When implementing a custom font, it appears correctly on the macOS version and in the iOS emulator. However, the font fails to display properly on both the Android emulator and on physical Android devices.

I declared it in my pubspec.yaml

fonts:
    - family: testfont
      fonts:
        - asset: assets/fonts/test/ML-KV-Ashi-Bold Bold.ttf

And use like this


import 'package:flutter/material.dart';

class MyWidget extends StatelessWidget {
  const MyWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: const Center(
        child: Text(
          'aebmfw',
          style: TextStyle(
            fontSize: 50,
            fontFamily: 'testfont',
          ),
        ),
      ),
    );
  }
}
ameenvga commented 4 months ago

No help at all in this issue?

ameenvga commented 4 months ago

@danagbemava-nc One solution is, instead of using the font files in the package use it in the project itself.

does not work at all in my case

bipinkrish commented 4 months ago

does not work at all in my case

@ameenvga I feel like, space is the problem

  • asset: assets/fonts/test/ML-KV-Ashi-Bold Bold.ttf

try with the valid file name for the font.

ameenvga commented 4 months ago

does not work at all in my case

@ameenvga I feel like, space is the problem

  • asset: assets/fonts/test/ML-KV-Ashi-Bold Bold.ttf

try with the valid file name for the font.

Nop. I have tried that one too. Does not work.