summaryrefslogtreecommitdiffstats
path: root/src/document.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-18 18:07:14 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-18 18:07:14 +0000
commite77956b4dbd029c9f6949f81fe083606f995c624 (patch)
tree74adda4df8986d65f70efb341c6235277361fd35 /src/document.cpp
parentupdated code to work on 0.92 code (diff)
parentLatvian translation update (diff)
downloadinkscape-e77956b4dbd029c9f6949f81fe083606f995c624.tar.gz
inkscape-e77956b4dbd029c9f6949f81fe083606f995c624.zip
update to trunk
(bzr r12588.1.39)
Diffstat (limited to 'src/document.cpp')
-rw-r--r--src/document.cpp183
1 files changed, 130 insertions, 53 deletions
diff --git a/src/document.cpp b/src/document.cpp
index 3715d8e6e..62e2f5b46 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -50,7 +50,7 @@
#include "document-private.h"
#include "document-undo.h"
#include "id-clash.h"
-#include "inkscape-private.h"
+#include "inkscape.h"
#include "inkscape-version.h"
#include "libavoid/router.h"
#include "persp3d.h"
@@ -154,6 +154,14 @@ SPDocument::~SPDocument() {
router = NULL;
}
+ if (oldSignalsConnected) {
+ priv->selChangeConnection.disconnect();
+ priv->desktopActivatedConnection.disconnect();
+ } else {
+ _selection_changed_connection.disconnect();
+ _desktop_activated_connection.disconnect();
+ }
+
if (priv) {
if (priv->partial) {
sp_repr_free_log(priv->partial);
@@ -208,17 +216,8 @@ SPDocument::~SPDocument() {
rerouting_handler_id = 0;
}
- if (oldSignalsConnected) {
- g_signal_handlers_disconnect_by_func(G_OBJECT(INKSCAPE),
- reinterpret_cast<gpointer>(DocumentUndo::resetKey),
- static_cast<gpointer>(this));
- } else {
- _selection_changed_connection.disconnect();
- _desktop_activated_connection.disconnect();
- }
-
if (keepalive) {
- inkscape_unref();
+ inkscape_unref(INKSCAPE);
keepalive = FALSE;
}
@@ -369,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) {
@@ -447,7 +446,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc,
rdf_set_defaults( document );
if (keepalive) {
- inkscape_ref();
+ inkscape_ref(INKSCAPE);
}
// Check if the document already has a perspective (e.g., when opening an existing
@@ -462,10 +461,14 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc,
DocumentUndo::setUndoSensitive(document, true);
// reset undo key when selection changes, so that same-key actions on different objects are not coalesced
- g_signal_connect(G_OBJECT(INKSCAPE), "change_selection",
- G_CALLBACK(DocumentUndo::resetKey), document);
- g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
- G_CALLBACK(DocumentUndo::resetKey), document);
+ document->priv->selChangeConnection = INKSCAPE.signal_selection_changed.connect(
+ sigc::hide(sigc::bind(
+ sigc::ptr_fun(&DocumentUndo::resetKey), document)
+ ));
+ document->priv->desktopActivatedConnection = INKSCAPE.signal_activate_desktop.connect(
+ sigc::hide(sigc::bind(
+ sigc::ptr_fun(&DocumentUndo::resetKey), document)
+ ));
document->oldSignalsConnected = true;
return document;
@@ -593,20 +596,97 @@ SPDocument *SPDocument::doUnref()
}
/// guaranteed not to return nullptr
-Inkscape::Util::Unit const* SPDocument::getDefaultUnit() const
+Inkscape::Util::Unit const* SPDocument::getDisplayUnit() const
{
SPNamedView const* nv = sp_document_namedview(this, NULL);
- return nv ? nv->getDefaultUnit() : unit_table.getUnit("pt");
+ return nv ? nv->getDisplayUnit() : unit_table.getUnit("px");
}
/// guaranteed not to return nullptr
// returns 'px' units as default, like legacy Inkscape
+// THIS SHOULD NOT BE USED... INSTEAD USE DOCUMENT SCALE
Inkscape::Util::Unit const& SPDocument::getSVGUnit() const
{
SPNamedView const* nv = sp_document_namedview(this, NULL);
return nv ? nv->getSVGUnit() : *unit_table.getUnit("px");
}
+/// 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;
+ if( root->viewBox_set ) {
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ if( root->viewBox.width() > 0.0 ) {
+ scale_x = root->width.computed / root->viewBox.width();
+ }
+ if( root->viewBox.height() > 0.0 ) {
+ scale_y = root->height.computed / root->viewBox.height();
+ }
+ scale = Geom::Scale(scale_x, scale_y);
+ }
+ // std::cout << "SPDocument::getDocumentScale():\n" << scale << std::endl;
+ return scale;
+}
+
+// Avoid calling root->updateRepr() twice by combining setting width and height.
+// (As done on every delete as clipboard calls this via fitToRect(). Also called in page-sizer.cpp)
+void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize)
+{
+ 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; // 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();
+
+ 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; // 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();
+
+ // 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();
+}
+
Inkscape::Util::Quantity SPDocument::getWidth() const
{
g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
@@ -624,25 +704,23 @@ Inkscape::Util::Quantity SPDocument::getWidth() const
return Inkscape::Util::Quantity(result, unit_table.getUnit(u));
}
-void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
+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");
- /* SVG does not support meters as a unit, so we must translate meters to
- * cm when writing */
- if (*width.unit == *unit_table.getUnit("m")) {
- root->width.value = width.value("cm");
- root->width.unit = SVGLength::CM;
- } else {
- root->width.value = width.quantity;
- root->width.unit = (SVGLength::Unit) width.unit->svgUnit();
- }
+ root->width.value = width.quantity;
+ root->width.unit = (SVGLength::Unit) width.unit->svgUnit();
- if (root->viewBox_set)
- root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom()));
+ if (root->viewBox_set && changeSize)
+ root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_width_converted) * root->viewBox.width(), root->viewBox.bottom()));
root->updateRepr();
}
@@ -665,25 +743,23 @@ Inkscape::Util::Quantity SPDocument::getHeight() const
return Inkscape::Util::Quantity(result, unit_table.getUnit(u));
}
-void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
+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");
- /* SVG does not support meters as a unit, so we must translate meters to
- * cm when writing */
- if (*height.unit == *unit_table.getUnit("m")) {
- root->height.value = height.value("cm");
- root->height.unit = SVGLength::CM;
- } else {
- root->height.value = height.quantity;
- root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
- }
+ root->height.value = height.quantity;
+ root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
- if (root->viewBox_set)
- root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height()));
+ if (root->viewBox_set && changeSize)
+ root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height()));
root->updateRepr();
}
@@ -721,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);
@@ -748,9 +824,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
rect.min() - Geom::Point(margin_left, margin_bottom),
rect.max() + Geom::Point(margin_right, margin_top));
-
- setWidth(Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.width(), "px", nv_units), nv_units));
- setHeight(Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.height(), "px", nv_units), nv_units));
+ setWidthAndHeight(
+ Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.width(), "px", nv_units), nv_units),
+ Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.height(), "px", nv_units), nv_units)
+ );
Geom::Translate const tr(
Geom::Point(0, old_height - rect_with_margins.height())