diff options
| author | damaxwell <damaxwell@alaska.edu> | 2023-07-19 02:25:24 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-19 12:25:24 +0200 |
| commit | 8a57395ee48ecee02c2eb833d232979730f0e445 (patch) | |
| tree | 7a66d64f2f4b8afd509db0a89d5bf25a2ab1c72b /crates/typst-library/src/text | |
| parent | f39bfa476222aa92a590d65f7c2d58612f24eef2 (diff) | |
Support OpenType writing script (#1697)
Diffstat (limited to 'crates/typst-library/src/text')
| -rw-r--r-- | crates/typst-library/src/text/mod.rs | 25 | ||||
| -rw-r--r-- | crates/typst-library/src/text/shaping.rs | 5 |
2 files changed, 30 insertions, 0 deletions
diff --git a/crates/typst-library/src/text/mod.rs b/crates/typst-library/src/text/mod.rs index f7c15c29..6cfcb7c7 100644 --- a/crates/typst-library/src/text/mod.rs +++ b/crates/typst-library/src/text/mod.rs @@ -265,6 +265,31 @@ pub struct TextElem { #[default(BottomEdge::Metric(BottomEdgeMetric::Baseline))] pub bottom_edge: BottomEdge, + /// The OpenType writing script setting. + /// + /// The combination of `{script}` and `{lang}` determine how + /// font features, such as glyph substitution, are implemented. + /// Frequently the value is a modified (all-lowercase) ISO 15924 script identifier, and + /// the `math` writing script is used for features appropriate + /// for mathematical symbols. + /// + /// When set to `{auto}`, the default and recommended setting, + /// an appropriate script is chosen for each block of characters + /// sharing a common Unicode script property. + /// + /// ```example + /// #let scedilla = [Ş] + /// #set text(font: "Linux Libertine", size: 20pt) + /// #scedilla // S with a cedilla + /// + /// #set text(script: "latn", lang: "ro") + /// #scedilla // S with a subscript comma + /// + /// #set text(script: "grek", lang: "ro") + /// #scedilla // S with a cedilla + /// ``` + pub script: Smart<WritingScript>, + /// An [ISO 639-1/2/3 language code.](https://en.wikipedia.org/wiki/ISO_639) /// /// Setting the correct language affects various parts of Typst: diff --git a/crates/typst-library/src/text/shaping.rs b/crates/typst-library/src/text/shaping.rs index 3ccac635..53289e26 100644 --- a/crates/typst-library/src/text/shaping.rs +++ b/crates/typst-library/src/text/shaping.rs @@ -634,6 +634,11 @@ fn shape_segment( let mut buffer = UnicodeBuffer::new(); buffer.push_str(text); buffer.set_language(language(ctx.styles)); + if let Some(script) = TextElem::script_in(ctx.styles).as_custom().and_then(|script| { + rustybuzz::Script::from_iso15924_tag(Tag::from_bytes(script.as_bytes())) + }) { + buffer.set_script(script) + } buffer.set_direction(match ctx.dir { Dir::LTR => rustybuzz::Direction::LeftToRight, Dir::RTL => rustybuzz::Direction::RightToLeft, |
