BGradient: preserve order of stops with same offset.
* Use merge sort, which is a stable sort, instead of the qsort used in BList::SortItems * This allows setting two stops with the same offset to create a sharp color change in a gradient. This trick is used to create stripe patterns with css gradients in some web pages. Fixes #10733.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
@@ -80,6 +81,7 @@ sort_color_stops_by_offset(const void* _left, const void* _right)
|
|||||||
return 1;
|
return 1;
|
||||||
else if ((*left)->offset < (*right)->offset)
|
else if ((*left)->offset < (*right)->offset)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,7 +434,13 @@ BGradient::ColorStops() const
|
|||||||
void
|
void
|
||||||
BGradient::SortColorStopsByOffset()
|
BGradient::SortColorStopsByOffset()
|
||||||
{
|
{
|
||||||
fColorStops.SortItems(sort_color_stops_by_offset);
|
// Use merge-sort because it's a stable algorithm: stops with the same
|
||||||
|
// offset will retain their original order. This can be used to have sharp
|
||||||
|
// color changes in the gradient.
|
||||||
|
// BList.SortItems uses a qsort, which isn't stable, and sometimes swaps
|
||||||
|
// such stops.
|
||||||
|
mergesort(fColorStops.Items(), fColorStops.CountItems(), sizeof(void*),
|
||||||
|
sort_color_stops_by_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user