Skip to content

Improved svg support#118

Merged
kunitoki merged 11 commits into
mainfrom
dev/improved_svg
Jun 27, 2026
Merged

Improved svg support#118
kunitoki merged 11 commits into
mainfrom
dev/improved_svg

Conversation

@kunitoki

Copy link
Copy Markdown
Owner

This pull request introduces a range of improvements and fixes to the SVG parsing and rendering code, with a focus on more accurate style inheritance, improved handling of SVG attributes (such as preserveAspectRatio, stroke-dasharray, and stroke-miterlimit), and a significant refactor of SVG filter primitive support. The changes also include bug fixes in XML entity handling and bounds calculation, as well as enhancements to code clarity and maintainability.

The most important changes are:

SVG Style and Attribute Handling Improvements

  • Improved inheritance of fill and stroke attributes in SVGParser::parseElement, ensuring child elements correctly inherit all relevant style properties from their parents unless explicitly overridden. This includes fill, stroke, opacity, dash array, join/cap, miter limit, and marker/clip attributes.
  • Enhanced stroke-dasharray and stroke-dashoffset parsing in both CSS and attribute styles, with correct handling of the "none" value and negative dash values being ignored. Added a strokeDashArrayNone flag to SVGElement to track explicit disabling of dashes. [1] [2] [3]
  • Changed stroke-miterlimit in SVGElement from a default value to std::optional, so it is only set if specified, and added support for inheriting it from parent elements. [1] [2]
  • Added support for parsing and storing preserveAspectRatio on the root SVG element, including fitting and justification, and storing these in SVGData. [1] [2]

SVG Filter Refactor

  • Refactored SVG filter support by introducing a base SVGFilterPrimitive class and specific primitives such as SVGFEBlend and SVGFEGaussianBlur, allowing for more extensible and accurate representation of SVG filter chains. The SVGFilter struct now contains a list of filter primitives instead of a single blur parameter.

SVG Parsing and Calculation Fixes

  • Improved bounds calculation in SVGDocument::calculateBounds to recursively visit all elements and apply transforms, ensuring accurate document bounds.
  • Fixed parsing of points attributes for polyline and polygon elements by removing empty strings from coordinate arrays. [1] [2]
  • Set the SVG viewBox to the computed bounds if no viewBox is specified but bounds are available, improving rendering of SVGs without explicit viewBox.

XML Entity Handling Bug Fixes

  • Fixed bugs in XML entity expansion and reading, ensuring correct substring indices are used when resolving entities, preventing parsing errors. [1] [2]

Code Quality and Maintenance

  • Added and clarified log messages, improved function signatures for clarity, and made minor code cleanups throughout the codebase. [1] [2] [3] [4]

These changes collectively improve SVG rendering fidelity, code extensibility, and robustness.

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.56780% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.91%. Comparing base (27cf12f) to head (adfb4b4).

Files with missing lines Patch % Lines
modules/yup_graphics/drawables/yup_Drawable.cpp 79.82% 46 Missing ⚠️
modules/yup_graphics/svg/yup_SVGParser.cpp 80.93% 41 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
+ Coverage   78.79%   78.91%   +0.11%     
==========================================
  Files         627      628       +1     
  Lines       61533    61870     +337     
==========================================
+ Hits        48487    48823     +336     
- Misses      13046    13047       +1     
Files with missing lines Coverage Δ
modules/yup_core/xml/yup_XmlDocument.cpp 84.28% <100.00%> (+1.94%) ⬆️
modules/yup_graphics/drawables/yup_Drawable.h 100.00% <100.00%> (ø)
modules/yup_graphics/svg/yup_SVGCssParser.cpp 99.63% <100.00%> (+<0.01%) ⬆️
modules/yup_graphics/svg/yup_SVGDocument.cpp 94.28% <100.00%> (+1.69%) ⬆️
modules/yup_graphics/svg/yup_SVGParser.cpp 81.71% <80.93%> (+1.36%) ⬆️
modules/yup_graphics/drawables/yup_Drawable.cpp 69.84% <79.82%> (+4.04%) ⬆️

... and 10 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27cf12f...adfb4b4. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kunitoki kunitoki merged commit 7730a90 into main Jun 27, 2026
40 checks passed
@kunitoki kunitoki deleted the dev/improved_svg branch June 27, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant