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

Skip to content

using variable font in flutter #33709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DJafari opened this issue Jun 1, 2019 · 41 comments
Closed

using variable font in flutter #33709

DJafari opened this issue Jun 1, 2019 · 41 comments
Labels
a: typography Text rendering, possibly libtxt c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter customer: crowd Affects or could affect many people, though not necessarily a specific customer. customer: money (g3) engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list

Comments

@DJafari
Copy link

DJafari commented Jun 1, 2019

Internal: b/215481602

is possible using variable fonts in flutter ?

@BondarenkoStas BondarenkoStas added the c: new feature Nothing broken; request for a new capability label Oct 8, 2019
@iapicca iapicca added a: typography Text rendering, possibly libtxt framework flutter/packages/flutter repository. See also f: labels. c: proposal A detailed proposal for a change to Flutter customer: crowd Affects or could affect many people, though not necessarily a specific customer. labels Jan 16, 2020
@misaelriojasftf
Copy link

I need variable fonts!

@orestesgaolin
Copy link
Contributor

orestesgaolin commented Apr 4, 2020

Has anyone succeed with using variable fonts in Flutter?

@surajmandalcell
Copy link

+1

@bluemix
Copy link

bluemix commented Jul 10, 2020

I hope there are updates to this.
+1

@srix55
Copy link

srix55 commented Oct 31, 2020

Need this. Especially when lots of fonts are bloating up my app size.

@rebel-codeaz
Copy link

Needed. I can add it in pubspec.yaml but dunno what to do next!
+1

@shyndman
Copy link
Contributor

shyndman commented Nov 19, 2020

I'd love to see this too.

One option for those who want to use a few variations of a variable font — you can create static "instantiations" at specific weights using fonttools, then use those.

fonttools varLib.mutator ./YourVariableFont-VF.ttf wght=140 wdth=85

@Hixie
Copy link
Contributor

Hixie commented Dec 11, 2020

In principle this works today using the FontFeature feature, but wght doesn't seem to work.

@shyndman
Copy link
Contributor

Ohhh, interesting. Do other axes?

@Hixie
Copy link
Contributor

Hixie commented Dec 12, 2020

I haven't tried anything but wght as far as the newfangled "variable fonts" axes go. In general lots of OpenType font features work, for example, I'm looking at code here that works with aalt and cwsh with values 1, 2, and 3 (using Raleway for aalt and BioRhyme Expanded for cwsh.)

If you have any test cases it would be great to attach them here, especially if there are open source fonts that you know support a particular axis (i.e. you've tested that specific .ttf file with other tools and they work), but when you try it with FontFeature in Flutter it doesn't work.

For wght in particular, let's track that using #67688.

@esDotDev
Copy link

esDotDev commented Jan 13, 2021

FontFeature

Is there any examples of how to do this? We have a variable font Fraunces (Fraunces-Italic-VariableFont_SOFT,WONK,opsz,wght.ttf) and would like to use it in Flutter.
https://fonts.google.com/specimen/Fraunces

In addition to the bundled weights and sizes, it has (new to me) properties like Softness and Wonkiness. Would these be supported currently?

@shyndman
Copy link
Contributor

shyndman commented Jan 13, 2021

As far as I can tell, this doesn't work yet.

I grabbed the Fraunces font you linked, checked the allowed ranges for the variation axes (opsz, wght, SOFT, and WONK), and built a little Flutter app that displays two Texts side-by-side — one using the variable font, one using an instance of the variable font restricted to specific values.

Here's the instancing command:

fonttools varLib.instancer -o Fraunces-var-instanced.ttf Fraunces-VariableFont_SOFT,WONK,opsz,wght.ttf opsz=140 wght=500 SOFT=0 WONK=1

And the app:

class VariableFontTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          Text(
            pangram,
            style: TextStyle(
              fontFamily: 'Fraunces',
              fontFeatures: [
                FontFeature('opsz', 140),
                FontFeature('wght', 500),
                FontFeature('SOFT', 0),
                FontFeature('WONK', 1),
              ],
            ),
          ),
          Text(
            pangram,
            style: TextStyle(
              fontFamily: 'Fraunces-var-instanced',
            ),
          ),
        ],
      ),
    );
  }
}

And the result:
Screen Shot 2021-01-13 at 5 41 55 PM

wght is the most obvious, but if you look carefully the other axes are not being picked up either.

To see what I mean, you can see the intended effects of each axis at https://github.com/undercasetype/Fraunces. Wonkiness is the easiest to pick up outside of weight, because it's essentially a set of stylistic alternatives.

@Hixie
Copy link
Contributor

Hixie commented Jan 13, 2021

There's a sample here: https://master-api.flutter.dev/flutter/dart-ui/FontFeature-class.html

edit: but yes, it seems the "variant" axes don't work yet.

@Hixie
Copy link
Contributor

Hixie commented Jan 13, 2021

(The hope is that we will work on this in the next few months; it's not super-high priority relative to e.g. getting the null safety migration working well, or getting desktop and web support to be more solid, but it is something we do care about and want to get working when we find the time. If anyone is interested in seeing if they can figure it out, don't hesitate to try. It's probably just a minor tweak to how we're passing the FontFeature data to HarfBuzz. If you want to try to contribute, you can see instructions on how to get started, build the engine, and hang out on our Discord in the CONTRIBUTOR.md doc in this repo.)

@shyndman
Copy link
Contributor

shyndman commented Jan 13, 2021

It's probably just a minor tweak to how we're passing the FontFeature data to HarfBuzz

This may need a bit of tweaking on the Dart side as well. It appears that axis values are floats, and FontFeature only supports integer values currently.

Correction:
The axis values are 32-bit fixed point (16.16). So likely double on the Dart-side.

@esDotDev
Copy link

Great, thx for all the info guys

@shyndman
Copy link
Contributor

Last bit of info I found — Harfbuzz represents the axis value as a float:
hb_variation_t
hb_font_set_variations

@Hixie
Copy link
Contributor

Hixie commented Jan 14, 2021

Ah, interesting. We will need some tweaks to the Dart API as well then, indeed.

@marchellodev

This comment has been minimized.

@DJafari
Copy link
Author

DJafari commented May 5, 2021

@Hixie any update about this feature ?

@Fabhi
Copy link

Fabhi commented May 27, 2021

Much needed

@bryanoltman
Copy link
Contributor

Marking this issue as P2 to match the internal bug b/215481602

@chinmaygarde chinmaygarde added P2 and removed engine flutter/engine repository. See also e: labels. labels Apr 25, 2022
@goderbauer
Copy link
Member

@jason-simmons is still working on the CanvasKit implementation for this.

@goderbauer goderbauer added the engine flutter/engine repository. See also e: labels. label Apr 28, 2022
@chinmaygarde
Copy link
Member

Per the internal issue, the P2-ness of this issue was related to its implementation on the mobile platforms which has been completed. Dropping the priority as Jason was pulled away to work on higher priority tasks ATM.

@chinmaygarde chinmaygarde added P2 Important issues not at the top of the work list and removed P2 labels May 2, 2022
@guidezpl
Copy link
Member

guidezpl commented Aug 5, 2022

Thanks @jason-simmons! Can you confirm this issue can be closed now that https://skia-review.googlesource.com/c/skia/+/563536 has been rolled in with #108821?

@jason-simmons
Copy link
Member

No - there will need to be a roll of CanvasKit into the engine that includes the Skia change, followed by a PR in the engine that integrates the web UI libraries with the CanvasKit API.

I've built the engine PR - it's just waiting on the CanvasKit roll.

@guidezpl
Copy link
Member

guidezpl commented Aug 5, 2022

Ah gotcha, makes sense.

it's just waiting on the CanvasKit roll.

I'm not sure if I understand all the rolls happening but isn't flutter/engine#35088 it?

@jason-simmons
Copy link
Member

The CanvasKit roll into Flutter Web is separate from the Skia->engine roll.

See https://github.com/flutter/engine/blob/main/lib/web_ui/README.md#rolling-canvaskit

@jtmcdole
Copy link
Member

customer:fun would also like this.

@zanderso
Copy link
Member

@jason-simmons Is this done? Can we close it?

@jason-simmons
Copy link
Member

This has landed on all platforms.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: typography Text rendering, possibly libtxt c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter customer: crowd Affects or could affect many people, though not necessarily a specific customer. customer: money (g3) engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list
Projects
None yet
Development

No branches or pull requests