Code

Changed default font from Bitstream Vera Sans to Sans. Not
[inkscape.git] / src / style.cpp
index dd81692823123f0b45c055ebe1da5f0cb3af22ca..a05cef252c1d789d0e0a7b88d813c66c159df1f4 100644 (file)
@@ -28,6 +28,7 @@
 #include "svg/svg.h"
 #include "svg/svg-color.h"
 #include "svg/svg-icc-color.h"
+#include "svg/svg-device-color.h"
 
 #include "display/canvas-bpath.h"
 #include "attributes.h"
@@ -362,7 +363,7 @@ sp_style_filter_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle *style)
     }
     if ( SP_IS_FILTER(ref))
     {
-        style->filter_modified_connection = 
+        style->filter_modified_connection =
            ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_filter_ref_modified), style));
     }
 
@@ -415,7 +416,7 @@ sp_style_fill_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPStyle
         style->fill_ps_modified_connection.disconnect();
     }
     if (SP_IS_PAINT_SERVER(ref)) {
-        style->fill_ps_modified_connection = 
+        style->fill_ps_modified_connection =
            ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_paint_server_ref_modified), style));
     }
 
@@ -432,7 +433,7 @@ sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPSty
         style->stroke_ps_modified_connection.disconnect();
     }
     if (SP_IS_PAINT_SERVER(ref)) {
-        style->stroke_ps_modified_connection = 
+        style->stroke_ps_modified_connection =
           ref->connectModified(sigc::bind(sigc::ptr_fun(&sp_style_paint_server_ref_modified), style));
     }
 
@@ -711,16 +712,19 @@ sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr)
             sp_style_read_dash(style, val);
         }
     }
+
     if (!style->stroke_dashoffset_set) {
-        /* fixme */
         val = repr->attribute("stroke-dashoffset");
         if (sp_svg_number_read_d(val, &style->stroke_dash.offset)) {
             style->stroke_dashoffset_set = TRUE;
+        } else if (val && !strcmp(val, "inherit")) {
+            style->stroke_dashoffset_set = TRUE;
+            style->stroke_dashoffset_inherit = TRUE;
         } else {
             style->stroke_dashoffset_set = FALSE;
         }
     }
-    
+
     /* -inkscape-font-specification */
     if (!style->text_private || !style->text->font_specification.set) {
         val = repr->attribute("-inkscape-font-specification");
@@ -747,7 +751,7 @@ 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(val, style, (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
+            sp_style_read_ifilter(val, style, (object) ? SP_OBJECT_DOCUMENT(object) : NULL);
         }
     }
     SPS_READ_PENUM_IF_UNSET(&style->enable_background, repr,
@@ -801,21 +805,21 @@ sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path)
 {
     g_return_if_fail(style != NULL);
     g_return_if_fail(path != "");
-    
+
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
     // not optimal: we reconstruct the node based on the prefs, then pass it to
     // sp_style_read for actual processing.
     Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument;
     Inkscape::XML::Node *tempnode = tempdoc->createElement("temp");
-    
+
     std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path);
     for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) {
         tempnode->setAttribute(i->getEntryName().data(), i->getString().data());
     }
 
     sp_style_read(style, NULL, tempnode);
-    
+
     Inkscape::GC::release(tempnode);
     Inkscape::GC::release(tempdoc);
     delete tempdoc;
@@ -1146,9 +1150,11 @@ sp_style_merge_property(SPStyle *style, gint id, gchar const *val)
             break;
         case SP_PROP_STROKE_DASHOFFSET:
             if (!style->stroke_dashoffset_set) {
-                /* fixme */
                 if (sp_svg_number_read_d(val, &style->stroke_dash.offset)) {
                     style->stroke_dashoffset_set = TRUE;
+                } else if (val && !strcmp(val, "inherit")) {
+                    style->stroke_dashoffset_set = TRUE;
+                    style->stroke_dashoffset_inherit = TRUE;
                 } else {
                     style->stroke_dashoffset_set = FALSE;
                 }
@@ -1440,16 +1446,19 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
     }
 
     if (!style->line_height.set || style->line_height.inherit) {
+        style->line_height.value = parent->line_height.value;
         style->line_height.computed = parent->line_height.computed;
         style->line_height.normal = parent->line_height.normal;
     }
 
     if (!style->letter_spacing.set || style->letter_spacing.inherit) {
+        style->letter_spacing.value = parent->letter_spacing.value;
         style->letter_spacing.computed = parent->letter_spacing.computed;
         style->letter_spacing.normal = parent->letter_spacing.normal;
     }
 
     if (!style->word_spacing.set || style->word_spacing.inherit) {
+        style->word_spacing.value = parent->word_spacing.value;
         style->word_spacing.computed = parent->word_spacing.computed;
         style->word_spacing.normal = parent->word_spacing.normal;
     }
@@ -1526,11 +1535,7 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
         style->stroke_miterlimit.value = parent->stroke_miterlimit.value;
     }
 
-    if (!style->stroke_dasharray_set && parent->stroke_dasharray_set) {
-        /** \todo
-         * This code looks wrong.  Why does the logic differ from the
-         * above properties? Similarly dashoffset below.
-         */
+    if (!style->stroke_dasharray_set || style->stroke_dasharray_inherit) {
         style->stroke_dash.n_dash = parent->stroke_dash.n_dash;
         if (style->stroke_dash.n_dash > 0) {
             style->stroke_dash.dash = g_new(gdouble, style->stroke_dash.n_dash);
@@ -1538,7 +1543,7 @@ sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
         }
     }
 
-    if (!style->stroke_dashoffset_set && parent->stroke_dashoffset_set) {
+    if (!style->stroke_dashoffset_set || style->stroke_dashoffset_inherit) {
         style->stroke_dash.offset = parent->stroke_dash.offset;
     }
 
@@ -1947,7 +1952,7 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
     if (style->text && parent->text) {
         sp_style_merge_string_prop_from_dying_parent(style->text->font_specification,
                                                      parent->text->font_specification);
-        
+
         sp_style_merge_string_prop_from_dying_parent(style->text->font_family,
                                                      parent->text->font_family);
     }
@@ -2100,10 +2105,11 @@ sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const pare
     }
 
     /* Note: this will need length handling once dasharray_offset supports units. */
-    if (!style->stroke_dashoffset_set && parent->stroke_dashoffset_set) {
+    if ((!style->stroke_dashoffset_set || style->stroke_dashoffset_inherit) && parent->stroke_dashoffset_set && !parent->stroke_dashoffset_inherit) {
         style->stroke_dash.offset = parent->stroke_dash.offset;
         style->stroke_dashoffset_set = parent->stroke_dashoffset_set;
-        /* fixme: we don't currently allow stroke-dashoffset to be `inherit'.  TODO: Try to
+        style->stroke_dashoffset_inherit = parent->stroke_dashoffset_inherit;
+        /* TODO: Try to
          * represent it as a normal SPILength; though will need to do something about existing
          * users of stroke_dash.offset and stroke_dashoffset_set. */
     }
@@ -2284,10 +2290,10 @@ sp_style_write_string(SPStyle const *const style, guint const flags)
     p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &style->stroke, NULL, flags);
 
     // stroke width affects markers, so write it if there's stroke OR any markers
-    if (!style->stroke.noneSet || 
+    if (!style->stroke.noneSet ||
         style->marker[SP_MARKER_LOC].set ||
         style->marker[SP_MARKER_LOC_START].set ||
-        style->marker[SP_MARKER_LOC_MID].set || 
+        style->marker[SP_MARKER_LOC_MID].set ||
         style->marker[SP_MARKER_LOC_END].set) {
         p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &style->stroke_width, NULL, flags);
     }
@@ -2326,9 +2332,13 @@ sp_style_write_string(SPStyle const *const style, guint const flags)
 
         /** \todo fixme: */
         if (style->stroke_dashoffset_set) {
-            Inkscape::CSSOStringStream os;
-            os << "stroke-dashoffset:" << style->stroke_dash.offset << ";";
-            p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
+            if (style->stroke_dashoffset_inherit) {
+                p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:inherit;");
+            } else {
+                Inkscape::CSSOStringStream os;
+                os << "stroke-dashoffset:" << style->stroke_dash.offset << ";";
+                p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
+            }
         } else if (flags == SP_STYLE_FLAG_ALWAYS) {
             p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:0;");
         }
@@ -2342,7 +2352,7 @@ sp_style_write_string(SPStyle const *const style, guint const flags)
         p += g_snprintf(p, c + BMAX - p, "marker:none;");
         marker_none = true;
     }
-    if (style->marker[SP_MARKER_LOC_START].set 
+    if (style->marker[SP_MARKER_LOC_START].set
        && (!master || strcmp(master, style->marker[SP_MARKER_LOC_START].value))) {
         p += g_snprintf(p, c + BMAX - p, "marker-start:%s;", style->marker[SP_MARKER_LOC_START].value);
     } else if (flags == SP_STYLE_FLAG_ALWAYS && !marker_none) {
@@ -2443,10 +2453,10 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to)
     p += sp_style_write_ipaint(p, c + BMAX - p, "stroke", &from->stroke, &to->stroke, SP_STYLE_FLAG_IFDIFF);
 
     // stroke width affects markers, so write it if there's stroke OR any markers
-    if (!from->stroke.noneSet || 
+    if (!from->stroke.noneSet ||
         from->marker[SP_MARKER_LOC].set ||
         from->marker[SP_MARKER_LOC_START].set ||
-        from->marker[SP_MARKER_LOC_MID].set || 
+        from->marker[SP_MARKER_LOC_MID].set ||
         from->marker[SP_MARKER_LOC_END].set) {
         p += sp_style_write_ilength(p, c + BMAX - p, "stroke-width", &from->stroke_width, &to->stroke_width, SP_STYLE_FLAG_IFDIFF);
     }
@@ -2478,9 +2488,13 @@ sp_style_write_difference(SPStyle const *const from, SPStyle const *const to)
         }
         /* fixme: */
         if (from->stroke_dashoffset_set) {
-            Inkscape::CSSOStringStream os;
-            os << "stroke-dashoffset:" << from->stroke_dash.offset << ";";
-            p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
+            if (from->stroke_dashoffset_inherit) {
+                p += g_snprintf(p, c + BMAX - p, "stroke-dashoffset:inherit;");
+            } else {
+                Inkscape::CSSOStringStream os;
+                os << "stroke-dashoffset:" << from->stroke_dash.offset << ";";
+                p += g_strlcpy(p, os.str().c_str(), c + BMAX - p);
+            }
         }
         p += sp_style_write_iscale24(p, c + BMAX - p, "stroke-opacity", &from->stroke_opacity, &to->stroke_opacity, SP_STYLE_FLAG_IFDIFF);
     }
@@ -2559,6 +2573,9 @@ sp_style_clear(SPStyle *style)
         g_free(style->stroke_dash.dash);
     }
 
+    style->stroke_dasharray_inherit = FALSE;
+    style->stroke_dashoffset_inherit = FALSE;
+
     /** \todo fixme: Do that text manipulation via parents */
     SPObject *object = style->object;
     SPDocument *document = style->document;
@@ -2766,9 +2783,9 @@ sp_text_style_new()
     ts->refcount = 1;
     sp_text_style_clear(ts);
 
-    ts->font_specification.value = g_strdup("Bitstream Vera Sans");
-    ts->font.value = g_strdup("Bitstream Vera Sans");
-    ts->font_family.value = g_strdup("Bitstream Vera Sans");
+    ts->font_specification.value = g_strdup("Sans");
+    ts->font.value = g_strdup("Sans");
+    ts->font_family.value = g_strdup("Sans");
 
     return ts;
 }
@@ -3171,6 +3188,17 @@ sp_style_read_ipaint(SPIPaint *paint, gchar const *str, SPStyle *style, SPDocume
                     }
                     paint->value.color.icc = tmp;
                 }
+                if (strneq(str, "device-gray(", 12) ||
+                    strneq(str, "device-rgb(", 11) ||
+                    strneq(str, "device-cmyk(", 12) ||
+                    strneq(str, "device-nchannel(", 16)) {
+                    SVGDeviceColor* tmp = new SVGDeviceColor();
+                    if ( ! sp_svg_read_device_color( str, &str, tmp ) ) {
+                        delete tmp;
+                        tmp = 0;
+                    }
+                    paint->value.color.device = tmp;
+                }
             }
         }
     }
@@ -3256,12 +3284,12 @@ sp_style_read_ifilter(gchar const *str, SPStyle * style, SPDocument *document)
         f->set = TRUE;
         f->inherit = TRUE;
         if (f->href && f->href->getObject())
-            f->href->detach(); 
+            f->href->detach();
     } else if(streq(str, "none")) {
         f->set = TRUE;
         f->inherit = FALSE;
         if (f->href && f->href->getObject())
-           f->href->detach(); 
+           f->href->detach();
     } else if (strneq(str, "url", 3)) {
         char *uri = extract_uri(str);
         if(uri == NULL || uri[0] == '\0') {
@@ -3295,7 +3323,7 @@ sp_style_read_ifilter(gchar const *str, SPStyle * style, SPDocument *document)
         f->set = FALSE;
         f->inherit = FALSE;
         if (f->href && f->href->getObject())
-            f->href->detach(); 
+            f->href->detach();
     }
 }
 
@@ -3862,7 +3890,7 @@ sp_style_set_property_url (SPObject *item, gchar const *property, SPObject *link
 
     SPCSSAttr *css = sp_repr_css_attr_new();
     if (linked) {
-        gchar *val = g_strdup_printf("url(#%s)", SP_OBJECT_ID(linked));
+        gchar *val = g_strdup_printf("url(#%s)", linked->getId());
         sp_repr_css_set_property(css, property, val);
         g_free(val);
     } else {