fix(app): keep diff typography and colours native to the host

This commit is contained in:
2026-10-21 18:40:49 +01:00
parent ada25a59e5
commit 32e1cac46f
10 changed files with 63 additions and 210 deletions
-93
View File
@@ -1,93 +0,0 @@
Copyright 2015 The Roboto Mono Project Authors (https://github.com/googlefonts/robotomono)
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.
Binary file not shown.
@@ -113,7 +113,7 @@ class _FileRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final mono = monospaceText(DefaultTextStyle.of(context).style); final mono = nativeDiffText(DefaultTextStyle.of(context).style);
final cupertino = usesCupertino(context); final cupertino = usesCupertino(context);
final leading = Icon(_kindIcon(context, file.kind)); final leading = Icon(_kindIcon(context, file.kind));
final title = Text(file.path, style: mono); final title = Text(file.path, style: mono);
@@ -6,12 +6,6 @@ import '../domain/unified_patch.dart';
/// Which form of a recorded patch the viewer is showing. /// Which form of a recorded patch the viewer is showing.
enum DiffForm { rendered, raw } enum DiffForm { rendered, raw }
/// The bundled code face (`assets/fonts/RobotoMono.ttf`, SIL OFL 1.1). Flutter
/// web cannot resolve a system monospace family, so the app carries one and
/// every target renders patch text the same way. The fallbacks are only for
/// hosts that cannot load the asset.
const codeFontFamily = 'RobotoMono';
/// The app's established platform switch: Material for Android/desktop/web, /// The app's established platform switch: Material for Android/desktop/web,
/// Cupertino for iOS and macOS. Feature widgets stay portable across all three /// Cupertino for iOS and macOS. Feature widgets stay portable across all three
/// targets instead of hard-coding one control set. /// targets instead of hard-coding one control set.
@@ -20,38 +14,29 @@ bool usesCupertino(BuildContext context) {
return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS; return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS;
} }
/// The app's code face for patch text. The size, weight and text scaler come /// Patch text inherits the host's typography, including its font and scaler.
/// from the caller's theme style, so code follows the operator's text size. /// A diff is not an exception to the native-defaults requirement.
TextStyle monospaceText(TextStyle base) => base.copyWith( TextStyle nativeDiffText(TextStyle base) => base;
fontFamily: codeFontFamily,
fontFamilyFallback: const ['Menlo', 'Consolas', 'Courier New', 'monospace'],
);
/// The distinguishable success/removal colours shared by the stat line and the /// Native semantic colours, never a bespoke diff palette. The recorded +/-
/// diff rows. A theme-aware green/red pair, never two shades of the same hue: /// markers carry meaning independently of colour. No background tint is added.
/// the light Material containers alone made additions and removals read alike.
({Color text, Color? background}) diffLineColors( ({Color text, Color? background}) diffLineColors(
BuildContext context, BuildContext context,
ChangeLineKind kind, ChangeLineKind kind,
) { ) {
final dark = usesCupertino(context)
? CupertinoTheme.of(context).brightness == Brightness.dark
: Theme.of(context).brightness == Brightness.dark;
return switch (kind) { return switch (kind) {
ChangeLineKind.add => ChangeLineKind.add => (
dark text: usesCupertino(context)
? (text: const Color(0xFF7FE0A8), background: const Color(0x297FE0A8)) ? CupertinoColors.systemGreen.resolveFrom(context)
: ( : Theme.of(context).colorScheme.primary,
text: const Color(0xFF116B33), background: null,
background: const Color(0xFFE3F3E7), ),
), ChangeLineKind.remove => (
ChangeLineKind.remove => text: usesCupertino(context)
dark ? CupertinoColors.destructiveRed.resolveFrom(context)
? (text: const Color(0xFFFF9E9E), background: const Color(0x29FF9E9E)) : Theme.of(context).colorScheme.error,
: ( background: null,
text: const Color(0xFFB3261E), ),
background: const Color(0xFFFBE7E5),
),
ChangeLineKind.context => (text: labelColor(context), background: null), ChangeLineKind.context => (text: labelColor(context), background: null),
}; };
} }
@@ -64,7 +64,7 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
final file = widget.file; final file = widget.file;
final cupertino = usesCupertino(context); final cupertino = usesCupertino(context);
final base = DefaultTextStyle.of(context).style; final base = DefaultTextStyle.of(context).style;
final mono = monospaceText(base); final mono = nativeDiffText(base);
final stat = changeStat(file.added, file.removed); final stat = changeStat(file.added, file.removed);
final tags = changeEntryTags(file); final tags = changeEntryTags(file);
return ConstrainedBox( return ConstrainedBox(
@@ -17,7 +17,7 @@ class PatchView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final parsed = file.parsedPatch; final parsed = file.parsedPatch;
final base = monospaceText(DefaultTextStyle.of(context).style); final base = nativeDiffText(DefaultTextStyle.of(context).style);
final stat = changeStat(parsed.added, parsed.removed); final stat = changeStat(parsed.added, parsed.removed);
return Semantics( return Semantics(
container: true, container: true,
@@ -106,7 +106,7 @@ class _HunkView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final base = monospaceText(DefaultTextStyle.of(context).style); final base = nativeDiffText(DefaultTextStyle.of(context).style);
final width = gutterWidth(hunk); final width = gutterWidth(hunk);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
+27 -16
View File
@@ -1,8 +1,22 @@
# D1 — run changes and the file diff viewer # D1 — run changes and the file diff viewer
New feature under `lib/features/changes/` plus a bundled code font. The only New feature under `lib/features/changes/`; no server, legacy web/Android or
tracked-file change is `pubspec.yaml` (the font family/assets declaration that pubspec changes remain after manager acceptance corrections.
Flutter web needs); no server, web or Android changes.
## Current manager acceptance (supersedes earlier presentation evidence below)
The pipeline's bundled font and fixed green/red palette were rejected against
the user's native-defaults requirement. Manager removed both and the font assets
without changing raw patch, capture or visit semantics. Typography inherits the
host; colours use native semantic roles and no row tint. The original candidate
and its review evidence remain referenced at15cca17; later font/palette evidence
in this note is historical, NOT evidence for the final native-defaults patch.
Updated regressions failed against the original overrides, then all47 focused
tests passed after correction; analyzer clean. Fresh fixture web build and
changes_probe passed (including absence of custom font), producing18 new captures
under approved temp/native-diff-manager-captures. Manager inspected both native
phone2x rendered views. Preview/shell integration and mobile remain unverified.
## Public API ## Public API
@@ -105,13 +119,12 @@ The manager owns shell/run-detail registration; this item does not edit them.
keeps each recorded line on one line and scrolls sideways, like the web's keeps each recorded line on one line and scrolls sideways, like the web's
`white-space: pre` pane, so a wrapped continuation can never be mistaken for a `white-space: pre` pane, so a wrapped continuation can never be mistaken for a
new patch line. new patch line.
- Code text uses **Roboto Mono**, bundled as `assets/fonts/RobotoMono.ttf` and - Patch/path text inherits the native host typography without a font-family,
declared in `pubspec.yaml`. Flutter web's CanvasKit cannot resolve a system size or weight override. Manager removed the candidate's bundled code font:
`monospace` family, so before the bundle the browser diff rendered in a a previous visual review requested it, but that contradicts the user's
proportional face. The font is SIL OFL 1.1; its licence ships beside it as explicit native-defaults requirement, which also applies to diffs. The web
`assets/fonts/OFL.txt`. The size, weight and text scaler come from the theme default may be proportional; no monospace guarantee is claimed. Raw patch
style, so code follows the operator's text size; no fixed content bytes are unchanged. No bundled font or pubspec change remains.
width/height.
- Rendered/Raw is a native Material `SegmentedButton` or Cupertino - Rendered/Raw is a native Material `SegmentedButton` or Cupertino
`CupertinoSlidingSegmentedControl`. Copy patch and Close are native Material `CupertinoSlidingSegmentedControl`. Copy patch and Close are native Material
buttons/icon button or Cupertino buttons with exact labels. buttons/icon button or Cupertino buttons with exact labels.
@@ -121,12 +134,10 @@ The manager owns shell/run-detail registration; this item does not edit them.
- Binary uses the honest binary message; truncated-with-patch shows the note plus - Binary uses the honest binary message; truncated-with-patch shows the note plus
the retained text; truncated-without-patch and mode-only show the recorded the retained text; truncated-without-patch and mode-only show the recorded
reason, never an invented empty diff. reason, never an invented empty diff.
- Additions and removals use distinguishable theme-aware hues, never two shades - Add/remove markers and stats use native semantic colours (Material primary/
of one container role: light `#116B33` text on `#E3F3E7` for additions and error; Cupertino systemGreen/destructiveRed), with no bespoke palette or added
`#B3261E` on `#FBE7E5` for removals; dark `#7FE0A8` and `#FF9E9E` on a 16% tint. +/- and recorded gutter numbers distinguish changes without colour.
wash of the same hue. `+N` and `-M` are separate spans in those hues. Each Rows share the hunk width, at least the dialog width.
changed line paints a tint across the whole hunk content width (at least the
dialog width), so short lines no longer produce short colour bars.
- A Cupertino list row lets its recorded path wrap instead of inheriting the - A Cupertino list row lets its recorded path wrap instead of inheriting the
tile's single ellipsized line, and the Cupertino dialog surface is inset from tile's single ellipsized line, and the Cupertino dialog surface is inset from
the window edge (16 on phones, 40 on wide windows) so its native rounded the window edge (16 on phones, 40 on wide windows) so its native rounded
-12
View File
@@ -61,18 +61,6 @@ flutter:
# the material Icons class. # the material Icons class.
uses-material-design: true uses-material-design: true
# The diff viewer's bundled code face. Flutter web has no resolvable system
# monospace family, so the app ships Roboto Mono (SIL OFL 1.1, licence beside
# the font) and the same face is used on every target.
fonts:
- family: RobotoMono
fonts:
- asset: assets/fonts/RobotoMono.ttf
weight: 400
assets:
- assets/fonts/OFL.txt
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets:
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
@@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -18,22 +16,14 @@ const _raggedPatch =
'-x\n' '-x\n'
' tail\n'; ' tail\n';
double _addGreenMinusRed(Color color) => color.g - color.r;
double _removeRedMinusGreen(Color color) => color.r - color.g;
void main() { void main() {
test('patch text uses the bundled code face, not a web fallback', () { test(
final style = monospaceText(const TextStyle(fontSize: 12)); 'patch typography preserves the native host style without overrides',
expect(style.fontFamily, codeFontFamily); () {
expect(style.fontFamilyFallback, contains('Menlo')); const native = TextStyle(fontSize: 19, fontFamily: 'host-font');
// Flutter web can only render a monospace diff if the build carries one. expect(nativeDiffText(native), same(native));
expect(File('assets/fonts/RobotoMono.ttf').existsSync(), isTrue); },
expect( );
File('pubspec.yaml').readAsStringSync(),
contains('family: $codeFontFamily'),
);
});
testWidgets( testWidgets(
'light and dark themes give additions and removals distinct hues', 'light and dark themes give additions and removals distinct hues',
@@ -45,29 +35,16 @@ void main() {
final context = tester.element(find.byType(Scaffold)); final context = tester.element(find.byType(Scaffold));
final add = diffLineColors(context, ChangeLineKind.add); final add = diffLineColors(context, ChangeLineKind.add);
final remove = diffLineColors(context, ChangeLineKind.remove); final remove = diffLineColors(context, ChangeLineKind.remove);
expect(add.background, isNotNull, reason: '$brightness add tint'); expect(add.background, isNull);
expect(remove.background, isNotNull, reason: '$brightness remove tint'); expect(remove.background, isNull);
expect(add.text, isNot(remove.text), reason: '$brightness text'); expect(add.text, isNot(remove.text), reason: '$brightness text');
expect( expect(add.text, Theme.of(context).colorScheme.primary);
_addGreenMinusRed(add.background!), expect(remove.text, Theme.of(context).colorScheme.error);
greaterThan(0.02),
reason: '$brightness additions read as green, not another red',
);
expect(
_removeRedMinusGreen(remove.background!),
greaterThan(0.02),
reason: '$brightness removals read as red, not another green',
);
expect(
_removeRedMinusGreen(remove.text),
greaterThan(0.02),
reason: '$brightness removal text is a red hue',
);
} }
}, },
); );
testWidgets('every diff line tint spans the hunk width, not its own text', ( testWidgets('every diff line shares the hunk width, not its own text width', (
tester, tester,
) async { ) async {
await tester.pumpWidget( await tester.pumpWidget(
+3 -18
View File
@@ -219,30 +219,15 @@ try {
throw new Error(`Root index is not text/html: ${contentType}`); throw new Error(`Root index is not text/html: ${contentType}`);
} }
// The diff's core content can only be monospaced if the web build ships a // Diff text inherits native host typography; it must not add a custom face.
// code face; CanvasKit cannot resolve the system `monospace` family.
const manifest = await evaluate("fetch('/assets/FontManifest.json').then(r => r.json())"); const manifest = await evaluate("fetch('/assets/FontManifest.json').then(r => r.json())");
const codeEntry = (Array.isArray(manifest) ? manifest : []).find( const codeEntry = (Array.isArray(manifest) ? manifest : []).find(
(entry) => entry.family === 'RobotoMono', (entry) => entry.family === 'RobotoMono',
); );
const codeAsset = codeEntry?.fonts?.[0]?.asset; if (codeEntry) throw new Error('Diff build still overrides native typography');
if (!codeAsset) {
throw new Error(`FontManifest has no RobotoMono family: ${JSON.stringify(manifest)}`);
}
const fontResponse = await evaluate(`fetch('/assets/${codeAsset}').then(async (r) => ({
status: r.status,
contentType: r.headers.get('content-type'),
bytes: (await r.arrayBuffer()).byteLength,
}))`);
evidence.checks.push({ evidence.checks.push({
check: 'the web build carries the diff code face', check: 'the web build does not register a custom diff font',
family: codeEntry.family,
asset: codeAsset,
...fontResponse,
}); });
if (fontResponse.status !== 200 || fontResponse.bytes < 10000) {
throw new Error(`Code face did not load: ${JSON.stringify(fontResponse)}`);
}
const firstLabels = await labels(); const firstLabels = await labels();
const firstBody = await bodyText(); const firstBody = await bodyText();