aboutsummaryrefslogtreecommitdiff
path: root/src/svg.c
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-07-27 12:52:51 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-07-27 12:54:47 +0200
commitc2081d28740e03d43b9dbbe9dbd5ac6484e8953a (patch)
treeeb1c8ac0965fee0139ee58db131a142b2150b4c8 /src/svg.c
parent59b746f013f60050b91cb5f6f8dd4a96c47f380e (diff)
Add SVG support for currentColor
The currentColor special value for the fill and stroke attributes allows an image to follow the same foreground color of the surounding text.
Diffstat (limited to 'src/svg.c')
-rw-r--r--src/svg.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/svg.c b/src/svg.c
index 98fe2ada..5536e9a3 100644
--- a/src/svg.c
+++ b/src/svg.c
@@ -31,6 +31,7 @@ typedef struct {
DilloUrl *url; /* Primary Key for the dicache */
int version; /* Secondary Key for the dicache */
int bgcolor; /* Parent widget background color */
+ int fgcolor; /* Parent widget foreground color */
} DilloSvg;
/*
@@ -71,9 +72,16 @@ static void Svg_write(DilloSvg *svg, void *Buf, uint_t BufSize)
if (strstr(Buf, "</svg>") == NULL)
return;
+ /* Use foreground as the current color, but transform to
+ * nanosvg color format (BGR). */
+ unsigned fg_r = (svg->fgcolor >> 16) & 0xff;
+ unsigned fg_g = (svg->fgcolor >> 8) & 0xff;
+ unsigned fg_b = (svg->fgcolor >> 0) & 0xff;
+ unsigned curcolor = NSVG_RGB(fg_r, fg_g, fg_b);
+
/* NULL-terminate Buf */
char *str = dStrndup(Buf, BufSize);
- NSVGimage *nimg = nsvgParse(str, "px", svg->Image->dpi);
+ NSVGimage *nimg = nsvgParse(str, "px", svg->Image->dpi, curcolor);
dFree(str);
if (nimg == NULL) {
@@ -149,6 +157,7 @@ void *a_Svg_new(DilloImage *Image, DilloUrl *url, int version)
svg->url = url;
svg->version = version;
svg->bgcolor = Image->bg_color;
+ svg->fgcolor = Image->fg_color;
return svg;
}