diff options
author | axtloss <axtlos@getcryst.al> | 2024-02-27 01:44:26 +0100 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-02-27 01:44:26 +0100 |
commit | c9b119217829f976a7830a0555650401cf9df2cb (patch) | |
tree | ed0aa12813af1091fe1096fb62b3495dfd0966d8 /fbwarn/src/parseBVG.c | |
parent | ae895bf260f2015816988bffe429f06faf653707 (diff) | |
download | fsverify-c9b119217829f976a7830a0555650401cf9df2cb.tar.gz fsverify-c9b119217829f976a7830a0555650401cf9df2cb.tar.bz2 |
add functionality to read from bvg file
Diffstat (limited to '')
-rw-r--r-- | fbwarn/src/parseBVG.c | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/fbwarn/src/parseBVG.c b/fbwarn/src/parseBVG.c index b71b55f..4209383 100644 --- a/fbwarn/src/parseBVG.c +++ b/fbwarn/src/parseBVG.c @@ -29,8 +29,6 @@ void BVGDrawCircle(BVGCircle *circle) { if (circle->drawSector) { DrawCircleSector(center, circle->radius, circle->startAngle, circle->endAngle, circle->segments, circle->color); } else { - printf("center: %f, %f\n", center.x, center.y); - printf("radius: %f, color: %d\n", circle->radius, circle->color.a); DrawCircle(circle->centerX, circle->centerY, circle->radius, circle->color); } } @@ -40,6 +38,14 @@ void BVGDrawRing(BVGRing *ring) { DrawRing(center, ring->inRadius, ring->outRadius, ring->startAngle, ring->endAngle, ring->segmets, ring->color); } +void BVGDrawTriangle(BVGTriangle *triangle) { + if (triangle->fill) { + DrawTriangle(triangle->corner1, triangle->corner2, triangle->corner3, triangle->color); + } else { + DrawTriangleLines(triangle->corner1, triangle->corner2, triangle->corner3, triangle->color); + } +} + void BVGDrawText(BVGText *text) { DrawText(text->text, text->x, text->y, text->fontSize, text->color); } @@ -61,9 +67,11 @@ FILE *readFile(char *path) { char *multiToSingle(char *s) { // allocating the size of lines is safe since characters arent added char *midresult = malloc (strlen(s)+1); + char *notab = malloc(strlen(s)+1); char *line; midresult = replaceStr(s, "\n", ""); - return replaceStr(midresult, ", ", ","); + notab = replaceStr(midresult, "\t", ""); + return replaceStr(notab, ", ", ","); } /* @@ -85,7 +93,11 @@ void collectArgs(char *res[], char *call, int n) { the res array contains only the values of each argument */ void orderArgs(char *res[], char *argv[], int n, char *knownArgs[]) { + if (argv == NULL || knownArgs == NULL) + exit(1); for(int i=0; i<n; i++) { + if (argv[i] == NULL) + continue; for(int j=0; j<n; j++) { if (strncmp(argv[i], knownArgs[j], strlen(knownArgs[j])) == 0) { res[j] = argv[i]+strlen(knownArgs[j])+1; @@ -120,7 +132,6 @@ Color *parseColorFromHex(char *hex) { */ bool parseBoolValue(char *value) { char *valueLower = strdup(strlwr(value)); - printf("Matching bool %s --- %s", valueLower, value); if (strcmp(valueLower, "false") == 0) { return false; } else { @@ -128,6 +139,19 @@ bool parseBoolValue(char *value) { } } +BVGIMG *BVGParseIMG(char *argv[2]) { + BVGIMG *result = malloc(sizeof(BVGIMG)); + size_t argN = 2; + char *args[argN]; + char *knownArgs[2] = {"width", "height"}; + orderArgs(args, argv, argN, knownArgs); + int width, height; + sscanf(args[0], "%d", &width); + sscanf(args[1], "%d", &height); + result->width=width; result->height=height; + return result; +} + /* Creates a BVGRectangle based on a BVG function call */ @@ -137,7 +161,6 @@ BVGRectangle *BVGParseRectangle(char *argv[7]) { size_t argN = 7; char *args[argN]; char *knownArgs[7] = {"x", "y", "width", "height", "color", "fill", "thickness"}; - //printf("118 Parsing...%s \n", args[0]); orderArgs(args, argv, argN, knownArgs); printf("119 Parsing...%s \n", args[0]); int x, y, width, height, r, g, b, a; @@ -275,6 +298,34 @@ BVGRing *BVGParseRing(char *argv[8]) { return result; } +BVGTriangle *BVGParseTriangle(char *argv[8]) { + BVGTriangle *result = malloc(sizeof(BVGTriangle)); + size_t argN = 8; + char *args[argN]; + char *knownArgs[8] = {"x1", "y1", "x2", "y2", "x3", "y3", "fill", "color"}; + orderArgs(args, argv, argN, knownArgs); + int x1, x2, x3; + int y1, y2, y3; + bool fill; + Color *clr; + sscanf(args[0], "%d", &x1); + sscanf(args[1], "%d", &y1); + sscanf(args[2], "%d", &x2); + sscanf(args[3], "%d", &y2); + sscanf(args[4], "%d", &x3); + sscanf(args[5], "%d", &y3); + fill = parseBoolValue(args[6]); + args[7] = args[7]+2; + args[7][strlen(args[7])-1] = '\0'; + clr = parseColorFromHex(args[7]); + result->corner1 = (Vector2){x1, y1}; + result->corner2 = (Vector2){x2, y2}; + result->corner3 = (Vector2){x3, y3}; + result->fill = fill; + result->color = *clr; + return result; +} + BVGText *BVGParseText(char *argv[5]) { BVGText *result = malloc(sizeof(BVGText)); size_t argN = 5; @@ -347,6 +398,13 @@ void matchFunctionCall(char *call) { BVGRing *ring = malloc(sizeof(BVGRing)); ring = BVGParseRing(argv); BVGDrawRing(ring); + } else if (strcmp(function, "triangle") == 0) { + char *argv[8]; + call = call+strlen("triangle ("); + collectArgs(argv, call, 8); + BVGTriangle *triangle = malloc(sizeof(BVGTriangle)); + triangle = BVGParseTriangle(argv); + BVGDrawTriangle(triangle); } else if (strcmp(function, "text") == 0) { char *argv[5]; call = call+strlen("text ("); |