summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-02-01 11:33:34 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-02-01 11:33:34 +0000
commit8876bc4df731a56a0153ef999feed9a70c2b887a (patch)
treeb4490d39ce050d302d621e25ce6b56ed3e119c38 /src
parentAdd correct preview for coninuing paths whith pencil and draw modes (diff)
parentFix some formatting problems and add formatting info at end of file. (diff)
downloadinkscape-8876bc4df731a56a0153ef999feed9a70c2b887a.tar.gz
inkscape-8876bc4df731a56a0153ef999feed9a70c2b887a.zip
update to trunk
(bzr r11950.1.246)
Diffstat (limited to 'src')
-rw-r--r--src/factory.h4
-rw-r--r--src/sp-item-transform.cpp47
-rw-r--r--src/sp-object.cpp34
-rw-r--r--src/ui/dialog/symbols.cpp136
4 files changed, 109 insertions, 112 deletions
diff --git a/src/factory.h b/src/factory.h
index a1df55277..d7f4cb2b9 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -63,7 +63,9 @@ public:
typename std::map<std::string const, CreateFunction *>::const_iterator it = this->_object_map.find(id);
if (it == this->_object_map.end()) {
- throw FactoryExceptions::TypeNotRegistered(id);
+ //throw FactoryExceptions::TypeNotRegistered(id);
+ g_warning("unknown type: %s", id.c_str());
+ return NULL;
}
return it->second();
diff --git a/src/sp-item-transform.cpp b/src/sp-item-transform.cpp
index 7fa591fee..05390c910 100644
--- a/src/sp-item-transform.cpp
+++ b/src/sp-item-transform.cpp
@@ -246,7 +246,7 @@ Geom::Affine get_scale_transform_for_variable_stroke(Geom::Rect const &bbox_visu
// 1) We start with a visual bounding box (w0, h0) which we want to transfer into another visual bounding box (w1, h1)
// 2) We will also know the geometric bounding box, which can be used to calculate the strokewidth. The strokewidth will however
- // be different for each of the four sides (left/right/top/bottom: r0l, r0r, r0t, r0b)
+ // be different for each of the four sides (left/right/top/bottom: r0l, r0r, r0t, r0b)
gdouble w0 = bbox_visual.width(); // will return a value >= 0, as required further down the road
gdouble h0 = bbox_visual.height();
@@ -258,8 +258,10 @@ Geom::Affine get_scale_transform_for_variable_stroke(Geom::Rect const &bbox_visu
// We will now try to calculate the affine transformation required to transform the first visual bounding box into
// the second one, while accounting for strokewidth
- gdouble r0w = w0 - bbox_geom.width(); // r0w is the average strokewidth of the left and right edges, i.e. 0.5*(r0l + r0r)
+ gdouble r0w = w0 - bbox_geom.width(); // r0w is the average strokewidth of the left and right edges, i.e. 0.5*(r0l + r0r)
gdouble r0h = h0 - bbox_geom.height(); // r0h is the average strokewidth of the top and bottom edges, i.e. 0.5*(r0t + r0b)
+ if ((r0w == Geom::infinity()) || (fabs(r0w) < 1e-6)) r0w = 0;
+ if ((r0h == Geom::infinity()) || (fabs(r0h) < 1e-6)) r0h = 0;
int flip_x = (w1 > 0) ? 1 : -1;
int flip_y = (h1 > 0) ? 1 : -1;
@@ -308,38 +310,21 @@ Geom::Affine get_scale_transform_for_variable_stroke(Geom::Rect const &bbox_visu
* Desired area of the geometric bounding box: A1 = (w1-r1w)*(h1-r1h)
* This is how the stroke should scale: r1w^2 = A1/A0 * r0w^2, AND
* r1h^2 = A1/A0 * r0h^2
- * Now we have to solve this set of two equations and find r1w and r1h; this too complicated to do by hand,
- * so I used wxMaxima for that (http://wxmaxima.sourceforge.net/). These lines can be copied into Maxima
- *
- * A1: (w1-r1w)*(h1-r1h);
- * s: A1/A0;
- * expr1a: r1w^2 = s*r0w^2;
- * expr1b: r1h^2 = s*r0h^2;
- * sol: solve([expr1a, expr1b], [r1h, r1w]);
- * sol[1][1]; sol[2][1]; sol[3][1]; sol[4][1];
- * sol[1][2]; sol[2][2]; sol[3][2]; sol[4][2];
- *
- * PS1: The last two lines are only needed for readability of the output, and can be omitted if desired
- * PS2: A0 is known beforehand and assumed to be constant, instead of using A0 = (w0-r0w)*(h0-r0h). This reduces the
- * length of the results significantly
- * PS3: You'll get 8 solutions, 4 for each of the strokewidths r1w and r1h. Some experiments quickly showed which of the solutions
- * lead to meaningful strokewidths
+ * These can be re-expressed as : r1w/r0w = r1h/r0h
+ * and : r1w*r1w*(w0 - r0w)*(h0 - r0h) = r0w*r0w*(w1 - r1w)*(h1 - r1h)
+ * This leads to a quadratic equation in r1w, solved as follows:
* */
- gdouble r0h2 = r0h*r0h;
- gdouble r0h3 = r0h2*r0h;
- gdouble r0w2 = r0w*r0w;
- gdouble w12 = w1*w1;
- gdouble h12 = h1*h1;
- gdouble A0 = bbox_geom.area();
- gdouble A02 = A0*A0;
-
- gdouble operant = 4*h1*w1*A0+r0h2*w12-2*h1*r0h*r0w*w1+h12*r0w2;
- if (operant < 0) {
+
+ gdouble A = w0*h0 - r0h*w0 - r0w*h0;
+ gdouble B = r0h*w1 + r0w*h1;
+ gdouble C = -w1*h1;
+
+ if (B*B - 4*A*C < 0) {
g_message("variable stroke scaling error : %d, %d, %f, %f, %f, %f, %f, %f", transform_stroke, preserve, r0w, r0h, w0, h0, w1, h1);
} else {
- // Of the eight roots, I verified experimentally that these are the two we need
- r1h = fabs((r0h*sqrt(operant)-r0h2*w1-h1*r0h*r0w)/(2*A0-2*r0h*r0w));
- r1w = fabs(-((h1*r0w*A0+r0h2*r0w*w1)*sqrt(operant)+(-3*h1*r0h*r0w*w1-h12*r0w2)*A0-r0h3*r0w*w12+h1*r0h2*r0w2*w1)/((r0h*A0-r0h2*r0w)*sqrt(operant)-2*h1*A02+(3*h1*r0h*r0w-r0h2*w1)*A0+r0h3*r0w*w1-h1*r0h2*r0w2));
+ gdouble det = (-B + sqrt(B*B - 4*A*C))/(2*A);
+ r1w = r0w*det;
+ r1h = r0h*det;
// If w1 < 0 then the scale will be wrong if we just assume that scale_x = (w1 - r1)/(w0 - r0);
// Therefore we here need the absolute values of w0, w1, h0, h1, and r0, as taken care of earlier
scale_x = (w1 - r1w)/(w0 - r0w);
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index 0e6eef6ae..764b5f260 100644
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
@@ -585,23 +585,22 @@ SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr)
void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) {
SPObject* object = this;
- try {
- const std::string typeString = NodeTraits::get_type_string(*child);
+ const std::string type_string = NodeTraits::get_type_string(*child);
- SPObject* ochild = SPFactory::instance().createObject(typeString);
-
- SPObject *prev = ref ? object->get_child_by_repr(ref) : NULL;
- object->attach(ochild, prev);
- sp_object_unref(ochild, NULL);
-
- ochild->invoke_build(object->document, child, object->cloned);
- } catch (const FactoryExceptions::TypeNotRegistered& e) {
+ SPObject* ochild = SPFactory::instance().createObject(type_string);
+ if (ochild == NULL) {
// Currenty, there are many node types that do not have
// corresponding classes in the SPObject tree.
// (rdf:RDF, inkscape:clipboard, ...)
// Thus, simply ignore this case for now.
return;
}
+
+ SPObject *prev = ref ? object->get_child_by_repr(ref) : NULL;
+ object->attach(ochild, prev);
+ sp_object_unref(ochild, NULL);
+
+ ochild->invoke_build(object->document, child, object->cloned);
}
void SPObject::release() {
@@ -645,21 +644,20 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) {
object->readAttr("inkscape:collect");
for (Inkscape::XML::Node *rchild = repr->firstChild() ; rchild != NULL; rchild = rchild->next()) {
- try {
- const std::string typeString = NodeTraits::get_type_string(*rchild);
-
- SPObject* child = SPFactory::instance().createObject(typeString);
+ const std::string typeString = NodeTraits::get_type_string(*rchild);
- object->attach(child, object->lastChild());
- sp_object_unref(child, NULL);
- child->invoke_build(document, rchild, object->cloned);
- } catch (const FactoryExceptions::TypeNotRegistered& e) {
+ SPObject* child = SPFactory::instance().createObject(typeString);
+ if (child == NULL) {
// Currenty, there are many node types that do not have
// corresponding classes in the SPObject tree.
// (rdf:RDF, inkscape:clipboard, ...)
// Thus, simply ignore this case for now.
continue;
}
+
+ object->attach(child, object->lastChild());
+ sp_object_unref(child, NULL);
+ child->invoke_build(document, rchild, object->cloned);
}
}
diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp
index 7079ca001..98754fb4f 100644
--- a/src/ui/dialog/symbols.cpp
+++ b/src/ui/dialog/symbols.cpp
@@ -76,7 +76,7 @@ namespace UI {
namespace Dialog {
- // See: http://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeModelColumnRecord.html
+// See: http://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeModelColumnRecord.html
class SymbolColumns : public Gtk::TreeModel::ColumnRecord
{
public:
@@ -399,11 +399,13 @@ SPDocument* SymbolsDialog::selectedSymbols() {
}
Glib::ustring SymbolsDialog::selectedSymbolId() {
- #if WITH_GTKMM_3_0
- std::vector<Gtk::TreePath> iconArray = iconView->get_selected_items();
- #else
- Gtk::IconView::ArrayHandle_TreePaths iconArray = iconView->get_selected_items();
- #endif
+
+#if WITH_GTKMM_3_0
+ std::vector<Gtk::TreePath> iconArray = iconView->get_selected_items();
+#else
+ Gtk::IconView::ArrayHandle_TreePaths iconArray = iconView->get_selected_items();
+#endif
+
if( !iconArray.empty() ) {
Gtk::TreeModel::Path const & path = *iconArray.begin();
Gtk::ListStore::iterator row = store->get_iter(path);
@@ -428,12 +430,12 @@ void SymbolsDialog::iconChanged() {
// First look for default style stored in <symbol>
gchar const* style = symbol->getAttribute("inkscape:symbol-style");
if( !style ) {
- // If no default style in <symbol>, look in documents.
- if( symbolDocument == currentDocument ) {
- style = style_from_use( symbol_id.c_str(), currentDocument );
- } else {
- style = symbolDocument->getReprRoot()->attribute("style");
- }
+ // If no default style in <symbol>, look in documents.
+ if( symbolDocument == currentDocument ) {
+ style = style_from_use( symbol_id.c_str(), currentDocument );
+ } else {
+ style = symbolDocument->getReprRoot()->attribute("style");
+ }
}
ClipboardManager *cm = ClipboardManager::get();
@@ -497,8 +499,8 @@ SPDocument* read_vss( gchar* fullname, gchar* filename ) {
while( std::getline( iss, line ) ) {
// std::cout << line << std::endl;
if( line.find( "svg:svg" ) == std::string::npos ) {
- tmpSVGOutput += line;
- tmpSVGOutput += "\n";
+ tmpSVGOutput += line;
+ tmpSVGOutput += "\n";
}
}
@@ -519,11 +521,11 @@ void SymbolsDialog::get_symbols() {
std::list<Glib::ustring> directories;
if( Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_EXISTS ) &&
- Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_IS_DIR ) ) {
+ Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_IS_DIR ) ) {
directories.push_back( INKSCAPE_SYMBOLSDIR );
}
if( Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_EXISTS ) &&
- Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) {
+ Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) {
directories.push_back( profile_path("symbols") );
}
@@ -534,55 +536,53 @@ void SymbolsDialog::get_symbols() {
GDir *dir = g_dir_open( (*it).c_str(), 0, &err );
if( dir ) {
- gchar *filename = 0;
- while( (filename = (gchar *)g_dir_read_name( dir ) ) != NULL) {
+ gchar *filename = 0;
+ while( (filename = (gchar *)g_dir_read_name( dir ) ) != NULL) {
- gchar *fullname = g_build_filename((*it).c_str(), filename, NULL);
+ gchar *fullname = g_build_filename((*it).c_str(), filename, NULL);
- if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR )
- && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) {
+ if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR )
+ && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) {
- Glib::ustring fn( filename );
- Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 );
+ Glib::ustring fn( filename );
+ Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 );
- SPDocument* symbol_doc = NULL;
+ SPDocument* symbol_doc = NULL;
#ifdef WITH_LIBVISIO
- if( tag.compare( "vss" ) == 0 ) {
-
- symbol_doc = read_vss( fullname, filename );
- if( symbol_doc ) {
- symbolSets[Glib::ustring(filename)]= symbol_doc;
- symbolSet->append(filename);
- }
- }
+ if( tag.compare( "vss" ) == 0 ) {
+
+ symbol_doc = read_vss( fullname, filename );
+ if( symbol_doc ) {
+ symbolSets[Glib::ustring(filename)]= symbol_doc;
+ symbolSet->append(filename);
+ }
+ }
#endif
- // Try to read all remaining files as SVG
- if( !symbol_doc ) {
+ // Try to read all remaining files as SVG
+ if( !symbol_doc ) {
- symbol_doc = SPDocument::createNewDoc( fullname, FALSE );
- if( symbol_doc ) {
+ symbol_doc = SPDocument::createNewDoc( fullname, FALSE );
+ if( symbol_doc ) {
const gchar *title = symbol_doc->getRoot()->title();
- // A user provided file may not have a title
- if( title != NULL ) {
- title = g_dpgettext2(NULL, "Symbol", title); // Translate
- }
-
- if( title == NULL ) {
- title = _("Unnamed Symbols");
+ // A user provided file may not have a title
+ if( title != NULL ) {
+ title = g_dpgettext2(NULL, "Symbol", title); // Translate
+ } else {
+ title = _("Unnamed Symbols");
}
- symbolSets[Glib::ustring(title)] = symbol_doc;
- symbolSet->append(title);
+ symbolSets[Glib::ustring(title)] = symbol_doc;
+ symbolSet->append(title);
+ }
+ }
+
}
+ g_free( fullname );
}
-
- }
- g_free( fullname );
- }
- g_dir_close( dir );
+ g_dir_close( dir );
}
}
}
@@ -644,16 +644,16 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen
for( ; l != NULL; l = l->next ) {
SPObject* use = SP_OBJECT(l->data);
if( SP_IS_USE( use ) ) {
- gchar const *href = use->getRepr()->attribute("xlink:href");
- if( href ) {
- Glib::ustring href2(href);
- Glib::ustring id2(id);
- id2 = "#" + id2;
- if( !href2.compare(id2) ) {
- style = use->getRepr()->attribute("style");
- break;
- }
- }
+ gchar const *href = use->getRepr()->attribute("xlink:href");
+ if( href ) {
+ Glib::ustring href2(href);
+ Glib::ustring id2(id);
+ id2 = "#" + id2;
+ if( !href2.compare(id2) ) {
+ style = use->getRepr()->attribute("style");
+ break;
+ }
+ }
}
}
return style;
@@ -810,8 +810,8 @@ void SymbolsDialog::setTargetDesktop(SPDesktop *desktop)
if (this->currentDesktop != desktop) {
this->currentDesktop = desktop;
if( !symbolSets[symbolSet->get_active_text()] ) {
- // Symbol set is from Current document, update
- rebuild();
+ // Symbol set is from Current document, update
+ rebuild();
}
}
}
@@ -819,3 +819,15 @@ void SymbolsDialog::setTargetDesktop(SPDesktop *desktop)
} //namespace Dialogs
} //namespace UI
} //namespace Inkscape
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-basic-offset:2
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=8:softtabstop=2:fileencoding=utf-8:textwidth=99 :