Bugfix of CJK punctuation adjustment (#1384)

This commit is contained in:
Peng Guanwen 2023-06-01 21:14:56 +08:00 committed by GitHub
parent 3093b566ab
commit a54cde71cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -98,7 +98,7 @@ impl ShapedGlyph {
matches!(self.c.script(), Hiragana | Katakana | Han) || self.c == '\u{30FC}' matches!(self.c.script(), Hiragana | Katakana | Han) || self.c == '\u{30FC}'
} }
pub fn is_cjk_adjustable(&self) -> bool { pub fn is_cjk_punctuation(&self) -> bool {
self.is_cjk_left_aligned_punctuation(true) self.is_cjk_left_aligned_punctuation(true)
|| self.is_cjk_right_aligned_punctuation() || self.is_cjk_right_aligned_punctuation()
|| self.is_cjk_center_aligned_punctuation(true) || self.is_cjk_center_aligned_punctuation(true)
@ -353,7 +353,7 @@ impl<'a> ShapedText<'a> {
pub fn cjk_justifiable_at_last(&self) -> bool { pub fn cjk_justifiable_at_last(&self) -> bool {
self.glyphs self.glyphs
.last() .last()
.map(|g| g.is_cjk_script() || g.is_cjk_adjustable()) .map(|g| g.is_cjk_script() || g.is_cjk_punctuation())
.unwrap_or(false) .unwrap_or(false)
} }
@ -763,12 +763,14 @@ pub fn is_gb_style(lang: Lang, region: Option<Region>) -> bool {
fn calculate_adjustability(ctx: &mut ShapingContext, lang: Lang, region: Option<Region>) { fn calculate_adjustability(ctx: &mut ShapingContext, lang: Lang, region: Option<Region>) {
let gb_style = is_gb_style(lang, region); let gb_style = is_gb_style(lang, region);
for glyph in &mut ctx.glyphs {
glyph.adjustability = glyph.base_adjustability(gb_style);
}
let mut glyphs = ctx.glyphs.iter_mut().peekable(); let mut glyphs = ctx.glyphs.iter_mut().peekable();
while let Some(glyph) = glyphs.next() { while let Some(glyph) = glyphs.next() {
glyph.adjustability = glyph.base_adjustability(gb_style);
// Only GB style needs further adjustment. // Only GB style needs further adjustment.
if glyph.is_cjk_adjustable() && !gb_style { if glyph.is_cjk_punctuation() && !gb_style {
continue; continue;
} }
@ -778,7 +780,8 @@ fn calculate_adjustability(ctx: &mut ShapingContext, lang: Lang, region: Option<
let Some(next) = glyphs.peek_mut() else { continue }; let Some(next) = glyphs.peek_mut() else { continue };
let width = glyph.x_advance; let width = glyph.x_advance;
let delta = width / 2.0; let delta = width / 2.0;
if next.is_cjk_adjustable() if glyph.is_cjk_punctuation()
&& next.is_cjk_punctuation()
&& (glyph.shrinkability().1 + next.shrinkability().0) >= delta && (glyph.shrinkability().1 + next.shrinkability().0) >= delta
{ {
let left_delta = glyph.shrinkability().1.min(delta); let left_delta = glyph.shrinkability().1.min(delta);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

@ -35,6 +35,8 @@
《书名》《测试》。 《书名》《测试》。
] ]
「『引号』」。“‘引号’”。
--- ---
// Test Variants of Mainland China, Hong Kong, and Japan. // Test Variants of Mainland China, Hong Kong, and Japan.