summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-05-26 04:48:38 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-05-26 04:48:38 +0000
commite299c9e196e7f071d34f4d2530ebda327e2fce37 (patch)
tree0ebf86419233819ff0ea9a0f40e4e5dec4036bd1 /src
parentexport markers API (diff)
downloadinkscape-e299c9e196e7f071d34f4d2530ebda327e2fce37.tar.gz
inkscape-e299c9e196e7f071d34f4d2530ebda327e2fce37.zip
method for dashing Path using an SPStyle
(bzr r1013)
Diffstat (limited to 'src')
-rw-r--r--src/livarot/Path.h4
-rw-r--r--src/livarot/PathCutting.cpp31
2 files changed, 35 insertions, 0 deletions
diff --git a/src/livarot/Path.h b/src/livarot/Path.h
index 291d8f157..8d7fd0a7e 100644
--- a/src/livarot/Path.h
+++ b/src/livarot/Path.h
@@ -15,6 +15,8 @@
#include "libnr/nr-point.h"
#include <libnr/nr-rect-l.h>
+struct SPStyle;
+
/*
* the Path class: a structure to hold path description and their polyline approximation (not kept in sync)
* the path description is built with regular commands like MoveTo() LineTo(), etc
@@ -170,6 +172,8 @@ public:
// dash the polyline
// the result is stored in the polyline, so you lose the original. make a copy before if needed
void DashPolyline(float head,float tail,float body,int nbD,float *dashs,bool stPlain,float stOffset);
+
+ void DashPolylineFromStyle(SPStyle *style, float scale, float min_len);
//utilitaire pour inkscape
void LoadArtBPath(void *iP,NR::Matrix const &tr,bool doTransformation);
diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp
index f21e02820..59de29676 100644
--- a/src/livarot/PathCutting.cpp
+++ b/src/livarot/PathCutting.cpp
@@ -14,6 +14,7 @@
*/
#include "Path.h"
+#include "style.h"
#include "livarot/path-description.h"
#include "libnr/n-art-bpath.h"
#include "libnr/nr-point-matrix-ops.h"
@@ -44,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)