diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-07-08 10:52:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-08 08:52:43 +0000 |
| commit | 0a3c6939dd274f40672484695d909c2cc0d0d755 (patch) | |
| tree | 465c10338230b895fdd06c8b3491f1734e8a2932 /crates/typst-library/src/text | |
| parent | 36ecbb2c8dccc1a31c43fee1466f1425844d8607 (diff) | |
Rewrite foundations of native elements (#6547)
Diffstat (limited to 'crates/typst-library/src/text')
| -rw-r--r-- | crates/typst-library/src/text/case.rs | 4 | ||||
| -rw-r--r-- | crates/typst-library/src/text/deco.rs | 113 | ||||
| -rw-r--r-- | crates/typst-library/src/text/lang.rs | 2 | ||||
| -rw-r--r-- | crates/typst-library/src/text/mod.rs | 59 | ||||
| -rw-r--r-- | crates/typst-library/src/text/raw.rs | 44 | ||||
| -rw-r--r-- | crates/typst-library/src/text/shift.rs | 33 | ||||
| -rw-r--r-- | crates/typst-library/src/text/smallcaps.rs | 5 | ||||
| -rw-r--r-- | crates/typst-library/src/text/smartquote.rs | 3 |
8 files changed, 128 insertions, 135 deletions
diff --git a/crates/typst-library/src/text/case.rs b/crates/typst-library/src/text/case.rs index 69dbf5e1..3b2ae450 100644 --- a/crates/typst-library/src/text/case.rs +++ b/crates/typst-library/src/text/case.rs @@ -37,9 +37,7 @@ pub fn upper( fn case(text: Caseable, case: Case) -> Caseable { match text { Caseable::Str(v) => Caseable::Str(case.apply(&v).into()), - Caseable::Content(v) => { - Caseable::Content(v.styled(TextElem::set_case(Some(case)))) - } + Caseable::Content(v) => Caseable::Content(v.set(TextElem::case, Some(case))), } } diff --git a/crates/typst-library/src/text/deco.rs b/crates/typst-library/src/text/deco.rs index d745a48f..8c1d5634 100644 --- a/crates/typst-library/src/text/deco.rs +++ b/crates/typst-library/src/text/deco.rs @@ -30,7 +30,6 @@ pub struct UnderlineElem { /// [care], /// ) /// ``` - #[resolve] #[fold] pub stroke: Smart<Stroke>, @@ -42,7 +41,6 @@ pub struct UnderlineElem { /// The Tale Of A Faraway Line I /// ] /// ``` - #[resolve] pub offset: Smart<Length>, /// The amount by which to extend the line beyond (or within if negative) @@ -53,7 +51,6 @@ pub struct UnderlineElem { /// underline(extent: 2pt)[Chapter 1] /// ) /// ``` - #[resolve] pub extent: Length, /// Whether the line skips sections in which it would collide with the @@ -84,7 +81,7 @@ pub struct UnderlineElem { impl Show for Packed<UnderlineElem> { #[typst_macros::time(name = "underline", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - if TargetElem::target_in(styles).is_html() { + if styles.get(TargetElem::target).is_html() { // Note: In modern HTML, `<u>` is not the underline element, but // rather an "Unarticulated Annotation" element (see HTML spec // 4.5.22). Using `text-decoration` instead is recommended by MDN. @@ -94,15 +91,18 @@ impl Show for Packed<UnderlineElem> { .pack()); } - Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration { - line: DecoLine::Underline { - stroke: self.stroke(styles).unwrap_or_default(), - offset: self.offset(styles), - evade: self.evade(styles), - background: self.background(styles), - }, - extent: self.extent(styles), - }]))) + Ok(self.body.clone().set( + TextElem::deco, + smallvec![Decoration { + line: DecoLine::Underline { + stroke: self.stroke.resolve(styles).unwrap_or_default(), + offset: self.offset.resolve(styles), + evade: self.evade.get(styles), + background: self.background.get(styles), + }, + extent: self.extent.resolve(styles), + }], + )) } } @@ -127,7 +127,6 @@ pub struct OverlineElem { /// [The Forest Theme], /// ) /// ``` - #[resolve] #[fold] pub stroke: Smart<Stroke>, @@ -139,7 +138,6 @@ pub struct OverlineElem { /// The Tale Of A Faraway Line II /// ] /// ``` - #[resolve] pub offset: Smart<Length>, /// The amount by which to extend the line beyond (or within if negative) @@ -150,7 +148,6 @@ pub struct OverlineElem { /// #set underline(extent: 4pt) /// #overline(underline[Typography Today]) /// ``` - #[resolve] pub extent: Length, /// Whether the line skips sections in which it would collide with the @@ -186,22 +183,25 @@ pub struct OverlineElem { impl Show for Packed<OverlineElem> { #[typst_macros::time(name = "overline", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - if TargetElem::target_in(styles).is_html() { + if styles.get(TargetElem::target).is_html() { return Ok(HtmlElem::new(tag::span) .with_attr(attr::style, "text-decoration: overline") .with_body(Some(self.body.clone())) .pack()); } - Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration { - line: DecoLine::Overline { - stroke: self.stroke(styles).unwrap_or_default(), - offset: self.offset(styles), - evade: self.evade(styles), - background: self.background(styles), - }, - extent: self.extent(styles), - }]))) + Ok(self.body.clone().set( + TextElem::deco, + smallvec![Decoration { + line: DecoLine::Overline { + stroke: self.stroke.resolve(styles).unwrap_or_default(), + offset: self.offset.resolve(styles), + evade: self.evade.get(styles), + background: self.background.get(styles), + }, + extent: self.extent.resolve(styles), + }], + )) } } @@ -225,7 +225,6 @@ pub struct StrikeElem { /// This is #strike(stroke: 1.5pt + red)[very stricken through]. \ /// This is #strike(stroke: 10pt)[redacted]. /// ``` - #[resolve] #[fold] pub stroke: Smart<Stroke>, @@ -239,7 +238,6 @@ pub struct StrikeElem { /// This is #strike(offset: auto)[low-ish]. \ /// This is #strike(offset: -3.5pt)[on-top]. /// ``` - #[resolve] pub offset: Smart<Length>, /// The amount by which to extend the line beyond (or within if negative) @@ -249,7 +247,6 @@ pub struct StrikeElem { /// This #strike(extent: -2pt)[skips] parts of the word. /// This #strike(extent: 2pt)[extends] beyond the word. /// ``` - #[resolve] pub extent: Length, /// Whether the line is placed behind the content. @@ -270,19 +267,22 @@ pub struct StrikeElem { impl Show for Packed<StrikeElem> { #[typst_macros::time(name = "strike", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - if TargetElem::target_in(styles).is_html() { + if styles.get(TargetElem::target).is_html() { return Ok(HtmlElem::new(tag::s).with_body(Some(self.body.clone())).pack()); } - Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration { - // Note that we do not support evade option for strikethrough. - line: DecoLine::Strikethrough { - stroke: self.stroke(styles).unwrap_or_default(), - offset: self.offset(styles), - background: self.background(styles), - }, - extent: self.extent(styles), - }]))) + Ok(self.body.clone().set( + TextElem::deco, + smallvec![Decoration { + // Note that we do not support evade option for strikethrough. + line: DecoLine::Strikethrough { + stroke: self.stroke.resolve(styles).unwrap_or_default(), + offset: self.offset.resolve(styles), + background: self.background.get(styles), + }, + extent: self.extent.resolve(styles), + }], + )) } } @@ -312,7 +312,6 @@ pub struct HighlightElem { /// stroke: fuchsia /// )[stroked highlighting]. /// ``` - #[resolve] #[fold] pub stroke: Sides<Option<Option<Stroke>>>, @@ -346,7 +345,6 @@ pub struct HighlightElem { /// ```example /// A long #highlight(extent: 4pt)[background]. /// ``` - #[resolve] pub extent: Length, /// How much to round the highlight's corners. See the @@ -357,7 +355,6 @@ pub struct HighlightElem { /// radius: 5pt, extent: 2pt /// )[carefully], it will be on the test. /// ``` - #[resolve] #[fold] pub radius: Corners<Option<Rel<Length>>>, @@ -369,25 +366,29 @@ pub struct HighlightElem { impl Show for Packed<HighlightElem> { #[typst_macros::time(name = "highlight", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - if TargetElem::target_in(styles).is_html() { + if styles.get(TargetElem::target).is_html() { return Ok(HtmlElem::new(tag::mark) .with_body(Some(self.body.clone())) .pack()); } - Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration { - line: DecoLine::Highlight { - fill: self.fill(styles), - stroke: self - .stroke(styles) - .unwrap_or_default() - .map(|stroke| stroke.map(Stroke::unwrap_or_default)), - top_edge: self.top_edge(styles), - bottom_edge: self.bottom_edge(styles), - radius: self.radius(styles).unwrap_or_default(), - }, - extent: self.extent(styles), - }]))) + Ok(self.body.clone().set( + TextElem::deco, + smallvec![Decoration { + line: DecoLine::Highlight { + fill: self.fill.get_cloned(styles), + stroke: self + .stroke + .resolve(styles) + .unwrap_or_default() + .map(|stroke| stroke.map(Stroke::unwrap_or_default)), + top_edge: self.top_edge.get(styles), + bottom_edge: self.bottom_edge.get(styles), + radius: self.radius.resolve(styles).unwrap_or_default(), + }, + extent: self.extent.resolve(styles), + }], + )) } } diff --git a/crates/typst-library/src/text/lang.rs b/crates/typst-library/src/text/lang.rs index a170714b..530b1f00 100644 --- a/crates/typst-library/src/text/lang.rs +++ b/crates/typst-library/src/text/lang.rs @@ -250,7 +250,7 @@ pub trait LocalName { where Self: Sized, { - Self::local_name(TextElem::lang_in(styles), TextElem::region_in(styles)) + Self::local_name(styles.get(TextElem::lang), styles.get(TextElem::region)) } } diff --git a/crates/typst-library/src/text/mod.rs b/crates/typst-library/src/text/mod.rs index 230f8e50..51663633 100644 --- a/crates/typst-library/src/text/mod.rs +++ b/crates/typst-library/src/text/mod.rs @@ -165,7 +165,6 @@ pub struct TextElem { font_list.map(|font_list| font_list.v) })] #[default(FontList(vec![FontFamily::new("Libertinus Serif")]))] - #[borrowed] #[ghost] pub font: FontList, @@ -260,7 +259,6 @@ pub struct TextElem { #[parse(args.named_or_find("size")?)] #[fold] #[default(TextSize(Abs::pt(11.0).into()))] - #[resolve] #[ghost] pub size: TextSize, @@ -292,7 +290,6 @@ pub struct TextElem { /// ```example /// #text(stroke: 0.5pt + red)[Stroked] /// ``` - #[resolve] #[ghost] pub stroke: Option<Stroke>, @@ -302,7 +299,6 @@ pub struct TextElem { /// #set text(tracking: 1.5pt) /// Distant text. /// ``` - #[resolve] #[ghost] pub tracking: Length, @@ -318,7 +314,6 @@ pub struct TextElem { /// #set text(spacing: 200%) /// Text with distant words. /// ``` - #[resolve] #[default(Rel::one())] #[ghost] pub spacing: Rel<Length>, @@ -341,7 +336,6 @@ pub struct TextElem { /// A #text(baseline: 3pt)[lowered] /// word. /// ``` - #[resolve] #[ghost] pub baseline: Length, @@ -483,7 +477,6 @@ pub struct TextElem { /// #set text(dir: rtl) /// هذا عربي. /// ``` - #[resolve] #[ghost] pub dir: TextDir, @@ -950,24 +943,24 @@ pub fn families(styles: StyleChain<'_>) -> impl Iterator<Item = &'_ FontFamily> .collect() }); - let tail = if TextElem::fallback_in(styles) { fallbacks.as_slice() } else { &[] }; - TextElem::font_in(styles).into_iter().chain(tail.iter()) + let tail = if styles.get(TextElem::fallback) { fallbacks.as_slice() } else { &[] }; + styles.get_ref(TextElem::font).into_iter().chain(tail.iter()) } /// Resolve the font variant. pub fn variant(styles: StyleChain) -> FontVariant { let mut variant = FontVariant::new( - TextElem::style_in(styles), - TextElem::weight_in(styles), - TextElem::stretch_in(styles), + styles.get(TextElem::style), + styles.get(TextElem::weight), + styles.get(TextElem::stretch), ); - let WeightDelta(delta) = TextElem::delta_in(styles); + let WeightDelta(delta) = styles.get(TextElem::delta); variant.weight = variant .weight .thicken(delta.clamp(i16::MIN as i64, i16::MAX as i64) as i16); - if TextElem::emph_in(styles).0 { + if styles.get(TextElem::emph).0 { variant.style = match variant.style { FontStyle::Normal => FontStyle::Italic, FontStyle::Italic => FontStyle::Normal, @@ -996,11 +989,11 @@ impl Resolve for TextSize { type Output = Abs; fn resolve(self, styles: StyleChain) -> Self::Output { - let factor = match EquationElem::size_in(styles) { + let factor = match styles.get(EquationElem::size) { MathSize::Display | MathSize::Text => 1.0, - MathSize::Script => EquationElem::script_scale_in(styles).0 as f64 / 100.0, + MathSize::Script => styles.get(EquationElem::script_scale).0 as f64 / 100.0, MathSize::ScriptScript => { - EquationElem::script_scale_in(styles).1 as f64 / 100.0 + styles.get(EquationElem::script_scale).1 as f64 / 100.0 } }; factor * self.0.resolve(styles) @@ -1123,7 +1116,7 @@ impl Resolve for TextDir { fn resolve(self, styles: StyleChain) -> Self::Output { match self.0 { - Smart::Auto => TextElem::lang_in(styles).dir(), + Smart::Auto => styles.get(TextElem::lang).dir(), Smart::Custom(dir) => dir, } } @@ -1236,67 +1229,67 @@ pub fn features(styles: StyleChain) -> Vec<Feature> { }; // Features that are on by default in Harfbuzz are only added if disabled. - if !TextElem::kerning_in(styles) { + if !styles.get(TextElem::kerning) { feat(b"kern", 0); } // Features that are off by default in Harfbuzz are only added if enabled. - if let Some(sc) = TextElem::smallcaps_in(styles) { + if let Some(sc) = styles.get(TextElem::smallcaps) { feat(b"smcp", 1); if sc == Smallcaps::All { feat(b"c2sc", 1); } } - if TextElem::alternates_in(styles) { + if styles.get(TextElem::alternates) { feat(b"salt", 1); } - for set in TextElem::stylistic_set_in(styles).sets() { + for set in styles.get(TextElem::stylistic_set).sets() { let storage = [b's', b's', b'0' + set / 10, b'0' + set % 10]; feat(&storage, 1); } - if !TextElem::ligatures_in(styles) { + if !styles.get(TextElem::ligatures) { feat(b"liga", 0); feat(b"clig", 0); } - if TextElem::discretionary_ligatures_in(styles) { + if styles.get(TextElem::discretionary_ligatures) { feat(b"dlig", 1); } - if TextElem::historical_ligatures_in(styles) { + if styles.get(TextElem::historical_ligatures) { feat(b"hlig", 1); } - match TextElem::number_type_in(styles) { + match styles.get(TextElem::number_type) { Smart::Auto => {} Smart::Custom(NumberType::Lining) => feat(b"lnum", 1), Smart::Custom(NumberType::OldStyle) => feat(b"onum", 1), } - match TextElem::number_width_in(styles) { + match styles.get(TextElem::number_width) { Smart::Auto => {} Smart::Custom(NumberWidth::Proportional) => feat(b"pnum", 1), Smart::Custom(NumberWidth::Tabular) => feat(b"tnum", 1), } - if TextElem::slashed_zero_in(styles) { + if styles.get(TextElem::slashed_zero) { feat(b"zero", 1); } - if TextElem::fractions_in(styles) { + if styles.get(TextElem::fractions) { feat(b"frac", 1); } - match EquationElem::size_in(styles) { + match styles.get(EquationElem::size) { MathSize::Script => feat(b"ssty", 1), MathSize::ScriptScript => feat(b"ssty", 2), _ => {} } - for (tag, value) in TextElem::features_in(styles).0 { + for (tag, value) in styles.get_cloned(TextElem::features).0 { tags.push(Feature::new(tag, value, ..)) } @@ -1306,8 +1299,8 @@ pub fn features(styles: StyleChain) -> Vec<Feature> { /// Process the language and region of a style chain into a /// rustybuzz-compatible BCP 47 language. pub fn language(styles: StyleChain) -> rustybuzz::Language { - let mut bcp: EcoString = TextElem::lang_in(styles).as_str().into(); - if let Some(region) = TextElem::region_in(styles) { + let mut bcp: EcoString = styles.get(TextElem::lang).as_str().into(); + if let Some(region) = styles.get(TextElem::region) { bcp.push('-'); bcp.push_str(region.as_str()); } diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs index e1f4cf13..67038163 100644 --- a/crates/typst-library/src/text/raw.rs +++ b/crates/typst-library/src/text/raw.rs @@ -158,7 +158,6 @@ pub struct RawElem { /// /// This is ```typ also *Typst*```, but inline! /// ```` - #[borrowed] pub lang: Option<EcoString>, /// The horizontal alignment that each line in a raw block should have. @@ -250,7 +249,6 @@ pub struct RawElem { Some(Spanned { v: Smart::Auto, .. }) => Some(Smart::Auto), None => None, })] - #[borrowed] pub theme: Smart<Option<Derived<DataSource, RawTheme>>>, /// The size for a tab stop in spaces. A tab is replaced with enough spaces to @@ -306,7 +304,7 @@ impl RawElem { impl Synthesize for Packed<RawElem> { fn synthesize(&mut self, _: &mut Engine, styles: StyleChain) -> SourceResult<()> { let seq = self.highlight(styles); - self.push_lines(seq); + self.lines = Some(seq); Ok(()) } } @@ -319,8 +317,8 @@ impl Packed<RawElem> { let count = lines.len() as i64; let lang = elem - .lang(styles) - .as_ref() + .lang + .get_ref(styles) .as_ref() .map(|s| s.to_lowercase()) .or(Some("txt".into())); @@ -337,8 +335,8 @@ impl Packed<RawElem> { }) }; - let syntaxes = LazyCell::new(|| elem.syntaxes(styles)); - let theme: &synt::Theme = match elem.theme(styles) { + let syntaxes = LazyCell::new(|| elem.syntaxes.get_cloned(styles)); + let theme: &synt::Theme = match elem.theme.get_ref(styles) { Smart::Auto => &RAW_THEME, Smart::Custom(Some(theme)) => theme.derived.get(), Smart::Custom(None) => return non_highlighted_result(lines).collect(), @@ -434,7 +432,7 @@ impl Packed<RawElem> { impl Show for Packed<RawElem> { #[typst_macros::time(name = "raw", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - let lines = self.lines().map(|v| v.as_slice()).unwrap_or_default(); + let lines = self.lines.as_deref().unwrap_or_default(); let mut seq = EcoVec::with_capacity((2 * lines.len()).saturating_sub(1)); for (i, line) in lines.iter().enumerate() { @@ -447,8 +445,8 @@ impl Show for Packed<RawElem> { let mut realized = Content::sequence(seq); - if TargetElem::target_in(styles).is_html() { - return Ok(HtmlElem::new(if self.block(styles) { + if styles.get(TargetElem::target).is_html() { + return Ok(HtmlElem::new(if self.block.get(styles) { tag::pre } else { tag::code @@ -458,9 +456,9 @@ impl Show for Packed<RawElem> { .spanned(self.span())); } - if self.block(styles) { + if self.block.get(styles) { // Align the text before inserting it into the block. - realized = realized.aligned(self.align(styles).into()); + realized = realized.aligned(self.align.get(styles).into()); realized = BlockElem::new() .with_body(Some(BlockBody::Content(realized))) .pack() @@ -474,14 +472,14 @@ impl Show for Packed<RawElem> { impl ShowSet for Packed<RawElem> { fn show_set(&self, styles: StyleChain) -> Styles { let mut out = Styles::new(); - out.set(TextElem::set_overhang(false)); - out.set(TextElem::set_lang(Lang::ENGLISH)); - out.set(TextElem::set_hyphenate(Smart::Custom(false))); - out.set(TextElem::set_size(TextSize(Em::new(0.8).into()))); - out.set(TextElem::set_font(FontList(vec![FontFamily::new("DejaVu Sans Mono")]))); - out.set(TextElem::set_cjk_latin_spacing(Smart::Custom(None))); - if self.block(styles) { - out.set(ParElem::set_justify(false)); + out.set(TextElem::overhang, false); + out.set(TextElem::lang, Lang::ENGLISH); + out.set(TextElem::hyphenate, Smart::Custom(false)); + out.set(TextElem::size, TextSize(Em::new(0.8).into())); + out.set(TextElem::font, FontList(vec![FontFamily::new("DejaVu Sans Mono")])); + out.set(TextElem::cjk_latin_spacing, Smart::Custom(None)); + if self.block.get(styles) { + out.set(ParElem::justify, false); } out } @@ -789,7 +787,7 @@ fn preprocess( let mut text = text.get(); if text.contains('\t') { - let tab_size = RawElem::tab_size_in(styles); + let tab_size = styles.get(RawElem::tab_size); text = align_tabs(&text, tab_size); } split_newlines(&text) @@ -809,11 +807,11 @@ fn styled( let mut body = TextElem::packed(piece).spanned(span); if span_offset > 0 { - body = body.styled(TextElem::set_span_offset(span_offset)); + body = body.set(TextElem::span_offset, span_offset); } if style.foreground != foreground { - body = body.styled(TextElem::set_fill(to_typst(style.foreground).into())); + body = body.set(TextElem::fill, to_typst(style.foreground).into()); } if style.font_style.contains(synt::FontStyle::BOLD) { diff --git a/crates/typst-library/src/text/shift.rs b/crates/typst-library/src/text/shift.rs index b7f3ed92..1a05d8f9 100644 --- a/crates/typst-library/src/text/shift.rs +++ b/crates/typst-library/src/text/shift.rs @@ -69,7 +69,7 @@ impl Show for Packed<SubElem> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { let body = self.body.clone(); - if TargetElem::target_in(styles).is_html() { + if styles.get(TargetElem::target).is_html() { return Ok(HtmlElem::new(tag::sub) .with_body(Some(body)) .pack() @@ -79,9 +79,9 @@ impl Show for Packed<SubElem> { show_script( styles, body, - self.typographic(styles), - self.baseline(styles), - self.size(styles), + self.typographic.get(styles), + self.baseline.get(styles), + self.size.get(styles), ScriptKind::Sub, ) } @@ -151,7 +151,7 @@ impl Show for Packed<SuperElem> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { let body = self.body.clone(); - if TargetElem::target_in(styles).is_html() { + if styles.get(TargetElem::target).is_html() { return Ok(HtmlElem::new(tag::sup) .with_body(Some(body)) .pack() @@ -161,9 +161,9 @@ impl Show for Packed<SuperElem> { show_script( styles, body, - self.typographic(styles), - self.baseline(styles), - self.size(styles), + self.typographic.get(styles), + self.baseline.get(styles), + self.size.get(styles), ScriptKind::Super, ) } @@ -177,13 +177,16 @@ fn show_script( size: Smart<TextSize>, kind: ScriptKind, ) -> SourceResult<Content> { - let font_size = TextElem::size_in(styles); - Ok(body.styled(TextElem::set_shift_settings(Some(ShiftSettings { - typographic, - shift: baseline.map(|l| -Em::from_length(l, font_size)), - size: size.map(|t| Em::from_length(t.0, font_size)), - kind, - })))) + let font_size = styles.resolve(TextElem::size); + Ok(body.set( + TextElem::shift_settings, + Some(ShiftSettings { + typographic, + shift: baseline.map(|l| -Em::from_length(l, font_size)), + size: size.map(|t| Em::from_length(t.0, font_size)), + kind, + }), + )) } /// Configuration values for sub- or superscript text. diff --git a/crates/typst-library/src/text/smallcaps.rs b/crates/typst-library/src/text/smallcaps.rs index 924a45e8..1c283893 100644 --- a/crates/typst-library/src/text/smallcaps.rs +++ b/crates/typst-library/src/text/smallcaps.rs @@ -64,8 +64,9 @@ pub struct SmallcapsElem { impl Show for Packed<SmallcapsElem> { #[typst_macros::time(name = "smallcaps", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - let sc = if self.all(styles) { Smallcaps::All } else { Smallcaps::Minuscules }; - Ok(self.body.clone().styled(TextElem::set_smallcaps(Some(sc)))) + let sc = + if self.all.get(styles) { Smallcaps::All } else { Smallcaps::Minuscules }; + Ok(self.body.clone().set(TextElem::smallcaps, Some(sc))) } } diff --git a/crates/typst-library/src/text/smartquote.rs b/crates/typst-library/src/text/smartquote.rs index 09cefd01..24787d06 100644 --- a/crates/typst-library/src/text/smartquote.rs +++ b/crates/typst-library/src/text/smartquote.rs @@ -83,13 +83,12 @@ pub struct SmartQuoteElem { /// #set smartquote(quotes: (single: ("[[", "]]"), double: auto)) /// 'Das sind eigene Anführungszeichen.' /// ``` - #[borrowed] pub quotes: Smart<SmartQuoteDict>, } impl PlainText for Packed<SmartQuoteElem> { fn plain_text(&self, text: &mut EcoString) { - if self.double.unwrap_or(true) { + if self.double.as_option().unwrap_or(true) { text.push_str("\""); } else { text.push_str("'"); |
