Skip to content

Commit d85095c

Browse files
committed
Fix font rendering for bold i
Fixes #1359 Maybe Fixes #1110
1 parent ab26ffd commit d85095c

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

frontends/rioterm/src/renderer/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,13 @@ impl Renderer {
152152
square.c
153153
};
154154

155-
let font_attrs = match (
156-
flags.contains(Flags::ITALIC),
157-
flags.contains(Flags::BOLD_ITALIC),
158-
flags.contains(Flags::BOLD),
159-
) {
160-
(true, _, _) => (Stretch::NORMAL, Weight::NORMAL, Style::Italic),
161-
(_, true, _) => (Stretch::NORMAL, Weight::BOLD, Style::Italic),
162-
(_, _, true) => (Stretch::NORMAL, Weight::BOLD, Style::Normal),
163-
_ => (Stretch::NORMAL, Weight::NORMAL, Style::Normal),
164-
};
155+
let font_attrs =
156+
match (flags.contains(Flags::BOLD), flags.contains(Flags::ITALIC)) {
157+
(true, true) => (Stretch::NORMAL, Weight::BOLD, Style::Italic),
158+
(true, false) => (Stretch::NORMAL, Weight::BOLD, Style::Normal),
159+
(false, true) => (Stretch::NORMAL, Weight::NORMAL, Style::Italic),
160+
_ => (Stretch::NORMAL, Weight::NORMAL, Style::Normal),
161+
};
165162

166163
if flags.contains(Flags::INVERSE) {
167164
std::mem::swap(&mut background_color, &mut foreground_color);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl GlyphCacheSession<'_> {
135135
let font_data = font_library_data.get(&self.font);
136136
let should_embolden = font_data.should_embolden;
137137
let should_italicize = font_data.should_italicize;
138+
let synth = font_data.synth;
138139

139140
if let Some((shared_data, offset, cache_key)) =
140141
font_library_data.get_data(&self.font)
@@ -144,6 +145,12 @@ impl GlyphCacheSession<'_> {
144145
offset,
145146
key: cache_key,
146147
};
148+
149+
let coords: Vec<_> = font_ref
150+
.variations()
151+
.normalized_coords(synth.variations().iter().copied())
152+
.collect();
153+
147154
let mut scaler = self
148155
.scale_context
149156
.builder(font_ref)
@@ -155,7 +162,7 @@ impl GlyphCacheSession<'_> {
155162
// .hint(!IS_MACOS)
156163
.hint(enable_hint)
157164
.size(self.quant_size.into())
158-
// .normalized_coords(coords)
165+
.normalized_coords(&coords)
159166
.build();
160167

161168
// let embolden = if IS_MACOS { 0.25 } else { 0. };

sugarloaf/src/font/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::font_introspector::text::cluster::Token;
1919
use crate::font_introspector::text::cluster::{CharCluster, Status};
2020
use crate::font_introspector::text::Codepoint;
2121
use crate::font_introspector::text::Script;
22-
use crate::font_introspector::{CacheKey, FontRef, Synthesis};
22+
use crate::font_introspector::{Attributes, CacheKey, FontRef, Synthesis};
2323
use crate::layout::FragmentStyle;
2424
use crate::SugarloafErrors;
2525
use dashmap::DashMap;
@@ -672,7 +672,14 @@ impl FontData {
672672
let should_embolden = font_spec.weight >= Some(700) && weight < Weight(700);
673673

674674
let stretch = attributes.stretch();
675-
let synth = attributes.synthesize(attributes);
675+
676+
let requested_weight = font_spec.weight.map(Weight).unwrap_or(Weight::NORMAL);
677+
let requested_style = match font_spec.style {
678+
SugarloafFontStyle::Italic => Style::Italic,
679+
SugarloafFontStyle::Normal => Style::Normal,
680+
};
681+
let requested_attrs = Attributes::new(stretch, requested_weight, requested_style);
682+
let synth = attributes.synthesize(requested_attrs);
676683

677684
let data = (!evictable).then_some(data);
678685

0 commit comments

Comments
 (0)