Code

Inkscape becomes unusable when trying to snap to the path of a traced bitmap or a...
authordvlierop2 <dvlierop2@users.sourceforge.net>
Mon, 10 Sep 2007 21:15:56 +0000 (21:15 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Mon, 10 Sep 2007 21:15:56 +0000 (21:15 +0000)
src/object-snapper.cpp
src/seltrans.cpp

index 960d4f115534de738552e39de634c10fd25f0e7e..ab222f286a44935e4167806f7f4c585c09e42569 100644 (file)
@@ -22,7 +22,9 @@
 #include "desktop.h"
 #include "inkscape.h"
 #include "prefs-utils.h"
-
+#include "sp-text.h"
+#include "sp-flowtext.h"
+#include "text-editing.h"
 
 Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d)
     : Snapper(nv, d), _snap_to_itemnode(true), _snap_to_itempath(true), 
@@ -80,7 +82,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* r,
                     i++;
                 }
     
-                if (i == it.end()) {
+                       if (i == it.end()) {
                     /* See if the item is within range */
                     if (SP_IS_GROUP(o)) {
                         _findCandidates(o, it, false, points_to_snap, snap_dim);
@@ -269,7 +271,29 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t,
                //Add the item's path to snap to
                if (_snap_to_itempath) {
                        if (!(_strict_snapping && !p_is_a_node)) {
-                               _paths_to_snap_to->push_back(Path_for_item(root_item, true, true));
+                               // Snapping to the path of characters is very cool, but for a large
+                                       // chunk of text this will take ages! So limit snapping to text paths
+                                       // containing max. 240 characters. Snapping the bbox will not be affected
+                                       bool very_lenghty_prose = false;
+                                       if (SP_IS_TEXT(root_item) || SP_IS_FLOWTEXT(root_item)) {
+                                               very_lenghty_prose =  sp_text_get_length(SP_TEXT(root_item)) > 240; 
+                                       }       
+                                       
+                                       // On my AMD 3000+, the snapping lag becomes annoying at approx. 240 chars
+                                       // which corresponds to a lag of 500 msec. This is for snapping a rect
+                                       // to a single line of text. 
+                                       
+                                       // Snapping for example to a traced bitmap is also very stressing for 
+                                       // the CPU, so we'll only snap to paths having no more than 500 nodes
+                                       // This also leads to a lag of approx. 500 msec (in my lousy test set-up). 
+                                       bool very_complex_path = false;
+                                       if (SP_IS_PATH(root_item)) {
+                                               very_complex_path = sp_nodes_in_path(SP_PATH(root_item)) > 500; 
+                                       }                                                                                
+                                       
+                                       if (!very_lenghty_prose && !very_complex_path) {
+                                       _paths_to_snap_to->push_back(Path_for_item(root_item, true, true));
+                                       }
                        }
                }
                        
index d9566d091ff38555f06ca8f7364756358e02a555..c680e0cd3b4908b11f2f64c8b4b7ee8dd23e2bcd 100644 (file)
@@ -1521,11 +1521,20 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
 
         } else {
 
+            // Let's leave this timer code here for a while. I'll probably need it in the near future (Diederik van Lierop)
+            /* GTimeVal starttime;
+            GTimeVal endtime;
+               g_get_current_time(&starttime); */
+            
             /* Snap to things with no constraint */
                        s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
                                               _bbox_points, it, dxy));
             s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE,
                                               _snap_points, it, dxy));
+               
+               /*g_get_current_time(&endtime);
+               double elapsed = ((((double)endtime.tv_sec - starttime.tv_sec) * G_USEC_PER_SEC + (endtime.tv_usec - starttime.tv_usec))) / 1000.0;
+               std::cout << "Time spent snapping: " << elapsed << std::endl; */
         }
 
         /* Pick one */