summaryrefslogtreecommitdiffstats
path: root/src/sp-guide.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-02-02 20:08:49 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-02-02 20:08:49 +0000
commit1d3b98e5f5311479cd87f20e3656b0133bff73bd (patch)
tree95eea2fcac18f236b31053e4d1493aa644760df0 /src/sp-guide.cpp
parentupdate to trunk (diff)
parentTranslations. Arabic translation update. (diff)
downloadinkscape-1d3b98e5f5311479cd87f20e3656b0133bff73bd.tar.gz
inkscape-1d3b98e5f5311479cd87f20e3656b0133bff73bd.zip
update to trunk
(bzr r13645.1.4)
Diffstat (limited to 'src/sp-guide.cpp')
-rw-r--r--src/sp-guide.cpp62
1 files changed, 55 insertions, 7 deletions
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 581c8a440..08b055508 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -22,7 +22,7 @@
#include <algorithm>
#include <cstring>
#include <string>
-#include "desktop-handles.h"
+
#include "display/sp-canvas.h"
#include "display/guideline.h"
#include "svg/svg.h"
@@ -37,6 +37,7 @@
#include <remove-last.h>
#include "inkscape.h"
#include "desktop.h"
+#include "sp-root.h"
#include "sp-namedview.h"
#include <2geom/angle.h>
#include "document.h"
@@ -152,6 +153,19 @@ void SPGuide::set(unsigned int key, const gchar *value) {
success += sp_svg_number_read_d(strarray[1], &newy);
g_strfreev (strarray);
if (success == 2) {
+ // If root viewBox set, interpret guides in terms of viewBox (90/96)
+ SPRoot *root = document->getRoot();
+ if( root->viewBox_set ) {
+ if(Geom::are_near((root->width.computed * root->viewBox.height()) / (root->viewBox.width() * root->height.computed), 1.0, Geom::EPSILON)) {
+ // for uniform scaling, try to reduce numerical error
+ double vbunit2px = (root->width.computed / root->viewBox.width() + root->height.computed / root->viewBox.height())/2.0;
+ newx = newx * vbunit2px;
+ newy = newy * vbunit2px;
+ } else {
+ newx = newx * root->width.computed / root->viewBox.width();
+ newy = newy * root->height.computed / root->viewBox.height();
+ }
+ }
this->point_on_line = Geom::Point(newx, newy);
} else if (success == 1) {
// before 0.46 style guideline definition.
@@ -185,7 +199,24 @@ SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::P
Geom::Point n = Geom::rot90(pt2 - pt1);
- sp_repr_set_point(repr, "position", pt1);
+ // If root viewBox set, interpret guides in terms of viewBox (90/96)
+ double newx = pt1.x();
+ double newy = pt1.y();
+
+ SPRoot *root = doc->getRoot();
+ if( root->viewBox_set ) {
+ // check to see if scaling is uniform
+ if(Geom::are_near((root->viewBox.width() * root->height.computed) / (root->width.computed * root->viewBox.height()), 1.0, Geom::EPSILON)) {
+ double px2vbunit = (root->viewBox.width()/root->width.computed + root->viewBox.height()/root->height.computed)/2.0;
+ newx = newx * px2vbunit;
+ newy = newy * px2vbunit;
+ } else {
+ newx = newx * root->viewBox.width() / root->width.computed;
+ newy = newy * root->viewBox.height() / root->height.computed;
+ }
+ }
+
+ sp_repr_set_point(repr, "position", Geom::Point( newx, newy ));
sp_repr_set_point(repr, "orientation", n);
SPNamedView *namedview = sp_document_namedview(doc, NULL);
@@ -207,7 +238,7 @@ void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Poin
void sp_guide_create_guides_around_page(SPDesktop *dt)
{
- SPDocument *doc=sp_desktop_document(dt);
+ SPDocument *doc=dt->getDocument();
std::list<std::pair<Geom::Point, Geom::Point> > pts;
Geom::Point A(0, 0);
@@ -227,7 +258,7 @@ void sp_guide_create_guides_around_page(SPDesktop *dt)
void sp_guide_delete_all_guides(SPDesktop *dt)
{
- SPDocument *doc=sp_desktop_document(dt);
+ SPDocument *doc=dt->getDocument();
const GSList *current;
while ( (current = doc->getResourceList("guide")) ) {
SPGuide* guide = SP_GUIDE(current->data);
@@ -318,8 +349,25 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit)
/* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit
case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
if (commit) {
+ // If root viewBox set, interpret guides in terms of viewBox (90/96)
+ double newx = point_on_line.x();
+ double newy = point_on_line.y();
+
+ SPRoot *root = document->getRoot();
+ if( root->viewBox_set ) {
+ // check to see if scaling is uniform
+ if(Geom::are_near((root->viewBox.width() * root->height.computed) / (root->width.computed * root->viewBox.height()), 1.0, Geom::EPSILON)) {
+ double px2vbunit = (root->viewBox.width()/root->width.computed + root->viewBox.height()/root->height.computed)/2.0;
+ newx = newx * px2vbunit;
+ newy = newy * px2vbunit;
+ } else {
+ newx = newx * root->viewBox.width() / root->width.computed;
+ newy = newy * root->viewBox.height() / root->height.computed;
+ }
+ }
+
//XML Tree being used here directly while it shouldn't be.
- sp_repr_set_point(getRepr(), "position", point_on_line);
+ sp_repr_set_point(getRepr(), "position", Geom::Point(newx, newy) );
}
/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
@@ -410,8 +458,8 @@ char* SPGuide::description(bool const verbose) const
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(this->point_on_line[X], "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(this->point_on_line[Y], "px");
- GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str());
- GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str());
+ GString *position_string_x = g_string_new(x_q.string(namedview->display_units).c_str());
+ GString *position_string_y = g_string_new(y_q.string(namedview->display_units).c_str());
gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));