From: buliabyak Date: Fri, 26 May 2006 04:48:38 +0000 (+0000) Subject: method for dashing Path using an SPStyle X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2717303e39af1fe525a83dc8e8e81bea8d5459eb;p=inkscape.git method for dashing Path using an SPStyle --- 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 +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; iDashPolyline(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 const &orig_pts, float head,float tail,float body,int nbD,float *dashs,bool stPlain,float stOffset)