diff options
author | Armin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de> | 2023-03-03 18:03:56 +0100 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2023-03-04 16:32:16 +0000 |
commit | ecae66c41d82fecddd630cfdc144055a069134b0 (patch) | |
tree | 2e657e7e0057a3ce31af895282bd7083d621d1e6 /include/basegfx | |
parent | 43dcdfae40c9c37032ed5e92cd0634feb53b706d (diff) |
MCGR: ColorSteps handling moved to tooling
Due to the fact that handling of a vector GradientSteps
will get used more often with ongoing changes I moved
some handling to tooling, see sortAndCorrectColorSteps.
That method sorts and corrects a vector of ColorSteps
so that only valid entreis remain in a sorted order,
for details please refer to the docu at function
definition. I took the occasion to rearrange that to
work on the single provided vector which is better for
speed & ressources.
Also changed the ColorStep constructor to not
automatically correct constructed entries: While that
is formally correct, it moves an invalid entry to 0.0
or 1.0, thus creating additional wrong Start/EndColor
entries. Those may then 'overlay' the correct entry
when corrections are applied to the vector of entries
which leads to getting the wanted Start/EndColor to be
factically deleted, what is an error.
Also rearranged FillGradientAttribute to now work
initially with ColorSteps, no longer requires the
Start/EndColor, also adapted all usages. This securely
allows start/end and in-between single-color sections
in gradients.
Also needed to re-formulate GradientRect &
GradientElliptical ::appendTransformationsAndColors
method for correct 2D mapping(s) - always incrementing
from the start to end conflicts with the adaption of
the start value for the inner loop mainly because
increment is at start of inner loop (pre-increment).
Corrected errors from clang plugin, but also some
wrong initialiations for basegfx::ColorSteps.
Change-Id: I292592ed9abcfa591f68a680479f4fcdda46cbeb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148196
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'include/basegfx')
-rw-r--r-- | include/basegfx/utils/gradienttools.hxx | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/include/basegfx/utils/gradienttools.hxx b/include/basegfx/utils/gradienttools.hxx index 793d07a75577..328a86b8335c 100644 --- a/include/basegfx/utils/gradienttools.hxx +++ b/include/basegfx/utils/gradienttools.hxx @@ -69,9 +69,18 @@ namespace basegfx // e.g. for usage in std::vector::insert // ensure [0.0 .. 1.0] range for mfOffset ColorStep(double fOffset = 0.0, const BColor& rColor = BColor()) - : mfOffset(std::max(0.0, std::min(fOffset, 1.0))) + : mfOffset(fOffset) , maColor(rColor) { + // NOTE: I originally *corrected* mfOffset here by using + // mfOffset(std::max(0.0, std::min(fOffset, 1.0))) + // While that is formally correct, it moves an invalid + // entry to 0.0 or 1.0, thus creating additional wrong + // Start/EndColor entries. That may then 'overlay' the + // cortrect entry when corrections are applied to the + // vector of entries (see sortAndCorrectColorSteps) + // which leads to getting the wanted Start/EndColor + // to be factically deleted, what is an error. } double getOffset() const { return mfOffset; } @@ -184,6 +193,26 @@ namespace basegfx namespace utils { + /* Helper to sort and correct ColorSteps. This will + sort and then correct the given ColorSteps. The + corrected version will + - be sorted + - have no double values + - have no values with offset < 0.0 + - have no values with offset > 1.0 + thus be ready to be used in multi-color gradients. + + NOTE: The returned version may be empty (!) if no + valid entries were contained + NOTE: It does not necessarily contain values for + offset == 0.0 and 1.0 if there were none + given (so no Start/EndColor) + NOTE: If it contains only one entry that entry is + set to StartColor and the Color is preserved. + This is also done when all Colors are the same + */ + BASEGFX_DLLPUBLIC void sortAndCorrectColorSteps(ColorSteps& rColorSteps); + /* Helper to grep the correct ColorStep out of ColorSteps and interpolate as needed for given relative value in fScaler in the range of [0.0 .. 1.0]. |