diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-24 00:39:43 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-24 00:41:15 +0200 |
| commit | 148a06c070e6376e6f86b878d08dfd4f0aef8a73 (patch) | |
| tree | 7330ecae5fa3dbb79c3bb3ce6a099205ec92d2c9 /src/library/text.rs | |
| parent | d546453880721d7a12ea228e5c1ed6c65b653ca2 (diff) | |
Switch from state to decorations for underline/strikethrough/overline
Diffstat (limited to 'src/library/text.rs')
| -rw-r--r-- | src/library/text.rs | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/library/text.rs b/src/library/text.rs index cfd2de99..f3e086c8 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -1,5 +1,4 @@ -use crate::eval::{Decoration, FontState, LineState}; -use crate::layout::Paint; +use crate::layout::{Decoration, LineDecoration, LineKind, Paint}; use super::*; @@ -155,47 +154,39 @@ fn lang_dir(iso: &str) -> Dir { /// `strike`: Set striken-through text. pub fn strike(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult<Value> { - line_impl(ctx, args, |font| &mut font.strikethrough) + line_impl(ctx, args, LineKind::Strikethrough) } /// `underline`: Set underlined text. pub fn underline(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult<Value> { - line_impl(ctx, args, |font| &mut font.underline) + line_impl(ctx, args, LineKind::Underline) } /// `overline`: Set text with an overline. pub fn overline(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult<Value> { - line_impl(ctx, args, |font| &mut font.overline) + line_impl(ctx, args, LineKind::Overline) } fn line_impl( _: &mut EvalContext, args: &mut Arguments, - substate: fn(&mut FontState) -> &mut Option<Rc<LineState>>, + kind: LineKind, ) -> TypResult<Value> { let stroke = args.named("stroke")?.or_else(|| args.eat()); let thickness = args.named::<Linear>("thickness")?.or_else(|| args.eat()); let offset = args.named("offset")?; let extent = args.named("extent")?.unwrap_or_default(); - let body = args.expect("body")?; - - // Suppress any existing strikethrough if strength is explicitly zero. - let line = thickness.map_or(true, |s| !s.is_zero()).then(|| { - Rc::new(LineState { - stroke: stroke.map(Paint::Color), - thickness, - offset, - extent, - }) - }); - let mut template = Template::new(); - template.save(); - template.modify(move |state| *substate(state.font_mut()) = line.clone()); - template += body; - template.restore(); + let mut body: Template = args.expect("body")?; + body.decorate(Decoration::Line(LineDecoration { + kind, + stroke: stroke.map(Paint::Color), + thickness, + offset, + extent, + })); - Ok(Value::Template(template)) + Ok(Value::Template(body)) } /// `link`: Set a link. |
