summaryrefslogtreecommitdiff
path: root/source/xps/xps-gradient.c
diff options
context:
space:
mode:
authorSimon Bünzli <zeniko@gmail.com>2013-07-21 10:49:42 +0200
committerRobin Watts <robin.watts@artifex.com>2013-08-28 13:35:53 +0100
commit1c431eb5477388dbcf94b24a382efc1fb63b639a (patch)
tree20e9b0f5d4c79416e9a67b1e70cb35213faa21b9 /source/xps/xps-gradient.c
parent299be6676f1c7283382a5b6cb2c9a1f9b0d088bd (diff)
downloadmupdf-1c431eb5477388dbcf94b24a382efc1fb63b639a.tar.xz
fix gradient ordering edge case
Gradients in XPS code are ordered by offset. If however two offsets are equal, the order of the colors depends on the sort algorithm instead of the original order in the document. This is shown e.g. in 2245*.xps: <GradientStop Offset="0" Color="#ff00ff00" /> <GradientStop Offset="0.5" Color="#ff0000ff" /> <GradientStop Offset="0.5" Color="#ff00ff00" /> <GradientStop Offset="1" Color="#ff00ffff" /> Tracking the original order of gradient stops and always sorting earlier stops first makes gradient ordering consistent.
Diffstat (limited to 'source/xps/xps-gradient.c')
-rw-r--r--source/xps/xps-gradient.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/source/xps/xps-gradient.c b/source/xps/xps-gradient.c
index 88ed470b..7d03f89d 100644
--- a/source/xps/xps-gradient.c
+++ b/source/xps/xps-gradient.c
@@ -14,6 +14,7 @@ struct stop
{
float offset;
float r, g, b, a;
+ int index;
};
static int cmp_stop(const void *a, const void *b)
@@ -25,7 +26,7 @@ static int cmp_stop(const void *a, const void *b)
return -1;
if (diff > 0)
return 1;
- return 0;
+ return astop->index - bstop->index;
}
static inline float lerp(float a, float b, float x)
@@ -57,6 +58,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
if (offset && color)
{
stops[count].offset = fz_atof(offset);
+ stops[count].index = count;
xps_parse_color(doc, base_uri, color, &colorspace, sample);