feat(svg): SvgIcon whole-file reader + addSvgIcon DSL stacking#173
Merged
Conversation
SvgIcon.read(file)/parse(xml) reads the practical icon subset of an SVG document: every path plus rect/circle/ellipse/line/polyline/polygon lowered to synthesized path data through the one tested parser, g-nesting with translate/scale/rotate/matrix transforms accumulated as exact affines on Bezier control points (via a package-private SvgPath.parseTransformed hook), and fill/stroke/stroke-width styling with SVG inheritance and defaults (missing fill = black, none skips, style attribute wins). addSvgIcon(icon, width) stacks the ordered layers back-to-front through LayerStack. Security: DOCTYPE refused (XXE cannot reach the file system). Out of scope by design: gradients, CSS, text, filters. 11 SvgIconTest cases incl. exact transform math, inheritance, XXE refusal and the DSL bridge; example ships a two-tone badge via SvgIcon.parse. Full gate: see below.
| } | ||
| String widthAttr = attrOrStyle(element, "stroke-width"); | ||
| if (widthAttr != null) { | ||
| strokeWidth = Double.parseDouble(widthAttr.replace("px", "").trim()); |
|
|
||
| private static double num(Element element, String attribute) { | ||
| String value = element.getAttribute(attribute).trim(); | ||
| return value.isEmpty() ? 0.0 : Double.parseDouble(value); |
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stacked on #172 (uses
SvgPath+ a package-privateparseTransformedaffine hook). Whole SVG files now drop into documents:<path>+rect/circle/ellipse/line/polyline/polygonlowered to synthesized path data through the one tested parser;<g>nesting withtranslate/scale/rotate/matrixaccumulated as exact affines (affine maps are exact on Bézier control points);fill/stroke/stroke-widthwith SVG inheritance and defaults (missing fill = black,noneskips,style=""wins over inherited).addSvgIcon(icon, width)on every flow builder — ordered layers throughLayerStack, height from the icon's aspect ratio.<use>.Verification
SvgIconTestcases: layer order/paints, black-fill default +none, shape lowering (circle → arc cubics), exacttranslate·scaleandrotate(90° about center)coordinates, inheritance +styleprecedence, width/height fallback, DOCTYPE refusal, four context-carrying error contracts, DSL bridge end-to-end../mvnw verify -pl .— 1287 tests, 0 failures, BUILD SUCCESS.Merge order
Stacked: merge #172 first (without deleting its branch), retarget this PR to develop, then merge.