mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Improve justification of Chinese/Japanese text (#542)
This commit is contained in:
parent
0b4dc6758e
commit
2c735294cd
@ -84,6 +84,7 @@ pub struct BoxElem {
|
|||||||
/// outset: (y: 3pt),
|
/// outset: (y: 3pt),
|
||||||
/// radius: 2pt,
|
/// radius: 2pt,
|
||||||
/// )[rectangle].
|
/// )[rectangle].
|
||||||
|
/// ```
|
||||||
#[resolve]
|
#[resolve]
|
||||||
#[fold]
|
#[fold]
|
||||||
pub outset: Sides<Option<Rel<Length>>>,
|
pub outset: Sides<Option<Rel<Length>>>,
|
||||||
|
@ -4,6 +4,7 @@ use std::str::FromStr;
|
|||||||
use rustybuzz::{Feature, Tag, UnicodeBuffer};
|
use rustybuzz::{Feature, Tag, UnicodeBuffer};
|
||||||
use typst::font::{Font, FontVariant};
|
use typst::font::{Font, FontVariant};
|
||||||
use typst::util::SliceExt;
|
use typst::util::SliceExt;
|
||||||
|
use unicode_script::{Script, UnicodeScript};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::layout::SpanMapper;
|
use crate::layout::SpanMapper;
|
||||||
@ -69,11 +70,24 @@ impl ShapedGlyph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the glyph is justifiable.
|
/// 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 {
|
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.
|
/// A side you can go toward.
|
||||||
enum Side {
|
enum Side {
|
||||||
/// To the left-hand side.
|
/// To the left-hand side.
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Loading…
x
Reference in New Issue
Block a user