diff --git a/app/fonts/README.md b/app/fonts/README.md index 3e76f7fc..8611d467 100644 --- a/app/fonts/README.md +++ b/app/fonts/README.md @@ -6,3 +6,22 @@ Christian Robertson, licensed under the Apache License, Version 2.0 from the Flutter SDK's DevTools assets. They give monospace text (artifact text previews, background task output) a real fixed-width face on every platform: Flutter web does not resolve the generic `monospace` family. + +## Optional interface fonts + +Chosen per device in Settings > Font (`lib/ui/theme/app_font.dart`). They are +declared as plain `assets:`, not `fonts:`, so Flutter web does not download them +at startup; the chosen family is registered on demand with a `FontLoader`. Each +directory holds the unmodified Regular (400), Medium (500), SemiBold (600) and +Bold (700) static TTFs and the family's SIL Open Font License 1.1 as `OFL.txt`, +which is also registered with `LicenseRegistry`. + +| Directory | Family | Source | Licence | +| --- | --- | --- | --- | +| `inter/` | Inter 4.1 | github.com/rsms/inter release v4.1, `Inter-4.1.zip`, `extras/ttf/` | OFL 1.1, (c) The Inter Project Authors | +| `ibm-plex-sans/` | IBM Plex Sans 1.1.0 | github.com/IBM/plex release `@ibm/plex-sans@1.1.0`, `ibm-plex-sans.zip`, `fonts/complete/ttf/` | OFL 1.1, (c) IBM Corp., Reserved Font Name "Plex" | +| `source-sans-3/` | Source Sans 3.052 | github.com/adobe-fonts/source-sans release 3.052R, `TTF-source-sans-3.052R.zip`; licence text from `LICENSE.md` at that tag | OFL 1.1, (c) Adobe, Reserved Font Name "Source" | +| `atkinson-hyperlegible-next/` | Atkinson Hyperlegible Next | github.com/googlefonts/atkinson-hyperlegible-next (no releases) at commit 7925f50f, `fonts/ttf/` and `OFL.txt` | OFL 1.1, (c) The Atkinson Hyperlegible Next Project Authors | + +The files are unmodified (no subsetting), so the Reserved Font Names stay +usable. diff --git a/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Bold.ttf b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Bold.ttf new file mode 100644 index 00000000..668a2d16 Binary files /dev/null and b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Bold.ttf differ diff --git a/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Medium.ttf b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Medium.ttf new file mode 100644 index 00000000..2136809d Binary files /dev/null and b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Medium.ttf differ diff --git a/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Regular.ttf b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Regular.ttf new file mode 100644 index 00000000..d0982cdc Binary files /dev/null and b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Regular.ttf differ diff --git a/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-SemiBold.ttf b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-SemiBold.ttf new file mode 100644 index 00000000..44dcac96 Binary files /dev/null and b/app/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-SemiBold.ttf differ diff --git a/app/fonts/atkinson-hyperlegible-next/OFL.txt b/app/fonts/atkinson-hyperlegible-next/OFL.txt new file mode 100644 index 00000000..88955733 --- /dev/null +++ b/app/fonts/atkinson-hyperlegible-next/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2020-2024 The Atkinson Hyperlegible Next Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/app/fonts/ibm-plex-sans/IBMPlexSans-Bold.ttf b/app/fonts/ibm-plex-sans/IBMPlexSans-Bold.ttf new file mode 100644 index 00000000..1d66b1a2 Binary files /dev/null and b/app/fonts/ibm-plex-sans/IBMPlexSans-Bold.ttf differ diff --git a/app/fonts/ibm-plex-sans/IBMPlexSans-Medium.ttf b/app/fonts/ibm-plex-sans/IBMPlexSans-Medium.ttf new file mode 100644 index 00000000..a3826c4e Binary files /dev/null and b/app/fonts/ibm-plex-sans/IBMPlexSans-Medium.ttf differ diff --git a/app/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf b/app/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf new file mode 100644 index 00000000..bd6817d5 Binary files /dev/null and b/app/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf differ diff --git a/app/fonts/ibm-plex-sans/IBMPlexSans-SemiBold.ttf b/app/fonts/ibm-plex-sans/IBMPlexSans-SemiBold.ttf new file mode 100644 index 00000000..09ec8cda Binary files /dev/null and b/app/fonts/ibm-plex-sans/IBMPlexSans-SemiBold.ttf differ diff --git a/app/fonts/ibm-plex-sans/OFL.txt b/app/fonts/ibm-plex-sans/OFL.txt new file mode 100644 index 00000000..c35c4c61 --- /dev/null +++ b/app/fonts/ibm-plex-sans/OFL.txt @@ -0,0 +1,93 @@ +Copyright © 2017 IBM Corp. with Reserved Font Name "Plex" + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/app/fonts/inter/Inter-Bold.ttf b/app/fonts/inter/Inter-Bold.ttf new file mode 100644 index 00000000..9fb9b751 Binary files /dev/null and b/app/fonts/inter/Inter-Bold.ttf differ diff --git a/app/fonts/inter/Inter-Medium.ttf b/app/fonts/inter/Inter-Medium.ttf new file mode 100644 index 00000000..458cd060 Binary files /dev/null and b/app/fonts/inter/Inter-Medium.ttf differ diff --git a/app/fonts/inter/Inter-Regular.ttf b/app/fonts/inter/Inter-Regular.ttf new file mode 100644 index 00000000..b7aaca8d Binary files /dev/null and b/app/fonts/inter/Inter-Regular.ttf differ diff --git a/app/fonts/inter/Inter-SemiBold.ttf b/app/fonts/inter/Inter-SemiBold.ttf new file mode 100644 index 00000000..47f8ab1d Binary files /dev/null and b/app/fonts/inter/Inter-SemiBold.ttf differ diff --git a/app/fonts/inter/OFL.txt b/app/fonts/inter/OFL.txt new file mode 100644 index 00000000..9b2ca37b --- /dev/null +++ b/app/fonts/inter/OFL.txt @@ -0,0 +1,92 @@ +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/app/fonts/source-sans-3/OFL.txt b/app/fonts/source-sans-3/OFL.txt new file mode 100644 index 00000000..88c07f79 --- /dev/null +++ b/app/fonts/source-sans-3/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2010-2022 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/app/fonts/source-sans-3/SourceSans3-Bold.ttf b/app/fonts/source-sans-3/SourceSans3-Bold.ttf new file mode 100644 index 00000000..85693ccc Binary files /dev/null and b/app/fonts/source-sans-3/SourceSans3-Bold.ttf differ diff --git a/app/fonts/source-sans-3/SourceSans3-Medium.ttf b/app/fonts/source-sans-3/SourceSans3-Medium.ttf new file mode 100644 index 00000000..fbc97bf3 Binary files /dev/null and b/app/fonts/source-sans-3/SourceSans3-Medium.ttf differ diff --git a/app/fonts/source-sans-3/SourceSans3-Regular.ttf b/app/fonts/source-sans-3/SourceSans3-Regular.ttf new file mode 100644 index 00000000..c5dd0b88 Binary files /dev/null and b/app/fonts/source-sans-3/SourceSans3-Regular.ttf differ diff --git a/app/fonts/source-sans-3/SourceSans3-Semibold.ttf b/app/fonts/source-sans-3/SourceSans3-Semibold.ttf new file mode 100644 index 00000000..4aff9a3a Binary files /dev/null and b/app/fonts/source-sans-3/SourceSans3-Semibold.ttf differ diff --git a/app/lib/application/app.dart b/app/lib/application/app.dart index afa998ed..bf2819ec 100644 --- a/app/lib/application/app.dart +++ b/app/lib/application/app.dart @@ -1,4 +1,5 @@ import '../ui/adaptive/platform.dart'; +import '../ui/theme/app_font_controller.dart'; import '../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -16,6 +17,7 @@ class MyApp extends StatelessWidget { this.cupertino, this.destination, this.onDestinationSelected, + this.fonts, }) : routerConfig = null; /// A host for a [Router]-owned location, so browser Back/Forward and deep @@ -25,6 +27,7 @@ class MyApp extends StatelessWidget { super.key, required RouterConfig this.routerConfig, this.cupertino, + this.fonts, }) : destinationBodies = const {}, destination = null, onDestinationSelected = null; @@ -35,20 +38,33 @@ class MyApp extends StatelessWidget { final ValueChanged? onDestinationSelected; final RouterConfig? routerConfig; + /// The device's interface font; defaults to the app's shared controller. + /// A change rebuilds the themes in place, without a restart. + final AppFontController? fonts; + @override Widget build(BuildContext context) { + final fonts = this.fonts ?? AppFontController.instance; + return ListenableBuilder( + listenable: fonts, + builder: (context, _) => _host(fonts.family), + ); + } + + Widget _host(String? fontFamily) { final router = routerConfig; if (cupertino ?? _platformIsCupertino) { + final theme = appCupertinoThemeWith(fontFamily: fontFamily); if (router != null) { return CupertinoApp.router( title: 'Pipelines', - theme: appCupertinoTheme, + theme: theme, routerConfig: router, ); } return CupertinoApp( title: 'Pipelines', - theme: appCupertinoTheme, + theme: theme, home: AdaptiveShell( destinationBodies: destinationBodies, cupertino: true, @@ -60,16 +76,16 @@ class MyApp extends StatelessWidget { if (router != null) { return MaterialApp.router( title: 'Pipelines', - theme: appLightTheme(), - darkTheme: appDarkTheme(), + theme: appLightTheme(fontFamily: fontFamily), + darkTheme: appDarkTheme(fontFamily: fontFamily), themeMode: ThemeMode.system, routerConfig: router, ); } return MaterialApp( title: 'Pipelines', - theme: appLightTheme(), - darkTheme: appDarkTheme(), + theme: appLightTheme(fontFamily: fontFamily), + darkTheme: appDarkTheme(fontFamily: fontFamily), themeMode: ThemeMode.system, home: AdaptiveShell( destinationBodies: destinationBodies, diff --git a/app/lib/application/bootstrap.dart b/app/lib/application/bootstrap.dart index eb9bd8af..3e8b016f 100644 --- a/app/lib/application/bootstrap.dart +++ b/app/lib/application/bootstrap.dart @@ -6,6 +6,8 @@ import 'app_url_strategy.dart'; import 'pipelines_root.dart'; import 'server_endpoint.dart'; import '../features/settings/settings_store.dart'; +import '../ui/theme/app_font_controller.dart'; +import '../ui/theme/app_font_licenses.dart'; /// Native builds must supply their server explicitly; there is no baked host. const configuredServerUrl = String.fromEnvironment('PIPELINES_SERVER_URL'); @@ -38,6 +40,10 @@ Future resolveLaunchServer({ ); } +/// How long the first frame waits for a stored font before drawing in the +/// system font. +const appFontStartupWait = Duration(milliseconds: 1500); + /// Resolves the endpoint for this launch and starts the normal composition. Future runPipelinesApp({ Uri? base, @@ -46,8 +52,13 @@ Future runPipelinesApp({ }) async { useAppUrlStrategy(); WidgetsFlutterBinding.ensureInitialized(); + registerAppFontLicenses(); + // The device's chosen font loads beside the session; a slow download does + // not hold the first frame, and applies when it lands. + final font = AppFontController.instance.restore(wait: appFontStartupWait); // A phone behind the web login reconnects with its kept session. await ServerSession.load(); + await font; final server = await resolveLaunchServer( base: base, configured: configured, diff --git a/app/lib/application/pipelines_root.dart b/app/lib/application/pipelines_root.dart index 58571328..ca121bde 100644 --- a/app/lib/application/pipelines_root.dart +++ b/app/lib/application/pipelines_root.dart @@ -14,6 +14,7 @@ import '../features/onboarding/onboarding_flow.dart'; import '../features/settings/server_connections.dart'; import '../features/settings/saved_servers_section.dart'; import '../features/settings/settings_store.dart'; +import '../ui/theme/app_font_controller.dart'; import '../ui/theme/app_theme.dart'; import 'pipelines_app.dart'; import 'server_endpoint.dart'; @@ -294,19 +295,23 @@ class _PipelinesRootState extends State { _servers.catalog.active?.endpoints.map(Uri.parse).toList() ?? const [], ); - return _cupertino - ? CupertinoApp( - title: 'Pipelines', - theme: appCupertinoTheme, - debugShowCheckedModeBanner: false, - home: flow, - ) - : MaterialApp( - title: 'Pipelines', - theme: appLightTheme(), - darkTheme: appDarkTheme(), - debugShowCheckedModeBanner: false, - home: flow, - ); + final fonts = AppFontController.instance; + return ListenableBuilder( + listenable: fonts, + builder: (context, _) => _cupertino + ? CupertinoApp( + title: 'Pipelines', + theme: appCupertinoThemeWith(fontFamily: fonts.family), + debugShowCheckedModeBanner: false, + home: flow, + ) + : MaterialApp( + title: 'Pipelines', + theme: appLightTheme(fontFamily: fonts.family), + darkTheme: appDarkTheme(fontFamily: fonts.family), + debugShowCheckedModeBanner: false, + home: flow, + ), + ); } } diff --git a/app/lib/features/settings/settings_font_section.dart b/app/lib/features/settings/settings_font_section.dart new file mode 100644 index 00000000..049aba7f --- /dev/null +++ b/app/lib/features/settings/settings_font_section.dart @@ -0,0 +1,139 @@ +import 'dart:async'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../ui/theme/app_font.dart'; +import '../../ui/theme/app_font_controller.dart'; +import 'settings_group.dart'; +import 'settings_row.dart'; +import 'settings_theme.dart'; + +const fontSectionTitle = 'Font'; +const fontSectionFooter = + 'Saved on this device only. Code keeps its monospace font.'; +const fontLoadingText = 'Loading…'; +const fontLoadFailedText = 'Could not load this font.'; +const fontSaveFailedText = 'Not saved on this device; it applies until reload.'; + +ValueKey settingsFontKey(AppFont font) => + ValueKey('settings-font-${font.id}'); + +/// The device's interface font: one row per option, each named in its own +/// face. Material rows are radio tiles, Cupertino rows carry the checkmark. +/// A choice is stored locally and applies as soon as its files load. +class SettingsFontSection extends StatefulWidget { + const SettingsFontSection({super.key, required this.controller}); + + final AppFontController controller; + + @override + State createState() => _SettingsFontSectionState(); +} + +class _SettingsFontSectionState extends State { + @override + void initState() { + super.initState(); + _preview(); + } + + @override + void didUpdateWidget(SettingsFontSection oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.controller != widget.controller) _preview(); + } + + /// Only the regular weight of each option, only once Settings is shown. + void _preview() { + for (final font in AppFont.values) { + unawaited(widget.controller.preview(font)); + } + } + + @override + Widget build(BuildContext context) => ListenableBuilder( + listenable: widget.controller, + builder: (context, _) => _group(context), + ); + + Widget _group(BuildContext context) { + final controller = widget.controller; + final cupertino = usesCupertinoControls(context); + final group = SettingsGroup( + title: fontSectionTitle, + footer: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const Text(fontSectionFooter), + if (controller.saveFailed) + Text( + fontSaveFailedText, + style: TextStyle(color: settingsErrorColor(context)), + ), + ], + ), + children: [ + for (final font in AppFont.values) + cupertino + ? _cupertinoRow(context, font) + : RadioListTile( + key: settingsFontKey(font), + value: font, + title: _name(context, font), + subtitle: _status(context, font), + ), + ], + ); + if (cupertino) return group; + return RadioGroup( + groupValue: controller.selected, + onChanged: (font) { + if (font != null) unawaited(controller.select(font)); + }, + child: group, + ); + } + + Widget _cupertinoRow(BuildContext context, AppFont font) => SettingsRow( + key: settingsFontKey(font), + title: _name(context, font), + subtitle: _status(context, font), + trailing: widget.controller.selected == font + ? Icon( + CupertinoIcons.check_mark, + color: CupertinoTheme.of(context).primaryColor, + ) + : null, + onTap: () => unawaited(widget.controller.select(font)), + ); + + /// The option's name in its own face once its regular weight has loaded; + /// the system face until then (and always for the system option). + Widget _name(BuildContext context, AppFont font) { + final family = widget.controller.canPreview(font) + ? font.family ?? _systemFamily(context) + : _systemFamily(context); + return Text(font.label, style: TextStyle(fontFamily: family)); + } + + Widget? _status(BuildContext context, AppFont font) { + final controller = widget.controller; + if (controller.selected != font) return null; + if (controller.loadFailed == font) { + return Text( + fontLoadFailedText, + style: TextStyle(color: settingsErrorColor(context)), + ); + } + return controller.loading ? const Text(fontLoadingText) : null; + } +} + +/// The platform's own interface family (Roboto, or the Cupertino system +/// face), independent of the font the theme currently applies. +String? _systemFamily(BuildContext context) => usesCupertinoControls(context) + ? const CupertinoTextThemeData().textStyle.fontFamily + : Typography.material2021( + platform: Theme.of(context).platform, + ).black.bodyLarge?.fontFamily; diff --git a/app/lib/features/settings/settings_screen.dart b/app/lib/features/settings/settings_screen.dart index 9b0b4e2e..943b1296 100644 --- a/app/lib/features/settings/settings_screen.dart +++ b/app/lib/features/settings/settings_screen.dart @@ -10,6 +10,8 @@ import '../attention/notify/notification_controller.dart'; import 'default_endpoint.dart'; import 'settings_controller.dart'; import 'settings_controls.dart'; +import 'settings_font_section.dart'; +import '../../ui/theme/app_font_controller.dart'; import 'settings_group.dart'; import 'settings_page_body.dart'; import 'settings_notifications_section.dart'; @@ -53,8 +55,12 @@ class SettingsScreen extends StatefulWidget { this.servers, this.deliveryService, this.deliveryServiceController, + this.fonts, }); + /// The device's interface font; defaults to the app's shared controller. + final AppFontController? fonts; + /// Android background delivery; hidden when absent or unsupported. final NotificationServiceBridge? deliveryService; final NotificationServiceController? deliveryServiceController; @@ -190,6 +196,10 @@ class _SettingsScreenState extends State { controller: _controller, workspaceField: _workspaceField, ), + // A device-local choice: a browser and a phone keep their own. + SettingsFontSection( + controller: widget.fonts ?? AppFontController.instance, + ), if (widget.notifications case final notifications?) SettingsNotificationsSection(controller: notifications), if (widget.deliveryService case final service? when service.supported) diff --git a/app/lib/ui/theme/app_font.dart b/app/lib/ui/theme/app_font.dart new file mode 100644 index 00000000..491378ae --- /dev/null +++ b/app/lib/ui/theme/app_font.dart @@ -0,0 +1,82 @@ +/// The interface typefaces a device can choose. [AppFont.system] keeps the +/// platform's own typography (Roboto on Android and the web, SF on iOS); every +/// other option is an open-licence (SIL OFL 1.1) family bundled under +/// `fonts//` as plain assets, not under pubspec `fonts:`, so a web +/// page downloads only the family it actually shows. +enum AppFont { + system('system', 'System default', null, null, []), + inter('inter', 'Inter', 'Inter', 'inter', [ + 'Inter-Regular.ttf', + 'Inter-Medium.ttf', + 'Inter-SemiBold.ttf', + 'Inter-Bold.ttf', + ]), + ibmPlexSans( + 'ibm-plex-sans', + 'IBM Plex Sans', + 'IBM Plex Sans', + 'ibm-plex-sans', + [ + 'IBMPlexSans-Regular.ttf', + 'IBMPlexSans-Medium.ttf', + 'IBMPlexSans-SemiBold.ttf', + 'IBMPlexSans-Bold.ttf', + ], + ), + sourceSans3( + 'source-sans-3', + 'Source Sans 3', + 'Source Sans 3', + 'source-sans-3', + [ + 'SourceSans3-Regular.ttf', + 'SourceSans3-Medium.ttf', + 'SourceSans3-Semibold.ttf', + 'SourceSans3-Bold.ttf', + ], + ), + atkinsonHyperlegible( + 'atkinson-hyperlegible-next', + 'Atkinson Hyperlegible Next', + 'Atkinson Hyperlegible Next', + 'atkinson-hyperlegible-next', + [ + 'AtkinsonHyperlegibleNext-Regular.ttf', + 'AtkinsonHyperlegibleNext-Medium.ttf', + 'AtkinsonHyperlegibleNext-SemiBold.ttf', + 'AtkinsonHyperlegibleNext-Bold.ttf', + ], + ); + + const AppFont(this.id, this.label, this.family, this._directory, this._files); + + /// The stored value. Stable across releases; never the display label. + final String id; + + /// The picker's name for the option. + final String label; + + /// The registered family name; null keeps the platform typography. + final String? family; + + final String? _directory; + final List _files; + + /// Every weight's asset (400, 500, 600 and 700, in that order). + List get assets => [ + for (final file in _files) 'fonts/$_directory/$file', + ]; + + /// The regular weight alone: enough to preview the option's name. + String? get previewAsset => _files.isEmpty ? null : assets.first; + + /// The licence shipped beside the files. + String? get licenseAsset => + _directory == null ? null : 'fonts/$_directory/OFL.txt'; + + /// The option a stored id names; an unknown or missing id is the default. + static AppFont fromId(String? id) => AppFont.values.firstWhere( + (font) => font.id == id, + orElse: () => AppFont.system, + ); +} diff --git a/app/lib/ui/theme/app_font_controller.dart b/app/lib/ui/theme/app_font_controller.dart new file mode 100644 index 00000000..3109282f --- /dev/null +++ b/app/lib/ui/theme/app_font_controller.dart @@ -0,0 +1,156 @@ +import 'dart:async'; + +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'app_font.dart'; +import 'app_font_store.dart'; + +/// Registers [assets] under [family]. Production reads them from the bundle; +/// tests substitute a recorder. +typedef AppFontAssetLoader = + Future Function(String family, List assets); + +/// Loads bundled font files on demand with a [FontLoader]. On the web each +/// asset is fetched only now, when its family is first previewed or chosen. +Future loadBundledFontAssets(String family, List assets) async { + final loader = FontLoader(family); + for (final asset in assets) { + loader.addFont(rootBundle.load(asset)); + } + await loader.load(); +} + +/// The device's interface font: the stored choice, the family the theme +/// actually uses, and the on-demand loading between the two. +/// +/// The theme keeps the previous family (at first the platform's) until the +/// chosen files are registered, then switches once; text never lays out in a +/// family that has not loaded, so nothing reflows more than once. +class AppFontController extends ChangeNotifier { + AppFontController({ + this._store = const SharedPreferencesAppFontStore(), + this._loader = loadBundledFontAssets, + }); + + /// The app's own controller: one per running app, shared by the theme + /// hosts and the Settings picker. + static final AppFontController instance = AppFontController(); + + final AppFontStore _store; + final AppFontAssetLoader _loader; + final Map> _assetLoads = >{}; + final Set _loadedAssets = {}; + + AppFont _selected = AppFont.system; + AppFont _applied = AppFont.system; + bool _saveFailed = false; + AppFont? _loadFailed; + + /// The option the picker shows as chosen. + AppFont get selected => _selected; + + /// The option the theme uses now. + AppFont get applied => _applied; + + /// The theme's family; null keeps the platform typography. + String? get family => _applied.family; + + /// The chosen family's files are still downloading. + bool get loading => _selected != _applied && _loadFailed != _selected; + + /// The last choice could not be stored on this device. + bool get saveFailed => _saveFailed; + + /// The chosen family's files could not be loaded; the theme kept [applied]. + AppFont? get loadFailed => _loadFailed; + + /// Whether [font]'s regular weight is registered, so its name can be drawn + /// in its own face. + bool canPreview(AppFont font) => + font.previewAsset == null || _loadedAssets.contains(font.previewAsset); + + /// Reads the stored choice and starts loading it. With [wait], returns once + /// it is applied or after [wait], whichever is first; a slower load still + /// applies when it finishes. + Future restore({Duration? wait}) async { + final font = await _store.load(); + if (font == AppFont.system || font == _selected) return; + _selected = font; + notifyListeners(); + final applying = _apply(font); + if (wait == null) return applying; + await Future.any(>[ + applying, + Future.delayed(wait), + ]); + } + + /// Chooses [font], stores it, and applies it once its files are loaded. + Future select(AppFont font) async { + if (font == _selected && _loadFailed != font) return; + _selected = font; + _loadFailed = null; + notifyListeners(); + final saved = await _store.save(font); + if (saved == _saveFailed) { + _saveFailed = !saved; + notifyListeners(); + } + await _apply(font); + } + + /// Loads [font]'s regular weight for its picker row. Failures are quiet: the + /// row keeps the current face and choosing it reports the problem. + Future preview(AppFont font) async { + final asset = font.previewAsset; + final family = font.family; + if (asset == null || family == null || _loadedAssets.contains(asset)) { + return; + } + try { + await _ensure(family, [asset]); + } catch (_) { + return; + } + notifyListeners(); + } + + Future _apply(AppFont font) async { + final family = font.family; + if (family != null) { + try { + await _ensure(family, font.assets); + } catch (_) { + if (_selected == font) { + _loadFailed = font; + notifyListeners(); + } + return; + } + } + // A later choice supersedes this one. + if (_selected != font || _applied == font) return; + _applied = font; + notifyListeners(); + } + + /// Registers the assets not yet loaded or loading, in one [FontLoader], and + /// waits for all of [assets]. A failed asset can be retried. + Future _ensure(String family, List assets) { + final missing = assets.where((a) => !_assetLoads.containsKey(a)).toList(); + if (missing.isNotEmpty) { + final load = _loader(family, missing); + for (final asset in missing) { + _assetLoads[asset] = load.then( + (_) => _loadedAssets.add(asset), + onError: (Object error, StackTrace stack) { + _assetLoads.remove(asset); + Error.throwWithStackTrace(error, stack); + }, + ); + } + } + return Future.wait(assets.map((a) => _assetLoads[a]!)); + } +} diff --git a/app/lib/ui/theme/app_font_licenses.dart b/app/lib/ui/theme/app_font_licenses.dart new file mode 100644 index 00000000..e7b5e631 --- /dev/null +++ b/app/lib/ui/theme/app_font_licenses.dart @@ -0,0 +1,23 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'app_font.dart'; + +bool _registered = false; + +/// Adds each bundled interface font's SIL Open Font License to the +/// [LicenseRegistry]. The texts are read from the bundle only when a licence +/// page asks for them. +void registerAppFontLicenses() { + if (_registered) return; + _registered = true; + LicenseRegistry.addLicense(() async* { + for (final font in AppFont.values) { + final asset = font.licenseAsset; + if (asset == null) continue; + yield LicenseEntryWithLineBreaks([ + font.label, + ], await rootBundle.loadString(asset)); + } + }); +} diff --git a/app/lib/ui/theme/app_font_store.dart b/app/lib/ui/theme/app_font_store.dart new file mode 100644 index 00000000..6a2ec375 --- /dev/null +++ b/app/lib/ui/theme/app_font_store.dart @@ -0,0 +1,60 @@ +import 'package:shared_preferences/shared_preferences.dart'; + +import 'app_font.dart'; + +/// The device's font choice. It lives in this device's (or browser's) own +/// preferences and is never sent to a server, so a phone and a browser signed +/// in to the same server keep their own choice. +const String appFontKey = 'pipelines.next.font.v1'; + +/// The persistence seam for the font choice. +abstract interface class AppFontStore { + Future load(); + + /// Whether the choice is actually stored. + Future save(AppFont font); +} + +/// `shared_preferences` storage. An unavailable or unreadable store means the +/// default; a failed save returns false rather than throwing. +class SharedPreferencesAppFontStore implements AppFontStore { + const SharedPreferencesAppFontStore(); + + @override + Future load() async { + try { + final preferences = await SharedPreferences.getInstance(); + return AppFont.fromId(preferences.getString(appFontKey)); + } catch (_) { + return AppFont.system; + } + } + + @override + Future save(AppFont font) async { + try { + final preferences = await SharedPreferences.getInstance(); + return await preferences.setString(appFontKey, font.id); + } catch (_) { + return false; + } + } +} + +/// An in-memory store for tests and fixtures. +class MemoryAppFontStore implements AppFontStore { + MemoryAppFontStore([this.font = AppFont.system]); + + AppFont font; + bool failSaves = false; + + @override + Future load() async => font; + + @override + Future save(AppFont font) async { + if (failSaves) return false; + this.font = font; + return true; + } +} diff --git a/app/lib/ui/theme/app_theme.dart b/app/lib/ui/theme/app_theme.dart index 2e2ca090..40ad5587 100644 --- a/app/lib/ui/theme/app_theme.dart +++ b/app/lib/ui/theme/app_theme.dart @@ -26,11 +26,20 @@ abstract final class AppColors { const _seed = Color(0xFF6750A4); -ThemeData appLightTheme() => ThemeData( - platform: kIsWeb ? TargetPlatform.android : null, - colorScheme: ColorScheme.fromSeed(seedColor: _seed), - pageTransitionsTheme: appPageTransitions, -); +/// [fontFamily] replaces the platform family throughout the text themes +/// (Material's, and Cupertino's for Cupertino widgets on a Material host), +/// keeping every size, weight and the text scaling; null keeps the system +/// typography. +ThemeData appLightTheme({String? fontFamily}) { + final scheme = ColorScheme.fromSeed(seedColor: _seed); + return ThemeData( + platform: kIsWeb ? TargetPlatform.android : null, + colorScheme: scheme, + pageTransitionsTheme: appPageTransitions, + fontFamily: fontFamily, + cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme), + ); +} /// Android and iOS keep their native transitions and interactive back gestures. /// Desktop hosts use the short horizontal slide. @@ -80,7 +89,7 @@ class FastSlidePageTransitionsBuilder extends PageTransitionsBuilder { } /// Material's dark scheme with gray surfaces stepping up from the page. -ThemeData appDarkTheme() { +ThemeData appDarkTheme({String? fontFamily}) { final scheme = ColorScheme.fromSeed( seedColor: _seed, @@ -100,6 +109,8 @@ ThemeData appDarkTheme() { colorScheme: scheme, scaffoldBackgroundColor: scheme.surface, pageTransitionsTheme: appPageTransitions, + fontFamily: fontFamily, + cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme), ); } @@ -107,3 +118,45 @@ const appCupertinoTheme = CupertinoThemeData( scaffoldBackgroundColor: AppColors.background, barBackgroundColor: AppColors.bar, ); + +/// [appCupertinoTheme] with every Cupertino text role in [fontFamily]; null +/// keeps the system typography. +CupertinoThemeData appCupertinoThemeWith({String? fontFamily}) => + fontFamily == null + ? appCupertinoTheme + : appCupertinoTheme.copyWith(textTheme: appCupertinoTextTheme(fontFamily)); + +/// The stock Cupertino text roles (sizes, weights, colours) in [fontFamily]. +/// Action roles take [primaryColor], as the stock roles do. +CupertinoTextThemeData appCupertinoTextTheme( + String fontFamily, { + Color primaryColor = CupertinoColors.systemBlue, +}) { + final base = CupertinoTextThemeData(primaryColor: primaryColor); + TextStyle face(TextStyle style) => style.copyWith(fontFamily: fontFamily); + return CupertinoTextThemeData( + textStyle: face(base.textStyle), + actionTextStyle: face(base.actionTextStyle), + actionSmallTextStyle: face(base.actionSmallTextStyle), + tabLabelTextStyle: face(base.tabLabelTextStyle), + navTitleTextStyle: face(base.navTitleTextStyle), + navLargeTitleTextStyle: face(base.navLargeTitleTextStyle), + navActionTextStyle: face(base.navActionTextStyle), + pickerTextStyle: face(base.pickerTextStyle), + dateTimePickerTextStyle: face(base.dateTimePickerTextStyle), + ); +} + +/// Cupertino widgets on a Material host derive their theme from Material's; +/// only the family is overridden, with Material's primary for actions. +NoDefaultCupertinoThemeData? _cupertinoOverride( + String? fontFamily, + ColorScheme scheme, +) => fontFamily == null + ? null + : CupertinoThemeData( + textTheme: appCupertinoTextTheme( + fontFamily, + primaryColor: scheme.primary, + ), + ); diff --git a/app/notes/interface-font-choice.md b/app/notes/interface-font-choice.md new file mode 100644 index 00000000..3ab07c94 --- /dev/null +++ b/app/notes/interface-font-choice.md @@ -0,0 +1,44 @@ +# Interface font choice (per device) + +Settings > Font offers System default (the default everywhere: Roboto on +Android and the web, SF in the iOS app), Inter, IBM Plex Sans, Source Sans 3 +and Atkinson Hyperlegible Next. Each option is named in its own face. + +- `lib/ui/theme/app_font.dart`: the options, stable stored ids and assets. +- `lib/ui/theme/app_font_store.dart`: `shared_preferences` key + `pipelines.next.font.v1`, so the choice belongs to this device or browser + and is never sent to the server. +- `lib/ui/theme/app_font_controller.dart`: `AppFontController.instance` + loads the chosen family with a `FontLoader` and only then switches the + theme (one switch, no reflow loop). Startup waits up to 1.5 s for a stored + font beside the session load, then draws in the system font and applies + the font when it lands. A failed load keeps the current face and says so. +- `lib/ui/theme/app_theme.dart`: `appLightTheme`/`appDarkTheme({fontFamily})` + and `appCupertinoThemeWith({fontFamily})` replace only the family in every + text role; sizes, weights and text scaling are unchanged. Explicit + `appMonospaceFamily` (RobotoMono) styles are untouched. +- `MyApp` and the onboarding host rebuild from the controller, so a choice + applies immediately on Material and Cupertino hosts. +- `lib/ui/theme/app_font_licenses.dart`: each `fonts//OFL.txt` is + registered with `LicenseRegistry`. The app has no licence page of its own + yet, so nothing shows them in the UI. + +## Web download cost + +The families are plain `assets:`, not pubspec `fonts:` (the web engine fetches +every `fonts:` family at boot). Browser resource log on the fixture build: +startup fetches no optional font; opening Settings fetches each family's +Regular weight for the previews (65–431 KB each); choosing one fetches its +other three weights. A stored choice fetches only its four files at startup. + +Build size (release web): `main.dart.js` 4,214,247 -> 4,232,251 bytes (+18 KB, ++5 KB gzip); `build/web` 43.6 -> 48.0 MB because the four families' 16 TTFs +(4.45 MB, 2.09 MB gzip) ship as on-demand assets. The APK grows by about the +same compressed amount (not measured). + +## Known gaps + +- Chat markdown code blocks were already in the proportional UI face, not + RobotoMono; they now follow the chosen font too. +- On the web Cupertino fixture, "System default" names an unregistered + `CupertinoSystemText` family, which the browser engine substitutes. diff --git a/app/pubspec.yaml b/app/pubspec.yaml index a1e6e95e..90b2201a 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -75,6 +75,13 @@ flutter: assets: - assets/harnesses/claude.png - assets/harnesses/opencode.png + # Optional interface fonts. Plain assets, not `fonts:`: the web engine + # downloads every `fonts:` family at startup, while these load on demand + # (lib/ui/theme/app_font_controller.dart). Licences: fonts/README.md. + - fonts/inter/ + - fonts/ibm-plex-sans/ + - fonts/source-sans-3/ + - fonts/atkinson-hyperlegible-next/ fonts: - family: RobotoMono diff --git a/app/test/features/settings/settings_font_section_test.dart b/app/test/features/settings/settings_font_section_test.dart new file mode 100644 index 00000000..fd8aedd3 --- /dev/null +++ b/app/test/features/settings/settings_font_section_test.dart @@ -0,0 +1,135 @@ +import 'dart:async'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/settings/settings_font_section.dart'; +import 'package:pipelines_app/ui/theme/app_font.dart'; +import 'package:pipelines_app/ui/theme/app_font_controller.dart'; +import 'package:pipelines_app/ui/theme/app_font_store.dart'; + +class _Harness { + _Harness({this.hold = false}); + + final bool hold; + final store = MemoryAppFontStore(); + final loads = []; + final held = >[]; + + late final fonts = AppFontController( + store: store, + loader: (family, assets) { + loads.addAll(assets); + if (!hold || assets.length == 1) return Future.value(); + final done = Completer(); + held.add(done); + return done.future; + }, + ); +} + +Future _pump( + WidgetTester tester, + _Harness harness, { + bool cupertino = false, +}) async { + final section = SingleChildScrollView( + child: SettingsFontSection(controller: harness.fonts), + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: section)) + : MaterialApp(home: Scaffold(body: section)), + ); + await tester.pumpAndSettle(); +} + +String? _familyOf(WidgetTester tester, AppFont font) => tester + .widget( + find.descendant( + of: find.byKey(settingsFontKey(font)), + matching: find.text(font.label), + ), + ) + .style + ?.fontFamily; + +void main() { + testWidgets('Material: every option is a radio named in its own face', ( + tester, + ) async { + final harness = _Harness(); + await _pump(tester, harness); + + expect(find.text(fontSectionTitle), findsOneWidget); + for (final font in AppFont.values) { + expect(find.byKey(settingsFontKey(font)), findsOneWidget); + expect(_familyOf(tester, font), font.family ?? 'Roboto'); + } + // Showing the picker fetched one regular weight per option, no more. + expect(harness.loads, [ + for (final font in AppFont.values) + if (font.previewAsset != null) font.previewAsset, + ]); + final group = tester.widget>( + find.byType(RadioGroup), + ); + expect(group.groupValue, AppFont.system); + }); + + testWidgets('Material: choosing a font stores it and shows it loading', ( + tester, + ) async { + final harness = _Harness(hold: true); + await _pump(tester, harness); + + await tester.tap(find.text('Source Sans 3')); + await tester.pump(); + expect(harness.store.font, AppFont.sourceSans3); + expect( + tester + .widget>(find.byType(RadioGroup)) + .groupValue, + AppFont.sourceSans3, + ); + expect(find.text(fontLoadingText), findsOneWidget); + expect(harness.fonts.family, isNull); + + harness.held.single.complete(); + await tester.pumpAndSettle(); + expect(find.text(fontLoadingText), findsNothing); + expect(harness.fonts.family, 'Source Sans 3'); + }); + + testWidgets('Cupertino: the chosen row carries the checkmark', ( + tester, + ) async { + final harness = _Harness(); + await _pump(tester, harness, cupertino: true); + + expect(find.byType(RadioListTile), findsNothing); + expect(_familyOf(tester, AppFont.system), 'CupertinoSystemText'); + Finder check(AppFont font) => find.descendant( + of: find.byKey(settingsFontKey(font)), + matching: find.byIcon(CupertinoIcons.check_mark), + ); + expect(check(AppFont.system), findsOneWidget); + + await tester.tap(find.text('Inter')); + await tester.pumpAndSettle(); + expect(check(AppFont.system), findsNothing); + expect(check(AppFont.inter), findsOneWidget); + expect(harness.store.font, AppFont.inter); + expect(harness.fonts.family, 'Inter'); + }); + + testWidgets('a failed save is said under the group', (tester) async { + final harness = _Harness(); + harness.store.failSaves = true; + await _pump(tester, harness); + + await tester.tap(find.text('Inter')); + await tester.pumpAndSettle(); + expect(find.text(fontSaveFailedText), findsOneWidget); + }); +} diff --git a/app/test/ui/theme/app_font_controller_test.dart b/app/test/ui/theme/app_font_controller_test.dart new file mode 100644 index 00000000..865ad00f --- /dev/null +++ b/app/test/ui/theme/app_font_controller_test.dart @@ -0,0 +1,156 @@ +import 'dart:async'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/theme/app_font.dart'; +import 'package:pipelines_app/ui/theme/app_font_controller.dart'; +import 'package:pipelines_app/ui/theme/app_font_store.dart'; + +/// Records each load and completes it when the test says so. +class _Loads { + final calls = <(String, List)>[]; + final pending = >[]; + bool immediate = true; + + Future call(String family, List assets) { + calls.add((family, assets)); + final done = Completer(); + pending.add(done); + if (immediate) done.complete(); + return done.future; + } +} + +void main() { + test('starts on the system default with no download', () async { + final loads = _Loads(); + final fonts = AppFontController( + store: MemoryAppFontStore(), + loader: loads.call, + ); + await fonts.restore(); + expect(fonts.selected, AppFont.system); + expect(fonts.family, isNull); + expect(loads.calls, isEmpty); + }); + + test('restore loads only the stored family, then applies it', () async { + final loads = _Loads()..immediate = false; + final fonts = AppFontController( + store: MemoryAppFontStore(AppFont.inter), + loader: loads.call, + ); + final restoring = fonts.restore(); + await pumpEventQueue(); + expect(fonts.selected, AppFont.inter); + expect(fonts.family, isNull, reason: 'system face until loaded'); + expect(fonts.loading, isTrue); + expect(loads.calls.single.$1, 'Inter'); + expect(loads.calls.single.$2, AppFont.inter.assets); + loads.pending.single.complete(); + await restoring; + expect(fonts.family, 'Inter'); + expect(fonts.loading, isFalse); + }); + + test( + 'restore with a wait returns at the deadline and applies later', + () async { + final loads = _Loads()..immediate = false; + final fonts = AppFontController( + store: MemoryAppFontStore(AppFont.sourceSans3), + loader: loads.call, + ); + await fonts.restore(wait: const Duration(milliseconds: 10)); + expect(fonts.family, isNull); + loads.pending.single.complete(); + await pumpEventQueue(); + expect(fonts.family, 'Source Sans 3'); + }, + ); + + test( + 'select stores the choice and applies it; system needs no load', + () async { + final store = MemoryAppFontStore(); + final loads = _Loads(); + final fonts = AppFontController(store: store, loader: loads.call); + await fonts.select(AppFont.atkinsonHyperlegible); + expect(store.font, AppFont.atkinsonHyperlegible); + expect(fonts.family, 'Atkinson Hyperlegible Next'); + await fonts.select(AppFont.system); + expect(store.font, AppFont.system); + expect(fonts.family, isNull); + expect(loads.calls, hasLength(1)); + }, + ); + + test('a newer choice wins over a slower earlier load', () async { + final loads = _Loads()..immediate = false; + final fonts = AppFontController( + store: MemoryAppFontStore(), + loader: loads.call, + ); + final first = fonts.select(AppFont.inter); + await pumpEventQueue(); + final second = fonts.select(AppFont.ibmPlexSans); + await pumpEventQueue(); + loads.pending[1].complete(); + await second; + expect(fonts.family, 'IBM Plex Sans'); + loads.pending[0].complete(); + await first; + expect(fonts.family, 'IBM Plex Sans'); + }); + + test( + 'preview loads the regular weight once; choosing loads the rest', + () async { + final loads = _Loads(); + final fonts = AppFontController( + store: MemoryAppFontStore(), + loader: loads.call, + ); + expect(fonts.canPreview(AppFont.inter), isFalse); + await fonts.preview(AppFont.inter); + await fonts.preview(AppFont.inter); + await fonts.preview(AppFont.system); + expect(fonts.canPreview(AppFont.inter), isTrue); + expect(fonts.canPreview(AppFont.system), isTrue); + expect(loads.calls.single.$1, 'Inter'); + expect(loads.calls.single.$2, ['fonts/inter/Inter-Regular.ttf']); + await fonts.select(AppFont.inter); + expect(loads.calls.last.$2, AppFont.inter.assets.skip(1).toList()); + }, + ); + + test( + 'a failed load keeps the current face, says so, and can retry', + () async { + var fail = true; + final fonts = AppFontController( + store: MemoryAppFontStore(), + loader: (family, assets) async { + if (fail) throw StateError('offline'); + }, + ); + await fonts.select(AppFont.inter); + expect(fonts.family, isNull); + expect(fonts.loadFailed, AppFont.inter); + expect(fonts.loading, isFalse); + fail = false; + await fonts.select(AppFont.inter); + expect(fonts.loadFailed, isNull); + expect(fonts.family, 'Inter'); + }, + ); + + test('a failed save is reported but the font still applies', () async { + final fonts = AppFontController( + store: MemoryAppFontStore()..failSaves = true, + loader: _Loads().call, + ); + await fonts.select(AppFont.inter); + expect(fonts.saveFailed, isTrue); + expect(fonts.family, 'Inter'); + }); +} diff --git a/app/test/ui/theme/app_font_store_test.dart b/app/test/ui/theme/app_font_store_test.dart new file mode 100644 index 00000000..7e6f46cf --- /dev/null +++ b/app/test/ui/theme/app_font_store_test.dart @@ -0,0 +1,69 @@ +import 'dart:io'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/theme/app_font.dart'; +import 'package:pipelines_app/ui/theme/app_font_store.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() => SharedPreferences.setMockInitialValues({})); + + test('nothing stored is the system default', () async { + expect(await const SharedPreferencesAppFontStore().load(), AppFont.system); + }); + + test( + 'a choice round-trips under its stable id, on the device only', + () async { + const store = SharedPreferencesAppFontStore(); + expect(await store.save(AppFont.ibmPlexSans), isTrue); + final preferences = await SharedPreferences.getInstance(); + expect(preferences.getKeys(), {appFontKey}); + expect(preferences.getString(appFontKey), 'ibm-plex-sans'); + expect(await store.load(), AppFont.ibmPlexSans); + + expect(await store.save(AppFont.system), isTrue); + expect(await store.load(), AppFont.system); + }, + ); + + test('an unknown stored id falls back to the system default', () async { + SharedPreferences.setMockInitialValues({ + appFontKey: 'comic-sans', + }); + expect(await const SharedPreferencesAppFontStore().load(), AppFont.system); + }); + + test('every bundled option has its four weights and its licence', () { + for (final font in AppFont.values) { + if (font == AppFont.system) { + expect(font.family, isNull); + expect(font.assets, isEmpty); + continue; + } + expect(font.assets, hasLength(4)); + expect(font.previewAsset, font.assets.first); + for (final asset in [...font.assets, font.licenseAsset!]) { + expect(File(asset).existsSync(), isTrue, reason: asset); + } + expect( + File(font.licenseAsset!).readAsStringSync(), + contains('SIL OPEN FONT LICENSE Version 1.1'), + ); + } + }); + + test('the optional fonts are assets, not startup fonts', () { + final pubspec = File('pubspec.yaml').readAsStringSync(); + final fonts = pubspec.substring(pubspec.indexOf('\n fonts:')); + for (final font in AppFont.values.where((f) => f.family != null)) { + expect(fonts, isNot(contains('family: ${font.family}'))); + expect( + pubspec, + contains(' - ${font.licenseAsset!.replaceAll('OFL.txt', '')}\n'), + ); + } + }); +} diff --git a/app/test/ui/theme/app_font_theme_test.dart b/app/test/ui/theme/app_font_theme_test.dart new file mode 100644 index 00000000..4f9e3ea5 --- /dev/null +++ b/app/test/ui/theme/app_font_theme_test.dart @@ -0,0 +1,95 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/application/app.dart'; +import 'package:pipelines_app/shell/destination.dart'; +import 'package:pipelines_app/ui/theme/app_font.dart'; +import 'package:pipelines_app/ui/theme/app_font_controller.dart'; +import 'package:pipelines_app/ui/theme/app_font_store.dart'; +import 'package:pipelines_app/ui/theme/app_theme.dart'; + +void main() { + test('Material themes take the family and keep sizes and weights', () { + for (final build in [ + appLightTheme, + appDarkTheme, + ]) { + final system = build().textTheme; + final inter = build(fontFamily: 'Inter').textTheme; + expect(build().textTheme.bodyMedium?.fontFamily, isNot('Inter')); + for (final (a, b) in <(TextStyle?, TextStyle?)>[ + (system.bodyMedium, inter.bodyMedium), + (system.titleMedium, inter.titleMedium), + (system.labelLarge, inter.labelLarge), + (system.headlineSmall, inter.headlineSmall), + ]) { + expect(b?.fontFamily, 'Inter'); + expect(b?.fontSize, a?.fontSize); + expect(b?.fontWeight, a?.fontWeight); + } + expect( + build( + fontFamily: 'Inter', + ).cupertinoOverrideTheme?.textTheme?.textStyle.fontFamily, + 'Inter', + ); + expect(build().cupertinoOverrideTheme, isNull); + } + }); + + test('the Cupertino theme takes the family in every text role', () { + expect(appCupertinoThemeWith(), same(appCupertinoTheme)); + final text = appCupertinoThemeWith(fontFamily: 'Inter').textTheme; + const stock = CupertinoTextThemeData(); + for (final (a, b) in <(TextStyle, TextStyle)>[ + (stock.textStyle, text.textStyle), + (stock.navTitleTextStyle, text.navTitleTextStyle), + (stock.navLargeTitleTextStyle, text.navLargeTitleTextStyle), + (stock.tabLabelTextStyle, text.tabLabelTextStyle), + (stock.actionTextStyle, text.actionTextStyle), + (stock.pickerTextStyle, text.pickerTextStyle), + ]) { + expect(b.fontFamily, 'Inter'); + expect(b.fontSize, a.fontSize); + expect(b.fontWeight, a.fontWeight); + } + expect( + appCupertinoThemeWith(fontFamily: 'Inter').scaffoldBackgroundColor, + AppColors.background, + ); + }); + + for (final cupertino in [false, true]) { + testWidgets('the ${cupertino ? 'Cupertino' : 'Material'} host switches ' + 'font live, without a restart', (tester) async { + final fonts = AppFontController( + store: MemoryAppFontStore(), + loader: (family, assets) async {}, + ); + String? family; + await tester.pumpWidget( + MyApp( + cupertino: cupertino, + fonts: fonts, + destination: AppDestination.settings, + destinationBodies: { + AppDestination.settings: (context) => Builder( + builder: (context) { + family = DefaultTextStyle.of(context).style.fontFamily; + return const Text('body'); + }, + ), + }, + ), + ); + final before = family; + expect(before, isNot('IBM Plex Sans')); + await fonts.select(AppFont.ibmPlexSans); + await tester.pumpAndSettle(); + expect(family, 'IBM Plex Sans'); + await fonts.select(AppFont.system); + await tester.pumpAndSettle(); + expect(family, before); + }); + } +} diff --git a/app/tool/search_selection_probe_entry.dart b/app/tool/search_selection_probe_entry.dart index 15365dee..a6342f5b 100644 --- a/app/tool/search_selection_probe_entry.dart +++ b/app/tool/search_selection_probe_entry.dart @@ -23,6 +23,8 @@ import 'package:pipelines_app/core/transport/pipelines_client.dart'; import 'package:pipelines_app/features/search/ui/search_bar_controls.dart' show searchFieldKey; import 'package:pipelines_app/ui/input/app_search_field.dart'; +import 'package:pipelines_app/ui/theme/app_font.dart'; +import 'package:pipelines_app/ui/theme/app_font_controller.dart'; import 'package:flutter/widgets.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; @@ -604,6 +606,13 @@ void main() { return; } configurePerfFixture(params); + // `?font=inter` chooses a font as Settings would; otherwise the stored one. + final font = params['font']; + unawaited( + font == null + ? AppFontController.instance.restore() + : AppFontController.instance.select(AppFont.fromId(font)), + ); _fillerRunCount = int.tryParse(params['runs'] ?? '') ?? 0; _fillerStepCount = int.tryParse(params['steps'] ?? '') ?? 0; final cupertino = params['platform'] == 'cupertino';