[dia] svg: support parsing of 12 bit color



commit a79de8826e8989f9417ca4ea75112704811a7b8e
Author: Hans Breuer <hans breuer org>
Date:   Sat Aug 3 18:09:22 2013 +0200

    svg: support parsing of 12 bit color

 lib/dia_svg.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index 5104189..f215a4a 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -168,9 +168,14 @@ svg_named_color (const char *name, gint32 *color)
 static gboolean
 _parse_color(gint32 *color, const char *str)
 {
-  if (str[0] == '#')
-    *color = strtol(str+1, NULL, 16) & 0xffffff;
-  else if (0 == strncmp(str, "none", 4))
+  if (str[0] == '#') {
+    char *endp = NULL;
+    guint32 val = strtol(str+1, &endp, 16);
+    if (endp - (str + 1) > 3) /* no 16-bit color here */
+      *color =  val & 0xffffff;
+    else /* weak estimation: Pango is reusing bits to fill */
+      *color = ((0xF & val)<<4) | ((0xF0 & val)<<8) | (((0xF00 & val)>>4)<<16);
+  } else if (0 == strncmp(str, "none", 4))
     *color = DIA_SVG_COLOUR_NONE;
   else if (0 == strncmp(str, "foreground", 10) || 0 == strncmp(str, "fg", 2) ||
           0 == strncmp(str, "inverse", 7))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]