Code

remove rudimental general-purpose clipart, add some Inkscape-related graphics, update...
[inkscape.git] / src / livarot / PathCutting.cpp
index 2bcc3f244f9e611117080f75afed8a948708d1c3..59de29676f21a6280e99d5410b440739b6ec4a5b 100644 (file)
@@ -5,9 +5,16 @@
  *  Created by fred on someday in 2004.
  *  public domain
  *
+ *  Additional Code by Authors:
+ *   Richard Hughes <cyreve@users.sf.net>
+ *
+ *  Copyright (C) 2005 Richard Hughes
+ *
+ *  Released under GNU GPL, read the file 'COPYING' for more information
  */
 
 #include "Path.h"
+#include "style.h"
 #include "livarot/path-description.h"
 #include "libnr/n-art-bpath.h"
 #include "libnr/nr-point-matrix-ops.h"
@@ -38,6 +45,36 @@ void  Path::DashPolyline(float head,float tail,float body,int nbD,float *dashs,b
   }
 }
 
+void  Path::DashPolylineFromStyle(SPStyle *style, float scale, float min_len)
+{
+    if (style->stroke_dash.n_dash) {
+
+        double dlen = 0.0;
+        for (int i = 0; i < style->stroke_dash.n_dash; i++) {
+            dlen += style->stroke_dash.dash[i] * scale;
+        }
+        if (dlen >= min_len) {
+            NRVpathDash dash;
+            dash.offset = style->stroke_dash.offset * scale;
+            dash.n_dash = style->stroke_dash.n_dash;
+            dash.dash = g_new(double, dash.n_dash);
+            for (int i = 0; i < dash.n_dash; i++) {
+                dash.dash[i] = style->stroke_dash.dash[i] * scale;
+            }
+            int    nbD=dash.n_dash;
+            float  *dashs=(float*)malloc((nbD+1)*sizeof(float));
+            while ( dash.offset >= dlen ) dash.offset-=dlen;
+            dashs[0]=dash.dash[0];
+            for (int i=1; i<nbD; i++) {
+                dashs[i]=dashs[i-1]+dash.dash[i];
+            }
+            // modulo dlen
+            this->DashPolyline(0.0, 0.0, dlen, nbD, dashs, true, dash.offset);
+            free(dashs);
+            g_free(dash.dash);
+        }
+    }
+}
 
 
 void Path::DashSubPath(int spL, int spP, std::vector<path_lineto> const &orig_pts, float head,float tail,float body,int nbD,float *dashs,bool stPlain,float stOffset)