Address Inter font review findings (#52)
- Set Inter only when DirectWrite resolves its family, so a name mismatch keeps the system font instead of a fallback on every run. - Rename init to init_theme and share the family name as a constant. - Make the test prove a semibold face: its glyphs are wider. - Ship the license from the same Inter release as the font. - Shorten the search placeholder so it fits at the minimum width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #52.
This commit is contained in:
1 parent
1016b68e41
commit
650dfd4bfa
3 files changed
+36
-26
No files matched your search
@@ -1,9 +1,8 @@
|
||||
Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
|
||||
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:
|
||||
https://openfontlicense.org
|
||||
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
@@ -44,7 +43,7 @@ new environment.
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
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
|
||||
|
||||
+32
-20
@@ -223,13 +223,20 @@ fn startup() -> Result<Setup, (Vec<String>, Preferences)> {
|
||||
})
|
||||
}
|
||||
|
||||
fn init(cx: &mut App) {
|
||||
gpui_kit::init(cx);
|
||||
let inter = include_bytes!("../assets/InterVariable.ttf");
|
||||
match cx.text_system().add_fonts(vec![Cow::Borrowed(inter)]) {
|
||||
// DirectWrite exposes the variable font's text optical size as its own family.
|
||||
Ok(()) => Theme::update(cx, |theme| theme.font_family = "Inter Variable Text".into()),
|
||||
Err(error) => eprintln!("Failed to load Inter: {error}"),
|
||||
/// DirectWrite exposes the variable font's text optical size as its own family.
|
||||
const INTER: &str = "Inter Variable Text";
|
||||
|
||||
/// Sets Inter as the interface font and adjusts the theme colours. Needs `gpui_kit::init` first.
|
||||
fn init_theme(cx: &mut App) {
|
||||
let text = cx.text_system();
|
||||
let ttf = include_bytes!("../assets/InterVariable.ttf");
|
||||
if let Err(error) = text.add_fonts(vec![Cow::Borrowed(ttf)]) {
|
||||
eprintln!("Failed to load Inter: {error}");
|
||||
}
|
||||
// A family that falls back costs a font lookup on every text run: keep the system font then.
|
||||
let inter = font(INTER);
|
||||
if text.get_font_for_id(text.resolve_font(&inter)) == Some(inter) {
|
||||
Theme::update(cx, |theme| theme.font_family = INTER.into());
|
||||
}
|
||||
// The default dark table header text has low contrast against its background.
|
||||
let dark = Rc::make_mut(&mut Theme::global_mut(cx).dark_theme);
|
||||
@@ -239,7 +246,8 @@ fn init(cx: &mut App) {
|
||||
fn main() {
|
||||
let app = gpui_kit::application().with_assets(gpui_kit::assets::Assets);
|
||||
app.run(move |cx| {
|
||||
init(cx);
|
||||
gpui_kit::init(cx);
|
||||
init_theme(cx);
|
||||
#[cfg(feature = "profile")]
|
||||
profile::start(cx);
|
||||
let options = WindowOptions {
|
||||
@@ -289,12 +297,13 @@ mod tests {
|
||||
use gpui_kit::component::{Theme, ThemeMode};
|
||||
use gpui_kit::{
|
||||
AppContext as _, FontWeight, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
||||
TestAppContext, VisualTestContext, WindowOptions, font, point,
|
||||
TestAppContext, VisualTestContext, WindowOptions, font, point, px,
|
||||
};
|
||||
|
||||
use super::{KeyStore, RootView, Screen, Setup};
|
||||
use super::{INTER, KeyStore, RootView, Screen, Setup};
|
||||
use crate::title_bar::{BAR_HEIGHT, BUTTON_WIDTH};
|
||||
|
||||
// Not #[gpui::test]: its text system is a no-op, and this checks DirectWrite's real one.
|
||||
#[test]
|
||||
fn inter_is_used_in_both_themes() {
|
||||
let platform = gpui_kit::platform::current_platform(false);
|
||||
@@ -304,19 +313,22 @@ mod tests {
|
||||
platform.text_system(),
|
||||
);
|
||||
cx.update(|cx| {
|
||||
super::init(cx);
|
||||
gpui_kit::init(cx);
|
||||
super::init_theme(cx);
|
||||
for mode in [ThemeMode::Light, ThemeMode::Dark] {
|
||||
Theme::change(mode, None, cx);
|
||||
let family = &Theme::global(cx).font_family;
|
||||
assert_eq!(family.as_str(), "Inter Variable Text");
|
||||
let text = cx.text_system();
|
||||
for weight in [FontWeight::NORMAL, FontWeight::SEMIBOLD] {
|
||||
let mut requested = font(family.clone());
|
||||
requested.weight = weight;
|
||||
let resolved = text.get_font_for_id(text.resolve_font(&requested));
|
||||
assert_eq!(resolved, Some(requested));
|
||||
}
|
||||
assert_eq!(Theme::global(cx).font_family.as_str(), INTER);
|
||||
}
|
||||
// DirectWrite returns the nearest weight, so only a wider glyph proves a semibold face.
|
||||
let text = cx.text_system();
|
||||
let [regular, semibold] = [FontWeight::NORMAL, FontWeight::SEMIBOLD].map(|weight| {
|
||||
let mut requested = font(INTER);
|
||||
requested.weight = weight;
|
||||
let id = text.resolve_font(&requested);
|
||||
assert_eq!(text.get_font_for_id(id), Some(requested));
|
||||
text.advance(id, px(14.), 'm').unwrap().width
|
||||
});
|
||||
assert!(semibold > regular, "{semibold:?} <= {regular:?}");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -168,8 +168,7 @@ impl StatsPage {
|
||||
let format_names = vec![SharedString::from(ALL_FORMATS)];
|
||||
let format_select = cx
|
||||
.new(|cx| SelectState::new(format_names.clone(), Some(IndexPath::new(0)), window, cx));
|
||||
let search_input =
|
||||
cx.new(|cx| InputState::new(window, cx).placeholder("Rechercher un champion"));
|
||||
let search_input = cx.new(|cx| InputState::new(window, cx).placeholder("Rechercher"));
|
||||
let charts = cx.new(|_| ChartsRow::new());
|
||||
let table = cx.new(|_| ChampionTable::new());
|
||||
|
||||
|
||||
Reference in new issue
Block a user