diff options
Diffstat (limited to 'src/livarot/PathCutting.cpp')
| -rw-r--r-- | src/livarot/PathCutting.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp index 0dc7ede50..49b2c5a78 100644 --- a/src/livarot/PathCutting.cpp +++ b/src/livarot/PathCutting.cpp @@ -58,31 +58,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) { + if (!style->stroke_dasharray.values.empty()) { double dlen = 0.0; - for (int i = 0; i < style->stroke_dash.n_dash; i++) { - dlen += style->stroke_dash.dash[i] * scale; + // Find total length + for (unsigned i = 0; i < style->stroke_dasharray.values.size(); i++) { + dlen += style->stroke_dasharray.values[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; + // Extract out dash pattern (relative positions) + double dash_offset = style->stroke_dashoffset.value * scale; + size_t n_dash = style->stroke_dasharray.values.size(); + double *dash = g_new(double, n_dash); + for (unsigned i = 0; i < n_dash; i++) { + dash[i] = style->stroke_dasharray.values[i] * scale; } - int nbD=dash.n_dash; + + // Convert relative positions to absolute postions + int nbD = n_dash; float *dashs=(float*)malloc((nbD+1)*sizeof(float)); - while ( dash.offset >= dlen ) dash.offset-=dlen; - dashs[0]=dash.dash[0]; + while ( dash_offset >= dlen ) dash_offset-=dlen; + dashs[0]=dash[0]; for (int i=1; i<nbD; i++) { - dashs[i]=dashs[i-1]+dash.dash[i]; + dashs[i]=dashs[i-1]+dash[i]; } + // modulo dlen - this->DashPolyline(0.0, 0.0, dlen, nbD, dashs, true, dash.offset); + this->DashPolyline(0.0, 0.0, dlen, nbD, dashs, true, dash_offset); + free(dashs); - g_free(dash.dash); + g_free(dash); } } } |
