mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 18:04:03 +01:00
Merge pull request #6217 from dotCooCoo/fix/ai-ate-vertical-roman
.ai import: type keeps Standard Vertical Roman Alignment from its editing data
This commit is contained in:
4 files changed
+73
-3
No files matched your search
@@ -3100,11 +3100,17 @@ fn the_vertical_fixture_reads_as_vertical_type() {
|
||||
l.doc.walk(|n| {
|
||||
if let vectorcraft_doc::NodeKind::Text(t) = &n.kind {
|
||||
let tcy: Vec<&str> = t.runs.iter().filter(|r| r.style.tate_chu_yoko).map(|r| r.text.as_str()).collect();
|
||||
found.push((t.plain_text(), t.vertical, tcy.join("|")));
|
||||
let roman: Vec<&str> = t.runs.iter().filter(|r| r.style.standard_vertical_roman).map(|r| r.text.as_str()).collect();
|
||||
found.push((t.plain_text(), t.vertical, tcy.join("|"), roman.join("|")));
|
||||
}
|
||||
});
|
||||
let want = [("Day 12\nnext", true, "12"), ("Vertical area type wraps", true, ""), ("On a path", true, "On a path")];
|
||||
assert_eq!(found, want.map(|(a, b, c)| (a.to_string(), b, c.to_string())), "{:?}", l.warnings);
|
||||
// Key 35 at 1 in the defaults: Standard Vertical Roman Alignment, except where a run has 3 or 2.
|
||||
let want = [
|
||||
("Day 12\nnext", true, "12", "Day "),
|
||||
("Vertical area type wraps", true, "", "Vertical area type wraps"),
|
||||
("On a path", true, "On a path", ""),
|
||||
];
|
||||
assert_eq!(found, want.map(|(a, b, c, d)| (a.to_string(), b, c.to_string(), d.to_string())), "{:?}", l.warnings);
|
||||
}
|
||||
|
||||
/// The text objects of [`frames_document_text`]: story 0 in its two frames, story 1 in its one (a
|
||||
|
||||
@@ -424,6 +424,9 @@ struct Style {
|
||||
caps: u8,
|
||||
/// Key 35 at 3: Tate-chu-yoko, the characters set across the column as one block.
|
||||
tate_chu_yoko: bool,
|
||||
/// Key 35 at 1 (Standard): Standard Vertical Roman Alignment, half-width characters upright in
|
||||
/// a column. Any other value, or no key in the run, its character style or the defaults, is off.
|
||||
standard_vertical_roman: bool,
|
||||
}
|
||||
|
||||
/// The text document of an editing copy.
|
||||
@@ -664,6 +667,7 @@ impl Texts {
|
||||
stroke_width: num("63").filter(|v| *v >= 0.0 && *v < 1e4).unwrap_or(1.0),
|
||||
caps: num("12").filter(|v| *v == 1.0 || *v == 2.0).map_or(0, |v| v as u8),
|
||||
tate_chu_yoko: num("35") == Some(3.0),
|
||||
standard_vertical_roman: num("35") == Some(1.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1206,6 +1210,7 @@ fn char_style(s: &Style, scale: f64, leading: Option<f64>) -> CharStyle {
|
||||
// At the default Small Caps size of Document Setup: the file's own isn't read.
|
||||
small_caps: (s.caps == 1).then(|| vectorcraft_doc::DocSetup::default().small_caps_size),
|
||||
tate_chu_yoko: s.tate_chu_yoko,
|
||||
standard_vertical_roman: s.standard_vertical_roman,
|
||||
..CharStyle::default()
|
||||
}
|
||||
}
|
||||
@@ -1328,6 +1333,35 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Key 35 of a character style at 1 (Standard) is Standard Vertical Roman Alignment, from the
|
||||
/// run, its character style or the document's defaults; at 2 (rotated), 3 (Tate-chu-yoko), a
|
||||
/// value that isn't one of those numbers, or with no key anywhere it is off.
|
||||
#[test]
|
||||
fn baseline_direction_one_is_standard_vertical_roman_alignment() {
|
||||
let texts = |defaults: &[u8]| Texts {
|
||||
stories: vec![],
|
||||
fonts: vec![],
|
||||
defaults: read(defaults).unwrap(),
|
||||
para_defaults: Val::Dict(BTreeMap::new()),
|
||||
char_sheets: vec![read(b"/0 ([Normal Character Style]) /6 << >>").unwrap(), read(b"/0 (Rotated) /6 << /35 2 >>").unwrap()],
|
||||
para_sheets: vec![],
|
||||
frames: vec![],
|
||||
};
|
||||
let roman = |defaults: &[u8], run: &[u8]| texts(defaults).style(Some(&read(run).unwrap())).standard_vertical_roman;
|
||||
assert!(roman(b"/35 1", b"/6 << >>"), "the document's defaults");
|
||||
assert!(roman(b"/35 2", b"/6 << /35 1 >>"), "the run's own");
|
||||
assert!(!roman(b"/35 1", b"/6 << /35 2 >>"), "the run's own rotated");
|
||||
assert!(!roman(b"/35 1", b"/5 1 /6 << >>"), "its character style's");
|
||||
assert!(roman(b"/35 2", b"/5 1 /6 << /35 1 >>"), "the run's own wins over its style");
|
||||
assert!(!roman(b"/0 0", b"/6 << >>"), "no key: off");
|
||||
for other in
|
||||
[&b"/6 << /35 3 >>"[..], b"/6 << /35 1.5 >>", b"/6 << /35 (1) >>", b"/6 << /35 -1 >>", b"/6 << /35 true >>", b"/6 << /35 [ 1 ] >>"]
|
||||
{
|
||||
assert!(!roman(b"/0 0", other), "{}", String::from_utf8_lossy(other));
|
||||
}
|
||||
assert!(texts(b"/35 3").style(None).tate_chu_yoko && !texts(b"/35 3").style(None).standard_vertical_roman);
|
||||
}
|
||||
|
||||
/// A right-to-left paragraph is laid out right to left even when it has no right-to-left
|
||||
/// letters (a dimension's label " 120.5 mm " reads "mm 120.5"); a left-to-right one, or one
|
||||
/// that doesn't say, goes by its letters.
|
||||
@@ -1597,6 +1631,7 @@ mod tests {
|
||||
stroke_width: 1.0,
|
||||
caps: 0,
|
||||
tate_chu_yoko: false,
|
||||
standard_vertical_roman: false,
|
||||
},
|
||||
)],
|
||||
path_spacing: 0.0,
|
||||
|
||||
@@ -2828,6 +2828,32 @@ fn a_tate_chu_yoko_run_is_marked() {
|
||||
assert_eq!(marked, [("§".to_string(), false), ("12".to_string(), true), ("§".to_string(), false)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_standard_baseline_run_keeps_standard_vertical_roman_alignment() {
|
||||
// Three runs over "ab12": "ab" with key 35 at 1 (Standard), "1" at 2 (rotated), "2" without it.
|
||||
// Horizontal type keeps the mark too.
|
||||
for vertical in [true, false] {
|
||||
let doc = text_document(&[("ab12\r", 0, (8200.0, 8180.0), (0.0, 0.0), 0.0)]);
|
||||
let doc = if vertical { vertical_text_document(&doc, 0.0) } else { doc };
|
||||
let run = |n: u32, own: &str| {
|
||||
format!(
|
||||
"<< /0 << /0 << /0 () /5 0 /6 << /0 0 /1 14.0 {own}/53 << /99 /CAITextPaint /0 << /0 2 /1 [ 1.0 0.0 1.0 0.0 0.0 ] >> >> >> >> >> /1 {n} >>"
|
||||
)
|
||||
};
|
||||
let one = run(5, "");
|
||||
assert!(doc.contains(&one));
|
||||
let doc = doc.replacen(&one, &format!("{} {} {}", run(2, "/35 1 "), run(1, "/35 2 "), run(2, "")), 1);
|
||||
let art = native_with_text(&(layer("Back", true, &square(10, 10)) + &layer("Spare", false, &text_object(0))), &doc);
|
||||
let r = import(&eps(&page_square(10, 10), &art)).unwrap();
|
||||
let texts = text_of(&r.document.layers[1]);
|
||||
assert_eq!(texts.len(), 1, "{:?}", r.warnings);
|
||||
assert_eq!(texts[0].vertical, vertical);
|
||||
let marked: Vec<(String, bool, bool)> =
|
||||
texts[0].runs.iter().map(|r| (r.text.clone(), r.style.standard_vertical_roman, r.style.tate_chu_yoko)).collect();
|
||||
assert_eq!(marked, [("ab".to_string(), true, false), ("1".to_string(), false, false), ("2".to_string(), false, false)], "{vertical}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orientation_and_tate_chu_yoko_values_it_cant_use_are_ignored() {
|
||||
for bad in ["(2)", "2.5", "1e300", "-2", "1", "true", "[ 2 ]"] {
|
||||
@@ -2840,6 +2866,8 @@ fn orientation_and_tate_chu_yoko_values_it_cant_use_are_ignored() {
|
||||
assert_eq!(texts.len(), 1, "{bad}: {:?}", r.warnings);
|
||||
assert!(!texts[0].vertical, "{bad}");
|
||||
assert!(texts[0].runs.iter().all(|r| !r.style.tate_chu_yoko), "{bad}");
|
||||
// Key 35 at 1 is Standard Vertical Roman Alignment; the other values leave it off.
|
||||
assert!(texts[0].runs.iter().all(|r| r.style.standard_vertical_roman == (bad == "1")), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -251,6 +251,7 @@ the app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPri
|
||||
the app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPrivateData` streams, a PDF's `AIPDFPrivateData` streams when it was saved with the editing data (#868), Zstandard or zlib, the EPS's in ASCII85) is not documented as a whole. VectorCraft reads its structure: layers and sublayers (names, order, visibility, lock, printing, preview, dimming, colour), groups as they were nested, compound paths (painted by their last path, or the last painted one, with the paths of groups inside them kept as their paths: #1410), clipping groups and layer clipping (several clipping paths in a clipping group, a layer or an opacity mask's art clip to their intersection, and a compound path of clipping paths stays one clip; clipping paths that would nest the art past the document's 32 levels stop the editing data from being read: #5789), object names, hidden and locked objects, fills and strokes (grey, CMYK, RGB, named and spot colours, spot colours defined in Lab with their Lab values (#1032), global process colours as global swatches at their tint; a stroke of width 0, `0 w`, on a path, a gradient-filled path, legacy type or in an art style comes in as a 0.25 pt hairline, as from PDF: #1671), linear and radial gradients, pattern fills with their patterns as pattern swatches (#1025), gradient and pattern names in the file up to their first newline (a name that another swatch, or a gradient or pattern defined earlier, already has is numbered "Sky 2"; a name without a newline is kept, and when another swatch has it, the pattern's swatch, or a named color sharing a gradient or pattern swatch's name, is numbered the same way), opacity, blend modes, isolation and knockout, embedded images where their matrix puts them, rotated ones too (#2269), with their alpha channel (CMYK images keep their ink amounts, as they do when a `.ai` opens from its PDF part, and an alpha channel that hides part of a CMYK image becomes a grayscale opacity mask), placed (linked) files as linked images in their place, each showing the low-resolution preview the file keeps of it until its file is found or relinked in the Links panel (#1264), with the folder the file keeps relative to the document's, where the link is looked for when its path is gone, guides, and every artboard where it is, with its center mark, cross hairs, video safe areas and video ruler pixel aspect ratio. VectorCraft reads `CropAreaActive`, an `/Int` in the dictionary that holds the artboard array, as the index of the active artboard in that array, and the file opens with that artboard active; without it, or when it names no artboard that opens, the first artboard is active. It also reads the Document Raster Effects Settings (resolution, color model, background, anti-alias, clipping mask, Add Around Object and Preserve Spot Colors), the author from the header's `%%For` (an EPS's own header when the editing data's has none), swatches for the header's `%%CMYKCustomColor` and `%%RGBCustomColor` colors that the document has none of, and `%%TemplateBox` in older files; a setting with a value of another type or out of range keeps its default. Objects on Path groups open live, with their path, their objects in order along it, Pivot and Rotate; one with a dragged spacing or other options opens as a plain group. A gradient with stops in the middle runs its whole ramp across its shape, and a gradient object does not pass its fill to the next path (#1390). An object whose art style is one fill and one stroke at most (solid colours, its own gradient, a variable-width profile) with Drop Shadow, Inner Glow, Outer Glow, Feather, Round Corners, Scribble, Offset Path, Outline Object, Outline Stroke, Convert to Shape, Tweak (only when it moves nothing), Pucker & Bloat at 0 or Bas Relief (read from its settings block: [raster effects reference](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/raster-effects-reference.html), [Photoshop File Formats Specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), [scripting the filter gallery](https://community.adobe.com/questions-712/scripting-support-for-the-filter-gallery-1064646)) comes in as itself with them and their saved settings. A path, compound path or group (not a clipping group) whose only effect is Transform (not with copies or Random) or a Free Distort whose corners make a parallelogram comes in as itself with it too, when neither it nor anything in it paints with a gradient or pattern and everything in it is a path, compound path or group with no opacity mask and no effects of its own; Transform that scales, rotates or reflects needs nothing in it to be stroked. Twist as the only effect is read the same way on an unstroked path or compound path whose segments are all straight. One with more, other effects (Zig Zag, a Pucker & Bloat of another amount, a Free Distort with other corners), an effect setting that is not read (an unknown key, a missing or out-of-range valueLine truncated
|
||||
the app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPrivateData` streams, a PDF's `AIPDFPrivateData` streams when it was saved with the editing data (#868), Zstandard or zlib, the EPS's in ASCII85) is not documented as a whole. VectorCraft reads its structure: layers and sublayers (names, order, visibility, lock, printing, preview, dimming, colour), groups as they were nested, compound paths (painted by their last path, or the last painted one, with the paths of groups inside them kept as their paths: #1410), clipping groups and layer clipping (several clipping paths in a clipping group, a layer or an opacity mask's art clip to their intersection, and a compound path of clipping paths stays one clip; clipping paths that would nest the art past the document's 32 levels stop the editing data from being read: #5789), object names, hidden and locked objects, fills and strokes (grey, CMYK, RGB, named and spot colours, spot colours defined in Lab with their Lab values (#1032), global process colours as global swatches at their tint; a stroke of width 0, `0 w`, on a path, a gradient-filled path, legacy type or in an art style comes in as a 0.25 pt hairline, as from PDF: #1671), linear and radial gradients, pattern fills with their patterns as pattern swatches (#1025), gradient and pattern names in the file up to their first newline (a name that another swatch, or a gradient or pattern defined earlier, already has is numbered "Sky 2"; a name without a newline is kept, and when another swatch has it, the pattern's swatch, or a named color sharing a gradient or pattern swatch's name, is numbered the same way), opacity, blend modes, isolation and knockout, embedded images where their matrix puts them, rotated ones too (#2269), with their alpha channel (CMYK images keep their ink amounts, as they do when a `.ai` opens from its PDF part, and an alpha channel that hides part of a CMYK image becomes a grayscale opacity mask), placed (linked) files as linked images in their place, each showing the low-resolution preview the file keeps of it until its file is found or relinked in the Links panel (#1264), with the folder the file keeps relative to the document's, where the link is looked for when its path is gone, guides, and every artboard where it is, with its center mark, cross hairs, video safe areas and video ruler pixel aspect ratio. VectorCraft reads `CropAreaActive`, an `/Int` in the dictionary that holds the artboard array, as the index of the active artboard in that array, and the file opens with that artboard active; without it, or when it names no artboard that opens, the first artboard is active. It also reads the Document Raster Effects Settings (resolution, color model, background, anti-alias, clipping mask, Add Around Object and Preserve Spot Colors), the author from the header's `%%For` (an EPS's own header when the editing data's has none), swatches for the header's `%%CMYKCustomColor` and `%%RGBCustomColor` colors that the document has none of, and `%%TemplateBox` in older files; a setting with a value of another type or out of range keeps its default. Objects on Path groups open live, with their path, their objects in order along it, Pivot and Rotate; one with a dragged spacing or other options opens as a plain group. A gradient with stops in the middle runs its whole ramp across its shape, and a gradient object does not pass its fill to the next path (#1390). An object whose art style is one fill and one stroke at most (solid colours, its own gradient, a variable-width profile) with Drop Shadow, Inner Glow, Outer Glow, Feather, Round Corners, Scribble, Offset Path, Outline Object, Outline Stroke, Convert to Shape, Tweak (only when it moves nothing), Pucker & Bloat at 0 or Bas Relief (read from its settings block: [raster effects reference](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/raster-effects-reference.html), [Photoshop File Formats Specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), [scripting the filter gallery](https://community.adobe.com/questions-712/scripting-support-for-the-filter-gallery-1064646)) comes in as itself with them and their saved settings. A path, compound path or group (not a clipping group) whose only effect is Transform (not with copies or Random) or a Free Distort whose corners make a parallelogram comes in as itself with it too, when neither it nor anything in it paints with a gradient or pattern and everything in it is a path, compound path or group with no opacity mask and no effects of its own; Transform that scales, rotates or reflects needs nothing in it to be stroked. Twist as the only effect is read the same way on an unstroked path or compound path whose segments are all straight. One with more, other effects (Zig Zag, a Pucker & Bloat of another amount, a Free Distort with other corners), an effect setting that is not read (an unknown key, a missing or out-of-range valueLine truncated
|
||||
|
||||
A run of type in the editing data whose baseline direction is 1 opens with Standard Vertical Roman Alignment (https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) on, which is VectorCraft's own mapping: its half-width characters stand upright in vertical type, and horizontal type keeps the mark with no change to its layout. A run whose baseline direction is 2 or 3 (Tate-chu-yoko), or that names none in the run, its character style or the document's defaults, opens with it off. The scripting reference lists 1, 2 and 3 as the Standard, vertical rotated and Tate-chu-yoko baseline directions (https://web.archive.org/web/20170621180804/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20VBScript%20Reference.pdf, page 256).
|
||||
A Scatter brush in the editing data whose last 15 numbers start with 1 comes into the Brushes panel in Tints. Each brush art section is read without its frame: an unnamed, unpainted rectangle with no settings of its own at the art's bounds (within 1/1000 pt), closed, or open with its first corner again at the end. A wider frame stays in the art, and an art group with a state or look of its own (hidden, locked, isolated, knockout, an opacity, a blend mode, a name, a mask, a note or an appearance) stays a group.
|
||||
|
||||
## Format by format
|
||||
|
||||
Reference in new issue
Block a user