summaryrefslogtreecommitdiff
path: root/src/layout/shaping.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-22 14:08:50 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-22 14:08:50 +0100
commit98336bfafb947f0b4d55a79c422b915bb417c185 (patch)
treebf0ead89a3d7eed3d8bb87d013c2a813633c75e4 /src/layout/shaping.rs
parent39f55481ed7bc5ebc6d310924e90e7b6c0760d3b (diff)
Better font family definitions ✒
Diffstat (limited to 'src/layout/shaping.rs')
-rw-r--r--src/layout/shaping.rs57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs
index df27e287..fd10b41e 100644
--- a/src/layout/shaping.rs
+++ b/src/layout/shaping.rs
@@ -6,10 +6,11 @@
use std::fmt::{self, Debug, Display, Formatter};
-use fontdock::{FaceId, FaceQuery, FallbackTree, FontVariant};
+use fontdock::{FaceId, FontVariant};
use ttf_parser::{Face, GlyphId};
use crate::env::FontLoader;
+use crate::exec::FamilyMap;
use crate::geom::{Dir, Length, Point, Size};
use crate::layout::{Element, Fill, Frame};
@@ -40,7 +41,7 @@ impl Shaped {
glyphs: vec![],
offsets: vec![],
font_size,
- color: color,
+ color,
}
}
@@ -98,7 +99,7 @@ impl Display for VerticalFontMetric {
pub fn shape(
text: &str,
dir: Dir,
- fallback: &FallbackTree,
+ families: &FamilyMap,
variant: FontVariant,
font_size: Length,
top_edge: VerticalFontMetric,
@@ -122,31 +123,33 @@ pub fn shape(
};
for c in chars {
- let query = FaceQuery { fallback: fallback.iter(), variant, c };
- if let Some(id) = loader.query(query) {
- let face = loader.face(id).get();
- let (glyph, glyph_width) = match lookup_glyph(face, c) {
- Some(v) => v,
- None => continue,
- };
-
- let units_per_em = f64::from(face.units_per_em().unwrap_or(1000));
- let convert = |units| units / units_per_em * font_size;
-
- // Flush the buffer and reset the metrics if we use a new font face.
- if shaped.face != id {
- place(&mut frame, shaped, width, top, bottom);
-
- shaped = Shaped::new(id, font_size, color);
- width = Length::ZERO;
- top = convert(f64::from(lookup_metric(face, top_edge)));
- bottom = convert(f64::from(lookup_metric(face, bottom_edge)));
+ for family in families.iter() {
+ if let Some(id) = loader.query(family, variant) {
+ let face = loader.face(id).get();
+ let (glyph, glyph_width) = match lookup_glyph(face, c) {
+ Some(v) => v,
+ None => continue,
+ };
+
+ let units_per_em = f64::from(face.units_per_em().unwrap_or(1000));
+ let convert = |units| units / units_per_em * font_size;
+
+ // Flush the buffer and reset the metrics if we use a new font face.
+ if shaped.face != id {
+ place(&mut frame, shaped, width, top, bottom);
+
+ shaped = Shaped::new(id, font_size, color);
+ width = Length::ZERO;
+ top = convert(f64::from(lookup_metric(face, top_edge)));
+ bottom = convert(f64::from(lookup_metric(face, bottom_edge)));
+ }
+
+ shaped.text.push(c);
+ shaped.glyphs.push(glyph);
+ shaped.offsets.push(width);
+ width += convert(f64::from(glyph_width));
+ break;
}
-
- shaped.text.push(c);
- shaped.glyphs.push(glyph);
- shaped.offsets.push(width);
- width += convert(f64::from(glyph_width));
}
}