feat(svg): stroke fidelity + colour/unit hardening for the beta SVG reader#180
Merged
Conversation
…eader - stroke-linecap/linejoin → native PDF J/j operators (new DocumentLineCap/ DocumentLineJoin, PathBuilder.lineCap()/lineJoin()); emitted only when non-default so default-styled output stays byte-identical - stroke-dasharray honoured; 147 CSS named colours, rgb()/rgba() with numbers or percentages, #rgb/#rgba/#rrggbb/#rrggbbaa hex, absolute length units (px/pt/pc/in/mm/cm) on stroke widths — all in new SvgColors/SvgStyles - fix: SvgIcon#node(width) now scales stroke width AND dash lengths by width/sourceWidth (they live in user units) — icons drawn below source size no longer render over-thick outlines - loud skips: one deduplicated warn-log per dropped kind in the reader (text/image/use/...) and in DocxSemanticBackend (geometry-only nodes); LayerStackNode/CanvasLayerNode now recurse so child text survives DOCX - unknown colours / relative units fail with the supported set listed - VectorPathExample gains a caps & joins demo; +22 tests
| int colon = entry.indexOf(':'); | ||
| String hex = entry.substring(colon + 1); | ||
| map.put(entry.substring(0, colon), DocumentColor.rgb( | ||
| Integer.parseInt(hex.substring(0, 2), 16), |
| String hex = entry.substring(colon + 1); | ||
| map.put(entry.substring(0, colon), DocumentColor.rgb( | ||
| Integer.parseInt(hex.substring(0, 2), 16), | ||
| Integer.parseInt(hex.substring(2, 4), 16), |
| map.put(entry.substring(0, colon), DocumentColor.rgb( | ||
| Integer.parseInt(hex.substring(0, 2), 16), | ||
| Integer.parseInt(hex.substring(2, 4), 16), | ||
| Integer.parseInt(hex.substring(4, 6), 16))); |
| return null; | ||
| } | ||
| DocumentColor color = DocumentColor.rgb( | ||
| Integer.parseInt(expanded.substring(0, 2), 16), |
| } | ||
| DocumentColor color = DocumentColor.rgb( | ||
| Integer.parseInt(expanded.substring(0, 2), 16), | ||
| Integer.parseInt(expanded.substring(2, 4), 16), |
| Integer.parseInt(expanded.substring(2, 4), 16), | ||
| Integer.parseInt(expanded.substring(4, 6), 16)); | ||
| if (expanded.length() == 8) { | ||
| color = color.withOpacity(Integer.parseInt(expanded.substring(6, 8), 16) / 255.0); |
| private static int channel(String value) { | ||
| String t = value.trim(); | ||
| if (t.endsWith("%")) { | ||
| double pct = Math.max(0, Math.min(100, Double.parseDouble(t.substring(0, t.length() - 1)))); |
| // pct/100*255 keeps 50% exact (127.5 → 128); pct*2.55 drifts to 127. | ||
| return (int) Math.round(pct / 100.0 * 255.0); | ||
| } | ||
| return Math.max(0, Math.min(255, (int) Math.round(Double.parseDouble(t)))); |
| private static double alpha(String value) { | ||
| String t = value.trim(); | ||
| double a = t.endsWith("%") | ||
| ? Double.parseDouble(t.substring(0, t.length() - 1)) / 100.0 |
| String t = value.trim(); | ||
| double a = t.endsWith("%") | ||
| ? Double.parseDouble(t.substring(0, t.length() - 1)) / 100.0 | ||
| : Double.parseDouble(t); |
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.
Hardening pass that makes the beta SVG surface render real-world exporter output faithfully — including the GraphCompose brand logos at any size.
Stroke fidelity
stroke-linecap/stroke-linejoin→ native PDFJ/joperators via newDocumentLineCap/DocumentLineJoin(also onPathBuilder.lineCap()/lineJoin()). Emitted only when non-default, so default-styled output is byte-identical (negative test guards it).stroke-dasharrayhonoured (odd lists doubled, all-zero = solid).SvgIcon#node(width)now scales stroke width and dash lengths bywidth/sourceWidth— they live in SVG user units. Icons drawn below source size previously rendered over-thick outlines (visible on the brand mark at 48 pt).Colour & unit grammar (new
SvgColors/SvgStyles)rgb()/rgba()with numbers or percentages,#rgb/#rgba/#rrggbb/#rrggbbaahex, absolute units (px/pt/pc/in/mm/cm) on stroke widths.em,%) fail with the supported set listed — never a wrong render.Loud skips (no more silent content loss)
text,image,use, masks, clips, filters) instead of silently.DocxSemanticBackendwarns once per geometry-only node kind it drops;LayerStackNode/CanvasLayerNodenow recurse so their semantic child text survives the Word export.Verification
./mvnw verify -pl .→ BUILD SUCCESS, +22 tests (SvgStylesTest,PdfPathStrokeStyleTestJ/j operator assertions,DocxGeometryDropTest, plus SVG-level cases inSvgIconTest/PathBuilderTest).assets/*.svgbrand logos render 1:1 at any size; the three marks now share a uniform relative stroke thickness (the scaling fix) with rounded caps/joins.VectorPathExamplegains a butt/round/square caps & joins demo;vector-path.pdfpreview refreshed.Senior-reviewed (six-lane) before commit; one consistency fix applied (CanvasLayerNode recursion). Independent of any other branch — clean off develop.
Next planned SVG feature:
ShapeOutline.path(...)clipper.