Skip to content

Commit 5d6bb98

Browse files
committed
Support disable font hinting: Ref #732
1 parent d13e6cf commit 5d6bb98

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

docs/docs/config/fonts.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ In case you would like to change:
8181
# family = "Noto Color Emoji"
8282
```
8383

84+
## Hinting
85+
86+
Enable or disable font hinting. It is enabled by default.
87+
88+
```toml
89+
[fonts]
90+
hinting = true
91+
```
92+
8493
## User interface
8594

8695
You can specify user interface font on Rio.

docs/docs/releases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ language: 'en'
1818
- Microsoft Windows: [Rio terminal is now available on WinGet packages](https://github.com/microsoft/winget-pkgs/pull/184792).
1919
- Microsoft Windows: [Rio terminal is now available on MINGW packages](https://github.com/msys2/MINGW-packages/pull/22248).
2020
- Allow MacOS automation via events.
21+
- Support disable font hinting: `fonts.hinting = false`.
2122
- Fix: Configuration updates triggered multiple times on one save.
2223
- Support to RetroArch shaders [@igorsaux](https://github.com/igorsaux).
2324
- Fix: Set notepad as a default editor on Windows by [@igorsaux](https://github.com/igorsaux).

sugarloaf/src/components/rich_text/image_cache/glyph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'a> GlyphCacheSession<'a> {
126126

127127
self.scaled_image.data.clear();
128128
let mut font_library_data = self.font_library.inner.lock();
129+
let enable_hint = font_library_data.hinting;
129130
let font_data = font_library_data.get(&self.font);
130131
let should_embolden = font_data.should_embolden;
131132
let should_italicize = font_data.should_italicize;
@@ -140,7 +141,7 @@ impl<'a> GlyphCacheSession<'a> {
140141
// As a result Apple's Quartz text renderer, which is targeted for Retina displays,
141142
// now ignores font hint information completely.
142143
// .hint(!IS_MACOS)
143-
.hint(true)
144+
.hint(enable_hint)
144145
.size(self.quant_size.into())
145146
// .normalized_coords(coords)
146147
.build();

sugarloaf/src/font/fonts.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ pub fn default_font_size() -> f32 {
4040
14.
4141
}
4242

43+
#[inline]
44+
pub fn default_font_hinting() -> bool {
45+
true
46+
}
47+
4348
fn default_font_family() -> String {
4449
DEFAULT_FONT_FAMILY.to_string()
4550
}
@@ -80,6 +85,8 @@ pub fn default_font_bold_italic() -> SugarloafFont {
8085
pub struct SugarloafFonts {
8186
#[serde(default = "default_font_size")]
8287
pub size: f32,
88+
#[serde(default = "default_font_hinting")]
89+
pub hinting: bool,
8390
#[serde(default = "Option::default")]
8491
pub features: Option<Vec<String>>,
8592
#[serde(default = "Option::default")]
@@ -104,6 +111,7 @@ impl Default for SugarloafFonts {
104111
fn default() -> SugarloafFonts {
105112
SugarloafFonts {
106113
features: None,
114+
hinting: true,
107115
size: default_font_size(),
108116
family: None,
109117
emoji: None,

sugarloaf/src/font/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub struct FontLibraryData {
123123
// Standard is fallback for everything, it is also the inner number 0
124124
pub inner: FxHashMap<usize, FontData>,
125125
pub stash: LruCache<usize, SharedData>,
126+
pub hinting: bool,
126127
}
127128

128129
impl Default for FontLibraryData {
@@ -131,6 +132,7 @@ impl Default for FontLibraryData {
131132
ui: FontArc::try_from_slice(FONT_CASCADIAMONO_REGULAR).unwrap(),
132133
inner: FxHashMap::default(),
133134
stash: LruCache::new(NonZeroUsize::new(2).unwrap()),
135+
hinting: true,
134136
}
135137
}
136138
}
@@ -243,6 +245,9 @@ impl FontLibraryData {
243245

244246
#[cfg(not(target_arch = "wasm32"))]
245247
pub fn load(&mut self, mut spec: SugarloafFonts) -> Vec<SugarloafFont> {
248+
// Configure hinting through spec
249+
self.hinting = spec.hinting;
250+
246251
let mut fonts_not_fount: Vec<SugarloafFont> = vec![];
247252

248253
// If fonts.family does exist it will overwrite all families

0 commit comments

Comments
 (0)