From 03edbe8876115f610c23e19b8bea66f0ea77841b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 24 Nov 2026 17:20:29 +0100 Subject: [PATCH] :bug: Keep Latin upright under upright orientation in all fonts Upright vertical runs were shaped with both `vert` and `vrt2`. On top of the vertical forms, `vrt2` swaps proportional glyphs such as Latin for forms already turned on their side. Shippori Mincho and BIZ UDMincho map Latin that way, so their Latin stayed sideways under text-orientation: upright. Noto Sans JP and Noto Serif JP do not, which hid the problem. Shape upright runs with `vert` only, as browsers do. Sideways runs are rotated by the layout, so mixed text does not need `vrt2`. For Noto Sans JP and Noto Serif JP the glyphs of kana, kanji and CJK punctuation are the same with or without `vrt2`. Add a Shippori Mincho subset as a test font. AI-assisted-by: claude-opus-5-5 --- .../src/fonts/shipporimincho-vrt2-test.ttf | Bin 0 -> 3268 bytes .../src/shapes/text_shaping/orientation.rs | 2 +- .../src/shapes/text_shaping/shaping.rs | 9 ++-- render-wasm/src/shapes/text_vertical/cells.rs | 44 ++++++++++++++++++ .../src/shapes/text_vertical/layout.rs | 2 +- render-wasm/src/shapes/text_vertical/mod.rs | 2 +- .../src/shapes/text_vertical/test_support.rs | 4 ++ 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 render-wasm/src/fonts/shipporimincho-vrt2-test.ttf diff --git a/render-wasm/src/fonts/shipporimincho-vrt2-test.ttf b/render-wasm/src/fonts/shipporimincho-vrt2-test.ttf new file mode 100644 index 0000000000000000000000000000000000000000..7de9b19bcb7d0e873bac0c2fcc2753e50e187ff0 GIT binary patch literal 3268 zcmb7HYiv}<6+Sa__uhR!ypL;p{aEj=_pZIWUbAcO1$!|Vh#e6K1VbRCCb$Od@UV?- zTu3Nwq@)3)s;!FDABob36tzj!w2D$GRn)3d@}rTW{vv5pr7fwDN>WszD&z+#yZz>_ z0Y6Zr&idY&bLO1yeCN!$BOpdZe!LW-;VlmgQIxzyEDLSZ@Xj40Z>g`8iTF0iJBLU1 zY|33W_Y#TSkY{#`v?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=*GIGp)0#&M0WKqS){<4?j*%RE0TH!nSfnS^*=nyK0&YI z4oZeK6|_=@^#%#ER5H!po|I&!YH|xoNm-A8ou*0RFe)k~v)A-;nF!E)F0dmT-IfUT>oRXiVT>rONovc^xdJ$zP_Ygv%w z2DYGU7;#h@Y;pQVN|HCNcP#^5x7b_x$%-oxy{LC_q#EX-6#>75TjkYzWJG#Zg7*8> zL+@Fv#~XLD$IZBoeM9`5a|+<%9N^#>39E@VRWl-bn`pH8or-F%Q5tTK4)16(ALbj` zpS5~dZjI(=p0z5jVU^74>*61C&EkC0eobZ zp*#k3zp5p17T^R?P1x??13rOWD+1W)y&zx|%)0@lE2O)waU*4bY%QHq$~fN@btc1s zM&)sPptGmb?{>L`yUpWcV|$J?*KhUrxw&&x^D^%6r=z)cqan~7i>viqwKoUsUPWc; ztT$^!lH!1BZeFjs0}Z^CanyzSTQ}4Rm!>$@i_nW30>X)9SqWci>Z}B#k@}2grd)yK z<9U|%vbgRs3qfyXuS5-LZjIX;Je`exr)GDugS*wbuxC?qQcpYfI)g3y^P&9>9^Jhr z7x1{<+#c*Sft(%J1~%yPdQOe)-=g-qG2GL85qc92Z-~RdAE2~^wv=6OHhUFKCry|{ bool { } /// Characters whose horizontal glyph needs a vertical alternate, normally -/// from `vert` / `vrt2`. When the face has no such substitution, the +/// from `vert`. When the face has no such substitution, the /// horizontal glyph rotates clockwise as a fallback. Covers UAX #50 `Tr`, /// plus comma/full-stop punctuation whose plain glyph sits in the wrong /// half of the vertical em box. diff --git a/render-wasm/src/shapes/text_shaping/shaping.rs b/render-wasm/src/shapes/text_shaping/shaping.rs index fd83a19bd6..6de2568c35 100644 --- a/render-wasm/src/shapes/text_shaping/shaping.rs +++ b/render-wasm/src/shapes/text_shaping/shaping.rs @@ -322,8 +322,11 @@ fn font_feature(font_features: FontFeatures) -> Option { } /// Shape one orientation segment on a single unbounded line. Upright -/// segments get the OpenType vertical substitution features so CJK -/// punctuation and brackets take their vertical forms. +/// segments get the OpenType `vert` feature so CJK punctuation and brackets +/// take their vertical forms. Not `vrt2`: on top of `vert`, it swaps +/// proportional glyphs such as Latin for forms already turned on their +/// side, which would set Latin sideways under text-orientation: upright. +/// Sideways runs are rotated by the layout instead. pub(crate) fn shape_segment( text: &str, font: &Font, @@ -338,7 +341,7 @@ pub(crate) fn shape_segment( let mut lang_iter = skia::Shaper::new_trivial_language_run_iterator(language, text.len()); let mut features = if upright { - vec![feature(b"vert"), feature(b"vrt2")] + vec![feature(b"vert")] } else { vec![] }; diff --git a/render-wasm/src/shapes/text_vertical/cells.rs b/render-wasm/src/shapes/text_vertical/cells.rs index df211211ba..ea9b6d5cdb 100644 --- a/render-wasm/src/shapes/text_vertical/cells.rs +++ b/render-wasm/src/shapes/text_vertical/cells.rs @@ -895,6 +895,50 @@ mod tests { ); } + /// The glyph each upright cell of `text` draws, with the glyph its + /// font maps the cell's character to, under text-orientation: upright. + fn upright_glyphs(font: &[u8], text: &str) -> Vec<(char, skia::GlyphId, skia::GlyphId)> { + let mut content = make_content(&[text], 1000.0); + content.paragraphs_mut()[0].children_mut()[0].text_orientation = TextOrientation::Upright; + let layout = layout_with(&provider(font), &content); + layout + .cells + .iter() + .map(|cell| { + let CellKind::Upright { run, glyph, .. } = cell.kind else { + panic!("expected an upright cell, got {:?}", cell.kind); + }; + let run = &layout.runs[run]; + let ch = char::decode_utf16(text.encode_utf16().skip(cell.start)) + .next() + .and_then(Result::ok) + .expect("a character at the cell start"); + (ch, run.glyphs[glyph], run.font.unichar_to_glyph(ch as i32)) + }) + .collect() + } + + #[test] + fn upright_latin_keeps_its_glyph_in_a_font_whose_vrt2_rotates_it() { + // `vrt2` swaps proportional Latin for glyphs already turned on their + // side, for fonts that set mixed text by substitution. Under + // text-orientation: upright the letters must stand upright. + for (ch, drawn, upright) in upright_glyphs(VRT2_TEST_FONT, "Aa") { + assert_eq!(drawn, upright, "{ch} is drawn with a rotated glyph"); + } + } + + #[test] + fn upright_punctuation_takes_its_vertical_form_in_a_font_with_vrt2() { + for (ch, drawn, horizontal) in upright_glyphs(VRT2_TEST_FONT, "縦、。") { + if ch == '縦' { + assert_eq!(drawn, horizontal, "{ch} keeps its glyph"); + } else { + assert_ne!(drawn, horizontal, "{ch} needs its vertical form"); + } + } + } + #[test] fn upright_latin_ink_is_centred_in_its_cell() { // A descender followed by an ascender (`gf`) must not touch: each diff --git a/render-wasm/src/shapes/text_vertical/layout.rs b/render-wasm/src/shapes/text_vertical/layout.rs index 01cd13cea2..9ede72cec8 100644 --- a/render-wasm/src/shapes/text_vertical/layout.rs +++ b/render-wasm/src/shapes/text_vertical/layout.rs @@ -39,7 +39,7 @@ pub enum CellKind { glyph: usize, count: usize, }, - /// An upright-flow character whose font lacks a `vert`/`vrt2` alternate, + /// An upright-flow character whose font lacks a `vert` alternate, /// rotated in its own cell so wrapping, kinsoku and editor offsets stay /// per character. SyntheticRotated { diff --git a/render-wasm/src/shapes/text_vertical/mod.rs b/render-wasm/src/shapes/text_vertical/mod.rs index c4e05eb40d..2b5b5e35dc 100644 --- a/render-wasm/src/shapes/text_vertical/mod.rs +++ b/render-wasm/src/shapes/text_vertical/mod.rs @@ -3,7 +3,7 @@ // module owns the whole vertical pipeline: // // segment spans by glyph orientation and shape each segment with -// SkShaper, OpenType `vert`/`vrt2` for upright runs (`text_shaping`) -> +// SkShaper, OpenType `vert` for upright runs (`text_shaping`) -> // derive cells: one per upright glyph cluster, one per rotated run, one per // composite (`cells`) -> JLREQ spacing and kinsoku-aware column breaks // (`flow`) -> place columns and annotations (`layout`, `annotations`) -> diff --git a/render-wasm/src/shapes/text_vertical/test_support.rs b/render-wasm/src/shapes/text_vertical/test_support.rs index 93aec7b896..a3d14372cf 100644 --- a/render-wasm/src/shapes/text_vertical/test_support.rs +++ b/render-wasm/src/shapes/text_vertical/test_support.rs @@ -25,6 +25,10 @@ pub(crate) const VMTX_TEST_FONT: &[u8] = include_bytes!("../../fonts/notosansjp- /// Noto Sans JP subset with GSUB `vert` and GPOS `vpal` for 、。「」あく. pub(crate) const VPAL_TEST_FONT: &[u8] = include_bytes!("../../fonts/notosansjp-vpal-test.ttf"); +/// Shippori Mincho subset for `Aa縦、。一`. Its `vrt2` swaps Latin for +/// glyphs turned on their side; its `vert` leaves Latin alone. +pub(crate) const VRT2_TEST_FONT: &[u8] = include_bytes!("../../fonts/shipporimincho-vrt2-test.ttf"); + /// Font size of every test span. pub(crate) const EM: f32 = 20.0;