evas_vg_load_svg: Fix colorstop offset parser

Summary:
Values different from numbers and percentages should be ignored
and the default values should be applied (zeros).
And set the min and max of the offset value to be 0, 1.
Also, this patch make that the offset is not input in the reverse order.

Test Plan:
Test SVG Image
```
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
    <linearGradient id="grad" x1="0" y1="0" x2="1" y2="1">
        <stop offset="10%" stop-color="white"/>
        <stop offset="0.2" stop-color="red"/>
        <stop offset="30% k" stop-color="blue"/>
        <stop offset="40%" stop-color="yellow"/>
        <stop offset="0.5m" stop-color="red"/>
        <stop offset="0.6 " stop-color="green"/>
        <stop offset="70%m" stop-color="black"/>
        <stop offset="80%" stop-color="white"/>
    </linearGradient>
    <rect x="20" y="20" width="160" height="160" fill="url(#grad)"/>
</svg>

```

Result
{F4792365}

Reviewers: Hermet, raster, kimcinoo

Reviewed By: Hermet

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D12318
This commit is contained in:
junsu choi 2022-01-12 11:34:29 +09:00 committed by Hermet Park
parent 92f77c5123
commit ef784708b9
2 changed files with 25 additions and 3 deletions

View File

@ -181,11 +181,22 @@ static inline double
_to_offset(const char *str)
{
char *end = NULL;
const char* str_end = str + strlen(str);
double parsed_value = eina_convert_strtod_c(str, &end);
char *ptr = strstr(str, "%");
if (strstr(str, "%"))
parsed_value = parsed_value / 100.0;
end = _skip_space(end, NULL);
if (ptr)
{
parsed_value = parsed_value / 100.0;
if (end != ptr || (end + 1) != str_end)
return 0;
}
else if (end != str_end)
{
return 0;
}
return parsed_value;
}

View File

@ -696,6 +696,7 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Efl_VG *parent, Vg_F
double fopacity = ((double) fill_opacity) / 255; //fill opacity if any exists.
stops = calloc(stop_count, sizeof(Efl_Gfx_Gradient_Stop));
i = 0;
double prevOffset = 0;
EINA_LIST_FOREACH(g->stops, l, stop)
{
// Use premultiplied color
@ -705,6 +706,16 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Efl_VG *parent, Vg_F
stops[i].b = (stop->b * opacity);
stops[i].a = (stop->a * fopacity);
stops[i].offset = stop->offset;
//NOTE: check the offset corner cases - refer to: https://svgwg.org/svg2-draft/pservers.html#StopNotes
if (stop->offset < prevOffset)
{
stops[i].offset = prevOffset;
}
else if (stop->offset > 1)
{
stops[i].offset = 1;
}
prevOffset = stops[i].offset;
i++;
}
efl_gfx_gradient_stop_set(grad_obj, stops, stop_count);