mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 21:57:52 +00:00
🐛 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
This commit is contained in:
parent
2fec140216
commit
03edbe8876
BIN
render-wasm/src/fonts/shipporimincho-vrt2-test.ttf
Normal file
BIN
render-wasm/src/fonts/shipporimincho-vrt2-test.ttf
Normal file
Binary file not shown.
@ -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.
|
||||
|
||||
@ -322,8 +322,11 @@ fn font_feature(font_features: FontFeatures) -> Option<Feature> {
|
||||
}
|
||||
|
||||
/// 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![]
|
||||
};
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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`) ->
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user