summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/src')
-rw-r--r--library/src/layout/container.rs1
-rw-r--r--library/src/text/shaping.rs16
2 files changed, 16 insertions, 1 deletions
diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs
index 0f81a1df..166d6c09 100644
--- a/library/src/layout/container.rs
+++ b/library/src/layout/container.rs
@@ -84,6 +84,7 @@ pub struct BoxElem {
/// outset: (y: 3pt),
/// radius: 2pt,
/// )[rectangle].
+ /// ```
#[resolve]
#[fold]
pub outset: Sides<Option<Rel<Length>>>,
diff --git a/library/src/text/shaping.rs b/library/src/text/shaping.rs
index b895b6f9..2dd0cd6d 100644
--- a/library/src/text/shaping.rs
+++ b/library/src/text/shaping.rs
@@ -4,6 +4,7 @@ use std::str::FromStr;
use rustybuzz::{Feature, Tag, UnicodeBuffer};
use typst::font::{Font, FontVariant};
use typst::util::SliceExt;
+use unicode_script::{Script, UnicodeScript};
use super::*;
use crate::layout::SpanMapper;
@@ -69,11 +70,24 @@ impl ShapedGlyph {
}
/// Whether the glyph is justifiable.
+ ///
+ /// Typst's basic justification strategy is to stretch all the spaces
+ /// in a line until the line fills the available width. However, some
+ /// scripts (notably Chinese and Japanese) don't use spaces.
+ ///
+ /// In Japanese typography, the convention is to insert space evenly
+ /// between all glyphs. I assume it's the same in Chinese.
pub fn is_justifiable(&self) -> bool {
- self.is_space() || matches!(self.c, ',' | '。' | '、')
+ self.is_space() || is_spaceless(self.c.script())
}
}
+/// Does this script separate its words using spaces?
+fn is_spaceless(script: Script) -> bool {
+ use Script::*;
+ matches!(script, Hiragana | Katakana | Han)
+}
+
/// A side you can go toward.
enum Side {
/// To the left-hand side.