From be7cfc85d08c545abfac08098b7b33b4bd71f37e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 27 Oct 2024 19:04:55 +0100 Subject: Split out four new crates (#5302) --- crates/typst-library/src/text/smallcaps.rs | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 crates/typst-library/src/text/smallcaps.rs (limited to 'crates/typst-library/src/text/smallcaps.rs') diff --git a/crates/typst-library/src/text/smallcaps.rs b/crates/typst-library/src/text/smallcaps.rs new file mode 100644 index 00000000..bf003bd1 --- /dev/null +++ b/crates/typst-library/src/text/smallcaps.rs @@ -0,0 +1,58 @@ +use crate::diag::SourceResult; +use crate::engine::Engine; +use crate::foundations::{elem, Content, Packed, Show, StyleChain}; +use crate::text::TextElem; + +/// Displays text in small capitals. +/// +/// # Example +/// ```example +/// Hello \ +/// #smallcaps[Hello] +/// ``` +/// +/// # Smallcaps fonts +/// By default, this enables the OpenType `smcp` feature for the font. Not all +/// fonts support this feature. Sometimes smallcaps are part of a dedicated +/// font. This is, for example, the case for the _Latin Modern_ family of fonts. +/// In those cases, you can use a show-set rule to customize the appearance of +/// the text in smallcaps: +/// +/// ```typ +/// #show smallcaps: set text(font: "Latin Modern Roman Caps") +/// ``` +/// +/// In the future, this function will support synthesizing smallcaps from normal +/// letters, but this is not yet implemented. +/// +/// # Smallcaps headings +/// You can use a [show rule]($styling/#show-rules) to apply smallcaps +/// formatting to all your headings. In the example below, we also center-align +/// our headings and disable the standard bold font. +/// +/// ```example +/// #set par(justify: true) +/// #set heading(numbering: "I.") +/// +/// #show heading: smallcaps +/// #show heading: set align(center) +/// #show heading: set text( +/// weight: "regular" +/// ) +/// +/// = Introduction +/// #lorem(40) +/// ``` +#[elem(title = "Small Capitals", Show)] +pub struct SmallcapsElem { + /// The content to display in small capitals. + #[required] + pub body: Content, +} + +impl Show for Packed { + #[typst_macros::time(name = "smallcaps", span = self.span())] + fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult { + Ok(self.body().clone().styled(TextElem::set_smallcaps(true))) + } +} -- cgit v1.2.3