diff options
author | Justin Luth <justin.luth@collabora.com> | 2024-02-07 17:25:50 -0500 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-02-21 08:46:39 +0100 |
commit | 07521972bcd1cfbbd15b2f60ada84ffc69f8f997 (patch) | |
tree | 6f2c9441dd273c30280b0024c5f91a080b73741e /oox | |
parent | d7cd7dff0e8f71b3d83b4c91b574f39248a25e2f (diff) |
tdf#159626 vml pattern import: add color, fix back/foreground
This depends on tdf#126533 which imports page style v:fill,
BUT ONLY IN ORDER TO support the unit tests.
The patch itself can stand alone
and fixes vml import into textboxes/shapes etc.
i.e. backporting could be possible by dropping the unit tests.
The pattern that VML uses to indicate foreground
and background is very different from what LO needs.
[Fortunately LO does not use the _guess_ from
vcl::bitmap::isHistorical8x8 to determine which
color is the background. Instead it always uses the first pixel.]
Documentation says that unspecified XML_fillcolor
and XML_color should be white, but observation
says it should be 25% gray (Word 2003).
25% gray == C0C0C0 == fillcolor="silver" == COL_LIGHTGRAY
Currently, we simply export as a colored, tiled image,
and not as a B&W type="pattern"
so no corresponding export changes need to be made to export.
Existing unit test documents that are affected:
-chart2export's PieChartDataLabels.docx (page background)
-ooxmlexport5's fdo77725.docx (minimized PieChartDataLabels.docx)
* both foreground and background are set to white => solid white
-sw/qa/core/data/ooxml/pass/fdo79131.docx (shape "inline")
make CppunitTest_sw_tiledrendering \
CPPUNIT_TEST_NAME=testTdf159626_yellowPatternFill
make CppunitTest_sw_tiledrendering \
CPPUNIT_TEST_NAME=testTdf159626_yellowPatternFillB
make CppunitTest_sw_tiledrendering \
CPPUNIT_TEST_NAME=testTdf159626_blackPatternFill
Change-Id: I9533ac4a7489081ffc62a10e900f5526abb906db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163106
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/vml/vmlformatting.cxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/oox/source/vml/vmlformatting.cxx b/oox/source/vml/vmlformatting.cxx index 029d5429d921..6182950973ee 100644 --- a/oox/source/vml/vmlformatting.cxx +++ b/oox/source/vml/vmlformatting.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp> #include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/XTextRange.hpp> + #include <o3tl/float_int_conversion.hxx> #include <o3tl/unit_conversion.hxx> #include <rtl/strbuf.hxx> @@ -46,6 +47,8 @@ #include <svx/svdtrans.hxx> #include <comphelper/propertysequence.hxx> #include <o3tl/string_view.hxx> +#include <svx/xbitmap.hxx> +#include <vcl/BitmapTools.hxx> #include <vcl/virdev.hxx> namespace oox::vml { @@ -843,6 +846,51 @@ void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& aFillProps.maBlipProps.mxFillGraphic = rGraphicHelper.importEmbeddedGraphic(moBitmapPath.value()); if (aFillProps.maBlipProps.mxFillGraphic.is()) { + if (nFillType == XML_pattern) + { + // VML provides an 8x8 black(background) and white(foreground) pattern + // along with specified background(color2) and foreground(color) colors, + // while LO needs the color applied directly to the pattern. + const Graphic aGraphic(aFillProps.maBlipProps.mxFillGraphic); + ::Color nBackColor; + ::Color nPixelColor; + bool bIs8x8 = vcl::bitmap::isHistorical8x8(aGraphic.GetBitmapEx(), + nBackColor, nPixelColor); + if (bIs8x8) + { + nBackColor + = ConversionHelper::decodeColor(rGraphicHelper, moColor2, + moOpacity2, API_RGB_WHITE) + .getColor(rGraphicHelper); + // Documentation says undefined == white; observation says lightgray + nPixelColor + = ConversionHelper::decodeColor(rGraphicHelper, moColor, + moOpacity, COL_LIGHTGRAY) + .getColor(rGraphicHelper); + + XOBitmap aXOB(aGraphic.GetBitmapEx()); + aXOB.Bitmap2Array(); + // LO uses the first pixel's color to represent background pixels + if (aXOB.GetBackgroundColor() == COL_WHITE) + { + // White always represents the foreground in VML => swap + aXOB.SetPixelColor(nBackColor); + aXOB.SetBackgroundColor(nPixelColor); + } + else + { + assert(aXOB.GetBackgroundColor() == COL_BLACK); + aXOB.SetPixelColor(nPixelColor); + aXOB.SetBackgroundColor(nBackColor); + } + aXOB.Array2Bitmap(); + + Graphic aLOPattern(aXOB.GetBitmap()); + aLOPattern.setOriginURL(aGraphic.getOriginURL()); + aFillProps.maBlipProps.mxFillGraphic = aLOPattern.GetXGraphic(); + } + } + aFillProps.moFillType = XML_blipFill; aFillProps.maBlipProps.moBitmapMode = (nFillType == XML_frame) ? XML_stretch : XML_tile; break; // do not break if bitmap is missing, but run to XML_solid instead |