summaryrefslogtreecommitdiff
path: root/src/shaping.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-04 19:06:20 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-04 19:06:20 +0200
commit0f7c70fd93db23ec866ae13aa2f146b7787afabf (patch)
tree7a67019fa77931e1722789cfd27997dd82a9b521 /src/shaping.rs
parent6672f8f7dfcb38bbda3ec92bdf95341c05e9a782 (diff)
Separate state and constraints 🧶
Diffstat (limited to 'src/shaping.rs')
-rw-r--r--src/shaping.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/shaping.rs b/src/shaping.rs
index d9e6e9fd..092f5e6e 100644
--- a/src/shaping.rs
+++ b/src/shaping.rs
@@ -7,20 +7,20 @@
use fontdock::{FaceId, FaceQuery, FallbackTree, FontStyle, FontVariant};
use ttf_parser::GlyphId;
+use crate::eval::TextState;
use crate::font::FontLoader;
use crate::geom::{Point, Size};
use crate::layout::{BoxLayout, Dir, LayoutAlign, LayoutElement, LayoutElements, Shaped};
-use crate::style::TextStyle;
/// Shape text into a box.
pub async fn shape(
text: &str,
dir: Dir,
align: LayoutAlign,
- style: &TextStyle,
+ state: &TextState,
loader: &mut FontLoader,
) -> BoxLayout {
- Shaper::new(text, dir, align, style, loader).shape().await
+ Shaper::new(text, dir, align, state, loader).shape().await
}
/// Performs super-basic text shaping.
@@ -40,16 +40,16 @@ impl<'a> Shaper<'a> {
text: &'a str,
dir: Dir,
align: LayoutAlign,
- style: &'a TextStyle,
+ state: &'a TextState,
loader: &'a mut FontLoader,
) -> Self {
- let mut variant = style.variant;
+ let mut variant = state.variant;
- if style.strong {
+ if state.strong {
variant.weight = variant.weight.thicken(300);
}
- if style.emph {
+ if state.emph {
variant.style = match variant.style {
FontStyle::Normal => FontStyle::Italic,
FontStyle::Italic => FontStyle::Normal,
@@ -61,11 +61,11 @@ impl<'a> Shaper<'a> {
text,
dir,
variant,
- fallback: &style.fallback,
+ fallback: &state.fallback,
loader,
- shaped: Shaped::new(FaceId::MAX, style.font_size()),
+ shaped: Shaped::new(FaceId::MAX, state.font_size()),
layout: BoxLayout {
- size: Size::new(0.0, style.font_size()),
+ size: Size::new(0.0, state.font_size()),
align,
elements: LayoutElements::new(),
},