Code

Fix for Bug #586955 (the unit for user defined document size is not refreshed if...
authorJazzyNico <nicoduf@yahoo.fr>
Sun, 26 Sep 2010 17:53:05 +0000 (19:53 +0200)
committerJazzyNico <nicoduf@yahoo.fr>
Sun, 26 Sep 2010 17:53:05 +0000 (19:53 +0200)
src/attributes.cpp
src/attributes.h
src/sp-namedview.cpp
src/sp-namedview.h
src/ui/widget/page-sizer.cpp

index c44a7da4e5f19ed106f200a8e4b4b16ea46a0bae..5d3a00826db704c48921e010144f8b9e4f874814 100644 (file)
@@ -111,6 +111,7 @@ static SPStyleProp const props[] = {
     {SP_ATTR_INKSCAPE_SNAP_PAGE, "inkscape:snap-page"},
     {SP_ATTR_INKSCAPE_CURRENT_LAYER, "inkscape:current-layer"},
     {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"},
+    {SP_ATTR_UNITS, "units"},
     {SP_ATTR_INKSCAPE_CONNECTOR_SPACING, "inkscape:connector-spacing"},
     /* SPColorProfile */
     {SP_ATTR_LOCAL, "local"},
index aadb4d16519f86b957e9ac95934f0bef146228b2..82ac962d0cbf6bb411a84739f760347a602046f9 100644 (file)
@@ -112,6 +112,7 @@ enum SPAttributeEnum {
     SP_ATTR_INKSCAPE_SNAP_PAGE,
     SP_ATTR_INKSCAPE_CURRENT_LAYER,
     SP_ATTR_INKSCAPE_DOCUMENT_UNITS,
+    SP_ATTR_UNITS,
     SP_ATTR_INKSCAPE_CONNECTOR_SPACING,
     /* SPColorProfile */
     SP_ATTR_LOCAL,
index 44c3bf62013c42d84cffbf5f6facce5f66a42c01..f7fdef94b9f6c290a9f3f9556d96cac1338e349d 100644 (file)
@@ -218,6 +218,7 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape:
     }
 
     sp_object_read_attr(object, "inkscape:document-units");
+    sp_object_read_attr(object, "units");
     sp_object_read_attr(object, "viewonly");
     sp_object_read_attr(object, "showguides");
     sp_object_read_attr(object, "showgrid");
@@ -572,6 +573,30 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
     }
+    case SP_ATTR_UNITS: {
+            SPUnit const *new_unit = NULL;
+
+            if (value) {
+                SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value);
+                if ( req_unit == NULL ) {
+                    g_warning("Unrecognized unit `%s'", value);
+                    /* fixme: Document errors should be reported in the status bar or
+                     * the like (e.g. as per
+                     * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
+                     * should be only for programmer errors. */
+                } else if ( req_unit->base == SP_UNIT_ABSOLUTE ||
+                            req_unit->base == SP_UNIT_DEVICE     ) {
+                    new_unit = req_unit;
+                } else {
+                    g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
+                              value);
+                    /* fixme: Don't use g_log (see above). */
+                }
+            }
+            nv->units = new_unit;
+            object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+            break;
+    }
     default:
             if (((SPObjectClass *) (parent_class))->set) {
                 ((SPObjectClass *) (parent_class))->set(object, key, value);
index 048096d8c0096e569761f332afb9f0d51be03425..5d8b7f1cb6aaa90e70125458460702722281a95d 100644 (file)
@@ -54,7 +54,8 @@ struct SPNamedView : public SPObjectGroup {
     bool grids_visible;
 
     SPUnit const *doc_units;
-
+    SPUnit const *units;
+    
     GQuark default_layer_id;
 
     double connector_spacing;
index 26763cc77e1a6aa41d2142971d6c9c29bbd91821..724848ca5f17bc39f819c295410c2d7d6210c2f4 100644 (file)
@@ -297,6 +297,15 @@ PageSizer::PageSizer(Registry & _wr)
     _portraitButton.set_group (group);
     _portraitButton.set_active (true);
 
+    // Setting default custom unit to document unit
+    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    SPNamedView *nv = sp_desktop_namedview(dt);
+    if (nv->units) {
+        _dimensionUnits.setUnit(nv->units);
+    } else if (nv->doc_units) {
+        _dimensionUnits.setUnit(nv->doc_units);
+    }
+    
     //## Set up custom size frame
     _customFrame.set_label(_("Custom size"));
     pack_start (_customFrame, false, false, 0);