diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-18 18:08:42 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-18 18:08:42 +0000 |
| commit | 0c67c166ce5fb0e447b5c957e9222610d9d0c559 (patch) | |
| tree | d10c904aed7d23568444776bda67b76cd574b36f /src/document.cpp | |
| parent | Added kaleidoscope mode (diff) | |
| parent | Latvian translation update (diff) | |
| download | inkscape-0c67c166ce5fb0e447b5c957e9222610d9d0c559.tar.gz inkscape-0c67c166ce5fb0e447b5c957e9222610d9d0c559.zip | |
update to trunk
(bzr r13708.1.18)
Diffstat (limited to 'src/document.cpp')
| -rw-r--r-- | src/document.cpp | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/src/document.cpp b/src/document.cpp index 2caefb4ed..62e2f5b46 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -368,7 +368,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, // Create SPRoot element const std::string typeString = NodeTraits::get_type_string(*rroot); - SPObject* rootObj = SPFactory::instance().createObject(typeString); + SPObject* rootObj = SPFactory::createObject(typeString); document->root = dynamic_cast<SPRoot*>(rootObj); if (document->root == 0) { @@ -611,7 +611,25 @@ Inkscape::Util::Unit const& SPDocument::getSVGUnit() const return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } -/// Returns document scale as defined by width/height and viewBox (real world to user-units). +/// Sets document scale (by changing viewBox) +void SPDocument::setDocumentScale( double scaleX, double scaleY ) { + + root->viewBox = Geom::Rect::from_xywh( + root->viewBox.left(), + root->viewBox.top(), + root->width.computed * scaleX, + root->height.computed * scaleY ); + root->viewBox_set = true; + root->updateRepr(); +} + +/// Sets document scale (by changing viewBox, x and y scaling equal) +void SPDocument::setDocumentScale( double scale ) { + setDocumentScale( scale, scale ); +} + +/// Returns document scale as defined by width/height (in pixels) and viewBox (real world to +/// user-units). Geom::Scale SPDocument::getDocumentScale() const { Geom::Scale scale; @@ -637,7 +655,11 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) old_width_units = unit_table.getUnit(root->width.unit); - gdouble old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; @@ -646,16 +668,22 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) old_height_units = unit_table.getUnit(root->height.unit); - gdouble old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - if (root->viewBox_set && changeSize) + // viewBox scaled by relative change in page size (maintains document scale). + if (root->viewBox_set && changeSize) { root->viewBox.setMax(Geom::Point( root->viewBox.left() + (root->width.value / old_width_converted ) * root->viewBox.width(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); + } root->updateRepr(); } @@ -678,17 +706,21 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) - old_units = unit_table.getUnit(root->width.unit); - gdouble old_converted = Inkscape::Util::Quantity::convert(root->width.value, old_units, width.unit); + old_width_units = unit_table.getUnit(root->width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_width_converted) * root->viewBox.width(), root->viewBox.bottom())); root->updateRepr(); } @@ -713,17 +745,21 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) - old_units = unit_table.getUnit(root->height.unit); - gdouble old_converted = Inkscape::Util::Quantity::convert(root->height.value, old_units, height.unit); + old_height_units = unit_table.getUnit(root->height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); root->updateRepr(); } @@ -761,7 +797,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const old_height = getHeight().value("px"); Inkscape::Util::Unit const *nv_units = unit_table.getUnit("px"); - if (root->height.unit) + if (root->height.unit && (root->height.unit != SVGLength::PERCENT)) nv_units = unit_table.getUnit(root->height.unit); SPNamedView *nv = sp_document_namedview(this, NULL); |
