Code

Added support for enable-background to SPStyle
authorkiirala <kiirala@users.sourceforge.net>
Wed, 26 Jul 2006 09:18:55 +0000 (09:18 +0000)
committerkiirala <kiirala@users.sourceforge.net>
Wed, 26 Jul 2006 09:18:55 +0000 (09:18 +0000)
src/display/nr-arena-item.h
src/display/nr-filter.h
src/style.cpp
src/style.h

index 7a6c676024e96cf18c03ab30e7c20addf36c75be..d38e44929269d10ee78d139052b68e363b4f7c49 100644 (file)
 #include "gc-soft-ptr.h"
 #include "nr-arena-forward.h"
 #include "display/nr-filter.h"
-/* TODO: without this, gcc barfs on clause "NR::Filter *filter" later on.
- * Obviously we shouldn't need to have the next three rows */
-namespace NR {
-class Filter;
-}
 
 // My testing shows that disabling cache reduces the amount 
 // of leaked memory when many documents are loaded one from the other,
index 15a852d10afc8603b23692aecb02eb8b41f205a9..c1012475c3bdb3bb2e715e616e1332422a3e98c4 100644 (file)
@@ -12,7 +12,7 @@
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
-#include "display/nr-arena-item.h"
+//#include "display/nr-arena-item.h"
 #include "display/nr-filter-primitive.h"
 #include "display/nr-filter-types.h"
 #include "libnr/nr-pixblock.h"
@@ -22,6 +22,8 @@
 #include "sp-filter-units.h"
 #include "gc-managed.h"
 
+struct NRArenaItem;
+
 namespace NR {
 
 class Filter : public Inkscape::GC::Managed<> {
index e0d6532d451a760b72f6b91e0f389e076e59ad28..6b5a953fd2e758526e67497be1afe979bab7116d 100644 (file)
@@ -372,6 +372,12 @@ static SPStyleEnum const enum_text_rendering[] = {
     {NULL, -1}
 };
 
+static SPStyleEnum const enum_enable_background[] = {
+    {"accumulate", SP_CSS_BACKGROUND_ACCUMULATE},
+    {"new", SP_CSS_BACKGROUND_NEW},
+    {NULL, -1}
+};
+
 /**
  * Release callback.
  */
@@ -669,9 +675,12 @@ sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr)
     if (!style->filter.set) {
         val = repr->attribute("filter");
         if (val) {
-            sp_style_read_ifilter(&style->filter, val, (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
+            sp_style_read_ifilter(&style->filter, val,
+                                  (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
         }
     }
+    SPS_READ_PENUM_IF_UNSET(&style->enable_background, repr,
+                            "enable-background", enum_enable_background, true);
             
     /* 3. Merge from parent */
     if (object) {
@@ -901,7 +910,8 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val)
             }
             break;
         case SP_PROP_ENABLE_BACKGROUND:
-            g_warning("Unimplemented style property SP_PROP_ENABLE_BACKGROUND: value: %s", val);
+            SPS_READ_IENUM_IF_UNSET(&style->enable_background, val,
+                                    enum_enable_background, true);
             break;
             /* Filter */
         case SP_PROP_FILTER:
@@ -1447,6 +1457,10 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
     if(style->filter.set && style->filter.inherit) {
         sp_style_merge_ifilter(&style->filter, &parent->filter);
     }
+
+    if(style->enable_background.inherit) {
+        style->enable_background.value = parent->enable_background.value;
+    }
 }
 
 template <typename T>
@@ -1900,6 +1914,18 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
             /* Leave as is.  (display doesn't inherit by default.) */
         }
 
+        /* enable-background - this is rather complicated, because
+         * it is valid only when applied to container elements.
+         * Let's check a simple case anyhow. */
+        if (parent->enable_background.set
+            && !parent->enable_background.inherit
+            && style->enable_background.inherit)
+        {
+            style->enable_background.set = true;
+            style->enable_background.inherit = false;
+            style->enable_background.value = parent->enable_background.value;
+        }
+
         /** \todo
          * fixme: Check that we correctly handle all properties that don't
          * inherit by default (as shown in
@@ -2218,6 +2244,8 @@ sp_style_write_string(SPStyle const *const style, guint const flags)
     /* filter: */
     p += sp_style_write_ifilter(p, c + BMAX - p, "filter", &style->filter, NULL, flags);
 
+    p += sp_style_write_ienum(p, c + BMAX - p, "enable-background", enum_enable_background, &style->enable_background, NULL, flags);
+
     /* fixme: */
     p += sp_text_style_write(p, c + BMAX - p, style->text, flags);
 
@@ -2335,6 +2363,8 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to)
     /* filter: */
     p += sp_style_write_ifilter(p, c + BMAX - p, "filter", &from->filter, &to->filter, SP_STYLE_FLAG_IFDIFF);
 
+    p += sp_style_write_ienum(p, c + BMAX - p, "enable-background", enum_enable_background, &from->enable_background, &to->enable_background, SP_STYLE_FLAG_IFSET);
+
     p += sp_text_style_write(p, c + BMAX - p, from->text, SP_STYLE_FLAG_IFDIFF);
 
     /** \todo
@@ -2487,11 +2517,14 @@ sp_style_clear(SPStyle *style)
     }
 
     style->filter.set = FALSE;
-//Are these really needed?
+    //Are these really needed?
     style->filter.inherit = FALSE;
     style->filter.uri = NULL;
     style->filter.filter = FALSE;
 
+    style->enable_background.value = SP_CSS_BACKGROUND_ACCUMULATE;
+    style->enable_background.set = false;
+    style->enable_background.inherit = false;
 }
 
 
@@ -3704,6 +3737,9 @@ sp_style_unset_property_attrs(SPObject *o)
     if (style->filter.set) {
         repr->setAttribute("filter", NULL);
     }
+    if (style->enable_background.set) {
+        repr->setAttribute("enable-background", NULL);
+    }
 }
 
 /**
index ad1459a732d2989e001988b21a3f809c1037330d..9a70881de927a462d783b107eaaa720e14fd1bfe 100644 (file)
@@ -336,6 +336,10 @@ struct SPStyle {
     /** Filter effect */
     SPIFilter filter;
 
+    /** enable-background, used for defining where filter effects get
+     * their background image */
+    SPIEnum enable_background;
+
     /// style belongs to a cloned object, must not href anything
     bool cloned; 
     /// style has hreffed its fill/stroke paintservers, needs to release.
@@ -501,6 +505,11 @@ enum SPCSSDisplay {
     SP_CSS_DISPLAY_TABLE_CAPTION
 };
 
+enum SPEnableBackground {
+    SP_CSS_BACKGROUND_ACCUMULATE,
+    SP_CSS_BACKGROUND_NEW
+};
+
 /// An SPTextStyle has a refcount, a font family, and a font name.
 struct SPTextStyle {
     int refcount;