Skip to content

Commit 6c54858

Browse files
acking-youclaude
andcommitted
fix(app-server): bundle Noto Sans SC for even Chinese on desktop
Chinese rendered with Flutter's default fonts looks thin and unevenly weighted on Windows: with no declared CJK font the OS picks a fallback face per glyph-run and synthesizes weights. Bundle Noto Sans SC (SIL OFL 1.1) and make it the app's primary family on desktop so 中文 and Latin share one evenly-weighted typeface. Desktop-only by design: the ~17 MB font would be dead weight on mobile, whose OS CJK fonts (iOS PingFang SC, Android Noto Sans CJK) already render Chinese well. The font is declared ONLY in pubspec-desktop.yaml (a copy of pubspec.yaml plus a fonts: block); the default pubspec.yaml omits it, so Android/iOS/test builds never bundle it. The 3 desktop release jobs copy the desktop manifest over pubspec.yaml before building; the 2 mobile jobs are untouched. - lib/src/fonts.dart: shared font config. isDesktop is gated on defaultTargetPlatform (NOT dart:io) so `flutter test` — which forces the platform to android — takes the mobile branch and never references the desktop-only family. - theme.dart: fontFamily = Noto Sans SC on desktop, null (system) on mobile, plus a CJK fallback chain (PingFang SC / Noto Sans CJK / Microsoft YaHei). - 10 monospace code/diff/command/markdown styles gain a CJK fallback so Chinese-in-code renders in a real face while ASCII stays monospaced. - release.yml: app-windows/linux/macos swap in pubspec-desktop.yaml. - AGENTS.md: documents the two-manifest scheme + local preview command. Engine caveat (unchanged): Flutter on Windows uses grayscale AA, not ClearType (flutter/flutter#63043), so CJK still reads marginally softer than a native Win32 app — but the thin/uneven weight (the reported complaint) is fixed. Verified: analyze clean, 81/81 tests pass (default no-font manifest), and on the live Windows app (desktop manifest) the new-session cards and title render in Noto Sans SC with even, properly-weighted strokes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent b35ed73 commit 6c54858

9 files changed

Lines changed: 367 additions & 6 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ jobs:
115115
- uses: Swatinem/rust-cache@v2
116116
with:
117117
key: app-windows
118+
# Desktop bundles Noto Sans SC (fixes thin/uneven Chinese on Windows);
119+
# mobile uses the OS CJK font, so only the desktop jobs swap in the
120+
# manifest that declares the font. See AGENTS.md › Fonts.
121+
- name: Activate desktop manifest (bundle Noto Sans SC)
122+
shell: bash
123+
working-directory: apps/flutter
124+
run: cp pubspec-desktop.yaml pubspec.yaml
118125
- name: Build Windows app
119126
working-directory: apps/flutter
120127
run: |
@@ -160,6 +167,10 @@ jobs:
160167
run: |
161168
sudo apt-get update -y
162169
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
170+
- name: Activate desktop manifest (bundle Noto Sans SC)
171+
shell: bash
172+
working-directory: apps/flutter
173+
run: cp pubspec-desktop.yaml pubspec.yaml
163174
- name: Build Linux app
164175
working-directory: apps/flutter
165176
run: |
@@ -255,6 +266,10 @@ jobs:
255266
- uses: Swatinem/rust-cache@v2
256267
with:
257268
key: app-macos
269+
- name: Activate desktop manifest (bundle Noto Sans SC)
270+
shell: bash
271+
working-directory: apps/flutter
272+
run: cp pubspec-desktop.yaml pubspec.yaml
258273
- name: Build macOS app
259274
working-directory: apps/flutter
260275
run: |

‎AGENTS.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,32 @@ cargo doc --workspace --no-deps
174174
flutter_rust_bridge_codegen generate # after editing crates/pocket-codex-bridge/src/api/
175175
```
176176

177+
### Fonts (desktop-only Noto Sans SC)
178+
179+
Chinese renders thin and unevenly weighted on Windows with Flutter's default
180+
fonts, so **desktop** builds bundle **Noto Sans SC** (`apps/flutter/assets/fonts/`,
181+
SIL OFL 1.1). To keep the ~17 MB out of the Android/iOS artifacts, the font is
182+
declared only in `apps/flutter/pubspec-desktop.yaml`, **not** the default
183+
`pubspec.yaml`:
184+
185+
- `pubspec.yaml` — the default used by mobile, `flutter test`, and local dev.
186+
No font. Source of truth for dependencies.
187+
- `pubspec-desktop.yaml` — a copy of `pubspec.yaml` **plus** a `fonts:` block.
188+
The desktop release jobs (`app-windows` / `app-linux` / `app-macos` in
189+
`.github/workflows/release.yml`) `cp pubspec-desktop.yaml pubspec.yaml` before
190+
building. **Keep its dependencies in sync with `pubspec.yaml`.**
191+
192+
`lib/src/fonts.dart` sets the primary family to `Noto Sans SC` only on desktop
193+
(gated on `defaultTargetPlatform`, so `flutter test` — forced to android — takes
194+
the mobile branch); mobile/web use the OS CJK font (PingFang SC / Noto Sans CJK).
195+
To preview the bundled font locally on desktop:
196+
197+
```bash
198+
cp apps/flutter/pubspec-desktop.yaml apps/flutter/pubspec.yaml
199+
(cd apps/flutter && fvm flutter pub get && fvm flutter run -d windows)
200+
git checkout -- apps/flutter/pubspec.yaml # restore before committing
201+
```
202+
177203
## 8. Working with submodules
178204

179205
`deps/codex` and `deps/pb-mapper` are git submodules. They pin specific
16.9 MB
Binary file not shown.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'
2+
3+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
4+
This license is copied below, and is also available with a FAQ at:
5+
https://scripts.sil.org/OFL
6+
7+
8+
-----------------------------------------------------------
9+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10+
-----------------------------------------------------------
11+
12+
PREAMBLE
13+
The goals of the Open Font License (OFL) are to stimulate worldwide
14+
development of collaborative font projects, to support the font creation
15+
efforts of academic and linguistic communities, and to provide a free and
16+
open framework in which fonts may be shared and improved in partnership
17+
with others.
18+
19+
The OFL allows the licensed fonts to be used, studied, modified and
20+
redistributed freely as long as they are not sold by themselves. The
21+
fonts, including any derivative works, can be bundled, embedded,
22+
redistributed and/or sold with any software provided that any reserved
23+
names are not used by derivative works. The fonts and derivatives,
24+
however, cannot be released under any other type of license. The
25+
requirement for fonts to remain under this license does not apply
26+
to any document created using the fonts or their derivatives.
27+
28+
DEFINITIONS
29+
"Font Software" refers to the set of files released by the Copyright
30+
Holder(s) under this license and clearly marked as such. This may
31+
include source files, build scripts and documentation.
32+
33+
"Reserved Font Name" refers to any names specified as such after the
34+
copyright statement(s).
35+
36+
"Original Version" refers to the collection of Font Software components as
37+
distributed by the Copyright Holder(s).
38+
39+
"Modified Version" refers to any derivative made by adding to, deleting,
40+
or substituting -- in part or in whole -- any of the components of the
41+
Original Version, by changing formats or by porting the Font Software to a
42+
new environment.
43+
44+
"Author" refers to any designer, engineer, programmer, technical
45+
writer or other person who contributed to the Font Software.
46+
47+
PERMISSION & CONDITIONS
48+
Permission is hereby granted, free of charge, to any person obtaining
49+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
50+
redistribute, and sell modified and unmodified copies of the Font
51+
Software, subject to the following conditions:
52+
53+
1) Neither the Font Software nor any of its individual components,
54+
in Original or Modified Versions, may be sold by itself.
55+
56+
2) Original or Modified Versions of the Font Software may be bundled,
57+
redistributed and/or sold with any software, provided that each copy
58+
contains the above copyright notice and this license. These can be
59+
included either as stand-alone text files, human-readable headers or
60+
in the appropriate machine-readable metadata fields within text or
61+
binary files as long as those fields can be easily viewed by the user.
62+
63+
3) No Modified Version of the Font Software may use the Reserved Font
64+
Name(s) unless explicit written permission is granted by the corresponding
65+
Copyright Holder. This restriction only applies to the primary font name as
66+
presented to the users.
67+
68+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69+
Software shall not be used to promote, endorse or advertise any
70+
Modified Version, except to acknowledge the contribution(s) of the
71+
Copyright Holder(s) and the Author(s) or with their explicit written
72+
permission.
73+
74+
5) The Font Software, modified or unmodified, in part or in whole,
75+
must be distributed entirely under this license, and must not be
76+
distributed under any other license. The requirement for fonts to
77+
remain under this license does not apply to any document created
78+
using the Font Software.
79+
80+
TERMINATION
81+
This license becomes null and void if any of the above conditions are
82+
not met.
83+
84+
DISCLAIMER
85+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93+
OTHER DEALINGS IN THE FONT SOFTWARE.

‎apps/flutter/lib/src/fonts.dart‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'package:flutter/foundation.dart';
2+
3+
/// Font configuration. Chinese rendered with Flutter's default (no declared
4+
/// CJK font) looks thin and unevenly weighted on Windows, because the OS picks
5+
/// a fallback face per glyph-run. To fix it we bundle Noto Sans SC — but ONLY
6+
/// in the desktop builds (Windows/macOS/Linux), which is where the problem is.
7+
/// Mobile (Android/iOS) keeps the OS CJK fonts (PingFang SC / Noto Sans CJK SC),
8+
/// which already render Chinese well, so those artifacts don't carry the ~17 MB.
9+
///
10+
/// Desktop bundling is done by swapping `pubspec-desktop.yaml` (which adds a
11+
/// `fonts:` block for the family below) over `pubspec.yaml` before the build —
12+
/// see the desktop jobs in .github/workflows/release.yml and the note in
13+
/// AGENTS.md. The default `pubspec.yaml` omits the font, so mobile/test never
14+
/// bundle it.
15+
16+
/// Family registered by the `fonts:` block in pubspec-desktop.yaml. Must match
17+
/// that block byte-for-byte, and is only actually registered on desktop builds.
18+
const desktopFontFamily = 'Noto Sans SC';
19+
20+
/// True on desktop OSes, where Noto Sans SC is bundled. Gated on
21+
/// [defaultTargetPlatform] (NOT `dart:io` Platform) on purpose: `flutter test`
22+
/// forces the platform to android, so tests take the mobile branch and never
23+
/// set the primary family to a face that isn't registered in the test harness.
24+
bool get isDesktop =>
25+
!kIsWeb &&
26+
(defaultTargetPlatform == TargetPlatform.windows ||
27+
defaultTargetPlatform == TargetPlatform.macOS ||
28+
defaultTargetPlatform == TargetPlatform.linux);
29+
30+
/// The app's primary font: the bundled Noto Sans SC on desktop, and the system
31+
/// default (null) on mobile/web so Latin keeps the native UI font and CJK falls
32+
/// to the OS face. Latin glyphs on desktop also come from Noto Sans SC, which
33+
/// the user asked for (one uniform typeface for 中英文).
34+
String? get appFontFamily => isDesktop ? desktopFontFamily : null;
35+
36+
/// CJK fallback for the primary text theme. On mobile (primary = system font)
37+
/// these resolve Chinese to the OS CJK face; on desktop they are extra
38+
/// insurance behind the bundled family. Harmless where a name isn't installed.
39+
const cjkFontFallback = ['PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei'];
40+
41+
/// CJK fallback for `fontFamily: 'monospace'` styles (command output, diffs,
42+
/// file paths, code blocks). 'monospace' has no Han glyphs, so without this
43+
/// Chinese-in-code re-falls-back to an ugly OS face. The bundled family is
44+
/// listed first (used on desktop; silently skipped where unregistered, e.g.
45+
/// mobile, falling through to the OS CJK names). Kept const so the many
46+
/// `const TextStyle(...)` code sites stay const.
47+
const monoCjkFallback = [
48+
desktopFontFamily,
49+
'PingFang SC',
50+
'Noto Sans CJK SC',
51+
'Microsoft YaHei',
52+
];

‎apps/flutter/lib/src/screens/api_service_screen.dart‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
44
import 'package:pocket_codex/l10n/gen/app_localizations.dart';
55
import 'package:pocket_codex/src/bridge_api.dart';
66
import 'package:pocket_codex/src/error_format.dart';
7+
import 'package:pocket_codex/src/fonts.dart';
78
import 'package:pocket_codex/src/providers.dart';
89
import 'package:pocket_codex/src/widgets/links.dart';
910

@@ -186,7 +187,11 @@ class _ProviderSnippet extends StatelessWidget {
186187
context,
187188
snippet,
188189
selectable: true,
189-
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
190+
style: const TextStyle(
191+
fontFamily: 'monospace',
192+
fontFamilyFallback: monoCjkFallback,
193+
fontSize: 12,
194+
),
190195
),
191196
],
192197
),

‎apps/flutter/lib/src/screens/app_session_screen.dart‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:pocket_codex/src/app_modes.dart';
1212
import 'package:pocket_codex/src/bridge_api.dart';
1313
import 'package:pocket_codex/src/context_status.dart';
1414
import 'package:pocket_codex/src/error_format.dart';
15+
import 'package:pocket_codex/src/fonts.dart';
1516
import 'package:pocket_codex/src/git_diff.dart';
1617
import 'package:pocket_codex/src/providers.dart';
1718
import 'package:pocket_codex/src/widgets/links.dart';
@@ -2526,7 +2527,11 @@ class _ApprovalCard extends StatelessWidget {
25262527
context,
25272528
_detail(),
25282529
selectable: true,
2529-
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
2530+
style: const TextStyle(
2531+
fontFamily: 'monospace',
2532+
fontFamilyFallback: monoCjkFallback,
2533+
fontSize: 12,
2534+
),
25302535
),
25312536
),
25322537
),
@@ -2752,7 +2757,11 @@ class _DiffFileTile extends StatelessWidget {
27522757
Expanded(
27532758
child: Text(
27542759
file.path,
2755-
style: const TextStyle(fontFamily: 'monospace', fontSize: 12.5),
2760+
style: const TextStyle(
2761+
fontFamily: 'monospace',
2762+
fontFamilyFallback: monoCjkFallback,
2763+
fontSize: 12.5,
2764+
),
27562765
overflow: TextOverflow.ellipsis,
27572766
),
27582767
),
@@ -2817,7 +2826,12 @@ class _DiffFileTile extends StatelessWidget {
28172826
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 1),
28182827
child: Text(
28192828
line.kind == DiffLineKind.hunk ? line.text : '$prefix${line.text}',
2820-
style: TextStyle(fontFamily: 'monospace', fontSize: 12, color: fg),
2829+
style: TextStyle(
2830+
fontFamily: 'monospace',
2831+
fontFamilyFallback: monoCjkFallback,
2832+
fontSize: 12,
2833+
color: fg,
2834+
),
28212835
),
28222836
);
28232837
}
@@ -3055,6 +3069,7 @@ class _FileChangeCardState extends State<_FileChangeCard> {
30553069
overflow: TextOverflow.ellipsis,
30563070
style: TextStyle(
30573071
fontFamily: 'monospace',
3072+
fontFamilyFallback: monoCjkFallback,
30583073
fontSize: 12,
30593074
color: muted,
30603075
),
@@ -3139,7 +3154,11 @@ class _CopyablePath extends StatelessWidget {
31393154
Expanded(
31403155
child: SelectableText(
31413156
path,
3142-
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
3157+
style: const TextStyle(
3158+
fontFamily: 'monospace',
3159+
fontFamilyFallback: monoCjkFallback,
3160+
fontSize: 12,
3161+
),
31433162
),
31443163
),
31453164
InkResponse(
@@ -3522,6 +3541,7 @@ class _ActivityCardState extends State<_ActivityCard> {
35223541
overflow: TextOverflow.ellipsis,
35233542
style: TextStyle(
35243543
fontFamily: 'monospace',
3544+
fontFamilyFallback: monoCjkFallback,
35253545
fontSize: 12,
35263546
color: muted,
35273547
),
@@ -3564,7 +3584,11 @@ class _ActivityCardState extends State<_ActivityCard> {
35643584
context,
35653585
body,
35663586
selectable: true,
3567-
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
3587+
style: const TextStyle(
3588+
fontFamily: 'monospace',
3589+
fontFamilyFallback: monoCjkFallback,
3590+
fontSize: 12,
3591+
),
35683592
),
35693593
),
35703594
),
@@ -3645,6 +3669,7 @@ MarkdownStyleSheet _markdownStyle(BuildContext context) {
36453669
blockSpacing: 10,
36463670
code: theme.textTheme.bodyMedium?.copyWith(
36473671
fontFamily: 'monospace',
3672+
fontFamilyFallback: monoCjkFallback,
36483673
backgroundColor: scheme.surfaceContainerHighest,
36493674
),
36503675
codeblockDecoration: BoxDecoration(

‎apps/flutter/lib/src/theme.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:pocket_codex/src/fonts.dart';
23

34
/// Brand seed colour for both schemes.
45
const _seed = Color(0xFF4C8DF6);
@@ -18,6 +19,8 @@ ThemeData lightTheme() => ThemeData(
1819
brightness: Brightness.light,
1920
),
2021
useMaterial3: true,
22+
fontFamily: appFontFamily,
23+
fontFamilyFallback: cjkFontFallback,
2124
scrollbarTheme: _scrollbarTheme,
2225
);
2326

@@ -28,5 +31,7 @@ ThemeData darkTheme() => ThemeData(
2831
brightness: Brightness.dark,
2932
),
3033
useMaterial3: true,
34+
fontFamily: appFontFamily,
35+
fontFamilyFallback: cjkFontFallback,
3136
scrollbarTheme: _scrollbarTheme,
3237
);

0 commit comments

Comments
 (0)