diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2023-03-11 18:39:06 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-03-14 07:40:00 +0000 |
commit | 260735ff98631b94ae8737cf1cead3e20bade618 (patch) | |
tree | 05153f2b33f6693a02ed14b8f19333973283ee10 /oox/qa | |
parent | 599722cf77310429a9b9bd2a348486a08b60de0d (diff) |
tdf#139618 Add WordArt fill types in pptx import
This fix uses a similar approach as in WpsContext::onEndElement, only
that here moTextOutlineProperties and maFillProperties are still
available whereas in WpsContext the properties need to be collected
from CharInteropGrabBag.
I have adapted unit test testTdf125573_FontworkScaleX because now the
gradient is imported, see comment in former version of the test.
Change-Id: I989ee475867c97b9f93c7e65cd25483611eec7bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148687
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox/qa')
-rw-r--r-- | oox/qa/unit/data/tdf139618_ImportWordArtGradient.pptx | bin | 0 -> 22072 bytes | |||
-rw-r--r-- | oox/qa/unit/data/tdf139618_ThemeColorTransparency.pptx | bin | 0 -> 26093 bytes | |||
-rw-r--r-- | oox/qa/unit/data/tdf139618_WordArtBitmapFill.pptx | bin | 0 -> 38286 bytes | |||
-rw-r--r-- | oox/qa/unit/export.cxx | 26 | ||||
-rw-r--r-- | oox/qa/unit/shape.cxx | 130 |
5 files changed, 156 insertions, 0 deletions
diff --git a/oox/qa/unit/data/tdf139618_ImportWordArtGradient.pptx b/oox/qa/unit/data/tdf139618_ImportWordArtGradient.pptx Binary files differnew file mode 100644 index 000000000000..8fd4bcc181f0 --- /dev/null +++ b/oox/qa/unit/data/tdf139618_ImportWordArtGradient.pptx diff --git a/oox/qa/unit/data/tdf139618_ThemeColorTransparency.pptx b/oox/qa/unit/data/tdf139618_ThemeColorTransparency.pptx Binary files differnew file mode 100644 index 000000000000..405135783e16 --- /dev/null +++ b/oox/qa/unit/data/tdf139618_ThemeColorTransparency.pptx diff --git a/oox/qa/unit/data/tdf139618_WordArtBitmapFill.pptx b/oox/qa/unit/data/tdf139618_WordArtBitmapFill.pptx Binary files differnew file mode 100644 index 000000000000..5da52ceb3c15 --- /dev/null +++ b/oox/qa/unit/data/tdf139618_WordArtBitmapFill.pptx diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx index 0e2a2669ee79..a98eaa5ce93f 100644 --- a/oox/qa/unit/export.cxx +++ b/oox/qa/unit/export.cxx @@ -1297,6 +1297,32 @@ CPPUNIT_TEST_FIXTURE(Test, testFontworkRectGradient) assertXPath(pXmlDoc, sElement + "w14:gs[3]/w14:schemeClr/w14:lumOff", "val", "60000"); assertXPath(pXmlDoc, sElement + "w14:gs[3]/w14:schemeClr/w14:alpha", "val", "70000"); } + +CPPUNIT_TEST_FIXTURE(Test, testThemeColorTransparency) +{ + // The document has first a Fontwork shape with solid fill theme color with transparency and + // outline transparency and second a textbox with character transparency. + // Without fix the transparency was not written to file. + loadFromURL(u"tdf139618_ThemeColorTransparency.pptx"); + + save("Impress Office Open XML"); + xmlDocUniquePtr pXmlDoc = parseExport("ppt/slides/slide1.xml"); + + // Make sure a:alpha is written for line color and for fill color. + // Make sure fill color is a schemeClr. + OString sElement = "/p:sld/p:cSld/p:spTree/p:sp[1]/p:txBody/a:p/a:r/a:rPr/"; + assertXPath(pXmlDoc, sElement + "a:ln/a:solidFill/a:srgbClr/a:alpha", "val", "25000"); + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr", "val", "accent1"); + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr/a:lumMod", "val", "60000"); + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr/a:lumOff", "val", "40000"); + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr/a:alpha", "val", "35000"); + + // Make sure a:alpha is written for characters and fill color is a schemeClr. + sElement = "/p:sld/p:cSld/p:spTree/p:sp[2]/p:txBody/a:p/a:r/a:rPr/"; + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr", "val", "accent4"); + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr/a:lumMod", "val", "75000"); + assertXPath(pXmlDoc, sElement + "a:solidFill/a:schemeClr/a:alpha", "val", "20000"); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx index b5a3fe8b1113..523003ee351a 100644 --- a/oox/qa/unit/shape.cxx +++ b/oox/qa/unit/shape.cxx @@ -16,7 +16,9 @@ #include <com/sun/star/awt/FontWeight.hpp> #include <com/sun/star/awt/Gradient.hpp> #include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/awt/XBitmap.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/BitmapMode.hpp> #include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/LineDash.hpp> #include <com/sun/star/drawing/LineJoint.hpp> @@ -24,6 +26,7 @@ #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> #include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/lang/Locale.hpp> #include <com/sun/star/text/XTextFrame.hpp> #include <com/sun/star/text/XTextRange.hpp> @@ -585,6 +588,133 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWriterFontworkDarkenTransparency) CPPUNIT_ASSERT_EQUAL(uno::Any(Color(208, 175, 114)), xShapeProps->getPropertyValue(u"FillColor")); } + +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testImportWordArtGradient) +{ + loadFromURL(u"tdf139618_ImportWordArtGradient.pptx"); + // Without the patch all WordArt was imported with solid color. Now gradient is imported. + // This test covers several aspects of import of gradient fill. + + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + + // linear gradient, MSO UI 21deg, solid transparency on outline + { + uno::Reference<beans::XPropertySet> xShapeProps(xDrawPage->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::FillStyle_GRADIENT), + xShapeProps->getPropertyValue(u"FillStyle")); + awt::Gradient aGradient; + xShapeProps->getPropertyValue(u"FillGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style); + CPPUNIT_ASSERT_EQUAL(sal_Int16(690), aGradient.Angle); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16760832), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(12582912), aGradient.EndColor); + + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::LineStyle_SOLID), + xShapeProps->getPropertyValue(u"LineStyle")); + sal_Int32 nOutlineColor; + xShapeProps->getPropertyValue(u"LineColor") >>= nOutlineColor; + CPPUNIT_ASSERT_EQUAL(sal_Int32(7384391), nOutlineColor); + sal_Int16 nLineTransparence; + xShapeProps->getPropertyValue(u"LineTransparence") >>= nLineTransparence; + CPPUNIT_ASSERT_EQUAL(sal_Int16(60), nLineTransparence); + } + + // radial gradient, direct color with transparency, focus center, dotted outline + // The stop color transparency is imported as transparency gradient with same geometry. + { + uno::Reference<beans::XPropertySet> xShapeProps(xDrawPage->getByIndex(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::FillStyle_GRADIENT), + xShapeProps->getPropertyValue(u"FillStyle")); + awt::Gradient aGradient; + xShapeProps->getPropertyValue(u"FillGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style); + CPPUNIT_ASSERT_EQUAL(sal_Int32(15132160), aGradient.EndColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(33760), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.XOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.YOffset); + + xShapeProps->getPropertyValue(u"FillTransparenceGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style); + // Transparency is encoded in gray color. + CPPUNIT_ASSERT_EQUAL(sal_Int32(5000268), aGradient.EndColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6710886), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.XOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(50), aGradient.YOffset); + + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::LineStyle_DASH), + xShapeProps->getPropertyValue(u"LineStyle")); + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::LineCap_ROUND), + xShapeProps->getPropertyValue(u"LineCap")); + CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(7384391)), + xShapeProps->getPropertyValue(u"LineColor")); + drawing::LineDash aLineDash; + xShapeProps->getPropertyValue(u"LineDash") >>= aLineDash; + CPPUNIT_ASSERT_EQUAL(drawing::DashStyle_ROUNDRELATIVE, aLineDash.Style); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aLineDash.Dots); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aLineDash.Dashes); + } + + // solid theme color accent 1, rectangular transparency gradient, focus top-right, no outline + // FillProperties::pushToPropMap imports this currently (Mar 2023) as color gradient. + // Thus no theme color is tested but direct color. + { + uno::Reference<beans::XPropertySet> xShapeProps(xDrawPage->getByIndex(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::FillStyle_GRADIENT), + xShapeProps->getPropertyValue(u"FillStyle")); + awt::Gradient aGradient; + xShapeProps->getPropertyValue(u"FillGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RECT, aGradient.Style); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4485828), aGradient.EndColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4485828), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int16(100), aGradient.XOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aGradient.YOffset); + + xShapeProps->getPropertyValue(u"FillTransparenceGradient") >>= aGradient; + CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RECT, aGradient.Style); + // Transparency is encoded in gray color. + CPPUNIT_ASSERT_EQUAL(sal_Int32(16777215), aGradient.EndColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aGradient.StartColor); + CPPUNIT_ASSERT_EQUAL(sal_Int16(100), aGradient.XOffset); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aGradient.YOffset); + + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::LineStyle_NONE), + xShapeProps->getPropertyValue(u"LineStyle")); + } +} + +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWordArtBitmapFill) +{ + // The document has a WordArt shape with bitmap fill. + // Without fix it was imported as solid color fill. + loadFromURL(u"tdf139618_WordArtBitmapFill.pptx"); + + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xShapeProps(xDrawPage->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::FillStyle_BITMAP), + xShapeProps->getPropertyValue(u"FillStyle")); + + // Test some bitmap properties + CPPUNIT_ASSERT_EQUAL(uno::Any(drawing::BitmapMode_REPEAT), + xShapeProps->getPropertyValue(u"FillBitmapMode")); + CPPUNIT_ASSERT_EQUAL(uno::Any(true), xShapeProps->getPropertyValue(u"FillBitmapTile")); + uno::Reference<awt::XBitmap> xBitmap; + xShapeProps->getPropertyValue(u"FillBitmap") >>= xBitmap; + + uno::Reference<graphic::XGraphic> xGraphic; + xGraphic.set(xBitmap, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW); + OUString sMimeType; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("MimeType") >>= sMimeType); + CPPUNIT_ASSERT_EQUAL(OUString("image/jpeg"), sMimeType); + awt::Size aSize100thMM; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Size100thMM") >>= aSize100thMM); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1592), aSize100thMM.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1592), aSize100thMM.Height); +} CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |