diff --git a/.github/actions/install-macos-thirdparty/action.yml b/.github/actions/install-macos-thirdparty/action.yml
index 4b32f14bc0e0..10608b7a7175 100644
--- a/.github/actions/install-macos-thirdparty/action.yml
+++ b/.github/actions/install-macos-thirdparty/action.yml
@@ -90,6 +90,7 @@ runs:
thirdparty/tinygltf \
thirdparty/laz-perf \
thirdparty/draco \
+ thirdparty/lunasvg \
thirdparty/clip \
thirdparty/fastmcpp
shasum -a 256 \
diff --git a/.gitmodules b/.gitmodules
index 83e508a0b61f..9e640971ec7a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -90,3 +90,6 @@
[submodule "thirdparty/draco"]
path = thirdparty/draco
url = https://github.com/google/draco
+[submodule "thirdparty/lunasvg"]
+ path = thirdparty/lunasvg
+ url = https://github.com/sammycage/lunasvg.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 292225921203..14666c6c4539 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -232,6 +232,7 @@ if(MESHLIB_USE_VCPKG)
opencascade xercesc openssl curl cpr
gdcm[^/]* socketxx openjph openjpeg-[^/]*
E57Format hpdf[^/]* tiff[^/]* tinyxml2\\.h tiny_?gltf[^/]* stb_[^/]*
+ lunasvg plutovg
)
list(JOIN VCPKG_PRIVATE_HEADERS "|" VCPKG_PRIVATE_HEADERS)
install(
diff --git a/doxygen/general_pages/ThirdpartyList.md b/doxygen/general_pages/ThirdpartyList.md
index dbb12bdae1d8..9a1f042e3782 100644
--- a/doxygen/general_pages/ThirdpartyList.md
+++ b/doxygen/general_pages/ThirdpartyList.md
@@ -55,6 +55,8 @@ Below is a summary of all modules and their dependencies, so you can see what ea
|Draco |library for compressing and decompressing 3D meshes and point clouds |Apache 2.0 |
|libe57format |library for reading & writing the E57 file format |Boost Software License |
|tinyxml2 |an efficient, C++ XML parser |zlib |
+|lunasvg |SVG rendering library in C++ |MIT |
+|plutovg |tiny 2D vector graphics library in C, used by lunasvg |MIT, FTL (FreeType License) |
|nlohmann-json |JSON for Modern C++ — used by the glTF reader/writer |MIT |
### MRSymbolMesh
diff --git a/requirements/vcpkg-linux.txt b/requirements/vcpkg-linux.txt
index aa601ea42c13..ca15edd59ffb 100644
--- a/requirements/vcpkg-linux.txt
+++ b/requirements/vcpkg-linux.txt
@@ -23,6 +23,7 @@ libe57format
libharu
libjpeg-turbo
libzip
+lunasvg
mimalloc
opencascade-minimal
openctm
diff --git a/requirements/windows.txt b/requirements/windows.txt
index 9f2a3db802c9..06c8e118c1cb 100644
--- a/requirements/windows.txt
+++ b/requirements/windows.txt
@@ -19,6 +19,7 @@ laz-perf
libe57format
libharu
libzip
+lunasvg
mimalloc[override]
opencascade-minimal
openctm
diff --git a/scripts/clone_submodules_emscripten_thirdparty.sh b/scripts/clone_submodules_emscripten_thirdparty.sh
index 0448816f9f43..eedc66273d38 100755
--- a/scripts/clone_submodules_emscripten_thirdparty.sh
+++ b/scripts/clone_submodules_emscripten_thirdparty.sh
@@ -18,6 +18,7 @@ SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
thirdparty/libE57Format \
thirdparty/libjpeg-turbo \
thirdparty/libzip \
+ thirdparty/lunasvg \
thirdparty/mbedtls \
thirdparty/onetbb \
thirdparty/OpenCTM-git \
diff --git a/scripts/clone_submodules_macos.sh b/scripts/clone_submodules_macos.sh
index 8a6937cef026..4ac0f5139519 100755
--- a/scripts/clone_submodules_macos.sh
+++ b/scripts/clone_submodules_macos.sh
@@ -16,6 +16,7 @@ if [[ $1 != --vcpkg ]]; then
thirdparty/glad
thirdparty/laz-perf
thirdparty/libE57Format
+ thirdparty/lunasvg
thirdparty/OpenCTM-git
thirdparty/tinygltf
)
diff --git a/scripts/sbom/vcpkg-sources.json b/scripts/sbom/vcpkg-sources.json
index b6cd0ce64df2..f930268e9f65 100644
--- a/scripts/sbom/vcpkg-sources.json
+++ b/scripts/sbom/vcpkg-sources.json
@@ -17,6 +17,7 @@
"Draco": ["draco"],
"libE57Format": ["libe57format"],
"tinyxml2": ["tinyxml2"],
+ "lunasvg": ["lunasvg"],
"nlohmann-json": ["nlohmann-json"],
"OpenVDB": ["openvdb"],
"GDCM": ["gdcm"],
diff --git a/source/MRIOExtras/CMakeLists.txt b/source/MRIOExtras/CMakeLists.txt
index f5cc823523bc..d79b889cbc7b 100644
--- a/source/MRIOExtras/CMakeLists.txt
+++ b/source/MRIOExtras/CMakeLists.txt
@@ -6,6 +6,7 @@ option(MRIOEXTRAS_NO_E57 "Disable E57 support" OFF)
option(MRIOEXTRAS_NO_GLTF "Disable glTF support" OFF)
option(MRIOEXTRAS_NO_JPEG "Disable JPEG support" OFF)
option(MRIOEXTRAS_NO_LAS "Disable LAS/LAZ support" OFF)
+option(MRIOEXTRAS_NO_LUNASVG "Disable SVG rasterization" OFF)
option(MRIOEXTRAS_NO_PDF "Disable PDF support" OFF)
option(MRIOEXTRAS_NO_PNG "Disable PNG support" OFF)
option(MRIOEXTRAS_NO_STEP "Disable STEP support" OFF)
@@ -74,6 +75,19 @@ IF(NOT MRIOEXTRAS_NO_LAS)
target_link_libraries(${PROJECT_NAME} PRIVATE LAZPERF::lazperf)
ENDIF()
+IF(NOT MRIOEXTRAS_NO_LUNASVG)
+ # static plutovg 1.3.1 links Threads::Threads, but its config does not find it
+ find_package(Threads)
+ # found first with the hints, since lunasvg's config looks for it without them
+ find_package(plutovg CONFIG REQUIRED
+ HINTS "${MESHLIB_THIRDPARTY_ROOT_DIR}"
+ )
+ find_package(lunasvg CONFIG REQUIRED
+ HINTS "${MESHLIB_THIRDPARTY_ROOT_DIR}"
+ )
+ target_link_libraries(${PROJECT_NAME} PRIVATE lunasvg::lunasvg)
+ENDIF()
+
IF(NOT MRIOEXTRAS_NO_PDF)
target_link_libraries(${PROJECT_NAME} PRIVATE hpdf)
ENDIF()
diff --git a/source/MRIOExtras/MRIOExtras.vcxproj b/source/MRIOExtras/MRIOExtras.vcxproj
index 6b2c4f1c664e..94d0dd035b8a 100644
--- a/source/MRIOExtras/MRIOExtras.vcxproj
+++ b/source/MRIOExtras/MRIOExtras.vcxproj
@@ -45,6 +45,7 @@
+
@@ -65,6 +66,7 @@
+ 15.0
diff --git a/source/MRIOExtras/MRIOExtrasConfig.cmake b/source/MRIOExtras/MRIOExtrasConfig.cmake
index 6288fa1ba3d0..ca40cc48339c 100644
--- a/source/MRIOExtras/MRIOExtrasConfig.cmake
+++ b/source/MRIOExtras/MRIOExtrasConfig.cmake
@@ -5,6 +5,8 @@ if(EMSCRIPTEN)
find_dependency(OpenCTM)
find_dependency(draco)
find_dependency(LAZPERF)
+ find_dependency(Threads) # plutovg 1.3.1's config does not find it
+ find_dependency(lunasvg)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/MRIOExtrasTargets.cmake")
diff --git a/source/MRIOExtras/MRSvgImage.cpp b/source/MRIOExtras/MRSvgImage.cpp
new file mode 100644
index 000000000000..506e84ecd23c
--- /dev/null
+++ b/source/MRIOExtras/MRSvgImage.cpp
@@ -0,0 +1,65 @@
+#include "MRSvgImage.h"
+#ifndef MRIOEXTRAS_NO_LUNASVG
+#include
+#include
+#include
+
+#include
+
+#include
+#include
+
+namespace MR::ImageLoad
+{
+
+Expected fromSvg( const std::filesystem::path& file, const Vector2i& resolution )
+{
+ std::ifstream in( file, std::ifstream::binary );
+ if ( !in )
+ return unexpected( "Cannot open file for reading " + utf8string( file ) );
+
+ return addFileNameInError( readCharBuffer( in ).and_then( [&] ( Buffer&& buf )
+ {
+ return fromSvg( buf.data(), buf.size(), resolution );
+ } ), file );
+}
+
+Expected fromSvg( const char* data, size_t size, const Vector2i& resolution )
+{
+ // lunasvg 3.5.0 does not skip a UTF-8 BOM
+ if ( hasBom( { data, size } ) )
+ {
+ data += 3;
+ size -= 3;
+ }
+ const auto doc = lunasvg::Document::loadFromData( data, size );
+ if ( !doc )
+ return unexpected( "Failed to parse SVG" );
+ const float width = doc->width();
+ const float height = doc->height();
+ if ( !( width > 0 && height > 0 ) )
+ return unexpected( "SVG has empty size" );
+ // lunasvg 3.5.0 renders a missing width or height as 100% of the viewBox, not as the reported size
+ doc->documentElement().setAttribute( "width", fmt::format( "{}", width ) );
+ doc->documentElement().setAttribute( "height", fmt::format( "{}", height ) );
+
+ // plutovg needs each side below 2^15 and computes byte sizes of the image in int
+ if ( resolution.x <= 0 || resolution.y <= 0 || resolution.x >= 32768 || resolution.y >= 32768
+ || size_t( resolution.x ) * size_t( resolution.y ) >= ( size_t( 1 ) << 29 ) )
+ return unexpected( "Invalid image resolution" );
+
+ Image image{ .pixels = std::vector( size_t( resolution.x ) * resolution.y, Color::transparent() ), .resolution = resolution };
+ lunasvg::Bitmap bitmap( ( uint8_t* )image.pixels.data(), resolution.x, resolution.y, resolution.x * 4 );
+ const float scale = std::min( resolution.x / width, resolution.y / height );
+ doc->render( bitmap, lunasvg::Matrix( scale, 0, 0, scale, ( resolution.x - scale * width ) / 2, ( resolution.y - scale * height ) / 2 ) );
+ bitmap.convertToRGBA();
+
+ // bitmap rows go from top to bottom, image rows from bottom to top
+ const auto row = [&] ( int y ) { return image.pixels.begin() + size_t( y ) * resolution.x; };
+ for ( int y = 0; y < resolution.y / 2; ++y )
+ std::swap_ranges( row( y ), row( y + 1 ), row( resolution.y - 1 - y ) );
+ return image;
+}
+
+} // namespace MR::ImageLoad
+#endif
diff --git a/source/MRIOExtras/MRSvgImage.h b/source/MRIOExtras/MRSvgImage.h
new file mode 100644
index 000000000000..e6470a9093d9
--- /dev/null
+++ b/source/MRIOExtras/MRSvgImage.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "config.h"
+#ifndef MRIOEXTRAS_NO_LUNASVG
+#include "exports.h"
+
+#include
+#include
+
+#include
+
+namespace MR::ImageLoad
+{
+
+/// rasterizes .SVG file into an image of given resolution (from 1 to 32767 in each dimension, fewer than 2^29 pixels in total), the SVG is scaled uniformly to fit the image and centered;
+/// unsupported SVG features are skipped, text is not drawn, and an image given by a file path is read from that path (relative to the current directory);
+/// the SVG must come from a trusted source, since some inputs take unbounded time or memory, or crash
+MRIOEXTRAS_API Expected fromSvg( const std::filesystem::path& file, const Vector2i& resolution );
+MRIOEXTRAS_API Expected fromSvg( const char* data, size_t size, const Vector2i& resolution );
+
+} // namespace MR::ImageLoad
+#endif
diff --git a/source/MRIOExtras/config_cmake.h.in b/source/MRIOExtras/config_cmake.h.in
index 4159ba200920..dd78c7c87100 100644
--- a/source/MRIOExtras/config_cmake.h.in
+++ b/source/MRIOExtras/config_cmake.h.in
@@ -6,6 +6,7 @@
#cmakedefine MRIOEXTRAS_NO_GLTF
#cmakedefine MRIOEXTRAS_NO_JPEG
#cmakedefine MRIOEXTRAS_NO_LAS
+#cmakedefine MRIOEXTRAS_NO_LUNASVG
#cmakedefine MRIOEXTRAS_NO_PDF
#cmakedefine MRIOEXTRAS_NO_PNG
#cmakedefine MRIOEXTRAS_NO_STEP
diff --git a/source/MRTest/MRSvgImageTests.cpp b/source/MRTest/MRSvgImageTests.cpp
new file mode 100644
index 000000000000..fcb91a469368
--- /dev/null
+++ b/source/MRTest/MRSvgImageTests.cpp
@@ -0,0 +1,248 @@
+#include
+#ifndef MRIOEXTRAS_NO_LUNASVG
+#include
+#include
+
+#include
+#include
+#include
+
+namespace MR
+{
+
+static Expected rasterize( const std::string& svg, const Vector2i& res )
+{
+ return ImageLoad::fromSvg( svg.data(), svg.size(), res );
+}
+
+// a file with symbols outside of any single code page in its name must be opened on Windows as well
+TEST( MRIOExtras, SvgImageUnicodeFileName )
+{
+ UniqueTemporaryFolder folder;
+ ASSERT_TRUE( bool( folder ) );
+ const auto path = folder / std::filesystem::path( u8"тест 文件 é.svg" );
+ std::ofstream( path, std::ofstream::binary ) << R"()";
+
+ const auto image = ImageLoad::fromSvg( path, { 2, 1 } );
+ ASSERT_TRUE( image ) << image.error();
+ EXPECT_EQ( ( *image )[Vector2i( 0, 0 )], Color::black() );
+ EXPECT_EQ( ( *image )[Vector2i( 1, 0 )], Color::transparent() );
+
+ const auto absent = ImageLoad::fromSvg( folder / "absent.svg", { 2, 1 } );
+ ASSERT_FALSE( absent );
+ EXPECT_TRUE( absent.error().starts_with( "Cannot open file for reading" ) ) << absent.error();
+}
+
+TEST( MRIOExtras, SvgImageRasterize )
+{
+ // red top-left quadrant, and blue horizontal line 1 wide at y = 3
+ const auto image = rasterize( R"svg()svg", { 8, 8 } );
+ ASSERT_TRUE( image ) << image.error();
+ ASSERT_EQ( image->resolution, Vector2i( 8, 8 ) );
+ // image rows go from bottom to top
+ EXPECT_EQ( ( *image )[Vector2i( 1, 6 )], Color::red() );
+ EXPECT_EQ( ( *image )[Vector2i( 6, 6 )], Color::transparent() );
+ EXPECT_EQ( ( *image )[Vector2i( 5, 3 )], Color::transparent() );
+ EXPECT_EQ( ( *image )[Vector2i( 5, 2 )], Color::blue() );
+ EXPECT_EQ( ( *image )[Vector2i( 5, 1 )], Color::blue() );
+ EXPECT_EQ( ( *image )[Vector2i( 5, 0 )], Color::transparent() );
+
+ // the stroke width is scaled by the group transform, so the line at y = 4 is 2 pixels wide
+ const auto scaled = rasterize( R"svg()svg", { 8, 8 } );
+ ASSERT_TRUE( scaled ) << scaled.error();
+ for ( int y = 2; y <= 5; ++y )
+ EXPECT_EQ( ( *scaled )[Vector2i( 4, y )], y == 3 || y == 4 ? Color::black() : Color::transparent() ) << y;
+}
+
+TEST( MRIOExtras, SvgImageFillRuleOpacity )
+{
+ const auto ring = [] ( const std::string& rule )
+ {
+ return rasterize( R"()", { 4, 4 } );
+ };
+ const auto evenOdd = ring( "evenodd" );
+ ASSERT_TRUE( evenOdd ) << evenOdd.error();
+ EXPECT_EQ( ( *evenOdd )[Vector2i( 0, 0 )], Color::black() );
+ EXPECT_EQ( ( *evenOdd )[Vector2i( 1, 1 )], Color::transparent() );
+ const auto nonZero = ring( "nonzero" );
+ ASSERT_TRUE( nonZero ) << nonZero.error();
+ EXPECT_EQ( ( *nonZero )[Vector2i( 1, 1 )], Color::black() );
+
+ // group opacity applies to the group as a whole, so the overlap of its rectangles is not darker
+ const auto image = rasterize( R"()", { 2, 1 } );
+ ASSERT_TRUE( image ) << image.error();
+ EXPECT_EQ( ( *image )[Vector2i( 0, 0 )], Color( 255, 255, 255, 127 ) );
+ EXPECT_EQ( ( *image )[Vector2i( 1, 0 )], Color( 255, 255, 255, 127 ) );
+}
+
+// use draws the referenced element moved by x, y and its transform, which inherits the style of use but keeps its own, also through a group or another use;
+// opacity of use applies to the drawn element, the elements in defs are not drawn by themselves, and a reference to a missing element draws nothing
+TEST( MRIOExtras, SvgImageUse )
+{
+ const auto image = rasterize( R"svg()svg", { 7, 1 } );
+ ASSERT_TRUE( image ) << image.error();
+ const Color expected[] = { Color::red(), Color::blue(), Color::green(), Color::red(), Color::blue(), Color( 0, 0, 0, 127 ), Color::transparent() };
+ for ( int x = 0; x < 7; ++x )
+ EXPECT_EQ( ( *image )[Vector2i( x, 0 )], expected[x] ) << x;
+}
+
+// the SVG is fitted uniformly in the center of a non-square image
+TEST( MRIOExtras, SvgImageAspectRatio )
+{
+ const std::string svg = R"()";
+ for ( const auto& res : { Vector2i( 4, 2 ), Vector2i( 2, 4 ) } )
+ {
+ const auto image = rasterize( svg, res );
+ ASSERT_TRUE( image ) << image.error();
+ // columns or rows 0 and 3 are empty
+ for ( int y = 0; y < res.y; ++y )
+ for ( int x = 0; x < res.x; ++x )
+ EXPECT_EQ( ( *image )[Vector2i( x, y )], ( res.x > res.y ? x : y ) % 3 == 0 ? Color::transparent() : Color::black() ) << x << ' ' << y;
+ }
+}
+
+// the viewBox, whose origin is not at zero as in icons with viewBox="0 -960 960 960", is fitted in the center of width and height
+TEST( MRIOExtras, SvgImageViewBox )
+{
+ // red square at the top left of the viewBox, blue one at the bottom right
+ const auto image = rasterize( R"()", { 12, 6 } );
+ ASSERT_TRUE( image ) << image.error();
+ // 2 pixels per viewBox unit, columns 0, 1, 10, 11 and rows 0, 5 are empty
+ for ( int y = 0; y < 6; ++y )
+ for ( int x = 0; x < 12; ++x )
+ EXPECT_EQ( ( *image )[Vector2i( x, y )], x >= 2 && x < 4 && y >= 3 && y < 5 ? Color::red() : x >= 8 && x < 10 && y >= 1 && y < 3 ? Color::blue() : Color::transparent() ) << x << ' ' << y;
+
+ // with only width or only height, the other side follows the aspect ratio of the viewBox
+ for ( const std::string size : { R"(width="4")", R"(height="2")" } )
+ {
+ const auto filled = rasterize( ")", { 4, 2 } );
+ ASSERT_TRUE( filled ) << filled.error();
+ EXPECT_EQ( std::count( filled->pixels.begin(), filled->pixels.end(), Color::red() ), 8 ) << size;
+ }
+}
+
+// currentColor is the color property of the element, even if it is inherited or set after it
+TEST( MRIOExtras, SvgImageCurrentColor )
+{
+ const auto image = rasterize( R"()", { 6, 3 } );
+ ASSERT_TRUE( image ) << image.error();
+ for ( int x : { 1, 4 } )
+ EXPECT_EQ( ( *image )[Vector2i( x, 1 )], Color::red() ) << x;
+}
+
+TEST( MRIOExtras, SvgImageDashes )
+{
+ // a stroke through the only row of pixels, dash ends are on pixel borders; opaque is '#', transparent is '.', otherwise '?'
+ const auto row = [] ( const std::string& stroke )
+ {
+ const auto image = rasterize( R"svg(", { 10, 1 } );
+ if ( !image )
+ return image.error();
+ std::string res;
+ for ( const auto& c : image->pixels )
+ res += c.a == 255 ? '#' : c.a == 0 ? '.' : '?';
+ return res;
+ };
+ EXPECT_EQ( row( R"(d="M0 0.5H8" stroke-dasharray="2")" ), "##..##...." );
+ EXPECT_EQ( row( R"(d="M0 0.5H8" stroke-dasharray="2 2" stroke-dashoffset="1")" ), "#..##..#.." );
+ EXPECT_EQ( row( R"(d="M0 0.5H8" stroke-dasharray="2,2" stroke-dashoffset="-1")" ), ".##..##..." );
+ EXPECT_EQ( row( R"(d="M0 0.5H8" style="stroke-dasharray: 1, 2, 3")" ), "#..###.#.." );
+ EXPECT_EQ( row( R"(d="M0 0.5H8" stroke-dasharray="0 0")" ), "########.." );
+}
+
+// features beyond plain shapes: gradients, style sheets, symbols, clip paths as exported from Figma
+TEST( MRIOExtras, SvgImageFeatures )
+{
+ const auto image = rasterize( R"svg()svg", { 8, 2 } );
+ ASSERT_TRUE( image ) << image.error();
+ const Color expected[] = { Color::red(), Color::red(), Color::blue(), Color::blue(), Color::green(), Color::green(), Color::black(), Color::transparent() };
+ for ( int x = 0; x < 8; ++x )
+ EXPECT_EQ( ( *image )[Vector2i( x, 0 )], expected[x] ) << x;
+}
+
+// a file as saved by editors: BOM, XML declaration, comment, DOCTYPE; text is not drawn, since no fonts are loaded
+TEST( MRIOExtras, SvgImageProlog )
+{
+ const auto image = rasterize( "\xEF\xBB\xBF" R"()"
+ R"()"
+ R"()", { 20, 10 } );
+ ASSERT_TRUE( image ) << image.error();
+ for ( int y = 0; y < 10; ++y )
+ for ( int x = 0; x < 20; ++x )
+ EXPECT_EQ( ( *image )[Vector2i( x, y )], x < 10 ? Color::red() : Color::transparent() ) << x << ' ' << y;
+}
+
+// an image is drawn from a data: URI
+TEST( MRIOExtras, SvgImageEmbeddedImage )
+{
+ // 1x1 red PNG
+ const auto image = rasterize( R"()", { 1, 1 } );
+ ASSERT_TRUE( image ) << image.error();
+ EXPECT_EQ( ( *image )[Vector2i( 0, 0 )], Color::red() );
+}
+
+TEST( MRIOExtras, SvgImageErrors )
+{
+ const std::pair errors[] = {
+ { "", "Failed to parse SVG" },
+ { "", "Failed to parse SVG" },
+ { "", "SVG has empty size" },
+ { R"()", "SVG has empty size" },
+ };
+ for ( const auto& [svg, error] : errors )
+ {
+ const auto image = rasterize( svg, { 1, 1 } );
+ ASSERT_FALSE( image ) << svg;
+ EXPECT_EQ( image.error(), error ) << svg;
+ }
+ for ( const Vector2i& res : { Vector2i( 0, 1 ), Vector2i( -1, 10 ), Vector2i( 32768, 1 ), Vector2i( 23200, 23200 ) } )
+ {
+ const auto invalid = rasterize( R"()", res );
+ ASSERT_FALSE( invalid ) << res.x << " " << res.y;
+ EXPECT_EQ( invalid.error(), "Invalid image resolution" );
+ }
+ // the largest side is accepted
+ const auto widest = rasterize( R"()", { 32767, 1 } );
+ ASSERT_TRUE( widest ) << widest.error();
+ EXPECT_TRUE( std::all_of( widest->pixels.begin(), widest->pixels.end(), [] ( const Color& c ) { return c == Color::red(); } ) );
+}
+
+// inputs that made other rasterizers fail or loop: deep and cyclic references, too many dashes
+TEST( MRIOExtras, SvgImageHardInputs )
+{
+ const auto chain = [] ( int length )
+ {
+ std::string shapes = R"()";
+ for ( int i = 1; i <= length; ++i )
+ shapes += "";
+ return shapes + "";
+ };
+ const std::string shapes[] = {
+ chain( 200 ),
+ R"svg()svg",
+ R"svg()svg",
+ R"()",
+ };
+ for ( const auto& s : shapes )
+ {
+ const auto image = rasterize( R"(", { 2, 1 } );
+ EXPECT_TRUE( image ) << s.substr( 0, 100 ) << ": " << image.error();
+ }
+}
+
+} // namespace MR
+#endif
diff --git a/source/MRTest/MRTest.vcxproj b/source/MRTest/MRTest.vcxproj
index c2cd58e31829..ca275a5e5b6f 100644
--- a/source/MRTest/MRTest.vcxproj
+++ b/source/MRTest/MRTest.vcxproj
@@ -74,6 +74,7 @@
+
diff --git a/source/MRTest/MRTest.vcxproj.filters b/source/MRTest/MRTest.vcxproj.filters
index 0c423b5f851a..98509af12096 100644
--- a/source/MRTest/MRTest.vcxproj.filters
+++ b/source/MRTest/MRTest.vcxproj.filters
@@ -76,6 +76,9 @@
Source Files
+
+ Source Files
+ Source Files
diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt
index ea7f3d1ca9c7..afcb966f3339 100644
--- a/thirdparty/CMakeLists.txt
+++ b/thirdparty/CMakeLists.txt
@@ -201,3 +201,8 @@ IF(NOT draco_FOUND)
ENDIF()
add_subdirectory(./draco)
ENDIF()
+
+set(LUNASVG_BUILD_EXAMPLES OFF)
+# loads no fonts, as vcpkg's plutovg by default
+set(PLUTOVG_DISABLE_FONT_FACE_CACHE_LOAD ON)
+add_subdirectory(./lunasvg)
diff --git a/thirdparty/cpm/package-lock.cmake b/thirdparty/cpm/package-lock.cmake
index ccbfe41541c2..36645843b0c7 100644
--- a/thirdparty/cpm/package-lock.cmake
+++ b/thirdparty/cpm/package-lock.cmake
@@ -124,6 +124,11 @@ set(MESHLIB_PACKAGE_libzip
GIT_TAG v1.11.4
)
+set(MESHLIB_PACKAGE_lunasvg
+ GIT_REPOSITORY https://github.com/sammycage/lunasvg.git
+ GIT_TAG 83c58df8103dc7dca423dfd824992af94d49bed6
+)
+
set(MESHLIB_PACKAGE_mbedtls
GIT_REPOSITORY https://github.com/Mbed-TLS/mbedtls
GIT_TAG v3.5.0
diff --git a/thirdparty/cpm/stage1/CMakeLists.txt b/thirdparty/cpm/stage1/CMakeLists.txt
index bf1e63abe628..e8e943ec9c3a 100644
--- a/thirdparty/cpm/stage1/CMakeLists.txt
+++ b/thirdparty/cpm/stage1/CMakeLists.txt
@@ -207,6 +207,14 @@ if(NOT draco_FOUND)
add_draco()
endif()
+function(add_lunasvg)
+ set(LUNASVG_BUILD_EXAMPLES OFF)
+ # loads no fonts, as vcpkg's plutovg by default
+ set(PLUTOVG_DISABLE_FONT_FACE_CACHE_LOAD ON)
+ meshlib_add_package(lunasvg)
+endfunction()
+add_lunasvg()
+
if(EMSCRIPTEN)
find_package(libjpeg-turbo)
if(NOT libjpeg-turbo_FOUND)
diff --git a/thirdparty/licenses/THIRD-PARTY-NOTICES.txt b/thirdparty/licenses/THIRD-PARTY-NOTICES.txt
index 14203fb424be..01f06f9c3697 100644
--- a/thirdparty/licenses/THIRD-PARTY-NOTICES.txt
+++ b/thirdparty/licenses/THIRD-PARTY-NOTICES.txt
@@ -2916,6 +2916,275 @@ must not be misrepresented as being the original software.
distribution.
+################################################################################
+lunasvg -- MIT
+https://github.com/sammycage/lunasvg
+################################################################################
+
+MIT License
+
+Copyright (c) 2020-2025 Samuel Ugochukwu
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
+################################################################################
+plutovg -- MIT AND FTL
+https://github.com/sammycage/plutovg
+################################################################################
+
+----- LICENSE -----
+
+MIT License
+
+Copyright (c) 2020-2026 Samuel Ugochukwu
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+----- source/FTL.TXT (plutovg-ft-math, plutovg-ft-raster, plutovg-ft-stroker, plutovg-ft-types) -----
+
+ The FreeType Project LICENSE
+ ----------------------------
+
+ 2006-Jan-27
+
+ Copyright 1996-2002, 2006 by
+ David Turner, Robert Wilhelm, and Werner Lemberg
+
+
+
+Introduction
+============
+
+ The FreeType Project is distributed in several archive packages;
+ some of them may contain, in addition to the FreeType font engine,
+ various tools and contributions which rely on, or relate to, the
+ FreeType Project.
+
+ This license applies to all files found in such packages, and
+ which do not fall under their own explicit license. The license
+ affects thus the FreeType font engine, the test programs,
+ documentation and makefiles, at the very least.
+
+ This license was inspired by the BSD, Artistic, and IJG
+ (Independent JPEG Group) licenses, which all encourage inclusion
+ and use of free software in commercial and freeware products
+ alike. As a consequence, its main points are that:
+
+ o We don't promise that this software works. However, we will be
+ interested in any kind of bug reports. (`as is' distribution)
+
+ o You can use this software for whatever you want, in parts or
+ full form, without having to pay us. (`royalty-free' usage)
+
+ o You may not pretend that you wrote this software. If you use
+ it, or only parts of it, in a program, you must acknowledge
+ somewhere in your documentation that you have used the
+ FreeType code. (`credits')
+
+ We specifically permit and encourage the inclusion of this
+ software, with or without modifications, in commercial products.
+ We disclaim all warranties covering The FreeType Project and
+ assume no liability related to The FreeType Project.
+
+
+ Finally, many people asked us for a preferred form for a
+ credit/disclaimer to use in compliance with this license. We thus
+ encourage you to use the following text:
+
+ """
+ Portions of this software are copyright � The FreeType
+ Project (www.freetype.org). All rights reserved.
+ """
+
+ Please replace with the value from the FreeType version you
+ actually use.
+
+
+Legal Terms
+===========
+
+0. Definitions
+--------------
+
+ Throughout this license, the terms `package', `FreeType Project',
+ and `FreeType archive' refer to the set of files originally
+ distributed by the authors (David Turner, Robert Wilhelm, and
+ Werner Lemberg) as the `FreeType Project', be they named as alpha,
+ beta or final release.
+
+ `You' refers to the licensee, or person using the project, where
+ `using' is a generic term including compiling the project's source
+ code as well as linking it to form a `program' or `executable'.
+ This program is referred to as `a program using the FreeType
+ engine'.
+
+ This license applies to all files distributed in the original
+ FreeType Project, including all source code, binaries and
+ documentation, unless otherwise stated in the file in its
+ original, unmodified form as distributed in the original archive.
+ If you are unsure whether or not a particular file is covered by
+ this license, you must contact us to verify this.
+
+ The FreeType Project is copyright (C) 1996-2000 by David Turner,
+ Robert Wilhelm, and Werner Lemberg. All rights reserved except as
+ specified below.
+
+1. No Warranty
+--------------
+
+ THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS
+ BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO
+ USE, OF THE FREETYPE PROJECT.
+
+2. Redistribution
+-----------------
+
+ This license grants a worldwide, royalty-free, perpetual and
+ irrevocable right and license to use, execute, perform, compile,
+ display, copy, create derivative works of, distribute and
+ sublicense the FreeType Project (in both source and object code
+ forms) and derivative works thereof for any purpose; and to
+ authorize others to exercise some or all of the rights granted
+ herein, subject to the following conditions:
+
+ o Redistribution of source code must retain this license file
+ (`FTL.TXT') unaltered; any additions, deletions or changes to
+ the original files must be clearly indicated in accompanying
+ documentation. The copyright notices of the unaltered,
+ original files must be preserved in all copies of source
+ files.
+
+ o Redistribution in binary form must provide a disclaimer that
+ states that the software is based in part of the work of the
+ FreeType Team, in the distribution documentation. We also
+ encourage you to put an URL to the FreeType web page in your
+ documentation, though this isn't mandatory.
+
+ These conditions apply to any software derived from or based on
+ the FreeType Project, not just the unmodified files. If you use
+ our work, you must acknowledge us. However, no fee need be paid
+ to us.
+
+3. Advertising
+--------------
+
+ Neither the FreeType authors and contributors nor you shall use
+ the name of the other for commercial, advertising, or promotional
+ purposes without specific prior written permission.
+
+ We suggest, but do not require, that you use one or more of the
+ following phrases to refer to this software in your documentation
+ or advertising materials: `FreeType Project', `FreeType Engine',
+ `FreeType library', or `FreeType Distribution'.
+
+ As you have not signed this license, you are not required to
+ accept it. However, as the FreeType Project is copyrighted
+ material, only this license, or another one contracted with the
+ authors, grants you the right to use, distribute, and modify it.
+ Therefore, by using, distributing, or modifying the FreeType
+ Project, you indicate that you understand and accept all the terms
+ of this license.
+
+4. Contacts
+-----------
+
+ There are two mailing lists related to FreeType:
+
+ o freetype@nongnu.org
+
+ Discusses general use and applications of FreeType, as well as
+ future and wanted additions to the library and distribution.
+ If you are looking for support, start in this list if you
+ haven't found anything to help you in the documentation.
+
+ o freetype-devel@nongnu.org
+
+ Discusses bugs, as well as engine internals, design issues,
+ specific licenses, porting, etc.
+
+ Our home page can be found at
+
+ http://www.freetype.org
+
+----- stb_image, stb_image_write, stb_truetype -----
+
+------------------------------------------------------------------------------
+This software is available under 2 licenses -- choose whichever you prefer.
+------------------------------------------------------------------------------
+ALTERNATIVE A - MIT License
+Copyright (c) 2017 Sean Barrett
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+------------------------------------------------------------------------------
+ALTERNATIVE B - Public Domain (www.unlicense.org)
+This is free and unencumbered software released into the public domain.
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
+software, either in source code form or as a compiled binary, for any purpose,
+commercial or non-commercial, and by any means.
+In jurisdictions that recognize copyright laws, the author or authors of this
+software dedicate any and all copyright interest in the software to the public
+domain. We make this dedication for the benefit of the public at large and to
+the detriment of our heirs and successors. We intend this dedication to be an
+overt act of relinquishment in perpetuity of all present and future rights to
+this software under copyright law.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+------------------------------------------------------------------------------
+
+
################################################################################
nlohmann-json -- MIT
https://github.com/nlohmann/json
diff --git a/thirdparty/licenses/manifest.json b/thirdparty/licenses/manifest.json
index 226b23924542..30e009098786 100644
--- a/thirdparty/licenses/manifest.json
+++ b/thirdparty/licenses/manifest.json
@@ -378,6 +378,36 @@
},
"version": "321ea883b7190d4e85cae5512a12e5eaa8f8731f"
},
+ {
+ "id": "lunasvg",
+ "modules": [
+ "MRIOExtras"
+ ],
+ "license": "MIT",
+ "upstream": "https://github.com/sammycage/lunasvg",
+ "source": {
+ "type": "submodule",
+ "path": "thirdparty/lunasvg"
+ },
+ "version": "83c58df8103dc7dca423dfd824992af94d49bed6"
+ },
+ {
+ "id": "plutovg",
+ "modules": [
+ "MRIOExtras"
+ ],
+ "license": "MIT AND FTL",
+ "upstream": "https://github.com/sammycage/plutovg",
+ "source": {
+ "type": "vcpkg-registry",
+ "ports": [
+ "plutovg"
+ ]
+ },
+ "version": {
+ "plutovg": "1.3.3#0"
+ }
+ },
{
"id": "nlohmann-json",
"modules": [
diff --git a/thirdparty/lunasvg b/thirdparty/lunasvg
new file mode 160000
index 000000000000..83c58df8103d
--- /dev/null
+++ b/thirdparty/lunasvg
@@ -0,0 +1 @@
+Subproject commit 83c58df8103dc7dca423dfd824992af94d49bed6
diff --git a/thirdparty/vcpkg/vcpkg.json b/thirdparty/vcpkg/vcpkg.json
index 09c75526773c..9489cc869f17 100644
--- a/thirdparty/vcpkg/vcpkg.json
+++ b/thirdparty/vcpkg/vcpkg.json
@@ -28,6 +28,7 @@
"libharu",
"libjpeg-turbo",
"libzip",
+ "lunasvg",
"opencascade-minimal",
"openctm",
"openvdb",