From a277985934e3823267b2d5b4e51f124ec3e73489 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Mon, 18 May 2026 17:01:02 +0300
Subject: [PATCH] nanosvg.h: revert old css style support:
Reverts commit 9509d7247c18b9ecc61778f4b7caeea84058c86c
Reverts commit 3291751d5ba8c7f933ef0992e6128d1b8c9edc2c
(cherry picked from commit 527fd96620315f8f56ed0e95c0e7cf65b770beb0)
---
src/nanosvg.h | 97 +++------------------------------------------------
1 file changed, 4 insertions(+), 93 deletions(-)
diff --git a/src/nanosvg.h b/src/nanosvg.h
index 63b1c5efc..9c9e8554a 100644
--- a/src/nanosvg.h
+++ b/src/nanosvg.h
@@ -448,13 +448,6 @@ typedef struct NSVGattrib
char visible;
} NSVGattrib;
-typedef struct NSVGstyles
-{
- char* name;
- char* description;
- struct NSVGstyles* next;
-} NSVGstyles;
-
typedef struct NSVGparser
{
NSVGattrib attr[NSVG_MAX_ATTR];
@@ -464,7 +457,6 @@ typedef struct NSVGparser
int cpts;
NSVGpath* plist;
NSVGimage* image;
- NSVGstyles* styles;
NSVGgradientData* gradients;
NSVGshape* shapesTail;
float viewMinx, viewMiny, viewWidth, viewHeight;
@@ -472,7 +464,6 @@ typedef struct NSVGparser
float dpi;
char pathFlag;
char defsFlag;
- char styleFlag;
} NSVGparser;
static void nsvg__xformIdentity(float* t)
@@ -670,18 +661,6 @@ static NSVGparser* nsvg__createParser(void)
return NULL;
}
-static void nsvg__deleteStyles(NSVGstyles* style) {
- while (style) {
- NSVGstyles *next = style->next;
- if (style->name)
- free(style->name);
- if (style->description)
- free(style->description);
- free(style);
- style = next;
- }
-}
-
static void nsvg__deletePaths(NSVGpath* path)
{
while (path) {
@@ -713,7 +692,6 @@ static void nsvg__deleteGradientData(NSVGgradientData* grad)
static void nsvg__deleteParser(NSVGparser* p)
{
if (p != NULL) {
- nsvg__deleteStyles(p->styles);
nsvg__deletePaths(p->plist);
nsvg__deleteGradientData(p->gradients);
nsvgDelete(p->image);
@@ -1876,14 +1854,6 @@ static int nsvg__parseAttr(NSVGparser* p, const char* name, const char* value)
} else if (strcmp(name, "id") == 0) {
strncpy(attr->id, value, 63);
attr->id[63] = '\0';
- } else if (strcmp(name, "class") == 0) {
- NSVGstyles* style = p->styles;
- while (style) {
- if (strcmp(style->name + 1, value) == 0) {
- nsvg__parseStyle(p, style->description);
- }
- style = style->next;
- }
} else {
return 0;
}
@@ -2794,15 +2764,13 @@ static void nsvg__startElement(void* ud, const char* el, const char** attr)
NSVGparser* p = (NSVGparser*)ud;
if (p->defsFlag) {
- // Skip everything but gradients and styles in defs
+ // Skip everything but gradients in defs
if (strcmp(el, "linearGradient") == 0) {
nsvg__parseGradient(p, attr, NSVG_PAINT_LINEAR_GRADIENT);
} else if (strcmp(el, "radialGradient") == 0) {
nsvg__parseGradient(p, attr, NSVG_PAINT_RADIAL_GRADIENT);
} else if (strcmp(el, "stop") == 0) {
nsvg__parseGradientStop(p, attr);
- } else if (strcmp(el, "style") == 0) {
- p->styleFlag = 1;
}
return;
}
@@ -2850,8 +2818,6 @@ static void nsvg__startElement(void* ud, const char* el, const char** attr)
p->defsFlag = 1;
} else if (strcmp(el, "svg") == 0) {
nsvg__parseSVG(p, attr);
- } else if (strcmp(el, "style") == 0) {
- p->styleFlag = 1;
}
}
@@ -2865,69 +2831,14 @@ static void nsvg__endElement(void* ud, const char* el)
p->pathFlag = 0;
} else if (strcmp(el, "defs") == 0) {
p->defsFlag = 0;
- } else if (strcmp(el, "style") == 0) {
- p->styleFlag = 0;
}
}
-static char *nsvg__strndup(const char *s, size_t n)
-{
- char *result;
- size_t len = strlen(s);
-
- if (n < len)
- len = n;
-
- result = (char *)malloc(len + 1);
- if (!result)
- return NULL;
-
- result[len] = '\0';
- return (char *)memcpy(result, s, len);
-}
-
static void nsvg__content(void* ud, const char* s)
{
- NSVGparser* p = (NSVGparser*)ud;
- if (p->styleFlag) {
-
- int state = 0;
- int class_count = 0;
- const char* start = s;
- while (*s) {
- char c = *s;
- if (state == 2) {
- if (c == '{') {
- start = s + 1;
- } else if (c == '}') {
- NSVGstyles *style = p->styles;
- while (class_count > 0) {
- style->description = nsvg__strndup(start, (size_t)(s - start));
- style = style->next;
- --class_count;
- }
- state = 0;
- }
- } else if (nsvg__isspace(c) || c == '{' || c == ',') {
- if (state == 1) {
- if (*start == '.') {
- NSVGstyles* next = p->styles;
- p->styles = (NSVGstyles*)malloc(sizeof(NSVGstyles));
- p->styles->description = NULL;
- p->styles->next = next;
- p->styles->name = nsvg__strndup(start, (size_t)(s - start));
- ++class_count;
- }
- start = s + 1;
- state = c == ',' ? 0 : 2;
- }
- } else if (state == 0) {
- start = s;
- state = 1;
- }
- s++;
- }
- }
+ NSVG_NOTUSED(ud);
+ NSVG_NOTUSED(s);
+ // empty
}
static void nsvg__imageBounds(NSVGparser* p, float* bounds)