First Commit

This commit is contained in:
2025-11-18 14:18:26 -07:00
parent 33eb6e3707
commit 27277ec342
6106 changed files with 3571167 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
FILE(COPY camera.svg DESTINATION "${CMAKE_BINARY_DIR}/examples")
add_executable(camera2png camera2png.c)
target_link_libraries(camera2png plutosvg)
add_executable(svg2png svg2png.c)
target_link_libraries(svg2png plutosvg)
if(PLUTOSVG_ENABLE_FREETYPE)
add_executable(emoji2png emoji2png.c)
target_link_libraries(emoji2png plutosvg)
endif()

340
3rdparty/plutosvg/examples/camera.svg vendored Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 130 KiB

34
3rdparty/plutosvg/examples/camera2png.c vendored Normal file
View File

@@ -0,0 +1,34 @@
#include <plutosvg.h>
#include <stdio.h>
int main(void)
{
plutosvg_document_t* document = NULL;
plutovg_surface_t* surface = NULL;
fprintf(stdout, "Loading 'camera.svg'\n");
document = plutosvg_document_load_from_file("camera.svg", -1, -1);
if(document == NULL) {
fprintf(stderr, "Unable to load 'camera.svg'\n");
goto cleanup;
}
fprintf(stdout, "Rendering 'camera.svg'\n");
surface = plutosvg_document_render_to_surface(document, NULL, -1, -1, NULL, NULL, NULL);
if(surface == NULL) {
fprintf(stderr, "Unable to render 'camera.svg'\n");
goto cleanup;
}
fprintf(stdout, "Writing 'camera.png'\n");
if(!plutovg_surface_write_to_png(surface, "camera.png")) {
fprintf(stderr, "Unable to write 'camera.png'\n");
goto cleanup;
}
cleanup:
plutovg_surface_destroy(surface);
plutosvg_document_destroy(document);
return 0;
}

56
3rdparty/plutosvg/examples/emoji2png.c vendored Normal file
View File

@@ -0,0 +1,56 @@
#include <plutosvg.h>
#include <stdio.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_MODULE_H
int main(int argc, char* argv[])
{
if(argc != 4) {
fprintf(stderr, "Usage: emoji2png font codepoint size\n");
return -1;
}
const char* filename = argv[1];
FT_ULong codepoint = strtoul(argv[2], NULL, 16);
FT_ULong size = strtoul(argv[3], NULL, 10);
FT_Library library = NULL;
FT_Face face = NULL;
FT_Error error = FT_Err_Ok;
if((error = FT_Init_FreeType(&library)))
goto cleanup;
if((error = FT_Property_Set(library, "ot-svg", "svg-hooks", plutosvg_ft_svg_hooks())))
goto cleanup;
if((error = FT_New_Face(library, filename, 0, &face)))
goto cleanup;
if((error = FT_Set_Pixel_Sizes(face, 0, size)))
goto cleanup;
if((error = FT_Load_Char(face, codepoint, FT_LOAD_RENDER | FT_LOAD_COLOR))) {
goto cleanup;
}
if(face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) {
plutovg_surface_t* surface = plutovg_surface_create_for_data(
face->glyph->bitmap.buffer, face->glyph->bitmap.width,
face->glyph->bitmap.rows, face->glyph->bitmap.pitch
);
char name[64];
sprintf(name, "emoji-%lx.png", codepoint);
plutovg_surface_write_to_png(surface, name);
plutovg_surface_destroy(surface);
fprintf(stdout, "Generated Emoji: %s\n", name);
} else {
fprintf(stderr, "The glyph for codepoint %lx is not in color mode.\n", codepoint);
}
cleanup:
if(error) fprintf(stderr, "freetype error: %s\n", FT_Error_String(error));
FT_Done_Face(face);
FT_Done_FreeType(library);
return error;
}

View File

@@ -0,0 +1,8 @@
fs = import('fs')
fs.copyfile('camera.svg')
executable('camera2png', 'camera2png.c', dependencies: plutosvg_dep)
executable('svg2png', 'svg2png.c', dependencies: plutosvg_dep)
if freetype_dep.found()
executable('emoji2png', 'emoji2png.c', dependencies: [plutosvg_dep, freetype_dep])
endif

63
3rdparty/plutosvg/examples/svg2png.c vendored Normal file
View File

@@ -0,0 +1,63 @@
#include <plutosvg.h>
#include <stdio.h>
#include <time.h>
static double elapsed_time(clock_t start, clock_t end)
{
return ((double)(end - start)) / CLOCKS_PER_SEC;
}
int main(int argc, char* argv[])
{
if(argc != 3 && argc != 4) {
fprintf(stderr, "Usage: svg2png input output [id]\n");
return -1;
}
const char* input = argv[1];
const char* output = argv[2];
const char* id = NULL;
if(argc == 4) {
id = argv[3];
}
plutosvg_document_t* document = NULL;
plutovg_surface_t* surface = NULL;
clock_t start, end;
start = clock();
document = plutosvg_document_load_from_file(input, -1, -1);
end = clock();
if(document == NULL) {
fprintf(stderr, "Unable to load '%s'\n", input);
goto cleanup;
}
fprintf(stdout, "Finished loading '%s' in %.3f seconds\n", input, elapsed_time(start, end));
start = clock();
surface = plutosvg_document_render_to_surface(document, id, -1, -1, NULL, NULL, NULL);
end = clock();
if(surface == NULL) {
fprintf(stderr, "Unable to render '%s'\n", input);
goto cleanup;
}
fprintf(stdout, "Finished rendering '%s' in %.3f seconds\n", input, elapsed_time(start, end));
start = clock();
if(!plutovg_surface_write_to_png(surface, output)) {
fprintf(stderr, "Unable to write '%s'\n", output);
goto cleanup;
}
end = clock();
fprintf(stdout, "Finished writing '%s' in %.3f seconds\n", output, elapsed_time(start, end));
cleanup:
plutovg_surface_destroy(surface);
plutosvg_document_destroy(document);
return 0;
}