Preserve EffectCraft source from 4035d181329e847d7a57bf3d059502ea2c91b560, based on Brandon Thomas original 94e1c86d89a866771f80ad1610afda9aa12e85d8. Algorithm unchanged; module imports only adapted.
Co-authored-by: Brandon Thomas <echelon@gmail.com>
XML readers skip an element, attribute list or notation declaration to its
first `>`, quotes and brackets included. The guard's scans now end these
declarations the same way. A `]` inside `<!ELEMENT svg ] >` no longer ends
the internal subset for `too_wide` and `prescan`, and a `[` in one no longer
lets a later `<!--` hide the entity declarations after it from `declared`.
declared() skipped a comment or CDATA section wherever `<!--` or
`<![CDATA[` appeared, including inside an entity's quoted value, another
declaration's literal or a processing instruction. With
`<!ENTITY c "<!--">` before a large entity, the scan skipped to the end
of the file, the large entity was never recorded, and
entities_expand_past let its references through to the XML reader.
- declared() reads a declaration's quoted literals and a processing
instruction as text: a comment or CDATA marker there starts nothing,
and the declarations after it are still read.
- prescan() counts the markup in an entity's value the same way, and a
comment, CDATA section or instruction that closes inside the value
still opens and closes no element.
- too_wide() and prescan() find the end of the internal subset past
quoted literals, comments and instructions, so a `]>` in a value no
longer ends the document type early.
* svg: floor declared() name window to a character boundary
If the MAX_NAME+1 cut split a UTF-8 character, get(..bound).unwrap_or(rest)
fell back to scanning the entire suffix. Floor the window instead, and
when recording an overlong name extend to the next character boundary so
the key is still longer than MAX_NAME.
* test(svg): assert declared() keys stay bounded after a multibyte cut
The overlong-name refusal alone also passed on the old unwrap_or(rest)
fallback, which recorded the whole suffix. Bound recorded keys to
MAX_NAME+4 so the test fails if the suffix is stored again.
* svg: a scene in local coordinates, with fill rules and element ids (#778, #789)
Document::from_tree_local keeps every node in its own user space, with its
transform relative to its parent, so an app can keep geometry editable apart
from where it is placed (EffectCraft's shape layers). Paths now carry their
fill rule, id and transform, and groups their id. from_tree is unchanged:
segments, strokes and group transforms stay absolute, path transforms are the
identity.
* craft-svg: place local text and glyph groups in their own frames (#789)
* svg: pattern paints carry their tile and content (#778, #789) (#1863)
Paint::Pattern now holds the resolved tile: id, rect, transform and the
content as scene nodes in tile space. Each pattern is converted once and
shared by every use; content past the depth limit, or a pattern that refers
back to itself, has none. In absolute scenes the tile transform maps to the
document.
* craft-svg: report scene-omitted group effects and unsupported elements (#789) (#1870)
tree::primitive::recognize (and Path::primitive) returns the axis-aligned
basic shape a path draws: one closed contour whose points all lie on a
(rounded) rectangle's or ellipse's outline and that encloses its area. usvg
turns rect, circle and ellipse into paths; apps that edit them as shapes get
them back from the segments.
#778, #789. Comments and CDATA are skipped, and a declaration name is
only scanned up to MAX_NAME+1, so a comment full of `<!ENTITYx` markers
is no longer a quadratic walk. Names longer than MAX_NAME are still
recorded so the expansion guard can refuse them. Closepath also clears
the smooth-control history, so S and T after Z start from the current
point rather than reflecting the pre-close control.
* svg: let SvgWriter name the encoding and write a DOCTYPE subset
VectorCraft's SVG document wrapper needs a Latin-1 declaration and a
<!DOCTYPE svg [ <!ENTITY …> ]> internal subset, including a minified
form with no extra newlines. The existing declaration was UTF-8 only,
and craft-xml's doctype helper writes only <!DOCTYPE name>.
Part of #778 and #789.
* svg: expose SvgWriter::as_str for a second pass on open markup
A consumer that rewrites character references or hashes the document
around a metadata element needs the text of an unclosed root. finish()
would close it first.
The geometry reader (craft_svg::paths) is the only part of the crate that
needs vectorcraft-geom and vectorcraft-pathops, and the tree is the only part
that needs craft-image-codecs. Both are now optional: paths is a default
feature and tree turns it on, so existing users build the same crate, while
an app that only needs SVG text, guards, path data, colours and the writer can
turn default features off and take no app crates or image codecs.
parse_color_alpha is parse_color keeping the alpha of #rgba, #rrggbbaa and
the fourth value of rgb()/hsl(). parse_color now calls it and still drops it.
Refs #778, #789
Correct the source-depth expectations (svg>g>path is 3 levels, 2 open), cover
Preflight and every rewrite_root_viewport refusal, and read a root width or
height written with px as the pixels the docs promise.
The base this branch was stacked on has landed separately: #1187 through #1182,
and #1198 through #1331 and #1465. Take main for everything outside crates/svg
so this PR carries only the SVG preflight and viewport rewrite.
In crates/svg, keep main's root_unitless_size, embedded data-URL and text-size
accounting, and check_document, now on top of the shared preflight. Embedded
SVGs still charge the reference-following height to the shared depth budget,
as on main, rather than the source depth.