diff options
| author | Matthew Petroff <matthew@mpetroff.net> | 2013-08-27 16:32:55 +0000 |
|---|---|---|
| committer | Matthew Petroff <matthew@mpetroff.net> | 2013-08-27 16:32:55 +0000 |
| commit | f10048be170a45921ae8fc65ccd2588a9ad2897d (patch) | |
| tree | c0abadf8d3b7ffb325061d797e5b8d9d8b2aefeb /src | |
| parent | Use real world units for page sizes. (diff) | |
| download | inkscape-f10048be170a45921ae8fc65ccd2588a9ad2897d.tar.gz inkscape-f10048be170a45921ae8fc65ccd2588a9ad2897d.zip | |
Added viewBox implement document unit support.
(bzr r12475.1.2)
Diffstat (limited to 'src')
32 files changed, 163 insertions, 92 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index 13e339abe..ea53b9cf7 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -240,7 +240,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid // display rect and zoom are now handled in sp_desktop_widget_realize() Geom::Rect const d(Geom::Point(0.0, 0.0), - Geom::Point(document->getWidth(), document->getHeight())); + Geom::Point(document->getWidth().value("px"), document->getHeight().value("px"))); SP_CTRLRECT(page)->setRectangle(d); SP_CTRLRECT(page_border)->setRectangle(d); @@ -257,7 +257,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid /* Connect event for page resize */ - _doc2dt[5] = document->getHeight(); + _doc2dt[5] = document->getHeight().value("px"); sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt); _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this)); @@ -1010,7 +1010,7 @@ void SPDesktop::zoom_page() { Geom::Rect d(Geom::Point(0, 0), - Geom::Point(doc()->getWidth(), doc()->getHeight())); + Geom::Point(doc()->getWidth().value("px"), doc()->getHeight().value("px"))); if (d.minExtent() < 1.0) { return; @@ -1027,12 +1027,12 @@ SPDesktop::zoom_page_width() { Geom::Rect const a = get_display_area(); - if (doc()->getWidth() < 1.0) { + if (doc()->getWidth().value("px") < 1.0) { return; } Geom::Rect d(Geom::Point(0, a.midpoint()[Geom::Y]), - Geom::Point(doc()->getWidth(), a.midpoint()[Geom::Y])); + Geom::Point(doc()->getWidth().value("px"), a.midpoint()[Geom::Y])); set_display_area(d, 10); } diff --git a/src/document.cpp b/src/document.cpp index 0b742e491..20c6fe331 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -534,16 +534,20 @@ SPDocument *SPDocument::doUnref() return NULL; } -gdouble SPDocument::getWidth() const +Inkscape::Util::Quantity SPDocument::getWidth() const { - g_return_val_if_fail(this->priv != NULL, 0.0); - g_return_val_if_fail(this->root != NULL, 0.0); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); - gdouble result = root->width.computed; + gdouble result = root->width.value; + SVGLength::Unit u = root->width.unit; if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.width(); } - return result; + if (u == SVGLength::NONE) { + u = SVGLength::PX; + } + return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } void SPDocument::setWidth(const Inkscape::Util::Quantity &width) @@ -570,16 +574,20 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) root->updateRepr(); } -gdouble SPDocument::getHeight() const +Inkscape::Util::Quantity SPDocument::getHeight() const { - g_return_val_if_fail(this->priv != NULL, 0.0); - g_return_val_if_fail(this->root != NULL, 0.0); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); - gdouble result = root->height.computed; + gdouble result = root->height.value; + SVGLength::Unit u = root->height.unit; if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.height(); } - return result; + if (u == SVGLength::NONE) { + u = SVGLength::PX; + } + return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } void SPDocument::setHeight(const Inkscape::Util::Quantity &height) @@ -606,9 +614,16 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) root->updateRepr(); } +void SPDocument::setViewBox(const Geom::Rect &viewBox) +{ + root->viewBox_set = true; + root->viewBox = viewBox; + root->updateRepr(); +} + Geom::Point SPDocument::getDimensions() const { - return Geom::Point(getWidth(), getHeight()); + return Geom::Point(getWidth().value("px"), getHeight().value("px")); } Geom::OptRect SPDocument::preferredBounds() const @@ -630,7 +645,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const w = rect.width(); double const h = rect.height(); - double const old_height = getHeight(); + double const old_height = getHeight().value("px"); Inkscape::Util::Unit const px = unit_table.getUnit("px"); /* in px */ diff --git a/src/document.h b/src/document.h index 6782c6206..ebee3a84c 100644 --- a/src/document.h +++ b/src/document.h @@ -227,12 +227,13 @@ public: SPDocument *doRef(); SPDocument *doUnref(); - gdouble getWidth() const; - gdouble getHeight() const; + Inkscape::Util::Quantity getWidth() const; + Inkscape::Util::Quantity getHeight() const; Geom::Point getDimensions() const; Geom::OptRect preferredBounds() const; void setWidth(const Inkscape::Util::Quantity &width); void setHeight(const Inkscape::Util::Quantity &height); + void setViewBox(const Geom::Rect &viewBox); void requestModified(); gint ensureUpToDate(); bool addResource(const gchar *key, SPObject *object); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index f7ab63c98..eddc5ba23 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -645,9 +645,9 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page Geom::Affine tp( Geom::Translate( bleedmargin_px, bleedmargin_px ) ); ctx->transform(tp); } else { - double high = doc->getHeight(); + double high = doc->getHeight().value("px"); if (ctx->_vector_based_target) - high *= Inkscape::Util::Quantity::convert(1, "px", "pt"); + high = Inkscape::Util::Quantity::convert(high, "px", "pt"); // this transform translates the export drawing to a virtual page (0,0)-(width,height) Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0), diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index 820d1c9d3..2f9d0ff25 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -35,6 +35,7 @@ #include "extension/effect.h" #include "extension/system.h" +#include "util/units.h" #include "grid.h" @@ -97,14 +98,14 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc /* get page size */ SPDocument * doc = document->doc(); bounding_area = Geom::Rect( Geom::Point(0,0), - Geom::Point(doc->getWidth(), doc->getHeight()) ); + Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px")) ); } else { Geom::OptRect bounds = selection->visualBounds(); if (bounds) { bounding_area = *bounds; } - gdouble doc_height = (document->doc())->getHeight(); + gdouble doc_height = (document->doc())->getHeight().value("px"); Geom::Rect temprec = Geom::Rect(Geom::Point(bounding_area.min()[Geom::X], doc_height - bounding_area.min()[Geom::Y]), Geom::Point(bounding_area.max()[Geom::X], doc_height - bounding_area.max()[Geom::Y])); diff --git a/src/extension/internal/latex-pstricks.cpp b/src/extension/internal/latex-pstricks.cpp index 2ece1ba87..c8e8e2f2e 100644 --- a/src/extension/internal/latex-pstricks.cpp +++ b/src/extension/internal/latex-pstricks.cpp @@ -117,8 +117,8 @@ unsigned int PrintLatex::begin (Inkscape::Extension::Print *mod, SPDocument *doc } // width and height in pt - _width = doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt"); - _height = doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt"); + _width = doc->getWidth().value("pt"); + _height = doc->getHeight().value("pt"); if (res >= 0) { @@ -128,10 +128,10 @@ unsigned int PrintLatex::begin (Inkscape::Extension::Print *mod, SPDocument *doc os << "\\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}\n"; // from now on we can output px, but they will be treated as pt - os << "\\begin{pspicture}(" << doc->getWidth() << "," << doc->getHeight() << ")\n"; + os << "\\begin{pspicture}(" << doc->getWidth().value("px") << "," << doc->getHeight().value("px") << ")\n"; } - m_tr_stack.push( Geom::Scale(1, -1) * Geom::Translate(0, doc->getHeight())); /// @fixme hardcoded doc2dt transform + m_tr_stack.push( Geom::Scale(1, -1) * Geom::Translate(0, doc->getHeight().value("px"))); /// @fixme hardcoded doc2dt transform return fprintf(_stream, "%s", os.str().c_str()); } diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index 57a71b467..b1c67aa81 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -602,7 +602,7 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, float bl } // flip y-axis - push_transform( Geom::Scale(1,-1) * Geom::Translate(0, doc->getHeight()) ); /// @fixme hardcoded desktop transform! + push_transform( Geom::Scale(1,-1) * Geom::Translate(0, doc->getHeight().value("px")) ); /// @fixme hardcoded desktop transform! // write the info to LaTeX Inkscape::SVGOStringStream os; @@ -611,7 +611,7 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, float bl // scaling of the image when including it in LaTeX os << " \\ifx\\svgwidth\\undefined%\n"; - os << " \\setlength{\\unitlength}{" << d.width() * Inkscape::Util::Quantity::convert(1, "px", "pt") << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 + os << " \\setlength{\\unitlength}{" << Inkscape::Util::Quantity::convert(d.width(), "px", "pt") << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 os << " \\ifx\\svgscale\\undefined%\n"; os << " \\relax%\n"; os << " \\else%\n"; diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 9f745cdea..a4dbd1428 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -75,6 +75,7 @@ #include "sp-flowtext.h" #include "svg/svg.h" #include "text-editing.h" +#include "util/units.h" //# DOM-specific includes @@ -945,7 +946,7 @@ static Geom::Affine getODFTransform(const SPItem *item) //### Get SVG-to-ODF transform Geom::Affine tf (item->i2dt_affine()); //Flip Y into document coordinates - double doc_height = SP_ACTIVE_DOCUMENT->getHeight(); + double doc_height = SP_ACTIVE_DOCUMENT->getHeight().value("px"); Geom::Affine doc2dt_tf = Geom::Affine(Geom::Scale(1.0, -1.0)); /// @fixme hardcoded desktop transform doc2dt_tf = doc2dt_tf * Geom::Affine(Geom::Translate(0, doc_height)); tf = tf * doc2dt_tf; diff --git a/src/file.cpp b/src/file.cpp index 5007cd901..bb66e3330 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -263,7 +263,7 @@ bool sp_file_open(const Glib::ustring &uri, // If the current desktop is empty, open the document there doc->ensureUpToDate(); // TODO this will trigger broken link warnings, etc. desktop->change_document(doc); - doc->emitResizedSignal(doc->getWidth(), doc->getHeight()); + doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); } else { // create a whole new desktop and window SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc. diff --git a/src/flood-context.cpp b/src/flood-context.cpp index a719f1202..c944e5683 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -797,7 +797,7 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even unsigned int height = (int)ceil(screen.height() * zoom_scale * padding); Geom::Point origin(screen.min()[Geom::X], - document->getHeight() - screen.height() - screen.min()[Geom::Y]); + document->getHeight().value("px") - screen.height() - screen.min()[Geom::Y]); origin[Geom::X] += (screen.width() * ((1 - padding) / 2)); origin[Geom::Y] += (screen.height() * ((1 - padding) / 2)); @@ -907,7 +907,7 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even } for (unsigned int i = 0; i < fill_points.size(); i++) { - Geom::Point pw = Geom::Point(fill_points[i][Geom::X] / zoom_scale, document->getHeight() + (fill_points[i][Geom::Y] / zoom_scale)) * affine; + Geom::Point pw = Geom::Point(fill_points[i][Geom::X] / zoom_scale, document->getHeight().value("px") + (fill_points[i][Geom::Y] / zoom_scale)) * affine; pw[Geom::X] = (int)MIN(width - 1, MAX(0, pw[Geom::X])); pw[Geom::Y] = (int)MIN(height - 1, MAX(0, pw[Geom::Y])); diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 75c002c57..db7b73e34 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -116,7 +116,7 @@ GdkPixbuf *sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename* double padding = 1.0; Geom::Point origin(screen.min()[Geom::X], - doc->getHeight() - screen[Geom::Y].extent() - screen.min()[Geom::Y]); + doc->getHeight().value("px") - screen[Geom::Y].extent() - screen.min()[Geom::Y]); origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2)); origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2)); diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index c43a207c8..b8b815b4c 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -34,6 +34,7 @@ #include "preferences.h" #include "rdf.h" #include "display/cairo-utils.h" +#include "util/units.h" /* This is an example of how to use libpng to read and write PNG files. * The file libpng.txt is much more verbose then this. If you have not @@ -415,7 +416,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, doc->ensureUpToDate(); /* Calculate translation by transforming to document coordinates (flipping Y)*/ - Geom::Point translation = Geom::Point(-area[Geom::X][0], area[Geom::Y][1] - doc->getHeight()); + Geom::Point translation = Geom::Point(-area[Geom::X][0], area[Geom::Y][1] - doc->getHeight().value("px")); /* This calculation is only valid when assumed that (x0,y0)= area.corner(0) and (x1,y1) = area.corner(2) * 1) a[0] * x0 + a[2] * y1 + a[4] = 0.0 diff --git a/src/inkview.cpp b/src/inkview.cpp index fd7f6b608..e65638df6 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -54,6 +54,7 @@ #include "document.h" #include "svg-view.h" #include "svg-view-widget.h" +#include "util/units.h" #ifdef WITH_INKJAR #include "io/inkjar.h" @@ -308,8 +309,8 @@ main (int argc, const char **argv) w = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title( GTK_WINDOW(w), ss.doc->getName() ); gtk_window_set_default_size (GTK_WINDOW (w), - MIN ((int)(ss.doc)->getWidth (), (int)gdk_screen_width () - 64), - MIN ((int)(ss.doc)->getHeight (), (int)gdk_screen_height () - 64)); + MIN ((int)(ss.doc)->getWidth().value("px"), (int)gdk_screen_width() - 64), + MIN ((int)(ss.doc)->getHeight().value("px"), (int)gdk_screen_height() - 64)); ss.window = w; g_signal_connect (G_OBJECT (w), "delete_event", (GCallback) sp_svgview_main_delete, &ss); @@ -318,7 +319,7 @@ main (int argc, const char **argv) (ss.doc)->ensureUpToDate(); ss.view = sp_svg_view_widget_new (ss.doc); (ss.doc)->doUnref (); - SP_SVG_VIEW_WIDGET(ss.view)->setResize( false, ss.doc->getWidth(), ss.doc->getHeight() ); + SP_SVG_VIEW_WIDGET(ss.view)->setResize( false, ss.doc->getWidth().value("px"), ss.doc->getHeight().value("px") ); gtk_widget_show (ss.view); gtk_container_add (GTK_CONTAINER (w), ss.view); diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index 062a75a7b..49af2be47 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -369,8 +369,8 @@ lpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::Effe void lpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B) { - Geom::Coord w = document->getWidth(); - Geom::Coord h = document->getHeight(); + Geom::Coord w = document->getWidth().value("px"); + Geom::Coord h = document->getHeight().value("px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double ulx = prefs->getDouble("/tools/lpetool/bbox_upperleftx", 0); diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 77ba3040f..c5a3e1e88 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -770,7 +770,7 @@ void Inkscape::ObjectSnapper::_clear_paths() const Geom::PathVector* Inkscape::ObjectSnapper::_getBorderPathv() const { - Geom::Rect const border_rect = Geom::Rect(Geom::Point(0,0), Geom::Point((_snapmanager->getDocument())->getWidth(),(_snapmanager->getDocument())->getHeight())); + Geom::Rect const border_rect = Geom::Rect(Geom::Point(0,0), Geom::Point((_snapmanager->getDocument())->getWidth().value("px"),(_snapmanager->getDocument())->getHeight().value("px"))); return _getPathvFromRect(border_rect); } @@ -787,8 +787,8 @@ Geom::PathVector* Inkscape::ObjectSnapper::_getPathvFromRect(Geom::Rect const re void Inkscape::ObjectSnapper::_getBorderNodes(std::vector<SnapCandidatePoint> *points) const { - Geom::Coord w = (_snapmanager->getDocument())->getWidth(); - Geom::Coord h = (_snapmanager->getDocument())->getHeight(); + Geom::Coord w = (_snapmanager->getDocument())->getWidth().value("px"); + Geom::Coord h = (_snapmanager->getDocument())->getHeight().value("px"); points->push_back(SnapCandidatePoint(Geom::Point(0,0), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); points->push_back(SnapCandidatePoint(Geom::Point(0,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); points->push_back(SnapCandidatePoint(Geom::Point(w,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); diff --git a/src/persp3d.cpp b/src/persp3d.cpp index 2744efb75..6ff2a6a85 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -24,6 +24,7 @@ #include "desktop-handles.h" #include <glibmm/i18n.h> #include "verbs.h" +#include "util/units.h" using Inkscape::DocumentUndo; @@ -191,10 +192,10 @@ Persp3D *persp3d_create_xml_element(SPDocument *document, Persp3DImpl *dup) {// repr = xml_doc->createElement("inkscape:perspective"); repr->setAttribute("sodipodi:type", "inkscape:persp3d"); - Proj::Pt2 proj_vp_x = Proj::Pt2 (0.0, document->getHeight()/2, 1.0); + Proj::Pt2 proj_vp_x = Proj::Pt2 (0.0, document->getHeight().value("px")/2, 1.0); Proj::Pt2 proj_vp_y = Proj::Pt2 (0.0, 1000.0, 0.0); - Proj::Pt2 proj_vp_z = Proj::Pt2 (document->getWidth(), document->getHeight()/2, 1.0); - Proj::Pt2 proj_origin = Proj::Pt2 (document->getWidth()/2, document->getHeight()/3, 1.0); + Proj::Pt2 proj_vp_z = Proj::Pt2 (document->getWidth().value("px"), document->getHeight().value("px")/2, 1.0); + Proj::Pt2 proj_origin = Proj::Pt2 (document->getWidth().value("px")/2, document->getHeight().value("px")/3, 1.0); if (dup) { proj_vp_x = dup->tmat.column (Proj::X); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 5976555f4..3c12b78bd 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2808,7 +2808,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) } // calculate the transform to be applied to objects to move them to 0,0 - Geom::Point move_p = Geom::Point(0, doc->getHeight()) - *c; + Geom::Point move_p = Geom::Point(0, doc->getHeight().value("px")) - *c; move_p[Geom::Y] = -move_p[Geom::Y]; Geom::Affine move = Geom::Affine(Geom::Translate(move_p)); @@ -3092,7 +3092,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) } // calculate the transform to be applied to objects to move them to 0,0 - Geom::Point move_p = Geom::Point(0, doc->getHeight()) - (r->min() + Geom::Point(0, r->dimensions()[Geom::Y])); + Geom::Point move_p = Geom::Point(0, doc->getHeight().value("px")) - (r->min() + Geom::Point(0, r->dimensions()[Geom::Y])); move_p[Geom::Y] = -move_p[Geom::Y]; Geom::Affine move = Geom::Affine(Geom::Translate(move_p)); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 961e53e04..f28a20a2b 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -275,7 +275,7 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { std::list<std::pair<Geom::Point, Geom::Point> > pts; Geom::Point A(0, 0); - Geom::Point C(doc->getWidth(), doc->getHeight()); + Geom::Point C(doc->getWidth().value("px"), doc->getHeight().value("px")); Geom::Point B(C[Geom::X], 0); Geom::Point D(0, C[Geom::Y]); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index a2eda6625..1b3a53828 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -50,6 +50,8 @@ #include "sp-switch.h" #include "sp-defs.h" #include "verbs.h" +#include "layer-model.h" +#include "selection-chemistry.h" using Inkscape::DocumentUndo; @@ -561,6 +563,35 @@ void SPGroup::translateChildItems(Geom::Translate const &tr) } } +// Recursively scale child items around a point +void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p) +{ + if ( hasChildren() ) { + for (SPObject *o = firstChild() ; o ; o = o->getNext() ) { + if ( SP_IS_ITEM(o) ) { + if (SP_IS_GROUP(o)) { + SP_GROUP(o)->scaleChildItemsRec(sc, p); + } else { + SPItem *item = reinterpret_cast<SPItem *>(o); + Geom::OptRect bbox = item->desktopVisualBounds(); + if (bbox) { + // Clear selection (TODO: save and restore selection) + sp_desktop_selection(SP_ACTIVE_DESKTOP)->clear(); + + // Scale item + Geom::Translate const s(p); + Geom::Affine final = s.inverse() * sc * s; + Inkscape::LayerModel layers = Inkscape::LayerModel(); + Inkscape::Selection selection(&layers, SP_ACTIVE_DESKTOP); + selection.add(item); + sp_selection_apply_affine(&selection, final, true, true); + } + } + } + } + } +} + CGroup::CGroup(SPGroup *group) { _group = group; } diff --git a/src/sp-item-group.h b/src/sp-item-group.h index c13fa2b75..0b9d019a5 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -53,6 +53,7 @@ struct SPGroup : public SPLPEItem { LayerMode layerDisplayMode(unsigned int display_key) const; void setLayerDisplayMode(unsigned int display_key, LayerMode mode); void translateChildItems(Geom::Translate const &tr); + void scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p); CGroup *group; diff --git a/src/sp-item.cpp b/src/sp-item.cpp index a4070c9b3..0ca9592c9 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -73,6 +73,8 @@ #include "live_effects/effect.h" #include "live_effects/lpeobject-reference.h" +#include "util/units.h" + #define noSP_ITEM_DEBUG_IDLE static void sp_item_build (SPObject *object, @@ -857,7 +859,7 @@ Geom::OptRect SPItem::desktopGeometricBounds() const Geom::OptRect SPItem::desktopVisualBounds() const { /// @fixme hardcoded desktop transform - Geom::Affine m = Geom::Scale(1, -1) * Geom::Translate(0, document->getHeight()); + Geom::Affine m = Geom::Scale(1, -1) * Geom::Translate(0, document->getHeight().value("px")); Geom::OptRect ret = documentVisualBounds(); if (ret) *ret *= m; return ret; @@ -1520,7 +1522,7 @@ Geom::Affine SPItem::i2dt_affine() const // TODO temp code to prevent crashing on command-line launch: ret = i2doc_affine() * Geom::Scale(1, -1) - * Geom::Translate(0, document->getHeight()); + * Geom::Translate(0, document->getHeight().value("px")); } return ret; } diff --git a/src/sp-root.h b/src/sp-root.h index e2bad917b..5e3f264bf 100644 --- a/src/sp-root.h +++ b/src/sp-root.h @@ -40,7 +40,7 @@ struct SPRoot : public SPGroup { SVGLength height; /* viewBox; */ - unsigned int viewBox_set : 1; + bool viewBox_set : true; Geom::Rect viewBox; /* preserveAspectRatio */ diff --git a/src/svg-view-widget.cpp b/src/svg-view-widget.cpp index d392943e0..567156fec 100644 --- a/src/svg-view-widget.cpp +++ b/src/svg-view-widget.cpp @@ -21,6 +21,7 @@ #include "document.h" #include "svg-view.h" #include "svg-view-widget.h" +#include "util/units.h" static void sp_svg_view_widget_class_init (SPSVGSPViewWidgetClass *klass); static void sp_svg_view_widget_init (SPSVGSPViewWidget *widget); @@ -175,8 +176,8 @@ static void sp_svg_view_widget_size_request(GtkWidget *widget, GtkRequisition *r gdouble width, height; svgv = static_cast<SPSVGView*> (v); - width = (v->doc())->getWidth () * svgv->_hscale; - height = (v->doc())->getHeight () * svgv->_vscale; + width = (v->doc())->getWidth().value("px") * svgv->_hscale; + height = (v->doc())->getHeight().value("px") * svgv->_vscale; if (width <= vw->maxwidth) { hpol = GTK_POLICY_NEVER; diff --git a/src/svg-view.cpp b/src/svg-view.cpp index 7559cbb24..f52608420 100644 --- a/src/svg-view.cpp +++ b/src/svg-view.cpp @@ -20,6 +20,7 @@ #include "sp-item.h" #include "svg-view.h" #include "sp-root.h" +#include "util/units.h" SPSVGView::SPSVGView(SPCanvasGroup *parent) { @@ -71,16 +72,16 @@ void SPSVGView::doRescale(bool event) if (!doc()) { return; } - if (doc()->getWidth () < 1e-9) { + if (doc()->getWidth().value("px") < 1e-9) { return; } - if (doc()->getHeight () < 1e-9) { + if (doc()->getHeight().value("px") < 1e-9) { return; } if (_rescale) { - _hscale = _width / doc()->getWidth (); - _vscale = _height / doc()->getHeight (); + _hscale = _width / doc()->getWidth().value("px"); + _vscale = _height / doc()->getHeight().value("px"); if (_keepaspect) { if (_hscale > _vscale) { _hscale = _vscale; @@ -95,8 +96,8 @@ void SPSVGView::doRescale(bool event) } if (event) { - emitResized (doc()->getWidth () * _hscale, - doc()->getHeight () * _vscale); + emitResized (doc()->getWidth().value("px") * _hscale, + doc()->getHeight().value("px") * _vscale); } } 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())); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 6493da84d..9d2d9b336 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -2132,8 +2132,8 @@ sp_desktop_widget_update_scrollbars (SPDesktopWidget *dtw, double scale) /* The desktop region we always show unconditionally */ SPDocument *doc = dtw->desktop->doc(); - Geom::Rect darea ( Geom::Point(-doc->getWidth(), -doc->getHeight()), - Geom::Point(2 * doc->getWidth(), 2 * doc->getHeight()) ); + Geom::Rect darea ( Geom::Point(-doc->getWidth().value("px"), -doc->getHeight().value("px")), + Geom::Point(2 * doc->getWidth().value("px"), 2 * doc->getHeight().value("px")) ); Geom::OptRect deskarea; if (Inkscape::Preferences::get()->getInt("/tools/bounding_box") == 0) { diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index dda453bc4..feb69cc64 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -42,6 +42,7 @@ #include "display/drawing.h" #include "io/sys.h" #include "sp-root.h" +#include "util/units.h" #include "icon.h" @@ -1137,7 +1138,7 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::Drawing &drawing, if ( object->parent == NULL ) { dbox = Geom::Rect(Geom::Point(0, 0), - Geom::Point(doc->getWidth(), doc->getHeight())); + Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px"))); } /* This is in document coordinates, i.e. pixels */ |
