diff options
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/shaping.rs | 57 | ||||
| -rw-r--r-- | src/layout/text.rs | 7 |
2 files changed, 34 insertions, 30 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)); } } diff --git a/src/layout/text.rs b/src/layout/text.rs index 7f8f97cc..2239afac 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -1,9 +1,10 @@ use std::fmt::{self, Debug, Formatter}; use std::rc::Rc; -use fontdock::{FallbackTree, FontVariant}; +use fontdock::FontVariant; use super::*; +use crate::exec::FamilyMap; /// A consecutive, styled run of text. #[derive(Clone, PartialEq)] @@ -14,8 +15,8 @@ pub struct TextNode { pub dir: Dir, /// How to align this text node in its parent. pub aligns: LayoutAligns, - /// The families used for font fallback. - pub families: Rc<FallbackTree>, + /// The list of font families for shaping. + pub families: Rc<FamilyMap>, /// The font variant, pub variant: FontVariant, /// The font size. |
