summaryrefslogtreecommitdiff
path: root/src/layout/text.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-24 17:12:34 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-24 17:12:34 +0100
commit73615f7e3ce23f2ea656d04ea9f96184f5ebdc0a (patch)
tree7691b792e1e4b33469a72c40fc76854f1de0814e /src/layout/text.rs
parent6720520ec06dd0718f81049b2b11e81664f7ef62 (diff)
Text shaping 🚀
- Shapes text with rustybuzz - Font fallback with family list - Tofus are shown in the first font Co-Authored-By: Martin <mhaug@live.de>
Diffstat (limited to 'src/layout/text.rs')
-rw-r--r--src/layout/text.rs39
1 files changed, 7 insertions, 32 deletions
diff --git a/src/layout/text.rs b/src/layout/text.rs
index 2239afac..39866907 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -1,50 +1,25 @@
use std::fmt::{self, Debug, Formatter};
-use std::rc::Rc;
-
-use fontdock::FontVariant;
use super::*;
-use crate::exec::FamilyMap;
+use crate::exec::FontProps;
/// A consecutive, styled run of text.
#[derive(Clone, PartialEq)]
pub struct TextNode {
- /// The text.
- pub text: String,
/// The text direction.
pub dir: Dir,
/// How to align this text node in its parent.
pub aligns: LayoutAligns,
- /// The list of font families for shaping.
- pub families: Rc<FamilyMap>,
- /// The font variant,
- pub variant: FontVariant,
- /// The font size.
- pub font_size: Length,
- /// The top end of the text bounding box.
- pub top_edge: VerticalFontMetric,
- /// The bottom end of the text bounding box.
- pub bottom_edge: VerticalFontMetric,
- /// The glyph fill.
- pub color: Fill,
+ /// The text.
+ pub text: String,
+ /// Properties used for font selection and layout.
+ pub props: FontProps,
}
impl Layout for TextNode {
fn layout(&self, ctx: &mut LayoutContext, _: &Areas) -> Fragment {
- Fragment::Frame(
- shape(
- &self.text,
- self.dir,
- &self.families,
- self.variant,
- self.font_size,
- self.top_edge,
- self.bottom_edge,
- self.color,
- &mut ctx.env.fonts,
- ),
- self.aligns,
- )
+ let frame = shape(&self.text, &mut ctx.env.fonts, &self.props);
+ Fragment::Frame(frame, self.aligns)
}
}