diff --git a/src/document.cpp b/src/document.cpp
index 57ac0f1f15ffde8c4ebb5e37bcf61d90dcae7830..2a9014e3e3a91893d6fefce6aa7b917768d139d8 100644 (file)
--- a/src/document.cpp
+++ b/src/document.cpp
#include <gtk/gtkmain.h>
#include <string>
#include <cstring>
+
#include "application/application.h"
#include "application/editor.h"
-#include "libnr/nr-matrix-fns.h"
-#include "xml/repr.h"
-#include "helper/units.h"
-#include "inkscape-private.h"
-#include "inkscape_version.h"
-#include "sp-object-repr.h"
-#include "sp-namedview.h"
#include "desktop.h"
-#include "document-private.h"
#include "dir-util.h"
-#include "unit-constants.h"
-#include "prefs-utils.h"
+#include "display/nr-arena-item.h"
+#include "document-private.h"
+#include "helper/units.h"
+#include "inkscape-private.h"
+#include "inkscape-version.h"
#include "libavoid/router.h"
-#include "libnr/nr-rect.h"
-#include "sp-item-group.h"
-#include "profile-manager.h"
#include "persp3d.h"
-
-#include "display/nr-arena-item.h"
-
-#include "dialogs/rdf.h"
-
+#include "preferences.h"
+#include "profile-manager.h"
+#include "rdf.h"
+#include "sp-item-group.h"
+#include "sp-namedview.h"
+#include "sp-object-repr.h"
#include "transf_mat_3x4.h"
+#include "unit-constants.h"
+#include "xml/repr.h"
#define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 1)
router(new Avoid::Router()),
perspectives(0),
current_persp3d(0),
- _collection_queue(0)
+ _collection_queue(0),
+ oldSignalsConnected(false)
{
// Don't use the Consolidate moves optimisation.
router->ConsolidateMoves = false;
modified_id = 0;
}
- _selection_changed_connection.disconnect();
- _desktop_activated_connection.disconnect();
+ if (oldSignalsConnected) {
+ g_signal_handlers_disconnect_by_func(G_OBJECT(INKSCAPE),
+ reinterpret_cast<gpointer>(sp_document_reset_key),
+ static_cast<gpointer>(this));
+ } else {
+ _selection_changed_connection.disconnect();
+ _desktop_activated_connection.disconnect();
+ }
if (keepalive) {
inkscape_unref();
SPDocument *document;
Inkscape::XML::Node *rroot;
Inkscape::Version sodipodi_version;
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
rroot = rdoc->root();
/* fixme: Not sure about this, but lets assume ::build updates */
rroot->setAttribute("sodipodi:version", SODIPODI_VERSION);
- rroot->setAttribute("inkscape:version", INKSCAPE_VERSION);
+ rroot->setAttribute("inkscape:version", Inkscape::version_string);
/* fixme: Again, I moved these here to allow version determining in ::build (Lauris) */
/* Quick hack 2 - get default image size into document */
// creating namedview
if (!sp_item_group_get_child_by_name((SPGroup *) document->root, NULL, "sodipodi:namedview")) {
// if there's none in the document already,
- Inkscape::XML::Node *r = NULL;
Inkscape::XML::Node *rnew = NULL;
- r = inkscape_get_repr(INKSCAPE, "template.base");
- // see if there's a template with id="base" in the preferences
- if (!r) {
- // if there's none, create an empty element
- rnew = rdoc->createElement("sodipodi:namedview");
- rnew->setAttribute("id", "base");
- } else {
- // otherwise, take from preferences
- rnew = r->duplicate(rroot->document());
+
+ rnew = rdoc->createElement("sodipodi:namedview");
+ //rnew->setAttribute("id", "base");
+
+ // Add namedview data from the preferences
+ // we can't use getAllEntries because this could produce non-SVG doubles
+ Glib::ustring pagecolor = prefs->getString("/template/base/pagecolor");
+ if (!pagecolor.empty()) {
+ rnew->setAttribute("pagecolor", pagecolor.data());
+ }
+ Glib::ustring bordercolor = prefs->getString("/template/base/bordercolor");
+ if (!bordercolor.empty()) {
+ rnew->setAttribute("bordercolor", bordercolor.data());
}
+ sp_repr_set_svg_double(rnew, "borderopacity",
+ prefs->getDouble("/template/base/borderopacity", 1.0));
+ sp_repr_set_svg_double(rnew, "objecttolerance",
+ prefs->getDouble("/template/base/objecttolerance", 10.0));
+ sp_repr_set_svg_double(rnew, "gridtolerance",
+ prefs->getDouble("/template/base/gridtolerance", 10.0));
+ sp_repr_set_svg_double(rnew, "guidetolerance",
+ prefs->getDouble("/template/base/guidetolerance", 10.0));
+ sp_repr_set_svg_double(rnew, "inkscape:pageopacity",
+ prefs->getDouble("/template/base/inkscape:pageopacity", 0.0));
+ sp_repr_set_int(rnew, "inkscape:pageshadow",
+ prefs->getInt("/template/base/inkscape:pageshadow", 2));
+ sp_repr_set_int(rnew, "inkscape:window-width",
+ prefs->getInt("/template/base/inkscape:window-width", 640));
+ sp_repr_set_int(rnew, "inkscape:window-height",
+ prefs->getInt("/template/base/inkscape:window-height", 480));
+
// insert into the document
rroot->addChild(rnew, NULL);
// clean up
G_CALLBACK(sp_document_reset_key), document);
g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
G_CALLBACK(sp_document_reset_key), document);
+ document->oldSignalsConnected = true;
} else {
document->_selection_changed_connection = Inkscape::NSApplication::Editor::connectSelectionChanged (sigc::mem_fun (*document, &SPDocument::reset_key));
document->_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*document, &SPDocument::reset_key));
+ document->oldSignalsConnected = false;
}
return document;
if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
root->viewBox.x1 = root->viewBox.x0 + sp_units_get_pixels (width, *unit);
} else { // set to width=
+ gdouble old_computed = root->width.computed;
root->width.computed = sp_units_get_pixels (width, *unit);
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
root->width.value = width;
root->width.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);
}
+
+ if (root->viewBox_set)
+ root->viewBox.x1 = root->viewBox.x0 + (root->width.computed / old_computed) * (root->viewBox.x1 - root->viewBox.x0);
}
SP_OBJECT (root)->updateRepr();
@@ -513,6 +543,7 @@ void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit
if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
root->viewBox.y1 = root->viewBox.y0 + sp_units_get_pixels (height, *unit);
} else { // set to height=
+ gdouble old_computed = root->height.computed;
root->height.computed = sp_units_get_pixels (height, *unit);
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
@@ -523,6 +554,9 @@ void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit
root->height.value = height;
root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);
}
+
+ if (root->viewBox_set)
+ root->viewBox.y1 = root->viewBox.y0 + (root->height.computed / old_computed) * (root->viewBox.y1 - root->viewBox.y0);
}
SP_OBJECT (root)->updateRepr();
return root->height.computed;
}
+Geom::Point sp_document_dimensions(SPDocument *doc)
+{
+ return Geom::Point(sp_document_width(doc), sp_document_height(doc));
+}
+
/**
- * Given an NR::Rect that may, for example, correspond to the bbox of an object,
+ * Given a Geom::Rect that may, for example, correspond to the bbox of an object,
* this function fits the canvas to that rect by resizing the canvas
* and translating the document root into position.
*/
void SPDocument::fitToRect(Geom::Rect const &rect)
{
- g_return_if_fail(!rect.isEmpty());
-
double const w = rect.width();
double const h = rect.height();
}
if ( NULL != document_language ) {
- gchar *pos = strchr(document_language, '_');
+ const char *pos = strchr(document_language, '_');
if ( NULL != pos ) {
return Glib::ustring(document_language, pos - document_language);
}
sp_document_setup_viewport (SPDocument *doc, SPItemCtx *ctx)
{
ctx->ctx.flags = 0;
- ctx->i2doc = NR::identity();
+ ctx->i2doc = Geom::identity();
/* Set up viewport in case svg has it defined as percentages */
if (SP_ROOT(doc->root)->viewBox_set) { // if set, take from viewBox
ctx->vp.x0 = SP_ROOT(doc->root)->viewBox.x0;
ctx->vp.x1 = 210 * PX_PER_MM;
ctx->vp.y1 = 297 * PX_PER_MM;
}
- ctx->i2vp = NR::identity();
+ ctx->i2vp = Geom::identity();
}
/**
s = find_items_in_area(s, SP_GROUP(o), dkey, area, test);
} else {
SPItem *child = SP_ITEM(o);
- boost::optional<Geom::Rect> box = to_2geom(sp_item_bbox_desktop(child));
+ Geom::OptRect box = sp_item_bbox_desktop(child);
if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
s = g_slist_append(s, child);
}
@@ -933,8 +970,8 @@ sp_document_item_from_list_at_point_bottom(unsigned int dkey, SPGroup *group, GS
Geom::Point const p, bool take_insensitive)
{
g_return_val_if_fail(group, NULL);
-
- gdouble delta = prefs_get_double_attribute ("options.cursortolerance", "value", 1.0);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
find_item_at_point(unsigned int dkey, SPGroup *group, Geom::Point const p, gboolean into_groups, bool take_insensitive = false, SPItem *upto = NULL)
{
SPItem *seen = NULL, *newseen = NULL;
-
- gdouble delta = prefs_get_double_attribute ("options.cursortolerance", "value", 1.0);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
if (!SP_IS_ITEM(o)) continue;
find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Point const p)
{
SPItem *seen = NULL;
-
- gdouble delta = prefs_get_double_attribute ("options.cursortolerance", "value", 1.0);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL ; o = SP_OBJECT_NEXT(o) ) {
if (!SP_IS_ITEM(o)) continue;
sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points)
{
GSList *items = NULL;
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// When picking along the path, we don't want small objects close together
// (such as hatching strokes) to obscure each other by their deltas,
// so we temporarily set delta to a small value
- gdouble saved_delta = prefs_get_double_attribute ("options.cursortolerance", "value", 1.0);
- prefs_set_double_attribute ("options.cursortolerance", "value", 0.25);
+ gdouble saved_delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
+ prefs->setDouble("/options/cursortolerance/value", 0.25);
for(unsigned int i = 0; i < points.size(); i++) {
SPItem *item = sp_document_item_at_point(document, key, points[i],
@@ -1085,7 +1123,7 @@ sp_document_items_at_points(SPDocument *document, unsigned const key, std::vecto
}
// and now we restore it back
- prefs_set_double_attribute ("options.cursortolerance", "value", saved_delta);
+ prefs->setDouble("/options/cursortolerance/value", saved_delta);
return items;
}