summaryrefslogtreecommitdiff
path: root/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2020-09-15 12:11:49 +0900
committerHermet Park <chuneon.park@samsung.com>2020-09-15 12:11:49 +0900
commit35f17a13fa0cd1de855cc2215e4f0ac9da6fb7bc (patch)
tree0a03fce07557e15edfaf987453811aa43d447ba2 /src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
parentc412406487579627b79f417f947ca512aa034ce0 (diff)
vg_load_svg: Support dasharray attribute for stroke
Summary: It supports stroke-dasharray, one of the stroke properties of svg. https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray Test Plan: [Test SVG] <svg viewBox="0 0 30 10" xmlns="http://www.w3.org/2000/svg"> <!-- No dashes nor gaps --> <line x1="0" y1="1" x2="30" y2="1" stroke="black" /> <!-- Dashes and gaps of the same size --> <line x1="0" y1="3" x2="30" y2="3" stroke="black" stroke-dasharray="4" /> <!-- Dashes and gaps of different sizes --> <line x1="0" y1="5" x2="30" y2="5" stroke="black" stroke-dasharray="4 1" /> <!-- Dashes and gaps of various sizes with an odd number of values --> <line x1="0" y1="7" x2="30" y2="7" stroke="black" stroke-dasharray="4 1 2" /> <!-- Dashes and gaps of various sizes with an even number of values --> <line x1="0" y1="9" x2="30" y2="9" stroke="black" stroke-dasharray="4 1 2 3" /> </svg> Reviewers: Hermet, smohanty Reviewed By: Hermet Subscribers: kimcinoo, herb, cedric, #committers, #reviewers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12146
Diffstat (limited to '')
-rw-r--r--src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
index f40bfa4915..246e3e2a0e 100644
--- a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
+++ b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
@@ -259,8 +259,6 @@ static struct {
259 259
260_PARSE_TAG(Efl_Gfx_Fill_Rule, fill_rule, fill_rule_tags, EFL_GFX_FILL_RULE_WINDING); 260_PARSE_TAG(Efl_Gfx_Fill_Rule, fill_rule, fill_rule_tags, EFL_GFX_FILL_RULE_WINDING);
261 261
262#if 0
263// unused at the moment
264/* parse the dash pattern used during stroking a path. 262/* parse the dash pattern used during stroking a path.
265 * Value: none | <dasharray> | inherit 263 * Value: none | <dasharray> | inherit
266 * Initial: none 264 * Initial: none
@@ -269,7 +267,8 @@ _PARSE_TAG(Efl_Gfx_Fill_Rule, fill_rule, fill_rule_tags, EFL_GFX_FILL_RULE_WINDI
269static inline void 267static inline void
270_parse_dash_array(const char *str, Efl_Gfx_Dash** dash, int *length) 268_parse_dash_array(const char *str, Efl_Gfx_Dash** dash, int *length)
271{ 269{
272 double tmp[30]; 270 // It is assumed that the length of the dasharray string is 255 or less.
271 double tmp[255];
273 char *end = NULL; 272 char *end = NULL;
274 int leni, gapi, count = 0, index = 0; 273 int leni, gapi, count = 0, index = 0;
275 274
@@ -291,20 +290,21 @@ _parse_dash_array(const char *str, Efl_Gfx_Dash** dash, int *length)
291 gapi = (2 * index + 1) % count; 290 gapi = (2 * index + 1) % count;
292 (*dash)[index].length = tmp[leni]; 291 (*dash)[index].length = tmp[leni];
293 (*dash)[index].gap = tmp[gapi]; 292 (*dash)[index].gap = tmp[gapi];
293 index++;
294 } 294 }
295 } 295 }
296 else 296 else
297 { // even case 297 { // even case
298 *length = count/2; 298 *length = count/2;
299 *dash = calloc(*length, sizeof(Efl_Gfx_Dash)); 299 *dash = calloc(*length, sizeof(Efl_Gfx_Dash));
300 while (index < count) 300 while (index < *length)
301 { 301 {
302 (*dash)[index].length = tmp[2 * index]; 302 (*dash)[index].length = tmp[2 * index];
303 (*dash)[index].gap = tmp[2 * index + 1]; 303 (*dash)[index].gap = tmp[2 * index + 1];
304 index++;
304 } 305 }
305 } 306 }
306} 307}
307#endif
308 308
309static Eina_Stringshare * 309static Eina_Stringshare *
310 _id_from_url(const char *url) 310 _id_from_url(const char *url)
@@ -865,6 +865,13 @@ _handle_stroke_opacity_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node,
865} 865}
866 866
867static void 867static void
868_handle_stroke_dasharray_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
869{
870 node->style->stroke.flags |= SVG_STROKE_FLAGS_DASH;
871 _parse_dash_array(value, &node->style->stroke.dash, &node->style->stroke.dash_count);
872}
873
874static void
868_handle_stroke_width_attr(Evas_SVG_Loader *loader, Svg_Node* node, const char *value) 875_handle_stroke_width_attr(Evas_SVG_Loader *loader, Svg_Node* node, const char *value)
869{ 876{
870 node->style->stroke.flags |= SVG_STROKE_FLAGS_WIDTH; 877 node->style->stroke.flags |= SVG_STROKE_FLAGS_WIDTH;
@@ -942,6 +949,7 @@ static const struct {
942 STYLE_DEF(stroke-linejoin, stroke_linejoin), 949 STYLE_DEF(stroke-linejoin, stroke_linejoin),
943 STYLE_DEF(stroke-linecap, stroke_linecap), 950 STYLE_DEF(stroke-linecap, stroke_linecap),
944 STYLE_DEF(stroke-opacity, stroke_opacity), 951 STYLE_DEF(stroke-opacity, stroke_opacity),
952 STYLE_DEF(stroke-dasharray, stroke_dasharray),
945 STYLE_DEF(transform, transform), 953 STYLE_DEF(transform, transform),
946 STYLE_DEF(display, display) 954 STYLE_DEF(display, display)
947}; 955};
@@ -2367,6 +2375,22 @@ _inherit_style(Svg_Style_Property *child, Svg_Style_Property *parent)
2367 { 2375 {
2368 child->stroke.join = parent->stroke.join; 2376 child->stroke.join = parent->stroke.join;
2369 } 2377 }
2378 if (!(child->stroke.flags & SVG_STROKE_FLAGS_DASH))
2379 {
2380 int i = 0;
2381 int count = parent->stroke.dash_count;
2382 if (count > 0)
2383 {
2384 if (child->stroke.dash) free(child->stroke.dash);
2385 child->stroke.dash = calloc(count, sizeof(Efl_Gfx_Dash));
2386 child->stroke.dash_count = count;
2387 for (i = 0; i < count; i++)
2388 {
2389 child->stroke.dash[i].length = parent->stroke.dash[i].length;
2390 child->stroke.dash[i].gap = parent->stroke.dash[i].gap;
2391 }
2392 }
2393 }
2370} 2394}
2371 2395
2372void 2396void