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 0000000000..7de9b19bcb Binary files /dev/null and b/render-wasm/src/fonts/shipporimincho-vrt2-test.ttf differ diff --git a/render-wasm/src/shapes/text_shaping/orientation.rs b/render-wasm/src/shapes/text_shaping/orientation.rs index 36dc56baf2..859a95779b 100644 --- a/render-wasm/src/shapes/text_shaping/orientation.rs +++ b/render-wasm/src/shapes/text_shaping/orientation.rs @@ -42,7 +42,7 @@ pub(crate) fn is_upright_char(c: char) -> 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;