From: JazzyNico Date: Sun, 26 Sep 2010 17:53:05 +0000 (+0200) Subject: Fix for Bug #586955 (the unit for user defined document size is not refreshed if... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=33a9f2598f529ec56970881c1e5af5c2c104c9bb;p=inkscape.git Fix for Bug #586955 (the unit for user defined document size is not refreshed if document is reopen). --- diff --git a/src/attributes.cpp b/src/attributes.cpp index c44a7da4e..5d3a00826 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -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"}, diff --git a/src/attributes.h b/src/attributes.h index aadb4d165..82ac962d0 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -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, diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 44c3bf620..f7fdef94b 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -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); diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 048096d8c..5d8b7f1cb 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -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; diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 26763cc77..724848ca5 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -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);