From abc0521ce024af29c7bf58cf404060f911e5b412 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 5 Oct 2013 15:42:38 -0400 Subject: Fix EMF/WMF import scale (Bug #1229120). Fixed bugs: - https://launchpad.net/bugs/1229120 (bzr r12662) --- src/extension/internal/emf-inout.cpp | 26 ++++++++++++++++++++++++++ src/extension/internal/wmf-inout.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'src') diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index d9489af31..4bca9dfd9 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -46,6 +46,10 @@ #include "clear-n_.h" #include "document.h" #include "util/units.h" +#include "shape-editor.h" +#include "sp-namedview.h" +#include "document-undo.h" +#include "inkscape.h" #include "emf-print.h" #include "emf-inout.h" @@ -3485,7 +3489,29 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { + bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); + Inkscape::DocumentUndo::setUndoSensitive(doc, false); + + doc->ensureUpToDate(); + + // Set document unit + Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); + Inkscape::SVGOStringStream os; + os << doc->getWidth().unit->abbr; + repr->setAttribute("inkscape:document-units", os.str().c_str()); + + // Set viewBox doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + + // Scale and translate objects + double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit->abbr); + ShapeEditor::blockSetItem(true); + doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, SP_ACTIVE_DOCUMENT->getHeight().value("px"))); + ShapeEditor::blockSetItem(false); + + doc->ensureUpToDate(); + + Inkscape::DocumentUndo::setUndoSensitive(doc, saved); } return doc; diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index e7dfa46d7..78fcdb66d 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -46,6 +46,10 @@ #include "util/units.h" #include "clear-n_.h" #include "document.h" +#include "shape-editor.h" +#include "sp-namedview.h" +#include "document-undo.h" +#include "inkscape.h" #include "wmf-inout.h" @@ -3173,7 +3177,29 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { + bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); + Inkscape::DocumentUndo::setUndoSensitive(doc, false); + + doc->ensureUpToDate(); + + // Set document unit + Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); + Inkscape::SVGOStringStream os; + os << doc->getWidth().unit->abbr; + repr->setAttribute("inkscape:document-units", os.str().c_str()); + + // Set viewBox doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + + // Scale and translate objects + double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit->abbr); + ShapeEditor::blockSetItem(true); + doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, SP_ACTIVE_DOCUMENT->getHeight().value("px"))); + ShapeEditor::blockSetItem(false); + + doc->ensureUpToDate(); + + Inkscape::DocumentUndo::setUndoSensitive(doc, saved); } return doc; -- cgit v1.2.3