Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@robert-ancell
Copy link
Contributor

Description

This allows a shell to set the system font to use by default.

Related Issues

flutter/flutter#51831

Tests

No tests added.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Reviewer Checklist

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla google-cla bot added the cla: yes label Dec 10, 2020
@robert-ancell robert-ancell marked this pull request as draft December 10, 2020 03:26
@robert-ancell
Copy link
Contributor Author

With this branch and the associated Linux shell changes in https://github.com/robert-ancell/engine/tree/linux-shell-system-font (which builds on #22486) I can get the GTK configured font to be used by adding the following to my test app:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        fontFamily: WidgetsBinding.instance.window.systemFontFamily,
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Font Test'),
    );
  }
}

I need some feedback on the following parts:

  • WidgetsBinding.instance.window.systemFontFamily seems like the correct way to get the configured font family in Dart, but it feels convoluted. Should this be exposed anywhere else?
  • The original theme was defined in Flutter in packages/flutter/lib/src/material/typography.dart - all the existing themes have constant font families set there, should we be dynamically generating a theme with systemFontFamily? This would mean the above app wouldn't need to explicitly set fontFamily in ThemeData.

@robert-ancell
Copy link
Contributor Author

CC @gspencergoog and @stuartmorgan.

@gspencergoog
Copy link
Contributor

@robert-ancell I think for now we will be keeping it as using systemFontFamily and adding the Theme widget at the top of the tree: it's somewhat unpredictable how the sizing on an arbitrary font might work out, and can cause drastic changes in the layout, so it seems like it could be better to be more explicit to set the font family to the system default. I feel a little sad saying that, though, so maybe we can add something in the future to make it easier to do, or more predictable layout-wise.

@HansMuller
Copy link

I agree with #22981 (comment). I think the support added for using a platform-specific font for Windows and Linux, flutter/flutter#51519, plus the existing support for Android and iOS/MacOS, is enough to comply with the Material Design spec. Wiring the platform's "system" font down in that way produces a relatively predictable text look/geometry.

Just providing simple access to the system font, as this PR does, does seem useful. Developers can choose to use the system font, if they're OK with the unpredictability.

@stuartmorgan-g
Copy link
Contributor

I think the support added for using a platform-specific font for Windows and Linux, [...] is enough to comply with the Material Design spec.

How so? The spec says "For platforms outside of Android and web products, use a system typeface that is preferred on that platform." Currently on Linux we're using one of a set of fonts that cover the default fonts on a subset of Linux distributions, which seems hard to argue is the same thing.

Two simple examples:

  • If a distro uses its own font (as Ubuntu does) and it's not on our hard-coded list, well use an essentially random font, not that platform's preferred typeface.
  • If someone is using a non-Ubuntu distribution, but happens to have the Ubuntu font installed, we will use it (because we had to pick an order to try them in), not that platform's preferred typeface.

Unless we are considering every form and distribution of Linux that isn't Android to be a single monolithic platform? The fact that we're already having to carve out an exception for Android in that demonstrates why it's a problematic framing.

@cbracken cbracken requested a review from HansMuller March 16, 2021 19:07
@gspencergoog
Copy link
Contributor

What's the status of this PR: has this been resolved in another way?
(@HansMuller do you have a response to @stuartmorgan's comment?)

@HansMuller
Copy link

My apologies for letting this sit for so long. I have no problem with the PR's direction: it enables developers to discover the platform's default system font.

@CaseyHillers CaseyHillers changed the base branch from master to main November 15, 2021 18:16
@godofredoc godofredoc changed the base branch from master to main November 24, 2021 07:29
@cbracken
Copy link
Member

cbracken commented Feb 9, 2022

@robert-ancell is this still WIP?

@robert-ancell robert-ancell marked this pull request as ready for review February 9, 2022 03:52
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@robert-ancell
Copy link
Contributor Author

@robert-ancell is this still WIP?

If this is the right location for this API then this should be ready for review/landing.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Sorry this languished for so long! It just fell off my radar.

@chinmaygarde
Copy link
Member

Can we address the conflict so this may land?

@robert-ancell
Copy link
Contributor Author

The build is failing due to a license break on main from a skia change, will have to merge once that is fixed

@chinmaygarde
Copy link
Member

That has been fixed now. Can you rebase please?

This allows a shell to set the system font to use by default.
@robert-ancell robert-ancell merged commit fccde49 into flutter:main Mar 14, 2022
@robert-ancell robert-ancell deleted the settings-system-font branch March 14, 2022 01:07
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2022
zanderso pushed a commit to flutter/flutter that referenced this pull request Mar 14, 2022
* ba6f4f5 Roll Skia from c88fff00c8fd to 02ea811ce869 (4 revisions) (flutter/engine#31955)

* 1a8033c Revert "Add a message when a key response takes too long. (#31945)" (flutter/engine#31962)

* ebcd86f68 Make sure the secondary vsync callback is called after the vsync callback (flutter/engine#31513)

* 2c94cc5 Generate a11y events for widgets that use kFlutterSemanticsFlagIsToggled (flutter/engine#31582)

* e21a58d [macOS, Keyboard] Refactor: Clean up keyboard initialization, connection, and unit test framework (flutter/engine#31940)

* 27e62d0 Set a11y roles for checks, toggles and sliders. (flutter/engine#31600)

* 5e760f6 Fix signals adding/removing a11y nodes in Linux. (flutter/engine#31601)

* 749dc3a Changed the default a11y node role from ATK_ROLE_FRAME to ATK_ROLE_PANEL (flutter/engine#31602)

* da7bae6 Animator stopped notifying delegate to render when pipeline is not empty (flutter/engine#31727)

* 77dd8af Roll Fuchsia Mac SDK from y2eJ9z95V... to j7jyFiU9e... (flutter/engine#31960)

* 3f803b2 Roll Skia from 02ea811ce869 to b141e485d248 (5 revisions) (flutter/engine#31961)

* 187a277 Roll Fuchsia Linux SDK from -9uFZIRSL... to k8Vq-HEG-... (flutter/engine#31971)

* 43975b2 Roll Skia from b141e485d248 to 1df655a42746 (13 revisions) (flutter/engine#31975)

* ab12f81 Roll Fuchsia Mac SDK from j7jyFiU9e... to g8opaxAq7... (flutter/engine#31978)

* 93b792f Roll Skia from 1df655a42746 to 38b9591b5a04 (1 revision) (flutter/engine#31979)

* d6964c0 Update jazzy to 0.14.1. (flutter/engine#31970)

* 31def4e Re-enable dart runner AOT builds (flutter/engine#31844)

* 887a193 Roll Fuchsia Linux SDK from k8Vq-HEG-... to mDjjSq8Im... (flutter/engine#31980)

* afd9ce1 Roll Fuchsia Mac SDK from g8opaxAq7... to f8IibBq3a... (flutter/engine#31983)

* f7d8314 Roll Fuchsia Linux SDK from mDjjSq8Im... to BEc_F0_Fp... (flutter/engine#31986)

* 503c02c Roll Fuchsia Mac SDK from f8IibBq3a... to oyZzinh6U... (flutter/engine#31987)

* caa3f3d Roll Fuchsia Linux SDK from BEc_F0_Fp... to obtypxiCA... (flutter/engine#31988)

* 4643016 Roll Dart SDK from 4fbe27c0f148 to 3e76a897013f (5 revisions) (flutter/engine#31989)

* 06d3d06 Roll Dart SDK from 3e76a897013f to 55b9ec4e382a (5 revisions) (flutter/engine#31991)

* cdf862b Roll Skia from 38b9591b5a04 to 6d19271fb148 (2 revisions) (flutter/engine#31992)

* bbebccd Roll Fuchsia Mac SDK from oyZzinh6U... to rmQ9yYUaF... (flutter/engine#31993)

* 56187fa Fix timestamp of touch events should use system startup time (flutter/engine#30422)

* 1dab008 Roll Fuchsia Linux SDK from obtypxiCA... to xYtoLAOvY... (flutter/engine#31995)

* fccde49 Add systemFontFamily to flutter/settings channel (flutter/engine#22981)

* 2a8c4f4 Roll Fuchsia Mac SDK from rmQ9yYUaF... to 84kG1vmHe... (flutter/engine#31996)

* e6cf464 Roll Skia from 6d19271fb148 to 7a61e5d65399 (1 revision) (flutter/engine#31997)

* 1cc349e Roll Fuchsia Linux SDK from xYtoLAOvY... to P8RdLi_Y_... (flutter/engine#31999)

* 25acd77 Roll Skia from 7a61e5d65399 to 02527b7182ea (1 revision) (flutter/engine#32000)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants