diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-04 12:49:46 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-04 13:21:31 +0200 |
| commit | ba5622b7b90b23e61942a9f4e6460bf9ea0b4bc8 (patch) | |
| tree | 374c326c7375094f370165e47dbe24dd01f16c11 /src/library/text | |
| parent | 507c5fc92563560426db0d86c0348880b0493467 (diff) | |
Move smallcaps into separate function
Diffstat (limited to 'src/library/text')
| -rw-r--r-- | src/library/text/mod.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index df00d87a..09c7fa17 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -84,8 +84,6 @@ impl TextNode { /// Whether to apply kerning ("kern"). pub const KERNING: bool = true; - /// Whether small capital glyphs should be used. ("smcp") - pub const SMALLCAPS: bool = false; /// Whether to apply stylistic alternates. ("salt") pub const ALTERNATES: bool = false; /// Which stylistic set to apply. ("ss01" - "ss20") @@ -119,6 +117,9 @@ impl TextNode { /// A case transformation that should be applied to the text. #[property(hidden)] pub const CASE: Option<Case> = None; + /// Whether small capital glyphs should be used. ("smcp") + #[property(hidden)] + pub const SMALLCAPS: bool = false; /// An URL the text should link to. #[property(hidden, referenced)] pub const LINK: Option<EcoString> = None; @@ -411,6 +412,26 @@ impl Fold for Vec<(Tag, u32)> { } } +/// Convert text to lowercase. +pub fn lower(_: &mut Context, args: &mut Args) -> TypResult<Value> { + case(Case::Lower, args) +} + +/// Convert text to uppercase. +pub fn upper(_: &mut Context, args: &mut Args) -> TypResult<Value> { + case(Case::Upper, args) +} + +/// Change the case of text. +fn case(case: Case, args: &mut Args) -> TypResult<Value> { + let Spanned { v, span } = args.expect("string or content")?; + Ok(match v { + Value::Str(v) => Value::Str(case.apply(&v).into()), + Value::Content(v) => Value::Content(v.styled(TextNode::CASE, Some(case))), + v => bail!(span, "expected string or content, found {}", v.type_name()), + }) +} + /// A case transformation on text. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Case { @@ -430,6 +451,12 @@ impl Case { } } +/// Display text in small capitals. +pub fn smallcaps(_: &mut Context, args: &mut Args) -> TypResult<Value> { + let body: Content = args.expect("content")?; + Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true))) +} + /// A toggle that turns on and off alternatingly if folded. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct Toggle; |
