Repository navigation
Conversation
ImageLoad::fromSvg renders an SVG at a given resolution, fitted uniformly in the center. lunasvg is built from a pinned commit on every platform with external resources and system fonts disabled, so an SVG never reads files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opacity 0.5 gives alpha 127, and lunasvg resolves an inherited fill="currentColor" at the ancestor. use fan-out to 10^6 elements does not finish, so it is no longer in the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lunasvg's package config calls find_dependency(plutovg) without hints, which misses a thirdparty root that is not on CMAKE_PREFIX_PATH (macOS Homebrew builds). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fedr
left a comment
There was a problem hiding this comment.
The code itself looks right: convertToRGBA un-premultiplies, the rows are flipped into Image order, and the resolution limit in the header matches plutovg's kMaxSize check (Bitmap::isNull also catches a non-positive size). Delegating to lunasvg is a good trade for icons with gradients, clip paths and CSS. A few things to settle before merging:
-
Untrusted input. The PR body says
usefan-out can stall the call, but the header does not. Since this is a public function, please add a line there saying the SVG must come from a trusted source, as icons do. -
The no-file-reading guarantee depends on the build.
LUNASVG_DISABLE_EXTERNAL_RESOURCESis a PRIVATE compile definition of lunasvg, so a build that picks up a stock lunasvg reads the files an SVG refers to, with no sign of it in MeshLib. Examples are the official vcpkg port without the overlay, or a lunasvg found throughCMAKE_PREFIX_PATHbefore theHINTS. Thedata:vs file test catches this in our CI only, so it is worth a comment next tofind_package( lunasvg ). -
(nit)
thirdparty/CMakeLists.txtbuilds lunasvg even whenMRIOEXTRAS_NO_LUNASVGis ON. -
(nit)
MRIOExtrasConfig.cmakehasfind_dependency( lunasvg )for Emscripten, but lunasvg's config looks for plutovg without hints, which is the problem the third commit fixes for MeshLib itself. Afind_dependency( plutovg )before it would spare downstream Emscripten consumers the same failure.
oitel
left a comment
There was a problem hiding this comment.
Why is a local copy of the lunasvg's vcpkg port used?
plutovg computes byte sizes in int, so 2^29 pixels or more overflowed and crashed; such resolutions now return the resolution error. The image buffer is wrapped as the lunasvg bitmap instead of copying from a second one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Very fine dashes on a long path never finish in plutovg, and use references multiplying to about 10^6 elements stall lunasvg. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A viewBox with a non-zero origin is fitted in width and height of another aspect ratio. The embedded image is a fixed PNG literal, so the tests compile with MRIOEXTRAS_NO_PNG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both are private dependencies of MRIOExtras, not reachable from MeshLib's public headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review.
|
|
The registry port builds the v3.5.0 tag, which doesn't have |
The SVG must be trusted anyway, so an <image> file path may be read; this drops the overlay port and the pin past 3.5.0. Fonts stay unloaded on every build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lunasvg 3.5.0 does not parse an SVG starting with a UTF-8 BOM, and the static config of its bundled plutovg 1.3.1 links Threads::Threads without finding it. Tests cover an editor prolog and that text is not drawn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Follow-up: lunasvg is now built without |
lunasvg 3.5.0 reports the missing side from the viewBox aspect ratio but renders it as 100% of the viewBox, so such an SVG was drawn smaller and off-centre. The reported size is now written back to the root element before rendering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The removed hard inputs overflow float-to-long casts inside plutovg, so their result depends on the platform. Also lists the test file in the filters and plutovg-ft-types under FTL in the notices, and drops a redundant include. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No other MeshLib source uses std::ranges algorithms, so the tests use the iterator forms that every CI toolchain has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds
ImageLoad::fromSvg( file | data, resolution )in the newMRIOExtras/MRSvgImage.h: renders an SVG into anImageof the given size (up to 32767 per side and fewer than 2^29 pixels, the limits of plutovg), scaled uniformly to fit and centered. It replaces the FreeType rasterizer of #7652 with lunasvg, which covers nearly all of static SVG (gradients, clip paths, masks, CSS, symbols, units).New dependency: lunasvg 3.5.0 (MIT) with plutovg (MIT; its rasterizer and stroker are FreeType-derived, FTL). No fonts are loaded, so text is not drawn. An
<image>is drawn from adata:URI or read from its file path, relative to the current directory. Two lunasvg 3.5.0 gaps are worked around: it does not skip a UTF-8 BOM, sofromSvgstrips it; and it renders the missing side of an SVG with onlywidthor onlyheightas 100% of the viewBox, sofromSvgsets both to the size lunasvg reports.thirdparty/lunasvgat v3.5.0, with its bundled plutovg 1.3.1;MRIOEXTRAS_NO_LUNASVGturns it off. Credits:ThirdpartyList.md,THIRD-PARTY-NOTICES.txt,manifest.json, SBOM sources.The SVG must come from a trusted source (documented in the header), since some inputs take unbounded time or memory or crash:
usereferences that multiply to ~10^6 drawn elements do not finish in reasonable time (#7652 returned an error there); a dash much shorter than its path (stroke-dasharray="0.001"on a path 10^5 long) never finishes, since plutovg sums dash lengths in a float; a CSS:first-of-typeor:last-of-typeselector loops forever when the adjacent sibling is of another type; a mask or clip path whose element covers more than about 23000 px per side overflows plutovg. The last two are fixed upstream after 3.5.0.Other known lunasvg 3.5.0 behavior: an inherited
fill="currentColor"resolves at the ancestor; opacity 0.5 gives alpha 127.Test plan:
MRIOExtras.SvgImage*tests (Unicode file name, orientation, fill rule, opacity,use, aspect ratio, viewBox fitting with only width or height, prolog with BOM / XML declaration / DOCTYPE, no text, currentColor, dashes, gradients / CSS / symbol / clip path,data:image, errors and resolution limits, hard inputs), Release and Debug, Windows MSBuild with vcpkg lunasvg 3.5.0scripts/check_third_party_licenses.py,scripts/check_vcxproj.pyfind_package(Threads)from MRIOExtras)Generated with Claude Code