summaryrefslogtreecommitdiff
path: root/src/layout/tree.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-05 13:39:33 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-05 13:39:33 +0200
commitd1c07260c0b67098a1b778262c76e6f31c5a5240 (patch)
tree6b78bd83ec83c85fab1e3bf289d52c8de456eca3 /src/layout/tree.rs
parent335fa2d118718b4dba539294a8ef6c96c5bbf09e (diff)
Move align out of BoxLayout 🍫
Diffstat (limited to 'src/layout/tree.rs')
-rw-r--r--src/layout/tree.rs42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index 4e15fb12..fde7833e 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -1,5 +1,7 @@
//! Layouting of syntax trees.
+use fontdock::FontStyle;
+
use super::*;
use crate::eval::Eval;
use crate::shaping;
@@ -25,7 +27,6 @@ impl<'a> TreeLayouter<'a> {
let layouter = LineLayouter::new(LineContext {
spaces: ctx.constraints.spaces.clone(),
sys: ctx.state.sys,
- align: ctx.state.align,
repeat: ctx.constraints.repeat,
line_spacing: ctx.state.text.line_spacing(),
});
@@ -99,16 +100,31 @@ impl<'a> TreeLayouter<'a> {
}
async fn layout_text(&mut self, text: &str) {
- self.layouter.add(
- shaping::shape(
- text,
- self.ctx.state.sys.primary,
- self.ctx.state.align,
- &self.ctx.state.text,
- &mut self.ctx.loader.borrow_mut(),
- )
- .await,
- );
+ let mut variant = self.ctx.state.text.variant;
+
+ if self.ctx.state.text.strong {
+ variant.weight = variant.weight.thicken(300);
+ }
+
+ if self.ctx.state.text.emph {
+ variant.style = match variant.style {
+ FontStyle::Normal => FontStyle::Italic,
+ FontStyle::Italic => FontStyle::Normal,
+ FontStyle::Oblique => FontStyle::Normal,
+ }
+ }
+
+ let boxed = shaping::shape(
+ text,
+ self.ctx.state.sys.primary,
+ self.ctx.state.text.font_size(),
+ variant,
+ &self.ctx.state.text.fallback,
+ &mut self.ctx.loader.borrow_mut(),
+ )
+ .await;
+
+ self.layouter.add(boxed, self.ctx.state.align);
}
async fn layout_heading(&mut self, heading: &NodeHeading) {
@@ -160,9 +176,7 @@ impl<'a> TreeLayouter<'a> {
};
let val = expr.v.eval(self.ctx).await;
-
let commands = val.span_with(expr.span).into_commands();
-
for command in commands {
self.execute_command(command, expr.span).await;
}
@@ -173,7 +187,7 @@ impl<'a> TreeLayouter<'a> {
match command {
LayoutSyntaxTree(tree) => self.layout_tree(&tree).await,
- Add(layout) => self.layouter.add(layout),
+ Add(layout, align) => self.layouter.add(layout, align),
AddSpacing(space, kind, axis) => match axis {
GenAxis::Primary => self.layouter.add_primary_spacing(space, kind),
GenAxis::Secondary => self.layouter.add_secondary_spacing(space, kind),