From f6c7cb873e7998ff0641131bba57c0f83e53b938 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 22 Jan 2010 23:20:06 +0000 Subject: add basic (but working) path support svn path=/trunk/libnsfb/; revision=9865 --- include/libnsfb_plot.h | 4 +- include/plot.h | 4 +- src/plot/api.c | 8 +- src/plot/generic.c | 205 ++++++++++++++++++++++++++-------------- test/bezier.c | 24 +++-- test/path.c | 10 +- test/polystar.c | 3 +- test/svgtiny.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 413 insertions(+), 92 deletions(-) create mode 100644 test/svgtiny.c diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h index 34be612..931243d 100644 --- a/include/libnsfb_plot.h +++ b/include/libnsfb_plot.h @@ -138,9 +138,9 @@ bool nsfb_plot_arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle */ bool nsfb_plot_point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c); -bool nsfb_plot_cubic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_colour_t c); +bool nsfb_plot_cubic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_plot_pen_t *pen); -bool nsfb_plot_quadratic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_colour_t cl); +bool nsfb_plot_quadratic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_plot_pen_t *pen); bool nsfb_plot_path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen); diff --git a/include/plot.h b/include/plot.h index a745eb4..38bed61 100644 --- a/include/plot.h +++ b/include/plot.h @@ -84,11 +84,11 @@ typedef bool (nsfb_plotfn_readrect_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colo /** Plot quadratic bezier spline */ -typedef bool (nsfb_plotfn_quadratic_bezier_t)(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_colour_t c); +typedef bool (nsfb_plotfn_quadratic_bezier_t)(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_plot_pen_t *pen); /** Plot cubic bezier spline */ -typedef bool (nsfb_plotfn_cubic_bezier_t)(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_colour_t c); +typedef bool (nsfb_plotfn_cubic_bezier_t)(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_plot_pen_t *pen); typedef bool (nsfb_plotfn_polylines_t)(nsfb_t *nsfb, int pointc, const nsfb_point_t *points, nsfb_plot_pen_t *pen); diff --git a/src/plot/api.c b/src/plot/api.c index 95644cc..f5c16f3 100644 --- a/src/plot/api.c +++ b/src/plot/api.c @@ -158,14 +158,14 @@ bool nsfb_plot_readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer) } -bool nsfb_plot_cubic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_colour_t c) +bool nsfb_plot_cubic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_plot_pen_t *pen) { - return nsfb->plotter_fns->cubic(nsfb, curve, ctrla, ctrlb, c); + return nsfb->plotter_fns->cubic(nsfb, curve, ctrla, ctrlb, pen); } -bool nsfb_plot_quadratic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_colour_t c) +bool nsfb_plot_quadratic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_plot_pen_t *pen) { - return nsfb->plotter_fns->quadratic(nsfb, curve, ctrla, c); + return nsfb->plotter_fns->quadratic(nsfb, curve, ctrla, pen); } bool nsfb_plot_path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen) diff --git a/src/plot/generic.c b/src/plot/generic.c index 287c2c0..2c3cdbb 100644 --- a/src/plot/generic.c +++ b/src/plot/generic.c @@ -516,11 +516,12 @@ static bool arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, #define N_SEG 30 static bool -cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_colour_t cl) +cubic_points(unsigned int pointc, + nsfb_point_t *point, + nsfb_bbox_t *curve, + nsfb_point_t *ctrla, + nsfb_point_t *ctrlb) { - nsfb_bbox_t line; - nsfb_plot_pen_t pen; - unsigned int seg_loop; double t; double one_minus_t; @@ -531,13 +532,13 @@ cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb double x; double y; - pen.stroke_colour = cl; - - x = curve->x0; - y = curve->y0; + point->x = curve->x0; + point->y = curve->y0; + point++; + pointc--; - for (seg_loop = 1; seg_loop <= N_SEG; ++seg_loop) { - t = (double)seg_loop / (double)N_SEG; + for (seg_loop = 1; seg_loop < pointc; ++seg_loop) { + t = (double)seg_loop / (double)pointc; one_minus_t = 1.0 - t; @@ -546,26 +547,45 @@ cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb c = 3.0 * t * t * one_minus_t; d = t * t * t; - line.x0 = x; - line.y0 = y; - x = a * curve->x0 + b * ctrla->x + c * ctrlb->x + d * curve->x1; y = a * curve->y0 + b * ctrla->y + c * ctrlb->y + d * curve->y1; - line.x1 = x; - line.y1 = y; - - nsfb->plotter_fns->line(nsfb, 1, &line, &pen); + point->x = x; + point->y = y; + point++; } + point->x = curve->x1; + point->y = curve->y1; + return true; } -static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_colour_t cl) +static bool +polylines(nsfb_t *nsfb, + int pointc, + const nsfb_point_t *points, + nsfb_plot_pen_t *pen) { + int point_loop; nsfb_bbox_t line; - nsfb_plot_pen_t pen; + if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) { + for (point_loop = 0; point_loop < (pointc - 1); point_loop++) { + line = *(nsfb_bbox_t *)&points[point_loop]; + nsfb->plotter_fns->line(nsfb, 1, &line, pen); + } + } + return true; +} + + +static bool +quadratic_points(unsigned int pointc, + nsfb_point_t *point, + nsfb_bbox_t *curve, + nsfb_point_t *ctrla) +{ unsigned int seg_loop; double t; double one_minus_t; @@ -575,13 +595,12 @@ static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsf double x; double y; - pen.stroke_colour = cl; - - x = curve->x0; - y = curve->y0; - - for (seg_loop = 1; seg_loop <= N_SEG; ++seg_loop) { - t = (double)seg_loop / (double)N_SEG; + point->x = curve->x0; + point->y = curve->y0; + point++; + pointc--; + for (seg_loop = 1; seg_loop < pointc; ++seg_loop) { + t = (double)seg_loop / (double)pointc; one_minus_t = 1.0 - t; @@ -589,36 +608,54 @@ static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsf b = 2.0 * t * one_minus_t; c = t * t; - line.x0 = x; - line.y0 = y; - x = a * curve->x0 + b * ctrla->x + c * curve->x1; y = a * curve->y0 + b * ctrla->y + c * curve->y1; - line.x1 = x; - line.y1 = y; - - nsfb->plotter_fns->line(nsfb, 1, &line, &pen); + point->x = x; + point->y = y; + point++; } + point->x = curve->x1; + point->y = curve->y1; + return true; } +static bool +quadratic(nsfb_t *nsfb, + nsfb_bbox_t *curve, + nsfb_point_t *ctrla, + nsfb_plot_pen_t *pen) +{ + nsfb_point_t points[N_SEG]; + + if (pen->stroke_type == NFSB_PLOT_OPTYPE_NONE) + return false; + + quadratic_points(N_SEG, points, curve, ctrla); -static bool polylines(nsfb_t *nsfb, int pointc, const nsfb_point_t *points, nsfb_plot_pen_t *pen) + return polylines(nsfb, N_SEG, points, pen); +} + +static bool +cubic(nsfb_t *nsfb, + nsfb_bbox_t *curve, + nsfb_point_t *ctrla, + nsfb_point_t *ctrlb, + nsfb_plot_pen_t *pen) { - int point_loop; - nsfb_bbox_t line; + nsfb_point_t points[N_SEG]; - if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) { - for (point_loop = 0; point_loop < (pointc - 1); point_loop++) { - line = *(nsfb_bbox_t *)&points[point_loop]; - nsfb->plotter_fns->line(nsfb, 1, &line, pen); - } - } - return true; + if (pen->stroke_type == NFSB_PLOT_OPTYPE_NONE) + return false; + + cubic_points(N_SEG, points, curve, ctrla,ctrlb); + + return polylines(nsfb, N_SEG, points, pen); } + static bool path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen) { @@ -626,40 +663,68 @@ path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen) nsfb_point_t *pts; nsfb_point_t *curpt; int ptc = 0; + nsfb_bbox_t curve; + nsfb_point_t ctrla; + nsfb_point_t ctrlb; + int added_count = 0; + + /* count the verticies in the path and add N_SEG extra for curves */ + for (path_loop = 0; path_loop < pathc; path_loop++) { + ptc++; + if ((pathop[path_loop].operation == NFSB_PLOT_PATHOP_QUAD) || + (pathop[path_loop].operation == NFSB_PLOT_PATHOP_CUBIC)) + ptc += N_SEG; + } - /* count the verticies in the path and add N_SEG extra for curves */ - for (path_loop = 0; path_loop < pathc; path_loop++) { - ptc++; - if ((pathop[path_loop].operation == NFSB_PLOT_PATHOP_QUAD) || - (pathop[path_loop].operation == NFSB_PLOT_PATHOP_QUAD)) - ptc += N_SEG; - } - - /* allocate storage for the vertexes */ - curpt = pts = malloc(ptc * sizeof(nsfb_point_t)); - - for (path_loop = 0; path_loop < pathc; path_loop++) { - switch (pathop[path_loop].operation) { - case NFSB_PLOT_PATHOP_QUAD: - curpt-=1; - break; - - case NFSB_PLOT_PATHOP_CUBIC: - curpt-=2; - break; - - default: - *curpt = pathop[path_loop].point; - curpt++; - } + /* allocate storage for the vertexes */ + curpt = pts = malloc(ptc * sizeof(nsfb_point_t)); + + for (path_loop = 0; path_loop < pathc; path_loop++) { + switch (pathop[path_loop].operation) { + case NFSB_PLOT_PATHOP_QUAD: + curpt-=2; + added_count -= 2; + curve.x0 = pathop[path_loop - 2].point.x; + curve.y0 = pathop[path_loop - 2].point.y; + ctrla.x = pathop[path_loop - 1].point.x; + ctrla.y = pathop[path_loop - 1].point.y; + curve.x1 = pathop[path_loop].point.x; + curve.y1 = pathop[path_loop].point.y; + quadratic_points(N_SEG, curpt, &curve, &ctrla); + curpt+=N_SEG; + added_count += N_SEG; + break; + + case NFSB_PLOT_PATHOP_CUBIC: + curpt-=3; + added_count -=3; + curve.x0 = pathop[path_loop - 3].point.x; + curve.y0 = pathop[path_loop - 3].point.y; + ctrla.x = pathop[path_loop - 2].point.x; + ctrla.y = pathop[path_loop - 2].point.y; + ctrlb.x = pathop[path_loop - 1].point.x; + ctrlb.y = pathop[path_loop - 1].point.y; + curve.x1 = pathop[path_loop].point.x; + curve.y1 = pathop[path_loop].point.y; + cubic_points(N_SEG, curpt, &curve, &ctrla, &ctrlb); + curpt += N_SEG; + added_count += N_SEG; + break; + + default: + *curpt = pathop[path_loop].point; + curpt++; + added_count ++; + break; } + } if (pen->fill_type != NFSB_PLOT_OPTYPE_NONE) { - polygon(nsfb, (int *)pts, path_loop, pen->fill_colour); + polygon(nsfb, (int *)pts, added_count, pen->fill_colour); } if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) { - polylines(nsfb, path_loop, pts, pen); + polylines(nsfb, added_count, pts, pen); } free(pts); diff --git a/test/bezier.c b/test/bezier.c index c523da8..d686349 100644 --- a/test/bezier.c +++ b/test/bezier.c @@ -55,17 +55,21 @@ int main(int argc, char **argv) box2.x1=400; box2.y1=400; + pen.stroke_colour = 0xff000000; + pen.fill_colour = 0xffff0000; + pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID; + pen.fill_type = NFSB_PLOT_OPTYPE_NONE; + for (loop=-300;loop < 600;loop+=100) { - ctrla.x = 100; - ctrla.y = loop; + ctrla.x = 100; + ctrla.y = loop; - ctrlb.x = 400; - ctrlb.y = 500 - loop; + ctrlb.x = 400; + ctrlb.y = 500 - loop; - nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, 0xff000000); + nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, &pen); } - pen.stroke_colour = 0xff000000; box2.x0=400; box2.y0=100; @@ -92,7 +96,9 @@ int main(int argc, char **argv) ctrla.x = 600; ctrla.y = 400; - nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, 0xffff0000); + pen.stroke_colour = 0xffff0000; + + nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, &pen); box2.x0=400; box2.y0=100; @@ -103,7 +109,9 @@ int main(int argc, char **argv) ctrla.x = 600; ctrla.y = 400; - nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, 0xff0000ff); + pen.stroke_colour = 0xff0000ff; + + nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, &pen); nsfb_update(nsfb, &box); diff --git a/test/path.c b/test/path.c index 26c471e..b62b43d 100644 --- a/test/path.c +++ b/test/path.c @@ -23,13 +23,13 @@ static int fill_shape(nsfb_plot_pathop_t *path, int xoff, int yoff) PENT(NFSB_PLOT_PATHOP_LINE, xoff + 100, yoff + 100); PENT(NFSB_PLOT_PATHOP_LINE, xoff + 100, yoff ); PENT(NFSB_PLOT_PATHOP_LINE, xoff + 200, yoff + 100); - //PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 200, yoff - 200); - //PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 300, yoff + 300); - //PENT(NFSB_PLOT_PATHOP_CUBIC, xoff + 300, yoff ); + PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 200, yoff - 200); + PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 300, yoff + 300); + PENT(NFSB_PLOT_PATHOP_CUBIC, xoff + 300, yoff ); PENT(NFSB_PLOT_PATHOP_LINE, xoff + 400, yoff + 100); PENT(NFSB_PLOT_PATHOP_LINE, xoff + 400, yoff ); - //PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 500, yoff + 200); - //PENT(NFSB_PLOT_PATHOP_QUAD, xoff + 500, yoff ); + PENT(NFSB_PLOT_PATHOP_MOVE, xoff + 500, yoff + 200); + PENT(NFSB_PLOT_PATHOP_QUAD, xoff + 500, yoff ); PENT(NFSB_PLOT_PATHOP_LINE, xoff + 600, yoff + 150); PENT(NFSB_PLOT_PATHOP_LINE, xoff, yoff + 150); PENT(NFSB_PLOT_PATHOP_LINE, xoff, yoff); diff --git a/test/polystar.c b/test/polystar.c index 25b1f42..6963cfb 100644 --- a/test/polystar.c +++ b/test/polystar.c @@ -62,6 +62,7 @@ int main(int argc, char **argv) pen.stroke_colour = 0xff000000; pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID; + for (rotate =0; rotate < (2 * M_PI); rotate += (M_PI / 8)) { /* claim the whole screen for update */ nsfb_claim(nsfb, &box); @@ -70,7 +71,7 @@ int main(int argc, char **argv) radius = (box.y1 / 2); - for (sides = 10; sides >=9; sides-=2) { + for (sides = 18; sides >=9; sides-=2) { points = malloc(sizeof(nsfb_point_t) * sides); for (loop = 0; loop < sides;loop+=2) { diff --git a/test/svgtiny.c b/test/svgtiny.c new file mode 100644 index 0000000..331284e --- /dev/null +++ b/test/svgtiny.c @@ -0,0 +1,247 @@ +/* + * This file is part of Libsvgtiny + * Licensed under the MIT License, + * http://opensource.org/licenses/mit-license.php + * Copyright 2008 James Bursa + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "libnsfb.h" +#include "libnsfb_plot.h" +#include "libnsfb_event.h" + + nsfb_t *nsfb; + nsfb_bbox_t screen_box; + uint8_t *fbptr; + int fbstride; + nsfb_event_t event; + +static int setup_fb(void) +{ + nsfb = nsfb_init(NSFB_FRONTEND_SDL); + if (nsfb == NULL) { + fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + return 1; + } + + if (nsfb_init_frontend(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb frontend\n"); + return 2; + } + + /* get the geometry of the whole screen */ + screen_box.x0 = screen_box.y0 = 0; + nsfb_get_geometry(nsfb, &screen_box.x1, &screen_box.y1, NULL); + + nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + + /* claim the whole screen for update */ + nsfb_claim(nsfb, &screen_box); + + nsfb_plot_clg(nsfb, 0xffffffff); + + return 0; +} + +int main(int argc, char *argv[]) +{ + FILE *fd; + float scale = 1.0; + struct stat sb; + char *buffer; + size_t size; + size_t n; + struct svgtiny_diagram *diagram; + svgtiny_code code; + + if (argc != 2 && argc != 3) { + fprintf(stderr, "Usage: %s FILE [SCALE]\n", argv[0]); + return 1; + } + + /* load file into memory buffer */ + fd = fopen(argv[1], "rb"); + if (!fd) { + perror(argv[1]); + return 1; + } + + if (stat(argv[1], &sb)) { + perror(argv[1]); + return 1; + } + size = sb.st_size; + + buffer = malloc(size); + if (!buffer) { + fprintf(stderr, "Unable to allocate %lld bytes\n", + (long long) size); + return 1; + } + + n = fread(buffer, 1, size, fd); + if (n != size) { + perror(argv[1]); + return 1; + } + + fclose(fd); + + /* read scale argument */ + if (argc == 3) { + scale = atof(argv[2]); + if (scale == 0) + scale = 1.0; + } + + /* create svgtiny object */ + diagram = svgtiny_create(); + if (!diagram) { + fprintf(stderr, "svgtiny_create failed\n"); + return 1; + } + + /* parse */ + code = svgtiny_parse(diagram, buffer, size, argv[1], 1000, 1000); + if (code != svgtiny_OK) { + fprintf(stderr, "svgtiny_parse failed: "); + switch (code) { + case svgtiny_OUT_OF_MEMORY: + fprintf(stderr, "svgtiny_OUT_OF_MEMORY"); + break; + case svgtiny_LIBXML_ERROR: + fprintf(stderr, "svgtiny_LIBXML_ERROR"); + break; + case svgtiny_NOT_SVG: + fprintf(stderr, "svgtiny_NOT_SVG"); + break; + case svgtiny_SVG_ERROR: + fprintf(stderr, "svgtiny_SVG_ERROR: line %i: %s", + diagram->error_line, + diagram->error_message); + break; + default: + fprintf(stderr, "unknown svgtiny_code %i", code); + break; + } + fprintf(stderr, "\n"); + } + + free(buffer); + + if (setup_fb() != 0) + return 1; + + for (unsigned int i = 0; i != diagram->shape_count; i++) { + nsfb_plot_pen_t pen; + pen.stroke_colour = svgtiny_RED(diagram->shape[i].stroke) | + svgtiny_GREEN(diagram->shape[i].stroke) << 8| + svgtiny_BLUE(diagram->shape[i].stroke) << 16; + pen.fill_colour = svgtiny_RED(diagram->shape[i].fill) | + svgtiny_GREEN(diagram->shape[i].fill) << 8| + svgtiny_BLUE(diagram->shape[i].fill) << 16; + + if (diagram->shape[i].fill == svgtiny_TRANSPARENT) + pen.fill_type = NFSB_PLOT_OPTYPE_NONE; + else + pen.fill_type = NFSB_PLOT_OPTYPE_SOLID; + + if (diagram->shape[i].stroke == svgtiny_TRANSPARENT) + pen.stroke_type = NFSB_PLOT_OPTYPE_NONE; + else + pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID; + + pen.stroke_width = scale * diagram->shape[i].stroke_width; + + if (diagram->shape[i].path) { + nsfb_plot_pathop_t *fb_path; + int fb_path_c; + unsigned int j; + fb_path = malloc(diagram->shape[i].path_length * 3 * sizeof(nsfb_plot_pathop_t)); + fb_path_c = 0; + + for (j = 0; + j != diagram->shape[i].path_length; ) { + switch ((int) diagram->shape[i].path[j]) { + case svgtiny_PATH_MOVE: + fb_path[fb_path_c].operation = NFSB_PLOT_PATHOP_MOVE; + fb_path[fb_path_c].point.x = scale * diagram->shape[i].path[j + 1]; + fb_path[fb_path_c].point.y = scale * diagram->shape[i].path[j + 2]; + fb_path_c++; + j += 3; + break; + + case svgtiny_PATH_CLOSE: + fb_path[fb_path_c].operation = NFSB_PLOT_PATHOP_LINE; + fb_path[fb_path_c].point.x = fb_path[0].point.x; + fb_path[fb_path_c].point.y = fb_path[0].point.y; + fb_path_c++; + j += 1; + break; + + case svgtiny_PATH_LINE: + fb_path[fb_path_c].operation = NFSB_PLOT_PATHOP_LINE; + fb_path[fb_path_c].point.x = scale * diagram->shape[i].path[j + 1]; + fb_path[fb_path_c].point.y = scale * diagram->shape[i].path[j + 2]; + fb_path_c++; + + j += 3; + break; + + case svgtiny_PATH_BEZIER: + fb_path[fb_path_c].operation = NFSB_PLOT_PATHOP_MOVE; + fb_path[fb_path_c].point.x = scale * diagram->shape[i].path[j + 1]; + fb_path[fb_path_c].point.y = scale * diagram->shape[i].path[j + 2]; + fb_path_c++; + fb_path[fb_path_c].operation = NFSB_PLOT_PATHOP_MOVE; + fb_path[fb_path_c].point.x = scale * diagram->shape[i].path[j + 3]; + fb_path[fb_path_c].point.y = scale * diagram->shape[i].path[j + 4]; + fb_path_c++; + fb_path[fb_path_c].operation = NFSB_PLOT_PATHOP_CUBIC; + fb_path[fb_path_c].point.x = scale * diagram->shape[i].path[j + 5]; + fb_path[fb_path_c].point.y = scale * diagram->shape[i].path[j + 6]; + fb_path_c++; + + j += 7; + break; + + default: + printf("error "); + j += 1; + } + } + + nsfb_plot_path(nsfb, fb_path_c, fb_path, &pen); + } else if (diagram->shape[i].text) { + /* printf("text %g %g '%s' ", + scale * diagram->shape[i].text_x, + scale * diagram->shape[i].text_y, + diagram->shape[i].text);*/ + } + } + + svgtiny_free(diagram); + + nsfb_update(nsfb, &screen_box); + + while (event.type != NSFB_EVENT_CONTROL) + nsfb_event(nsfb, &event, -1); + + return 0; +} + +/* + +cc -g -std=c99 -D_BSD_SOURCE -I/home/vince/netsurf/libnsfb/include/ -I/home/vince/netsurf/libnsfb/src -I/usr/local/include -I/usr/include/libxml2 -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Werror -pedantic -Wno-overlength-strings -DNDEBUG -O2 -DBUILD_TARGET_Linux -DBUILD_HOST_Linux -o build-Linux-Linux-release-lib-static/test_svgtiny.o -c test/svgtiny.c + +cc -o build-Linux-Linux-release-lib-static/test_svgtiny build-Linux-Linux-release-lib-static/test_svgtiny.o -Wl,--whole-archive -lnsfb -Wl,--no-whole-archive -lSDL -Lbuild-Linux-Linux-release-lib-static/ -lnsfb -lsvgtiny -lxml2 + + */ -- cgit v1.2.3