Deps: Swap lunasvg for plutosvg

This commit is contained in:
Stenzek 2025-04-13 13:08:50 +10:00
parent 79cb5779b4
commit cf7feec9c4
No known key found for this signature in database
17 changed files with 73 additions and 216 deletions

View File

@ -16,7 +16,7 @@ find_package(ZLIB REQUIRED) # 1.3, but Mac currently doesn't use it.
find_package(PNG 1.6.40 REQUIRED)
find_package(JPEG REQUIRED)
find_package(Freetype 2.13.2 REQUIRED) # 2.13.3, but flatpak is still on 2.13.2.
find_package(lunasvg 2.4.1 REQUIRED)
find_package(plutosvg 0.0.6 REQUIRED)
find_package(cpuinfo REQUIRED)
find_package(DiscordRPC 3.4.0 REQUIRED)
find_package(SoundTouch 2.3.3 REQUIRED)

View File

@ -19,4 +19,4 @@ set(SRCS
add_library(imgui ${SRCS})
target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_include_directories(imgui INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(imgui PUBLIC Freetype::Freetype lunasvg::lunasvg)
target_link_libraries(imgui PUBLIC Freetype::Freetype plutosvg::plutosvg)

View File

@ -29,7 +29,7 @@
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)include;$(ProjectDir)src;$(DepsIncludeDir)freetype2;$(DepsIncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)include;$(ProjectDir)src;$(DepsIncludeDir)freetype2;$(DepsIncludeDir)plutosvg;$(DepsIncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<Import Project="..\msvc\vsprops\Targets.props" />

View File

@ -91,8 +91,8 @@
// - plutosvg is currently easier to install, as e.g. it is part of vcpkg. It will support more fonts and may load them faster. See misc/freetype/README for instructions.
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
#define IMGUI_ENABLE_FREETYPE_LUNASVG
#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
//---- Use stb_truetype to build and rasterize the font atlas (default)
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.

View File

@ -51,10 +51,7 @@
#error "Cannot enable both IMGUI_ENABLE_FREETYPE_LUNASVG and IMGUI_ENABLE_FREETYPE_PLUTOSVG"
#endif
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
#include FT_OTSVG_H // <freetype/otsvg.h>
#include FT_BBOX_H // <freetype/ftbbox.h>
#include <algorithm>
#include <lunasvg_c.h>
#error Lunasvg is not supported
#endif
#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG
#include <plutosvg.h>
@ -93,14 +90,6 @@ static void* (*GImGuiFreeTypeAllocFunc)(size_t size, void* user_data) = ImGuiFre
static void (*GImGuiFreeTypeFreeFunc)(void* ptr, void* user_data) = ImGuiFreeTypeDefaultFreeFunc;
static void* GImGuiFreeTypeAllocatorUserData = nullptr;
// Lunasvg support
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
static FT_Error ImGuiLunasvgPortInit(FT_Pointer* state);
static void ImGuiLunasvgPortFree(FT_Pointer* state);
static FT_Error ImGuiLunasvgPortRender(FT_GlyphSlot slot, FT_Pointer* _state);
static FT_Error ImGuiLunasvgPortPresetSlot(FT_GlyphSlot slot, FT_Bool cache, FT_Pointer* _state);
#endif
//-------------------------------------------------------------------------
// Code
//-------------------------------------------------------------------------
@ -818,13 +807,6 @@ static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas)
// If you don't call FT_Add_Default_Modules() the rest of code may work, but FreeType won't use our custom allocator.
FT_Add_Default_Modules(ft_library);
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
// Install svg hooks for FreeType
// https://freetype.org/freetype2/docs/reference/ft2-properties.html#svg-hooks
// https://freetype.org/freetype2/docs/reference/ft2-svg_fonts.html#svg_fonts
SVG_RendererHooks hooks = { ImGuiLunasvgPortInit, ImGuiLunasvgPortFree, ImGuiLunasvgPortRender, ImGuiLunasvgPortPresetSlot };
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", &hooks);
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG
// With plutosvg, use provided hooks
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", plutosvg_ft_svg_hooks());
@ -850,137 +832,6 @@ void ImGuiFreeType::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* u
GImGuiFreeTypeAllocatorUserData = user_data;
}
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
// For more details, see https://gitlab.freedesktop.org/freetype/freetype-demos/-/blob/master/src/rsvg-port.c
// The original code from the demo is licensed under CeCILL-C Free Software License Agreement (https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/LICENSE.TXT)
struct LunasvgPortState
{
LunasvgPortState();
~LunasvgPortState();
FT_Error err = FT_Err_Ok;
lunasvg_matrix* matrix = nullptr;
lunasvg_document* svg = nullptr;
};
LunasvgPortState::LunasvgPortState()
{
matrix = lunasvg_matrix_create();
}
LunasvgPortState::~LunasvgPortState()
{
lunasvg_matrix_destroy(matrix);
if (svg)
lunasvg_document_destroy(svg);
}
static FT_Error ImGuiLunasvgPortInit(FT_Pointer* _state)
{
*_state = IM_NEW(LunasvgPortState)();
return FT_Err_Ok;
}
static void ImGuiLunasvgPortFree(FT_Pointer* _state)
{
IM_DELETE(*(LunasvgPortState**)_state);
}
static FT_Error ImGuiLunasvgPortRender(FT_GlyphSlot slot, FT_Pointer* _state)
{
LunasvgPortState* state = *(LunasvgPortState**)_state;
// If there was an error while loading the svg in ImGuiLunasvgPortPresetSlot(), the renderer hook still get called, so just returns the error.
if (state->err != FT_Err_Ok)
return state->err;
// rows is height, pitch (or stride) equals to width * sizeof(int32)
lunasvg_bitmap* bitmap = lunasvg_bitmap_create_with_data((uint8_t*)slot->bitmap.buffer, slot->bitmap.width, slot->bitmap.rows, slot->bitmap.pitch);
lunasvg_document_set_identity_matrix(state->svg); // Reset the svg matrix to the default value
lunasvg_document_render(state->svg, bitmap, state->matrix); // state->matrix is already scaled and translated
lunasvg_bitmap_destroy(bitmap);
state->err = FT_Err_Ok;
return state->err;
}
static FT_Error ImGuiLunasvgPortPresetSlot(FT_GlyphSlot slot, FT_Bool cache, FT_Pointer* _state)
{
FT_SVG_Document document = (FT_SVG_Document)slot->other;
LunasvgPortState* state = *(LunasvgPortState**)_state;
FT_Size_Metrics& metrics = document->metrics;
// This function is called twice, once in the FT_Load_Glyph() and another right before ImGuiLunasvgPortRender().
// If it's the latter, don't do anything because it's // already done in the former.
if (cache)
return state->err;
if (state->svg)
lunasvg_document_destroy(state->svg);
state->svg = lunasvg_document_load_from_data(document->svg_document, document->svg_document_length);
if (state->svg == nullptr)
{
state->err = FT_Err_Invalid_SVG_Document;
return state->err;
}
lunasvg_box* box = lunasvg_box_create();
double box_x, box_y, box_w, box_h;
lunasvg_document_get_box(state->svg, box);
lunasvg_box_get_values(box, &box_x, &box_y, &box_w, &box_h);
double scale = std::min(metrics.x_ppem / box_w, metrics.y_ppem / box_h);
double xx = (double)document->transform.xx / (1 << 16);
double xy = -(double)document->transform.xy / (1 << 16);
double yx = -(double)document->transform.yx / (1 << 16);
double yy = (double)document->transform.yy / (1 << 16);
double x0 = (double)document->delta.x / 64 * box_w / metrics.x_ppem;
double y0 = -(double)document->delta.y / 64 * box_h / metrics.y_ppem;
// Scale and transform, we don't translate the svg yet
lunasvg_matrix_identity(state->matrix);
lunasvg_matrix_scale(state->matrix, scale, scale);
lunasvg_matrix_transform(state->matrix, xx, xy, yx, yy, x0, y0);
lunasvg_document_set_matrix(state->svg, state->matrix);
// Pre-translate the matrix for the rendering step
lunasvg_matrix_translate(state->matrix, -box_x, -box_y);
// Get the box again after the transformation
lunasvg_document_get_box(state->svg, box);
lunasvg_box_get_values(box, &box_x, &box_y, &box_w, &box_h);
lunasvg_box_destroy(box);
// Calculate the bitmap size
slot->bitmap_left = FT_Int(box_x);
slot->bitmap_top = FT_Int(-box_y);
slot->bitmap.rows = (unsigned int)(ImCeil((float)box_h));
slot->bitmap.width = (unsigned int)(ImCeil((float)box_w));
slot->bitmap.pitch = slot->bitmap.width * 4;
slot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA;
// Compute all the bearings and set them correctly. The outline is scaled already, we just need to use the bounding box.
double metrics_width = box_w;
double metrics_height = box_h;
double horiBearingX = box_x;
double horiBearingY = -box_y;
double vertBearingX = slot->metrics.horiBearingX / 64.0 - slot->metrics.horiAdvance / 64.0 / 2.0;
double vertBearingY = (slot->metrics.vertAdvance / 64.0 - slot->metrics.height / 64.0) / 2.0;
slot->metrics.width = FT_Pos(IM_ROUND(metrics_width * 64.0)); // Using IM_ROUND() assume width and height are positive
slot->metrics.height = FT_Pos(IM_ROUND(metrics_height * 64.0));
slot->metrics.horiBearingX = FT_Pos(horiBearingX * 64);
slot->metrics.horiBearingY = FT_Pos(horiBearingY * 64);
slot->metrics.vertBearingX = FT_Pos(vertBearingX * 64);
slot->metrics.vertBearingY = FT_Pos(vertBearingY * 64);
if (slot->metrics.vertAdvance == 0)
slot->metrics.vertAdvance = FT_Pos(metrics_height * 1.2 * 64.0);
state->err = FT_Err_Ok;
return state->err;
}
#endif // #ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
//-----------------------------------------------------------------------------
#ifdef __GNUC__

View File

@ -115,7 +115,7 @@ ZSTD=1.5.7
CPUINFO=3ebbfd45645650c4940bf0f3b4d25ab913466bb0
DISCORD_RPC=cc59d26d1d628fbd6527aac0ac1d6301f4978b92
LUNASVG=4a1c98ccb1da8a5a92ddc4f97339869b1ae556f4
PLUTOSVG=bc845bb6b6511e392f9e1097b26f70cf0b3c33be
SHADERC=4daf9d466ad00897f755163dd26f528d14e1db44
SOUNDTOUCH=463ade388f3a51da078dc9ed062bf28e4ba29da7
SPIRV_CROSS=vulkan-sdk-1.4.309.0
@ -130,7 +130,7 @@ if [[ "$SKIP_DOWNLOAD" != true && ! -f "libbacktrace-$LIBBACKTRACE.tar.gz" ]]; t
-O "https://github.com/libsdl-org/SDL/releases/download/release-$SDL3/SDL3-$SDL3.tar.gz" \
-o "cpuinfo-$CPUINFO.tar.gz" "https://github.com/stenzek/cpuinfo/archive/$CPUINFO.tar.gz" \
-o "discord-rpc-$DISCORD_RPC.tar.gz" "https://github.com/stenzek/discord-rpc/archive/$DISCORD_RPC.tar.gz" \
-o "lunasvg-$LUNASVG.tar.gz" "https://github.com/stenzek/lunasvg/archive/$LUNASVG.tar.gz" \
-o "plutosvg-$PLUTOSVG.tar.gz" "https://github.com/stenzek/plutosvg/archive/$PLUTOSVG.tar.gz" \
-o "shaderc-$SHADERC.tar.gz" "https://github.com/stenzek/shaderc/archive/$SHADERC.tar.gz" \
-o "soundtouch-$SOUNDTOUCH.tar.gz" "https://github.com/stenzek/soundtouch/archive/$SOUNDTOUCH.tar.gz"
fi
@ -140,7 +140,7 @@ baf8aebd22002b762d803ba0e1e389b6b4415159334e9d34bba1a938f6de8ce6 libbacktrace-$
f87be7b4dec66db4098e9c167b2aa34e2ca10aeb5443bdde95ae03185ed513e0 SDL3-$SDL3.tar.gz
b60832071919220d2fe692151fb420fa9ea489aa4c7a2eb0e01c830cbe469858 cpuinfo-$CPUINFO.tar.gz
297cd48a287a9113eec44902574084c6ab3b6a8b28d02606765a7fded431d7d8 discord-rpc-$DISCORD_RPC.tar.gz
5fe7abc6c4601f21fa56ffbf12507e80684942c3134b7888701ede836e6287e2 lunasvg-$LUNASVG.tar.gz
cc8eed38daf68aaaaa96e904f68f5524c02f10b5d42062b91cdc93f93445f68a plutosvg-$PLUTOSVG.tar.gz
167109d52b65f6eedd66103971b869a71632fe27a63efc2ba5b0e5a1912a094c shaderc-$SHADERC.tar.gz
fe45c2af99f6102d2704277d392c1c83b55180a70bfd17fb888cc84a54b70573 soundtouch-$SOUNDTOUCH.tar.gz
EOF
@ -530,11 +530,11 @@ cmake --build build --parallel
ninja -C build install
cd ..
echo "Building lunasvg..."
rm -fr "lunasvg-$LUNASVG"
tar xf "lunasvg-$LUNASVG.tar.gz"
cd "lunasvg-$LUNASVG"
cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DLUNASVG_BUILD_EXAMPLES=OFF -B build -G Ninja
echo "Building plutosvg..."
rm -fr "plutosvg-$PLUTOSVG"
tar xf "plutosvg-$PLUTOSVG.tar.gz"
cd "plutosvg-$PLUTOSVG"
cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DPLUTOSVG_ENABLE_FREETYPE=ON -DPLUTOSVG_BUILD_EXAMPLES=OFF -B build -G Ninja
cmake --build build --parallel
ninja -C build install
cd ..

View File

@ -83,7 +83,7 @@ ZSTD=1.5.7
CPUINFO=3ebbfd45645650c4940bf0f3b4d25ab913466bb0
DISCORD_RPC=cc59d26d1d628fbd6527aac0ac1d6301f4978b92
LUNASVG=4a1c98ccb1da8a5a92ddc4f97339869b1ae556f4
PLUTOSVG=bc845bb6b6511e392f9e1097b26f70cf0b3c33be
SHADERC=4daf9d466ad00897f755163dd26f528d14e1db44
SOUNDTOUCH=463ade388f3a51da078dc9ed062bf28e4ba29da7
SPIRV_CROSS=vulkan-sdk-1.4.309.0
@ -97,7 +97,7 @@ if [[ "$SKIP_DOWNLOAD" != true && ! -f "libbacktrace-$LIBBACKTRACE.tar.gz" ]]; t
-O "https://github.com/libsdl-org/SDL/releases/download/release-$SDL3/SDL3-$SDL3.tar.gz" \
-o "cpuinfo-$CPUINFO.tar.gz" "https://github.com/stenzek/cpuinfo/archive/$CPUINFO.tar.gz" \
-o "discord-rpc-$DISCORD_RPC.tar.gz" "https://github.com/stenzek/discord-rpc/archive/$DISCORD_RPC.tar.gz" \
-o "lunasvg-$LUNASVG.tar.gz" "https://github.com/stenzek/lunasvg/archive/$LUNASVG.tar.gz" \
-o "plutosvg-$PLUTOSVG.tar.gz" "https://github.com/stenzek/plutosvg/archive/$PLUTOSVG.tar.gz" \
-o "shaderc-$SHADERC.tar.gz" "https://github.com/stenzek/shaderc/archive/$SHADERC.tar.gz" \
-o "soundtouch-$SOUNDTOUCH.tar.gz" "https://github.com/stenzek/soundtouch/archive/$SOUNDTOUCH.tar.gz"
fi
@ -107,7 +107,7 @@ baf8aebd22002b762d803ba0e1e389b6b4415159334e9d34bba1a938f6de8ce6 libbacktrace-$
f87be7b4dec66db4098e9c167b2aa34e2ca10aeb5443bdde95ae03185ed513e0 SDL3-$SDL3.tar.gz
b60832071919220d2fe692151fb420fa9ea489aa4c7a2eb0e01c830cbe469858 cpuinfo-$CPUINFO.tar.gz
297cd48a287a9113eec44902574084c6ab3b6a8b28d02606765a7fded431d7d8 discord-rpc-$DISCORD_RPC.tar.gz
5fe7abc6c4601f21fa56ffbf12507e80684942c3134b7888701ede836e6287e2 lunasvg-$LUNASVG.tar.gz
cc8eed38daf68aaaaa96e904f68f5524c02f10b5d42062b91cdc93f93445f68a plutosvg-$PLUTOSVG.tar.gz
167109d52b65f6eedd66103971b869a71632fe27a63efc2ba5b0e5a1912a094c shaderc-$SHADERC.tar.gz
fe45c2af99f6102d2704277d392c1c83b55180a70bfd17fb888cc84a54b70573 soundtouch-$SOUNDTOUCH.tar.gz
EOF
@ -462,11 +462,11 @@ cmake --build build --parallel
ninja -C build install
cd ..
echo "Building lunasvg..."
rm -fr "lunasvg-$LUNASVG"
tar xf "lunasvg-$LUNASVG.tar.gz"
cd "lunasvg-$LUNASVG"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$INSTALLDIR" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DBUILD_SHARED_LIBS=ON -DLUNASVG_BUILD_EXAMPLES=OFF -B build -G Ninja
echo "Building plutosvg..."
rm -fr "plutosvg-$PLUTOSVG"
tar xf "plutosvg-$PLUTOSVG.tar.gz"
cd "plutosvg-$PLUTOSVG"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$INSTALLDIR" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DBUILD_SHARED_LIBS=ON -DPLUTOSVG_ENABLE_FREETYPE=ON -DPLUTOSVG_BUILD_EXAMPLES=OFF -B build -G Ninja
cmake --build build --parallel
ninja -C build install
cd ..

View File

@ -50,7 +50,7 @@ QT=6.9.0
CPUINFO=3ebbfd45645650c4940bf0f3b4d25ab913466bb0
DISCORD_RPC=cc59d26d1d628fbd6527aac0ac1d6301f4978b92
LUNASVG=4a1c98ccb1da8a5a92ddc4f97339869b1ae556f4
PLUTOSVG=bc845bb6b6511e392f9e1097b26f70cf0b3c33be
SHADERC=4daf9d466ad00897f755163dd26f528d14e1db44
SOUNDTOUCH=463ade388f3a51da078dc9ed062bf28e4ba29da7
SPIRV_CROSS=vulkan-sdk-1.4.309.0
@ -97,7 +97,7 @@ fa645589cc3f939022401a926825972a44277dead8ec8607d9f2662e6529c9a4 qttools-everyw
1d5581ef5fc7c7bc556f2403017983683993bbebfcdf977ef8f180f604668c3f qttranslations-everywhere-src-$QT.tar.xz
b60832071919220d2fe692151fb420fa9ea489aa4c7a2eb0e01c830cbe469858 cpuinfo-$CPUINFO.tar.gz
297cd48a287a9113eec44902574084c6ab3b6a8b28d02606765a7fded431d7d8 discord-rpc-$DISCORD_RPC.tar.gz
5fe7abc6c4601f21fa56ffbf12507e80684942c3134b7888701ede836e6287e2 lunasvg-$LUNASVG.tar.gz
cc8eed38daf68aaaaa96e904f68f5524c02f10b5d42062b91cdc93f93445f68a plutosvg-$PLUTOSVG.tar.gz
167109d52b65f6eedd66103971b869a71632fe27a63efc2ba5b0e5a1912a094c shaderc-$SHADERC.tar.gz
fe45c2af99f6102d2704277d392c1c83b55180a70bfd17fb888cc84a54b70573 soundtouch-$SOUNDTOUCH.tar.gz
EOF
@ -120,7 +120,7 @@ curl -L \
-O "https://download.qt.io/official_releases/qt/${QT%.*}/$QT/submodules/qttranslations-everywhere-src-$QT.tar.xz" \
-o "cpuinfo-$CPUINFO.tar.gz" "https://github.com/stenzek/cpuinfo/archive/$CPUINFO.tar.gz" \
-o "discord-rpc-$DISCORD_RPC.tar.gz" "https://github.com/stenzek/discord-rpc/archive/$DISCORD_RPC.tar.gz" \
-o "lunasvg-$LUNASVG.tar.gz" "https://github.com/stenzek/lunasvg/archive/$LUNASVG.tar.gz" \
-o "plutosvg-$PLUTOSVG.tar.gz" "https://github.com/stenzek/plutosvg/archive/$PLUTOSVG.tar.gz" \
-o "shaderc-$SHADERC.tar.gz" "https://github.com/stenzek/shaderc/archive/$SHADERC.tar.gz" \
-o "soundtouch-$SOUNDTOUCH.tar.gz" "https://github.com/stenzek/soundtouch/archive/$SOUNDTOUCH.tar.gz"
@ -394,11 +394,11 @@ cmake --build build --parallel
cmake --install build
cd ..
echo "Building lunasvg..."
rm -fr "lunasvg-$LUNASVG"
tar xf "lunasvg-$LUNASVG.tar.gz"
cd "lunasvg-$LUNASVG"
cmake "${CMAKE_COMMON[@]}" "$CMAKE_ARCH_UNIVERSAL" -DBUILD_SHARED_LIBS=ON -DLUNASVG_BUILD_EXAMPLES=OFF -B build
echo "Building plutosvg..."
rm -fr "plutosvg-$PLUTOSVG"
tar xf "plutosvg-$PLUTOSVG.tar.gz"
cd "plutosvg-$PLUTOSVG"
cmake "${CMAKE_COMMON[@]}" "$CMAKE_ARCH_UNIVERSAL" -DBUILD_SHARED_LIBS=ON -DPLUTOSVG_ENABLE_FREETYPE=ON -DPLUTOSVG_BUILD_EXAMPLES=OFF -B build
cmake --build build --parallel
cmake --install build
cd ..

View File

@ -59,7 +59,7 @@ set ZSTD=1.5.7
set CPUINFO=3ebbfd45645650c4940bf0f3b4d25ab913466bb0
set DISCORD_RPC=cc59d26d1d628fbd6527aac0ac1d6301f4978b92
set LUNASVG=4a1c98ccb1da8a5a92ddc4f97339869b1ae556f4
set PLUTOSVG=bc845bb6b6511e392f9e1097b26f70cf0b3c33be
set SHADERC=4daf9d466ad00897f755163dd26f528d14e1db44
set SOUNDTOUCH=463ade388f3a51da078dc9ed062bf28e4ba29da7
set SPIRV_CROSS=vulkan-sdk-1.4.309.0
@ -83,7 +83,7 @@ call :downloadfile "zstd-%ZSTD%.zip" "https://github.com/facebook/zstd/archive/r
call :downloadfile "cpuinfo-%CPUINFO%.zip" "https://github.com/stenzek/cpuinfo/archive/%CPUINFO%.zip" 3430f8bae57623347b2b30a8ff041b0288f90ad99b4c2487c3d520863ce4a4e3 || goto error
call :downloadfile "discord-rpc-%DISCORD_RPC%.zip" "https://github.com/stenzek/discord-rpc/archive/%DISCORD_RPC%.zip" 4492cbe690a16546da9a9d89f14340352cad3b0ac5484b969749d6ab6f1ee836 || goto error
call :downloadfile "lunasvg-%LUNASVG%.zip" "https://github.com/stenzek/lunasvg/archive/%LUNASVG%.zip" 536d00fcafcb71b1e3680516266a0299e87b8723f0d29c1c1bcd9c4118de4d00 || goto error
call :downloadfile "plutosvg-%PLUTOSVG%.zip" "https://github.com/stenzek/plutosvg/archive/%PLUTOSVG%.zip" ae6c6bd93a9ea0451b853545595b2c6c99104b22c193afd8e00cfbc0f3e27298 || goto error
call :downloadfile "shaderc-%SHADERC%.zip" "https://github.com/stenzek/shaderc/archive/%SHADERC%.zip" cafd87502d799060d2b6bbf9c885226f75f6e0b21e8cd87a43806da019412811 || goto error
call :downloadfile "soundtouch-%SOUNDTOUCH%.zip" "https://github.com/stenzek/soundtouch/archive/%SOUNDTOUCH%.zip" 107a1941181a69abe28018b9ad26fc0218625758ac193bc979abc9e26b7c0c3a || goto error
call :downloadfile "dxcompiler-%DXCOMPILER%.zip" "https://www.nuget.org/api/v2/package/Microsoft.Direct3D.DXC/%DXCOMPILER%" eb4f6a3bb6b08aaa62f435b3dbf26b180702ca52398d3650d0dd538f56742cdc || goto error
@ -292,11 +292,11 @@ cmake --build build --parallel || goto error
ninja -C build install || goto error
cd .. || goto error
echo Building lunasvg...
rmdir /S /Q "lunasvg-%LUNASVG%"
%SEVENZIP% x "lunasvg-%LUNASVG%.zip" || goto error
cd "lunasvg-%LUNASVG%" || goto error
cmake %ARM64TOOLCHAIN% -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="%INSTALLDIR%" -DCMAKE_INSTALL_PREFIX="%INSTALLDIR%" -DBUILD_SHARED_LIBS=ON -DLUNASVG_BUILD_EXAMPLES=OFF -B build -G Ninja
echo Building plutosvg...
rmdir /S /Q "plutosvg-%PLUTOSVG%"
%SEVENZIP% x "plutosvg-%PLUTOSVG%.zip" || goto error
cd "plutosvg-%PLUTOSVG%" || goto error
cmake %ARM64TOOLCHAIN% -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="%INSTALLDIR%" -DCMAKE_INSTALL_PREFIX="%INSTALLDIR%" -DBUILD_SHARED_LIBS=ON -DPLUTOSVG_ENABLE_FREETYPE=ON -DPLUTOSVG_BUILD_EXAMPLES=OFF -B build -G Ninja
cmake --build build --parallel || goto error
ninja -C build install || goto error
cd .. || goto error

View File

@ -57,7 +57,7 @@ set ZSTD=1.5.7
set CPUINFO=3ebbfd45645650c4940bf0f3b4d25ab913466bb0
set DISCORD_RPC=cc59d26d1d628fbd6527aac0ac1d6301f4978b92
set LUNASVG=4a1c98ccb1da8a5a92ddc4f97339869b1ae556f4
set PLUTOSVG=bc845bb6b6511e392f9e1097b26f70cf0b3c33be
set SHADERC=4daf9d466ad00897f755163dd26f528d14e1db44
set SOUNDTOUCH=463ade388f3a51da078dc9ed062bf28e4ba29da7
set SPIRV_CROSS=vulkan-sdk-1.4.309.0
@ -81,7 +81,7 @@ call :downloadfile "zstd-%ZSTD%.zip" "https://github.com/facebook/zstd/archive/r
call :downloadfile "cpuinfo-%CPUINFO%.zip" "https://github.com/stenzek/cpuinfo/archive/%CPUINFO%.zip" 3430f8bae57623347b2b30a8ff041b0288f90ad99b4c2487c3d520863ce4a4e3 || goto error
call :downloadfile "discord-rpc-%DISCORD_RPC%.zip" "https://github.com/stenzek/discord-rpc/archive/%DISCORD_RPC%.zip" 4492cbe690a16546da9a9d89f14340352cad3b0ac5484b969749d6ab6f1ee836 || goto error
call :downloadfile "lunasvg-%LUNASVG%.zip" "https://github.com/stenzek/lunasvg/archive/%LUNASVG%.zip" 536d00fcafcb71b1e3680516266a0299e87b8723f0d29c1c1bcd9c4118de4d00 || goto error
call :downloadfile "plutosvg-%PLUTOSVG%.zip" "https://github.com/stenzek/plutosvg/archive/%PLUTOSVG%.zip" ae6c6bd93a9ea0451b853545595b2c6c99104b22c193afd8e00cfbc0f3e27298 || goto error
call :downloadfile "shaderc-%SHADERC%.zip" "https://github.com/stenzek/shaderc/archive/%SHADERC%.zip" cafd87502d799060d2b6bbf9c885226f75f6e0b21e8cd87a43806da019412811 || goto error
call :downloadfile "soundtouch-%SOUNDTOUCH%.zip" "https://github.com/stenzek/soundtouch/archive/%SOUNDTOUCH%.zip" 107a1941181a69abe28018b9ad26fc0218625758ac193bc979abc9e26b7c0c3a || goto error
call :downloadfile "dxcompiler-%DXCOMPILER%.zip" "https://www.nuget.org/api/v2/package/Microsoft.Direct3D.DXC/%DXCOMPILER%" eb4f6a3bb6b08aaa62f435b3dbf26b180702ca52398d3650d0dd538f56742cdc || goto error
@ -289,11 +289,11 @@ cmake --build build --parallel || goto error
ninja -C build install || goto error
cd .. || goto error
echo Building lunasvg...
rmdir /S /Q "lunasvg-%LUNASVG%"
%SEVENZIP% x "lunasvg-%LUNASVG%.zip" || goto error
cd "lunasvg-%LUNASVG%" || goto error
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="%INSTALLDIR%" -DCMAKE_INSTALL_PREFIX="%INSTALLDIR%" -DBUILD_SHARED_LIBS=ON -DLUNASVG_BUILD_EXAMPLES=OFF -B build -G Ninja
echo Building plutosvg...
rmdir /S /Q "plutosvg-%PLUTOSVG%"
%SEVENZIP% x "plutosvg-%PLUTOSVG%.zip" || goto error
cd "plutosvg-%PLUTOSVG%" || goto error
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="%INSTALLDIR%" -DCMAKE_INSTALL_PREFIX="%INSTALLDIR%" -DBUILD_SHARED_LIBS=ON -DPLUTOSVG_ENABLE_FREETYPE=ON -DPLUTOSVG_BUILD_EXAMPLES=OFF -B build -G Ninja
cmake --build build --parallel || goto error
ninja -C build install || goto error
cd .. || goto error

View File

@ -113,7 +113,7 @@ declare -a DEPLIBS=(
"libcpuinfo.so"
"libdiscord-rpc.so"
"liblunasvg.so"
"libplutosvg.so.0"
"libshaderc_ds.so"
"libsoundtouch.so.2"
"libspirv-cross-c-shared.so.0"

View File

@ -1,19 +1,20 @@
# SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
# SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <stenzek@gmail.com>
# SPDX-License-Identifier: CC-BY-NC-ND-4.0
name: lunasvg
name: plutosvg
buildsystem: cmake-ninja
builddir: true
config-opts:
- "-DCMAKE_BUILD_TYPE=Release"
- "-DBUILD_SHARED_LIBS=ON"
- "-DLUNASVG_BUILD_EXAMPLES=OFF"
- "-DPLUTOSVG_ENABLE_FREETYPE=ON"
- "-DPLUTOSVG_BUILD_EXAMPLES=OFF"
build-options:
strip: true
sources:
- type: git
url: "https://github.com/stenzek/lunasvg.git"
commit: "9af1ac7b90658a279b372add52d6f77a4ebb482c"
url: "https://github.com/stenzek/plutosvg.git"
commit: "bc845bb6b6511e392f9e1097b26f70cf0b3c33be"
cleanup:
- /bin
- /include

View File

@ -35,7 +35,7 @@ modules:
- "modules/22-cpuinfo.yaml"
- "modules/23-discord-rpc.yaml"
- "modules/24-soundtouch.yaml"
- "modules/25-lunasvg.yaml"
- "modules/25-plutosvg.yaml"
- "modules/30-sdl3.yaml"
# Main module.

View File

@ -212,7 +212,7 @@ if(WIN32)
#set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/translations")
set(DEPS_TO_COPY cpuinfo.dll discord-rpc.dll dxcompiler.dll dxil.dll freetype.dll harfbuzz.dll jpeg62.dll libpng16.dll
libsharpyuv.dll libwebp.dll libwebpdemux.dll libwebpmux.dll lunasvg.dll SDL3.dll shaderc_shared.dll
libsharpyuv.dll libwebp.dll libwebpdemux.dll libwebpmux.dll plutosvg.dll SDL3.dll shaderc_shared.dll
soundtouch.dll spirv-cross-c-shared.dll zlib1.dll zstd.dll)
foreach(DEP ${DEPS_TO_COPY})
list(APPEND DEP_BINS "${CMAKE_PREFIX_PATH}/bin/${DEP}")

View File

@ -77,7 +77,7 @@ target_precompile_headers(util PRIVATE "pch.h")
target_include_directories(util PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_include_directories(util PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(util PUBLIC common simpleini imgui)
target_link_libraries(util PRIVATE libchdr lzma JPEG::JPEG PNG::PNG WebP::libwebp lunasvg::lunasvg ZLIB::ZLIB SoundTouch::SoundTouchDLL xxhash Zstd::Zstd reshadefx)
target_link_libraries(util PRIVATE libchdr lzma JPEG::JPEG PNG::PNG WebP::libwebp plutosvg::plutosvg ZLIB::ZLIB SoundTouch::SoundTouchDLL xxhash Zstd::Zstd reshadefx)
if(ENABLE_X11)
target_sources(util PRIVATE
@ -331,7 +331,7 @@ function(add_util_resources target)
install_imported_dep_library(Shaderc::shaderc_shared)
install_imported_dep_library(spirv-cross-c-shared)
install_imported_dep_library(SoundTouch::SoundTouchDLL)
install_imported_dep_library(lunasvg::lunasvg)
install_imported_dep_library(plutosvg::plutosvg)
else()
# Prevent CMake from overriding the RPATH in the binary. i.e. use the build locations.
# This is needed for Flatpak builds, since the libs are in /app.

View File

@ -17,9 +17,8 @@
#include "common/scoped_guard.h"
#include "common/string_util.h"
#include "lunasvg_c.h"
#include <jpeglib.h>
#include <plutosvg.h>
#include <png.h>
#include <webp/decode.h>
#include <webp/encode.h>
@ -391,26 +390,32 @@ bool Image::RasterizeSVG(const std::span<const u8> data, u32 width, u32 height,
return false;
}
std::unique_ptr<lunasvg_document, void (*)(lunasvg_document*)> doc(
lunasvg_document_load_from_data(data.data(), data.size()), lunasvg_document_destroy);
std::unique_ptr<plutosvg_document, void (*)(plutosvg_document*)> doc(
plutosvg_document_load_from_data(reinterpret_cast<const char*>(data.data()), static_cast<int>(data.size_bytes()),
static_cast<float>(width), static_cast<float>(height), nullptr, nullptr),
plutosvg_document_destroy);
if (!doc)
{
Error::SetStringView(error, "lunasvg_document_load_from_data() failed");
Error::SetStringView(error, "plutosvg_document_load_from_data() failed");
return false;
}
std::unique_ptr<lunasvg_bitmap, void (*)(lunasvg_bitmap*)> bitmap(
lunasvg_document_render_to_bitmap(doc.get(), width, height, 0), lunasvg_bitmap_destroy);
const plutovg_color_t current_color = {.r = 1.0f, .g = 1.0f, .b = 1.0f, .a = 1.0f};
std::unique_ptr<plutovg_surface, void (*)(plutovg_surface*)> bitmap(
plutosvg_document_render_to_surface(doc.get(), nullptr, static_cast<int>(width), static_cast<int>(height),
&current_color, nullptr, nullptr),
plutovg_surface_destroy);
if (!bitmap)
{
Error::SetStringView(error, "lunasvg_document_render_to_bitmap() failed");
Error::SetStringView(error, "plutosvg_document_render_to_surface() failed");
return false;
}
// lunasvg works in BGRA, swap to RGBA
Resize(width, height, ImageFormat::RGBA8, false);
SwapBGRAToRGBA(m_pixels.get(), m_pitch, lunasvg_bitmap_data(bitmap.get()), lunasvg_bitmap_stride(bitmap.get()), width,
height);
SwapBGRAToRGBA(m_pixels.get(), m_pitch, plutovg_surface_get_data(bitmap.get()),
plutovg_surface_get_stride(bitmap.get()), width, height);
return true;
}

View File

@ -6,7 +6,7 @@
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions);CPUINFO_SHARED=1;ENABLE_VULKAN=1;ENABLE_SDL=1</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Platform)'!='ARM64'">%(PreprocessorDefinitions);ENABLE_OPENGL=1</PreprocessorDefinitions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)dep\xxhash\include;$(SolutionDir)dep\kissfft\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\libchdr\include;$(SolutionDir)dep\cubeb\include;$(SolutionDir)dep\d3d12ma\include;$(SolutionDir)dep\vulkan\include;$(SolutionDir)dep\ffmpeg\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)dep\xxhash\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\libchdr\include;$(SolutionDir)dep\cubeb\include;$(SolutionDir)dep\d3d12ma\include;$(SolutionDir)dep\vulkan\include;$(SolutionDir)dep\ffmpeg\include;$(DepsIncludeDir)plutosvg;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Platform)'!='ARM64'">%(AdditionalIncludeDirectories);$(SolutionDir)dep\glad\include</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
@ -25,7 +25,7 @@
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)spirv_cross</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies);freetype.lib;jpeg.lib;libpng16.lib;libwebp.lib;lunasvg.lib;SDL3.lib;soundtouch.lib;zlib.lib;zstd.lib</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);freetype.lib;jpeg.lib;libpng16.lib;libwebp.lib;plutosvg.lib;SDL3.lib;soundtouch.lib;zlib.lib;zstd.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@ -41,7 +41,7 @@
<DepsDLLs Include="$(DepsBinDir)libwebp.dll" />
<DepsDLLs Include="$(DepsBinDir)libwebpdemux.dll" />
<DepsDLLs Include="$(DepsBinDir)libwebpmux.dll" />
<DepsDLLs Include="$(DepsBinDir)lunasvg.dll" />
<DepsDLLs Include="$(DepsBinDir)plutosvg.dll" />
<DepsDLLs Include="$(DepsBinDir)SDL3.dll" />
<DepsDLLs Include="$(DepsBinDir)shaderc_shared.dll" />
<DepsDLLs Include="$(DepsBinDir)soundtouch.dll" />