summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-08-27 16:32:55 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-08-27 16:32:55 +0000
commitf10048be170a45921ae8fc65ccd2588a9ad2897d (patch)
treec0abadf8d3b7ffb325061d797e5b8d9d8b2aefeb /src/ui
parentUse real world units for page sizes. (diff)
downloadinkscape-f10048be170a45921ae8fc65ccd2588a9ad2897d.tar.gz
inkscape-f10048be170a45921ae8fc65ccd2588a9ad2897d.zip
Added viewBox implement document unit support.
(bzr r12475.1.2)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/aboutbox.cpp5
-rw-r--r--src/ui/dialog/document-properties.cpp43
-rw-r--r--src/ui/dialog/document-properties.h4
-rw-r--r--src/ui/dialog/export.cpp6
-rw-r--r--src/ui/dialog/print.cpp8
-rw-r--r--src/ui/widget/page-sizer.cpp5
6 files changed, 42 insertions, 29 deletions
diff --git a/src/ui/dialog/aboutbox.cpp b/src/ui/dialog/aboutbox.cpp
index 6f1137e46..121773b6d 100644
--- a/src/ui/dialog/aboutbox.cpp
+++ b/src/ui/dialog/aboutbox.cpp
@@ -34,6 +34,7 @@
#include "svg-view-widget.h"
#include "sp-text.h"
#include "text-editing.h"
+#include "util/units.h"
#include "inkscape-version.h"
@@ -175,8 +176,8 @@ Gtk::Widget *build_splash_widget() {
GtkWidget *v=sp_svg_view_widget_new(doc);
- double width=doc->getWidth();
- double height=doc->getHeight();
+ double width=doc->getWidth().value("px");
+ double height=doc->getHeight().value("px");
doc->doUnref();
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp
index 430f28474..272b85d2a 100644
--- a/src/ui/dialog/document-properties.cpp
+++ b/src/ui/dialog/document-properties.cpp
@@ -54,6 +54,8 @@
#include <gtkmm/stock.h>
#include <gtkmm/table.h>
+#include <2geom/transforms.h>
+
using std::pair;
namespace Inkscape {
@@ -169,6 +171,9 @@ DocumentProperties::DocumentProperties()
signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
+
+ _rum_deflt.getUnitMenu()->signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::onDocUnitChange));
+ _old_doc_unit = _rum_deflt.getUnit();
}
void DocumentProperties::init()
@@ -1436,28 +1441,12 @@ void DocumentProperties::update()
double const doc_w = sp_desktop_document(dt)->getRoot()->width.value;
Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit).abbr;
if (doc_w_unit == "") {
- if (nv->units) {
- doc_w_unit = nv->units->abbr;
- } else {
- if (nv->doc_units) {
- doc_w_unit = nv->doc_units->abbr;
- } else {
- doc_w_unit = "px";
- }
- }
+ doc_w_unit = "px";
}
double const doc_h = sp_desktop_document(dt)->getRoot()->height.value;
Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit).abbr;
if (doc_h_unit == "") {
- if (nv->units) {
- doc_h_unit = nv->units->abbr;
- } else {
- if (nv->doc_units) {
- doc_h_unit = nv->doc_units->abbr;
- } else {
- doc_h_unit = "px";
- }
- }
+ doc_h_unit = "px";
}
_page_sizer.setDim(Inkscape::Util::Quantity(doc_w, doc_w_unit), Inkscape::Util::Quantity(doc_h, doc_h_unit));
_page_sizer.updateFitMarginsUI(nv->getRepr());
@@ -1642,6 +1631,24 @@ void DocumentProperties::onRemoveGrid()
}
}
+/** Callback for document unit change. */
+void DocumentProperties::onDocUnitChange()
+{
+ SPDocument *doc = SP_ACTIVE_DOCUMENT;
+ Inkscape::Util::Unit doc_unit = _rum_deflt.getUnit();
+
+ // Set viewBox
+ Inkscape::Util::Quantity width = doc->getWidth();
+ Inkscape::Util::Quantity height = doc->getHeight();
+ doc->setViewBox(Geom::Rect::from_xywh(0, 0, width.value(doc_unit), height.value(doc_unit)));
+
+ // Scale and translate objects
+ gdouble scale = Inkscape::Util::Quantity::convert(1, _old_doc_unit, doc_unit);
+ doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, doc->getHeight().value("px")));
+
+ _old_doc_unit = doc_unit;
+ DocumentUndo::done(doc, SP_VERB_NONE, _("Changed document unit"));
+}
} // namespace Dialog
} // namespace UI
diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h
index 56fed30c4..56abf9741 100644
--- a/src/ui/dialog/document-properties.h
+++ b/src/ui/dialog/document-properties.h
@@ -216,6 +216,10 @@ private:
// callback methods for buttons on grids page.
void onNewGrid();
void onRemoveGrid();
+
+ // callback for document unit change
+ Inkscape::Util::Unit _old_doc_unit;
+ void onDocUnitChange();
};
} // namespace Dialog
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index 2c92608d7..c98e23000 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -762,7 +762,7 @@ void Export::onAreaToggled ()
}
case SELECTION_PAGE:
bbox = Geom::Rect(Geom::Point(0.0, 0.0),
- Geom::Point(doc->getWidth(), doc->getHeight()));
+ Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px")));
// std::cout << "Using selection: PAGE" << std::endl;
key = SELECTION_PAGE;
@@ -1475,8 +1475,8 @@ void Export::detectSize() {
doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
Geom::Point x(0.0, 0.0);
- Geom::Point y(doc->getWidth(),
- doc->getHeight());
+ Geom::Point y(doc->getWidth().value("px"),
+ doc->getHeight().value("px"));
Geom::Rect bbox(x, y);
if (bbox_equal(bbox,current_bbox)) {
diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp
index 4c8c77f96..3ce75327f 100644
--- a/src/ui/dialog/print.cpp
+++ b/src/ui/dialog/print.cpp
@@ -49,8 +49,8 @@ static void draw_page(
if (junk->_tab->as_bitmap()) {
// Render as exported PNG
- gdouble width = (junk->_doc)->getWidth();
- gdouble height = (junk->_doc)->getHeight();
+ gdouble width = (junk->_doc)->getWidth().value("px");
+ gdouble height = (junk->_doc)->getHeight().value("px");
gdouble dpi = junk->_tab->bitmap_dpi();
std::string tmp_png;
std::string tmp_base = "inkscape-print-png-XXXXXX";
@@ -195,8 +195,8 @@ Print::Print(SPDocument *doc, SPItem *base) :
// set up paper size to match the document size
gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
GtkPageSetup *page_setup = gtk_page_setup_new();
- gdouble doc_width = _doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt");
- gdouble doc_height = _doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt");
+ gdouble doc_width = _doc->getWidth().value("pt");
+ gdouble doc_height = _doc->getHeight().value("pt");
GtkPaperSize *paper_size;
if (doc_width > doc_height) {
gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index 5a289096c..94c7b453a 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -476,12 +476,12 @@ PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool
if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
- double const old_height = doc->getHeight();
+ Inkscape::Util::Quantity const old_height = doc->getHeight();
doc->setWidth (w);
doc->setHeight (h);
// The origin for the user is in the lower left corner; this point should remain stationary when
// changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this
- Geom::Translate const vert_offset(Geom::Point(0, (old_height - h.quantity)));
+ Geom::Translate const vert_offset(Geom::Point(0, (old_height.value("px") - h.value("px"))));
doc->getRoot()->translateChildItems(vert_offset);
DocumentUndo::done(doc, SP_VERB_NONE, _("Set page size"));
}
@@ -709,6 +709,7 @@ PageSizer::on_value_changed()
void
PageSizer::on_units_changed()
{
+ if (_widgetRegistry->isUpdating()) return;
_unit = _dimensionUnits.getUnit().abbr;
setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()),
Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit()));