1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
use std::fmt::{self, Debug, Formatter};
use std::rc::Rc;
use fontdock::{FallbackTree, FontVariant};
use super::*;
use crate::shaping;
/// A text node.
#[derive(Clone, PartialEq)]
pub struct Text {
/// The text.
pub text: String,
/// How to align this text node in its parent.
pub align: BoxAlign,
/// The text direction.
pub dir: Dir,
/// The font size.
pub font_size: Length,
/// The families used for font fallback.
pub families: Rc<FallbackTree>,
/// The font variant,
pub variant: FontVariant,
}
impl Layout for Text {
fn layout(&self, ctx: &mut LayoutContext, _: &Areas) -> Layouted {
let mut env = ctx.env.borrow_mut();
Layouted::Layout(
shaping::shape(
&mut env.fonts,
&self.text,
self.dir,
self.font_size,
&self.families,
self.variant,
),
self.align,
)
}
}
impl Debug for Text {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "Text({})", self.text)
}
}
impl From<Text> for LayoutNode {
fn from(text: Text) -> Self {
Self::Text(text)
}
}
|