summaryrefslogtreecommitdiff
path: root/oox/source
diff options
context:
space:
mode:
authorArmin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de>2023-06-05 17:15:34 +0200
committerArmin Le Grand <Armin.Le.Grand@me.com>2023-06-09 10:17:07 +0200
commita6e72e2b314e64f3199f3eaf1ecf78157446f6dd (patch)
treee830caf26f28e3090868159687e504779759ea3c /oox/source
parentbbf5f97967fb3cde25829e1c428ace31d7d5b8c7 (diff)
MCGR: tdf#155479 repair gradient SVG export for MCGR
Unfortunately SVG export is based on metafiles and thus there is (in principle) no way to get the BGradient/ColorStop/MCGR data transfered as needed. For that, using UNO API to read the model or using B2DPrimitives would help - as is better for the export respectively. Since there is not the time to re-design SVG export I added this 'compromize' as a fix. It gets the needed data transported over the metafile (that part is the compromize). It then exports the MCGR data to SVG (at least - as was already there - if it's a linear/axial gradient). This happens now with all Gradient Stops when there is a MCGR gradient. That part is/will hopefully be re-usable if SVG export gets redesigned. I also added a handling for StepCount feature, so when used (in LO, others do not have that) 'hard' color stops get generated to make the gradient look identical for SVG export. Had to make adding of that extra-information in metafiles dependent on exporting really to SVG. There are 51 cases which use 'MetaActionType::COMMENT' which would potentially have to be adapted. Also added code to solve the problem for TransparencePrimitive2D at VclMetafileProcessor2D::processTransparencePrimitive2D. This will now - also only for SVG export - directly create the needed MetaFloatTransparentAction and add additional MCGR information. This will be used on SVG export to write a 'Mask' as was done before. This is now capable of creating fill MCGR-Masks in the sense that any number of TransparencyStops will be supported. Change-Id: Ic6d022714eae96b8fbc09e60652851ac5799b757 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152623 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'oox/source')
-rw-r--r--oox/source/export/drawingml.cxx56
1 files changed, 14 insertions, 42 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index bd58cbf21249..5b0772550471 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -761,6 +761,15 @@ void DrawingML::WriteGradientFill(
basegfx::utils::prepareColorStops(*pTransparenceGradient, aAlphaStops, aSingleAlpha);
}
+ // apply steps if used. Need to do that before synchronizeColorStops
+ // since that may add e.g. for AlphaStops all-the-same no-data entries,
+ // so the number of entries might change
+ if (pGradient->GetSteps())
+ {
+ aColorStops.doApplySteps(pGradient->GetSteps());
+ aAlphaStops.doApplySteps(pGradient->GetSteps());
+ }
+
// synchronize ColorStops and AlphaStops as preparation to export
// so also gradients 'coupled' indirectly using the 'FillTransparenceGradient'
// method (at import time) will be exported again
@@ -790,48 +799,11 @@ void DrawingML::WriteGradientFill(
}
case awt::GradientStyle_AXIAL:
{
- // we need to 'double' the gradient to make it appear as what we call
- // 'axial', but also scale and mirror in doing so
- basegfx::BColorStops aNewColorStops;
- basegfx::BColorStops aNewAlphaStops;
-
- // add mirrored gradients, scaled to [0.0 .. 0.5]
- basegfx::BColorStops::const_reverse_iterator aRevCurrColor(aColorStops.rbegin());
- basegfx::BColorStops::const_reverse_iterator aRevCurrAlpha(aAlphaStops.rbegin());
-
- while (aRevCurrColor != aColorStops.rend() && aRevCurrAlpha != aAlphaStops.rend())
- {
- aNewColorStops.emplace_back((1.0 - aRevCurrColor->getStopOffset()) * 0.5, aRevCurrColor->getStopColor());
- aNewAlphaStops.emplace_back((1.0 - aRevCurrAlpha->getStopOffset()) * 0.5, aRevCurrAlpha->getStopColor());
- aRevCurrColor++;
- aRevCurrAlpha++;
- }
-
- basegfx::BColorStops::const_iterator aCurrColor(aColorStops.begin());
- basegfx::BColorStops::const_iterator aCurrAlpha(aAlphaStops.begin());
-
- if (basegfx::fTools::equalZero(aCurrColor->getStopOffset()))
- {
- // Caution: do not add 1st entry again, that would be double since it was
- // already added as last element of the inverse run above. But only if
- // the gradient has a start entry for 0.0 aka StartColor, else it is correct.
- // Since aColorStops and aAlphaStops are already synched (see
- // synchronizeColorStops above), testing one of them is sufficient here.
- aCurrColor++;
- aCurrAlpha++;
- }
-
- // add non-mirrored gradients, translated and scaled to [0.5 .. 1.0]
- while (aCurrColor != aColorStops.end() && aCurrAlpha != aAlphaStops.end())
- {
- aNewColorStops.emplace_back((aCurrColor->getStopOffset() * 0.5) + 0.5, aCurrColor->getStopColor());
- aNewAlphaStops.emplace_back((aCurrAlpha->getStopOffset() * 0.5) + 0.5, aCurrAlpha->getStopColor());
- aCurrColor++;
- aCurrAlpha++;
- }
-
- aColorStops = aNewColorStops;
- aAlphaStops = aNewAlphaStops;
+ // use tooling to convert from GradientStyle_AXIAL to GradientStyle_LINEAR
+ // NOTE: Since aColorStops and aAlphaStops are already synched (see
+ // synchronizeColorStops above) this can be done directly here
+ aColorStops.doApplyAxial();
+ aAlphaStops.doApplyAxial();
// remember being axial
bAxial = true;