Code

excise never-used code and stale comments
[inkscape.git] / src / style.cpp
index ee67469ade716ac45dc3e9710748d83d23b53aa3..deffba366670dca9018b8e66ba5ed195e7142511 100644 (file)
@@ -23,6 +23,7 @@
 #include "xml/croco-node-iface.h"
 
 #include "svg/svg.h"
+#include "svg/svg-color.h"
 
 #include "display/canvas-bpath.h"
 #include "attributes.h"
@@ -145,7 +146,7 @@ static gint sp_style_write_ifontsize(gchar *p, gint len, gchar const *key, SPIFo
 static gint sp_style_write_ilengthornormal(gchar *p, gint const len, gchar const *const key, SPILengthOrNormal const *const val, SPILengthOrNormal const *const base, guint const flags);
 static gint sp_style_write_itextdecoration(gchar *p, gint const len, gchar const *const key, SPITextDecoration const *const val, SPITextDecoration const *const base, guint const flags);
 
-void css2_unescape_unquote (SPIString *val);
+static void css2_unescape_unquote(SPIString *val);
 
 static void sp_style_paint_clear(SPStyle *style, SPIPaint *paint, unsigned hunref, unsigned unset);
 
@@ -389,8 +390,14 @@ sp_style_new()
     sp_style_clear(style);
 
     style->cloned = false;
-    style->hreffed = false;
-    style->listening = false;
+
+    style->color_hreffed = false;
+    style->fill_hreffed = false;
+    style->stroke_hreffed = false;
+
+    style->color_listening = false;
+    style->fill_listening = false;
+    style->stroke_listening = false;
 
     return style;
 }
@@ -725,7 +732,7 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val)
             if (!style->text_private) sp_style_privatize_text(style);
             if (!style->text->font_family.set) {
                 sp_style_read_istring(&style->text->font_family, val);
-                css2_unescape_unquote (&style->text->font_family);
+                css2_unescape_unquote(&style->text->font_family);
             }
             break;
         case SP_PROP_FONT_SIZE:
@@ -1239,15 +1246,15 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
         // expressible in the current font family, but that's difficult to
         // find out, so jumping by 3 seems an appropriate approximation
         style->font_weight.computed = (parent_val <= SP_CSS_FONT_WEIGHT_100 + 3
-                           ? (unsigned)SP_CSS_FONT_WEIGHT_100
-                           : parent_val - 3);
+                                       ? (unsigned)SP_CSS_FONT_WEIGHT_100
+                                       : parent_val - 3);
         g_assert(style->font_weight.computed <= (unsigned) SP_CSS_FONT_WEIGHT_900);
     } else if (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLDER) {
         unsigned const parent_val = parent->font_weight.computed;
         g_assert(parent_val <= SP_CSS_FONT_WEIGHT_900);
         style->font_weight.computed = (parent_val >= SP_CSS_FONT_WEIGHT_900 - 3
-                           ? (unsigned)SP_CSS_FONT_WEIGHT_900
-                           : parent_val + 3);
+                                       ? (unsigned)SP_CSS_FONT_WEIGHT_900
+                                       : parent_val + 3);
         g_assert(style->font_weight.computed <= (unsigned) SP_CSS_FONT_WEIGHT_900);
     }
 
@@ -1257,15 +1264,15 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
     } else if (style->font_stretch.value == SP_CSS_FONT_STRETCH_NARROWER) {
         unsigned const parent_val = parent->font_stretch.computed;
         style->font_stretch.computed = (parent_val == SP_CSS_FONT_STRETCH_ULTRA_CONDENSED
-                        ? parent_val
-                        : parent_val - 1);
+                                        ? parent_val
+                                        : parent_val - 1);
         g_assert(style->font_stretch.computed <= (unsigned) SP_CSS_FONT_STRETCH_ULTRA_EXPANDED);
     } else if (style->font_stretch.value == SP_CSS_FONT_STRETCH_WIDER) {
         unsigned const parent_val = parent->font_stretch.computed;
         g_assert(parent_val <= SP_CSS_FONT_STRETCH_ULTRA_EXPANDED);
         style->font_stretch.computed = (parent_val == SP_CSS_FONT_STRETCH_ULTRA_EXPANDED
-                        ? parent_val
-                        : parent_val + 1);
+                                        ? parent_val
+                                        : parent_val + 1);
         g_assert(style->font_stretch.computed <= (unsigned) SP_CSS_FONT_STRETCH_ULTRA_EXPANDED);
     }
 
@@ -1847,7 +1854,7 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
 
         /* display is in principle similar to opacity, but implementation is easier. */
         if ( parent->display.set && !parent->display.inherit
-                    && parent->display.value == SP_CSS_DISPLAY_NONE ) {
+             && parent->display.value == SP_CSS_DISPLAY_NONE ) {
             style->display.value = SP_CSS_DISPLAY_NONE;
             style->display.set = true;
             style->display.inherit = false;
@@ -2002,15 +2009,27 @@ sp_style_merge_ipaint(SPStyle *style, SPIPaint *paint, SPIPaint const *parent)
             paint->value.paint.uri = parent->value.paint.uri;
             if (paint->value.paint.server) {
                 if (style->object && !style->cloned) { // href paintserver for style of non-clones only
-                    style->hreffed = true;
                     sp_object_href(SP_OBJECT(paint->value.paint.server), style);
+                    if (paint == &style->fill) {
+                        style->fill_hreffed = true;
+                    } else if (paint == &style->stroke) {
+                        style->stroke_hreffed = true;
+                    } else if (paint == &style->color) {
+                        style->color_hreffed = true;
+                    }
                 }
                 if (style->object || style->cloned) { // connect to signals for style of real objects or clones (this excludes temp styles)
                     g_signal_connect(G_OBJECT(paint->value.paint.server), "release",
                                      G_CALLBACK(sp_style_paint_server_release), style);
                     g_signal_connect(G_OBJECT(paint->value.paint.server), "modified",
                                      G_CALLBACK(sp_style_paint_server_modified), style);
-                    style->listening = true;
+                    if (paint == &style->fill) {
+                        style->fill_listening = true;
+                    } else if (paint == &style->stroke) {
+                        style->stroke_listening = true;
+                    } else if (paint == &style->color) {
+                        style->color_listening = true;
+                    }
                 }
             }
             break;
@@ -2858,14 +2877,26 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
                 paint->value.paint.server = SP_PAINT_SERVER(ps);
                 if (style->object && !style->cloned) {
                     sp_object_href(SP_OBJECT(paint->value.paint.server), style);
-                    style->hreffed = true;
+                    if (paint == &style->fill) {
+                        style->fill_hreffed = true;
+                    } else if (paint == &style->stroke) {
+                        style->stroke_hreffed = true;
+                    } else if (paint == &style->color) {
+                        style->color_hreffed = true;
+                    }
                 }
                 if (style->object || style->cloned) {
                     g_signal_connect(G_OBJECT(paint->value.paint.server), "release",
                                      G_CALLBACK(sp_style_paint_server_release), style);
                     g_signal_connect(G_OBJECT(paint->value.paint.server), "modified",
                                      G_CALLBACK(sp_style_paint_server_modified), style);
-                    style->listening = true;
+                    if (paint == &style->fill) {
+                        style->fill_listening = true;
+                    } else if (paint == &style->stroke) {
+                        style->stroke_listening = true;
+                    } else if (paint == &style->color) {
+                        style->color_listening = true;
+                    }
                 }
             } else {
                 paint->value.paint.server = NULL;
@@ -3324,14 +3355,15 @@ sp_style_write_ipaint(gchar *b, gint const len, gchar const *const key,
             return g_snprintf(b, len, "%s:currentColor;", key);
         } else {
             switch (paint->type) {
-            case SP_PAINT_TYPE_COLOR:
-                return g_snprintf(b, len, "%s:#%06x;", key, sp_color_get_rgba32_falpha(&paint->value.color, 0.0) >> 8);
-                break;
-            case SP_PAINT_TYPE_PAINTSERVER:
+                case SP_PAINT_TYPE_COLOR: {
+                    char color_buf[8];
+                    sp_svg_write_color(color_buf, sizeof(color_buf), sp_color_get_rgba32_ualpha(&paint->value.color, 0));
+                    return g_snprintf(b, len, "%s:%s;", key, color_buf);
+                }
+                case SP_PAINT_TYPE_PAINTSERVER:
                     return g_snprintf(b, len, "%s:url(%s);", key, paint->value.paint.uri);
-                break;
-            default:
-                break;
+                default:
+                    break;
             }
             return g_snprintf(b, len, "%s:none;", key);
         }
@@ -3402,15 +3434,38 @@ sp_style_paint_clear(SPStyle *style, SPIPaint *paint,
                      unsigned hunref, unsigned unset)
 {
     if (hunref && (paint->type == SP_PAINT_TYPE_PAINTSERVER) && paint->value.paint.server) {
-        if (style->hreffed) {
-            sp_object_hunref(SP_OBJECT(paint->value.paint.server), style);
-            style->hreffed = false;
-        }
-        if (style->listening) {
-            g_signal_handlers_disconnect_matched(G_OBJECT(paint->value.paint.server),
+        if (paint == &style->fill) {
+            if (style->fill_hreffed) {
+                sp_object_hunref(SP_OBJECT(paint->value.paint.server), style);
+                style->fill_hreffed = false;
+            }
+            if (style->fill_listening) {
+                g_signal_handlers_disconnect_matched(G_OBJECT(paint->value.paint.server),
                                                  G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, style);
-            style->listening = false;
+                style->fill_listening = false;
+            }
+        } else if (paint == &style->stroke) {
+            if (style->stroke_hreffed) {
+                sp_object_hunref(SP_OBJECT(paint->value.paint.server), style);
+                style->stroke_hreffed = false;
+            }
+            if (style->stroke_listening) {
+                g_signal_handlers_disconnect_matched(G_OBJECT(paint->value.paint.server),
+                                                 G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, style);
+                style->stroke_listening = false;
+            }
+        } else if (paint == &style->color) {
+            if (style->color_hreffed) {
+                sp_object_hunref(SP_OBJECT(paint->value.paint.server), style);
+                style->color_hreffed = false;
+            }
+            if (style->color_listening) {
+                g_signal_handlers_disconnect_matched(G_OBJECT(paint->value.paint.server),
+                                                 G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, style);
+                style->color_listening = false;
+            }
         }
+
         paint->value.paint.server = NULL;
         paint->value.paint.uri = NULL;
         paint->type = SP_PAINT_TYPE_NONE;
@@ -3527,7 +3582,7 @@ sp_css_attr_from_object(SPObject *object, guint const flags)
     SPStyle const *const style = SP_OBJECT_STYLE(object);
     if (style == NULL)
         return NULL;
-    return sp_css_attr_from_style (style, flags);
+    return sp_css_attr_from_style(style, flags);
 }
 
 /**
@@ -3682,18 +3737,18 @@ sp_css_attr_scale(SPCSSAttr *css, double ex)
  * ALL strings (check CSS spec), in which case this should be part of
  * read_istring.
  */
-void
-css2_unescape_unquote (SPIString *val)
+static void
+css2_unescape_unquote(SPIString *val)
 {
     if (val->set && val->value && strlen(val->value) >= 2) {
 
-       /// \todo unescape all \-escaped chars
+        /// \todo unescape all \-escaped chars
 
         int l = strlen(val->value);
-        if ((val->value[0] == '"' && val->value[l - 1] == '"') ||
-            (val->value[0] == '\'' && val->value[l - 1] == '\'')) {
-                memcpy (val->value, val->value+1, l - 2);
-                val->value[l - 2] = '\0';
+        if ( ( val->value[0] == '"' && val->value[l - 1] == '"' )  ||
+             ( val->value[0] == '\'' && val->value[l - 1] == '\'' )  ) {
+            memcpy(val->value, val->value + 1, l - 2);
+            val->value[l - 2] = '\0';
         }
     }
 }