hexagram/examples/svg.c
XANTRONIX Development 1bda9eda26 Port Python to C
2024-01-14 22:32:46 -05:00

105 lines
2.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
#include <cairo-svg.h>
#include <hexagram/path.h>
static char *path_data =
"M 23.246093 0,"
" 0 13.382812,"
"V 44.689453"
"L 0.0839844 44.640625,"
" 24.033203 58.505859,"
" 24.001953 86.332031,"
" 22.841796 87"
"h 4.478516"
"L 26.068359 86.275391,"
" 26.099609 58.449219,"
" 50.083984 44.640625,"
" 74.033203 58.505859,"
" 74.001953 86.332031,"
" 72.841796 87"
"h 4.478516"
"L 76.068359 86.275391,"
" 76.099609 58.449219,"
" 100 44.689453,"
"V 13.365234"
"L 76.919921 0"
"H 73.246093"
"L 50.015625 13.373047,"
" 26.919921 0"
"Z"
"M 25.083984 1.25,"
" 49.033203 15.115234,"
" 49.001953, 42.941406,"
" 25.017578 56.75,"
" 1.0019531 42.845703,"
"l 0.033203 -27.75"
"z"
"m 50 0,"
" 24.017576 13.904297,"
" -0.0352 27.75"
"L 75.017578 56.75,"
" 51.068359 42.884766,"
" 51.099609 15.058594"
"Z";
static int usage(int argc, char **argv, const char *message, ...) {
if (message) {
va_list args;
va_start(args, message);
vfprintf(stderr, message, args);
fprintf(stderr, "\n");
va_end(args);
}
fprintf(stderr, "usage: %s output.svg\n", argv[0]);
return 1;
}
int main(int argc, char **argv) {
int width = 1280,
height = 480;
cairo_surface_t *surface;
cairo_t *bg;
if (argc != 2) {
return usage(argc, argv, "No output SVG file specified");
}
surface = cairo_svg_surface_create(argv[1], width, height);
/*
* Set up the rendering surfaces
*/
bg = cairo_create(surface);
/*
* Draw the background layer
*/
if (hexagram_path_run(bg, path_data, strlen(path_data)) < 0) {
printf("Oh noes!\n");
goto error_path_run;
}
cairo_stroke(bg);
cairo_destroy(bg);
cairo_surface_destroy(surface);
return 0;
error_path_run:
return -1;
}