Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

lunasvg

> 前端框架
Open source

SVG rendering and manipulation library in C++

1.2K stars0 likes1 views
WebsiteGitHub

About

SVG rendering and manipulation library in C++

Interested in HTML rendering? Explore a related library, PlutoBook, built for paged HTML rendering.

LunaSVG

LunaSVG is an SVG rendering library in C++, designed to be lightweight and portable, offering efficient rendering and manipulation of Scalable Vector Graphics (SVG) files.

Basic Usage

cpp
#include 

using namespace lunasvg;

int main()
{
    auto document = Document::loadFromFile("tiger.svg");
    if(document == nullptr)
        return -1;
    auto bitmap = document->renderToBitmap();
    if(bitmap.isNull())
        return -1;
    bitmap.writeToPng("tiger.png");
    return 0;
}

Dynamic Styling

…
summer.png winter.png

Hit Testing

This example demonstrates SVG element hit testing using elementFromPoint(x, y) in LunaSVG. It loads an SVG containing three shapes, performs point-based hit detection, and applies a skew transform with a black stroke to each matched element. The results are saved as original.png and modified.png for visual comparison.

…
original.png modified.png
log
Element at (30, 30): red-rect
Element at (200, 70): blue-circle
Element at (310, 50): green-rect
No element found at (0, 0)

Features

LunaSVG supports nearly all graphical features outlined in the SVG 1.1 and SVG 1.2 Tiny specifications. The primary exceptions are animation, filters, and scripts. As LunaSVG is designed for static rendering, animation is unlikely to be supported in the future. However, support for filters may be added. It currently handles a wide variety of elements, including:

Installation

Follow the steps below to install LunaSVG using either CMake or Meson.

Using CMake

bash
git clone https://github.com/sammycage/lunasvg.git
cd lunasvg
cmake -B build .
cmake --build build
cmake --install build

After installing LunaSVG, you can include the library in your CMake projects using find_package:

cmake
find_package(lunasvg REQUIRED)

# Link LunaSVG to your target
target_link_libraries(your_target_name PRIVATE lunasvg::lunasvg)

Alternatively, you can use CMake's FetchContent to include LunaSVG directly in your project without needing to install it first:

cmake
include(FetchContent)
FetchContent_Declare(
    lunasvg
    GIT_REPOSITORY https://github.com/sammycage/lunasvg.git
    GIT_TAG master  # Specify the desired branch or tag
)
FetchContent_MakeAvailable(lunasvg)

# Link LunaSVG to your target
target_link_libraries(your_target_name PRIVATE lunasvg::lunasvg)

Replace your_target_name with the name of your executable or library target.

Build Options LunaSVG provides several build options that can be configured using -D flags when running cmake. Below is a list of available options:

USE_SYSTEM_PLUTOVG (default: OFF): Use the system-installed plutovg library (version 1.0.0 or higher) instead of the bundled submodule. If the system library is not found, the build will fall back to using the submodule. Example:

bash
cmake -B build -DUSE_SYSTEM_PLUTOVG=ON .
cmake --build build

Using Meson

bash
git clone https://github.com/sammycage/lunasvg.git
cd lunasvg
meson setup build
meson compile -C build
meson install -C build

After installing LunaSVG, you can include the library in your Meson projects using the dependency function:

meson
lunasvg_dep = dependency('lunasvg', required: true)

Alternatively, add lunasvg.wrap to your subprojects directory to include LunaSVG directly in your project without needing to install it first. Create a file named lunasvg.wrap with the following content:

ini
[wrap-git]
url = https://github.com/sammycage/lunasvg.git
revision = head
depth = 1

[provide]
lunasvg = lunasvg_dep

You can retrieve the dependency from the wrap fallback with:

meson
lunasvg_dep = dependency('lunasvg', fallback: ['lunasvg', 'lunasvg_dep'])

Demo

LunaSVG provides a command-line tool svg2png for converting SVG files to PNG format.

Usage:

bash
svg2png [filename] [resolution] [bgColor]

Examples:

bash
$ svg2png input.svg
$ svg2png input.svg 512x512
$ svg2png input.svg 512x512 0xff00ffff

Projects Using LunaSVG

  • OpenSiv3D
  • PICsimLab
  • MoneyManagerEx
  • RmlUi
  • EKA2L1
  • ObEngine
  • OTTO
  • EmulationStation-DE
  • SvgBooga
  • Dear ImGui
  • Multi Theft Auto: San Andreas
  • eScada Solutions
  • CARLA Simulator
  • AUI Framework
  • Software Companions
  • node-canvas

License

LunaSVG is licensed under the MIT License, see LICENSE for more information.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ccppcssplutovgpng

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架