Skip to content

Commit f6d744a

Browse files
committed
text: Bundle 'Source Code Pro' font into the app
We'll probably want to bundle more fonts into the app, like Source Sans 3, which we use for most text in Zulip web. But now at least we can see the process works! :) Fixes: #64
1 parent 6a6a4d3 commit f6d744a

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed
Binary file not shown.
175 KB
Binary file not shown.

lib/widgets/content.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,11 @@ InlineSpan inlineCode(InlineCodeNode node) {
355355

356356
// Use a light gray background, instead of a border.
357357
return TextSpan(
358-
style: kMonospaceTextStyle.merge(const TextStyle(
359-
backgroundColor: Color(0xffeeeeee),
360-
fontSize: 0.825 * kBaseFontSize,
361-
)),
358+
style: kMonospaceTextStyle
359+
.merge(const TextStyle(
360+
backgroundColor: Color(0xffeeeeee),
361+
fontSize: 0.825 * kBaseFontSize))
362+
.merge(weightVariableTextStyle(null)), // TODO(a11y) pass a BuildContext
362363
children: _buildInlineList(node.nodes));
363364

364365
// Another fun solution -- we can in fact have a border! Like so:
@@ -378,10 +379,11 @@ InlineSpan inlineCode(InlineCodeNode node) {
378379
// ]);
379380
}
380381

381-
final _kCodeStyle = kMonospaceTextStyle.merge(const TextStyle(
382-
backgroundColor: Color.fromRGBO(255, 255, 255, 1),
383-
fontSize: 0.825 * kBaseFontSize,
384-
));
382+
final _kCodeStyle = kMonospaceTextStyle
383+
.merge(const TextStyle(
384+
backgroundColor: Color.fromRGBO(255, 255, 255, 1),
385+
fontSize: 0.825 * kBaseFontSize))
386+
.merge(weightVariableTextStyle(null)); // TODO(a11y) pass a BuildContext
385387

386388
// const _kInlineCodeLeftBracket = '⸤';
387389
// const _kInlineCodeRightBracket = '⸣';
@@ -638,4 +640,6 @@ InlineSpan _errorUnimplemented(UnimplementedNode node) {
638640

639641
const errorStyle = TextStyle(fontWeight: FontWeight.bold, color: Colors.red);
640642

641-
final errorCodeStyle = kMonospaceTextStyle.merge(const TextStyle(color: Colors.red));
643+
final errorCodeStyle = kMonospaceTextStyle
644+
.merge(const TextStyle(color: Colors.red))
645+
.merge(weightVariableTextStyle(null)); // TODO(a11y) pass a BuildContext

lib/widgets/text.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import 'package:flutter/widgets.dart';
44

55
/// A mergeable [TextStyle] with 'Source Code Pro' and platform-aware fallbacks.
66
///
7+
/// Callers should also call [weightVariableTextStyle] and merge that in too,
8+
/// because for this font, we use "variable font" assets with a "wght" axis.
9+
///
710
/// Example:
811
///
912
/// ```dart
10-
/// kMonospaceTextStyle.merge(const TextStyle(color: Colors.red))
13+
/// kMonospaceTextStyle
14+
/// .merge(const TextStyle(color: Colors.red))
15+
/// .merge(weightVariableTextStyle(context))
1116
/// ```
1217
final TextStyle kMonospaceTextStyle = TextStyle(
13-
fontFamily: 'Source Code Pro', // TODO supply font
18+
fontFamily: 'Source Code Pro',
1419

1520
// Oddly, iOS doesn't handle 'monospace':
1621
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20monospace.20font.20fallback/near/1570622

pubspec.yaml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,9 @@ flutter:
9494
# For details regarding adding assets from package dependencies, see
9595
# https://flutter.dev/assets-and-images/#from-packages
9696

97-
# To add custom fonts to your application, add a fonts section here,
98-
# in this "flutter" section. Each entry in this list should have a
99-
# "family" key with the font family name, and a "fonts" key with a
100-
# list giving the asset and other descriptors for the font. For
101-
# example:
102-
# fonts:
103-
# - family: Schyler
104-
# fonts:
105-
# - asset: fonts/Schyler-Regular.ttf
106-
# - asset: fonts/Schyler-Italic.ttf
107-
# style: italic
108-
# - family: Trajan Pro
109-
# fonts:
110-
# - asset: fonts/TrajanPro.ttf
111-
# - asset: fonts/TrajanPro_Bold.ttf
112-
# weight: 700
113-
#
114-
# For details regarding fonts from package dependencies,
115-
# see https://flutter.dev/custom-fonts/#from-packages
97+
fonts:
98+
- family: Source Code Pro
99+
fonts:
100+
- asset: assets/SourceCodePro-VariableFont_wght.ttf
101+
- asset: assets/SourceCodePro-Italic-VariableFont_wght.ttf
102+
style: italic

0 commit comments

Comments
 (0)