Skip to content

Instantly share code, notes, and snippets.

@m-carrasco
Last active January 30, 2023 19:42
Show Gist options
  • Save m-carrasco/77bff1fb93f5bbee5e58843f5db90e6d to your computer and use it in GitHub Desktop.
Save m-carrasco/77bff1fb93f5bbee5e58843f5db90e6d to your computer and use it in GitHub Desktop.
Lunasvg diff
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 53ec5ef..25f4bd9 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.3)
-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 17)
project(svg2png CXX)
diff --git a/example/svg2png.cpp b/example/svg2png.cpp
index f9c33d7..8f26807 100644
--- a/example/svg2png.cpp
+++ b/example/svg2png.cpp
@@ -3,6 +3,8 @@
#include <iostream>
#include <sstream>
+#include <filesystem>
+#include <fstream>
#include <lunasvg.h>
@@ -48,7 +50,16 @@ int main(int argc, char** argv)
std::uint32_t bgColor = 0x00000000;
if(!setup(argc, argv, filename, width, height, bgColor)) return help();
- auto document = Document::loadFromFile(filename);
+ std::uintmax_t size = std::filesystem::file_size(argv[1]);
+ std::fstream f1;
+ f1.open(argv[1], std::ios::in | std::ios::binary);
+ char* buffer = (char*)calloc(size, sizeof(char));
+ f1.read(buffer, size);
+ f1.close();
+
+ auto document = Document::loadFromData(buffer, size);
+ free(buffer);
+
if(!document) return help();
auto bitmap = document->renderToBitmap(width, height, bgColor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment