include/oox/vml/vmlshape.hxx       |    6 ++++++
 oox/qa/unit/data/watermark.docx    |binary
 oox/qa/unit/vml.cxx                |   22 ++++++++++++++++++++++
 oox/source/vml/vmlshape.cxx        |    7 +++++++
 oox/source/vml/vmlshapecontext.cxx |   28 ++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+)

New commits:
commit e13f25f22e2ae6094d3fb3fdd27c2256fe7acf89
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Dec 16 10:16:02 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Dec 17 08:28:26 2021 +0100

    VML import: handle <v:imagedata gain="..." blacklevel="...">
    
    Map it to (the UNO API of) GraphicDrawMode::Watermark, similar to what
    the binary import does in SvxMSDffManager::ImportGraphic() and how the
    drawingML import does it in
    oox::drawingml::GraphicProperties::pushToPropMap().
    
    On export, the drawingML export is used, and that already maps
    GraphicDrawMode::Watermark to <a:lum bright="70000" contrast="-70000">.
    
    Change-Id: I33986a03bf3d3863da5c5b1f0a2e0da0fa595c9e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126908
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 90556b6df0f6378fb60d7dee18b2f5d275ece530)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126942

diff --git a/include/oox/vml/vmlshape.hxx b/include/oox/vml/vmlshape.hxx
index 19c82384efcd..7a17bda51ccd 100644
--- a/include/oox/vml/vmlshape.hxx
+++ b/include/oox/vml/vmlshape.hxx
@@ -113,6 +113,12 @@ struct ShapeTypeModel
     OptValue<OUString> moCropTop; ///< Specifies how much to crop the image 
from the top down as a fraction of picture size.
     OUString maLayoutFlowAlt; ///< Specifies the alternate layout flow for 
text in textboxes.
 
+    /// An adjustment for the intensity of all colors, i.e. contrast, on a 
0..0x10000 scale.
+    sal_Int32 mnGain = 0x10000;
+
+    /// The image brightness, on a 0..0x10000 scale.
+    sal_Int16 mnBlacklevel = 0;
+
     explicit            ShapeTypeModel();
 
     void                assignUsed( const ShapeTypeModel& rSource );
diff --git a/oox/qa/unit/data/watermark.docx b/oox/qa/unit/data/watermark.docx
new file mode 100644
index 000000000000..c9eacff9a643
Binary files /dev/null and b/oox/qa/unit/data/watermark.docx differ
diff --git a/oox/qa/unit/vml.cxx b/oox/qa/unit/vml.cxx
index 6d8a5cf93912..9dcaaef83cc4 100644
--- a/oox/qa/unit/vml.cxx
+++ b/oox/qa/unit/vml.cxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/drawing/ColorMode.hpp>
 
 using namespace ::com::sun::star;
 
@@ -214,6 +215,27 @@ CPPUNIT_TEST_FIXTURE(OoxVmlTest, testGraphicStroke)
     CPPUNIT_ASSERT_EQUAL(drawing::LineStyle_SOLID, eLineStyle);
 }
 
+CPPUNIT_TEST_FIXTURE(OoxVmlTest, testWatermark)
+{
+    // Given a document with a picture watermark, and the "washout" checkbox 
is ticked on the Word
+    // UI:
+    // When loading that document:
+    load(u"watermark.docx");
+
+    // Then make sure the watermark effect is not lost on import:
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> 
xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                                 uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+    drawing::ColorMode eMode{};
+    xShape->getPropertyValue("GraphicColorMode") >>= eMode;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 3
+    // - Actual  : 0
+    // i.e. the color mode was STANDARD, not WATERMARK.
+    CPPUNIT_ASSERT_EQUAL(drawing::ColorMode_WATERMARK, eMode);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index 81abe64e5322..38b632be843b 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -47,6 +47,7 @@
 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/drawing/ColorMode.hpp>
 #include <sal/log.hxx>
 #include <oox/drawingml/shapepropertymap.hxx>
 #include <oox/helper/graphichelper.hxx>
@@ -991,6 +992,12 @@ Reference< XShape > SimpleShape::createPictureObject(const 
Reference< XShapes >&
 
             aPropSet.setProperty(PROP_GraphicCrop, aGraphicCrop);
         }
+
+        if (maTypeModel.mnGain == -70 && maTypeModel.mnBlacklevel == 70)
+        {
+            // Map MSO 'washout' to our watermark colormode.
+            aPropSet.setProperty(PROP_GraphicColorMode, 
uno::makeAny(drawing::ColorMode_WATERMARK));
+        }
     }
     return xShape;
 }
diff --git a/oox/source/vml/vmlshapecontext.cxx 
b/oox/source/vml/vmlshapecontext.cxx
index e9284747774b..4ed3f83fd076 100644
--- a/oox/source/vml/vmlshapecontext.cxx
+++ b/oox/source/vml/vmlshapecontext.cxx
@@ -395,6 +395,34 @@ ContextHandlerRef ShapeTypeContext::onCreateContext( 
sal_Int32 nElement, const A
             mrTypeModel.moCropLeft = rAttribs.getString(XML_cropleft);
             mrTypeModel.moCropRight = rAttribs.getString(XML_cropright);
             mrTypeModel.moCropTop = rAttribs.getString(XML_croptop);
+
+            // Gain / contrast.
+            OptValue<OUString> oGain = rAttribs.getString(XML_gain);
+            sal_Int32 nGain = 0x10000;
+            if (oGain.has() && oGain.get().endsWith("f"))
+            {
+                nGain = oGain.get().toInt32();
+            }
+            if (nGain < 0x10000)
+            {
+                nGain *= 101; // 100 + 1 to round
+                nGain /= 0x10000;
+                nGain -= 100;
+            }
+            mrTypeModel.mnGain = nGain;
+
+            // Blacklevel / brightness.
+            OptValue<OUString> oBlacklevel = 
rAttribs.getString(XML_blacklevel);
+            sal_Int16 nBlacklevel = 0;
+            if (oBlacklevel.has() && oBlacklevel.get().endsWith("f"))
+            {
+                nBlacklevel = oBlacklevel.get().toInt32();
+            }
+            if (nBlacklevel != 0)
+            {
+                nBlacklevel /= 327;
+            }
+            mrTypeModel.mnBlacklevel = nBlacklevel;
         }
         break;
         case NMSP_vmlWord | XML_wrap:

Reply via email to