mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 08:52:45 +01:00
combo: #6048
This commit is contained in:
commit
8f5f9db06a
3 files changed
+30
-2
No files matched your search
@@ -10,7 +10,8 @@
|
||||
//! locally, never committed): the blend's own art on `%_` lines, a group holding the key objects
|
||||
//! and the spine, each object's `/ArtDictionary` naming its part (`ShapeBlendPathType`: `K` a key,
|
||||
//! `S` the spine) and a key's id (`ShapeBlendPathID`); then the steps drawn, a group on plain
|
||||
//! lines; then `(Adobe Path Blends) 1 0 n XP` and `n` bytes as hex on `%` lines. Those bytes
|
||||
//! lines; then `(Adobe Path Blends) 1 0 n XP` and `n` bytes as hex on `%` lines (`%_%` lines
|
||||
//! for a blend in hidden art, as an opacity mask's is: all of it is on `%_` lines). Those bytes
|
||||
//! start `DCBA`. A blend whose spine was never edited has no spine part: only its keys.
|
||||
//!
|
||||
//! The reader reads the words after `DCBA` (little endian) this way. Word 1 is the spacing: 0 is
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
//! - Any other line starting with `%` is a [`Tok::Comment`] (the section markers).
|
||||
//! - `%_` later in a line starts tokens too, hidden (a pseudo-comment operator after its
|
||||
//! operands, as a gradient stop's `… 50 100 %_Bs`: AI7 spec §1.4.3); any other `%` later in a
|
||||
//! line starts a comment that is skipped.
|
||||
//! line starts a comment that is skipped, but for a line of hex digits after `%_` (a hidden
|
||||
//! blend's record), a hidden [`Tok::Comment`].
|
||||
//! - The binary image data after `%%BeginData:` is one [`Tok::Data`]; the binary preview of a placed
|
||||
//! file is one [`Tok::Preview`].
|
||||
//! - A document included whole (`%%BeginDocument:` … `%%EndDocument` lines, DSC 3.0 p. 68, nested
|
||||
@@ -222,6 +223,12 @@ impl<'a> Lexer<'a> {
|
||||
if prefixed && PLACE.iter().chain(&NOTES).chain(&RELATIVE).any(|m| line.starts_with(m)) {
|
||||
return Some(Token { tok: Tok::Comment(line.get(1..).unwrap_or_default()), hidden: true });
|
||||
}
|
||||
// And a line of hex digits, as a hidden blend's record is written (`%_%4443…`
|
||||
// after its `XP`), like the plain one on `%` lines.
|
||||
let digits = line.get(1..).unwrap_or_default();
|
||||
if prefixed && !digits.trim_ascii_end().is_empty() && digits.trim_ascii_end().iter().all(u8::is_ascii_hexdigit) {
|
||||
return Some(Token { tok: Tok::Comment(digits), hidden: true });
|
||||
}
|
||||
// A comment later in a line.
|
||||
continue;
|
||||
}
|
||||
@@ -470,6 +477,10 @@ mod tests {
|
||||
let toks = all(b"1 % a note (\n2 %_Bs\n3 %_ 4\n");
|
||||
let words: Vec<_> = toks.iter().map(|t| (t.tok.clone(), t.hidden)).collect();
|
||||
assert_eq!(words, [(Tok::Num(1.0), false), (Tok::Num(2.0), false), (Tok::Word(b"Bs"), true), (Tok::Num(3.0), false)]);
|
||||
// A hidden line of hex digits (a hidden blend's record) is a comment; other text after
|
||||
// `%_%` stays skipped.
|
||||
let toks = all(b"%_%44434241\n%_% not hex\n%_%\n1\n");
|
||||
assert_eq!(toks, [t(Tok::Comment(b"44434241"), true), t(Tok::Num(1.0), false)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -9550,6 +9550,22 @@ fn a_blend_comes_in_as_a_live_blend() {
|
||||
assert!(!s.warnings.iter().any(|w| w == super::blend::DRAWN), "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A blend in an opacity mask's art is written on `%_` lines, its record's hex digits on `%_%`
|
||||
/// lines: it comes in live there too.
|
||||
#[test]
|
||||
fn a_blend_in_an_opacity_mask_comes_in_live() {
|
||||
let body = blend_file("%_10 50 m\n%_110 50 L\n", [Some("A"), Some("B")], &blend_record(&['A', 'B']));
|
||||
let mask_art: String = body.lines().map(|l| if l.starts_with("%_") { format!("{l}\n") } else { format!("%_{l}\n") }).collect();
|
||||
assert!(mask_art.contains("\n%_%44434241"), "{mask_art}");
|
||||
let mask = format!("%_/ArtDictionary :\n%_/Mask :\n%_X=\n%_u\n{mask_art}%_U\n%_X+\n%_(Art) ,\n%_; (AI9_Mask) ,\n%_;\n");
|
||||
let s = read_ok(&layer(&format!("{RED}0 0 m\n0 80 L\n80 80 L\n80 0 L\nf\n{mask}")));
|
||||
let m = art(&s.doc)[0].extras().mask.clone().expect("a mask");
|
||||
let blend = m.art.children().and_then(|c| c.first()).cloned().unwrap_or(m.art.clone());
|
||||
let NodeKind::Blend { children, spec } = &blend.kind else { panic!("a live blend: {:?} {:?}", blend.kind, s.warnings) };
|
||||
assert_eq!((children.len(), spec.spacing), (2, vectorcraft_doc::live::BlendSpacing::Steps(3)));
|
||||
assert!(!s.warnings.iter().any(|w| w == super::blend::DRAWN), "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A blend whose spine was never edited has no spine written, only its keys: its spine is the
|
||||
/// straight line between the keys' centers, in the record's order, and the blend comes in live.
|
||||
/// With the record naming the keys in their order (here the left key, named `B`, first) the blend
|
||||
|
||||
Reference in new issue
Block a user