summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-05-24 00:15:15 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2017-06-01 08:10:22 +0200
commit5bc597c49207be961454cc333425f6d2a9230347 (patch)
tree5e4fd831621dd1913bb1256f3724059b2c7367dc /sw
parent8421372dd3c25c7852de388e3c8cc4a8b65dc2de (diff)
Watermark: docx interoperability
Before patch: Document created in MS Word: <v:shapetype id="_x0000_t136" o:spt="136" ...> <v:shape type="#_x0000_t136" ...> Imported to LO and exported: <v:shapetype id="shapetype_136" o:spt="136" ...> <v:shape type="shapetype_136" ...> Then again imported to MS Word and exported: <v:shapetype id="shapetype_136" o:spid="_x0000_m1026" o:spt="100" ...> <v:shape type="#shapetype_136" ...> In this moment LO after import had shape in the navigator but it wasn't visible. Patch: * vmshapecontext.cxx is changed to read ShapeType from id instead of o:spt when o:spid is present. * vmlexport.cxx added o:spid for Word to identify inserted watermark * edfxol.cxx changed name of shape to "PowerPlusWaterMarkObject" for Word * tests Change-Id: I25322628838a98c45cbeed64144d04977b2ea9ba Reviewed-on: https://gerrit.libreoffice.org/37969 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport7.cxx4
-rw-r--r--sw/qa/extras/uiwriter/data/watermark.docxbin0 -> 18768 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx23
-rw-r--r--sw/source/core/edit/edfcol.cxx17
4 files changed, 38 insertions, 6 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
index b538e9f990da..e7f24005cd92 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
@@ -106,6 +106,10 @@ DECLARE_OOXMLEXPORT_TEST(testTextWatermark, "textWatermark.docx")
return;
assertXPath(pXmlHeader1, "/w:hdr[1]/w:p[1]/w:r[1]/w:pict[1]/v:shape[1]","id","PowerPlusWaterMarkObject93701316");
+
+ //The second problem was that Word uses also "o:spid"
+ const OUString& sSpid = getXPath(pXmlHeader1, "/w:hdr[1]/w:p[1]/w:r[1]/w:pict[1]/v:shape[1]","spid");
+ CPPUNIT_ASSERT(!sSpid.isEmpty());
}
DECLARE_OOXMLEXPORT_TEST(testPictureWatermark, "pictureWatermark.docx")
diff --git a/sw/qa/extras/uiwriter/data/watermark.docx b/sw/qa/extras/uiwriter/data/watermark.docx
new file mode 100644
index 000000000000..0b26d4442e98
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/watermark.docx
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 4594b5ba4936..e8c81d6e575b 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -100,6 +100,7 @@
#include <comphelper/configurationhelper.hxx>
#include <editeng/unolingu.hxx>
#include <config_features.h>
+#include <sfx2/watermarkitem.hxx>
static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
@@ -121,6 +122,7 @@ public:
void testDOCXAutoTextMultiple();
void testDOTMAutoText();
void testDOCXAutoTextGallery();
+ void testWatermarkDOCX();
void testTdf67238();
void testFdo75110();
void testFdo75898();
@@ -243,6 +245,7 @@ public:
CPPUNIT_TEST(testDOCXAutoTextMultiple);
CPPUNIT_TEST(testDOTMAutoText);
CPPUNIT_TEST(testDOCXAutoTextGallery);
+ CPPUNIT_TEST(testWatermarkDOCX);
CPPUNIT_TEST(testTdf67238);
CPPUNIT_TEST(testFdo75110);
CPPUNIT_TEST(testFdo75898);
@@ -819,6 +822,26 @@ void SwUiWriterTest::testDOCXAutoTextGallery()
CPPUNIT_ASSERT_EQUAL(OUString("Multiple"), pGlossary->GetLongName(0));
}
+void SwUiWriterTest::testWatermarkDOCX()
+{
+ SwDoc* const pDoc = createDoc("watermark.docx");
+ SwDocShell* pDocShell = pDoc->GetDocShell();
+ const SfxPoolItem* pItem;
+ SfxItemState eState = pDocShell->GetViewShell()->GetViewFrame()->GetDispatcher()->QueryState(SID_WATERMARK, pItem);
+
+ CPPUNIT_ASSERT(eState >= SfxItemState::DEFAULT);
+ CPPUNIT_ASSERT(pItem);
+ CPPUNIT_ASSERT_EQUAL((unsigned short)SID_WATERMARK, pItem->Which());
+
+ const SfxWatermarkItem* pWatermark = static_cast<const SfxWatermarkItem*>(pItem);
+ CPPUNIT_ASSERT_EQUAL(OUString("CustomWatermark"), pWatermark->GetText());
+ //TODO: VML import textpath style
+ //CPPUNIT_ASSERT_EQUAL(OUString("DejaVu Sans Light"), pWatermark->GetFont());
+ CPPUNIT_ASSERT_EQUAL((sal_Int16)45, pWatermark->GetAngle());
+ CPPUNIT_ASSERT_EQUAL((sal_uInt32)0x548dd4, pWatermark->GetColor());
+ CPPUNIT_ASSERT_EQUAL((sal_Int16)50, pWatermark->GetTransparency());
+}
+
void SwUiWriterTest::testFdo74981()
{
// create a document with an input field
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index dc5f4b9d8853..bd139d75799c 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -60,6 +60,8 @@
#include <pagefrm.hxx>
#include <sfx2/watermarkitem.hxx>
+#define WATERMARK_NAME "PowerPlusWaterMarkObject"
+
namespace
{
@@ -114,8 +116,8 @@ bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rSer
return false;
}
-/// Search for a frame named rShapeName of type rServiceName in xText.
-uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText, const OUString& rServiceName, const OUString& rShapeName)
+/// Search for a frame with WATERMARK_NAME in name of type rServiceName in xText. Returns found name in rShapeName.
+uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText, const OUString& rServiceName, OUString& rShapeName)
{
uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
@@ -144,9 +146,12 @@ uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XTex
continue;
uno::Reference<container::XNamed> xNamed(xWatermark, uno::UNO_QUERY);
- if (xNamed->getName() != rShapeName)
+
+ if (!xNamed->getName().match(WATERMARK_NAME))
continue;
+ rShapeName = xNamed->getName();
+
uno::Reference<drawing::XShape> xShape(xWatermark, uno::UNO_QUERY);
return xShape;
}
@@ -283,7 +288,7 @@ SfxWatermarkItem SwEditShell::GetWatermark()
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
OUString aShapeServiceName = "com.sun.star.drawing.CustomShape";
- static const OUString sWatermark = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK();
+ OUString sWatermark = "";
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark);
if (xWatermark.is())
@@ -349,7 +354,7 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark)
xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
OUString aShapeServiceName = "com.sun.star.drawing.CustomShape";
- static const OUString sWatermark = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK();
+ OUString sWatermark = WATERMARK_NAME;
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark);
bool bDeleteWatermark = rWatermark.GetText().isEmpty();
@@ -490,7 +495,7 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark)
xPropertySet->setPropertyValue("CustomShapeGeometry", uno::makeAny(comphelper::containerToSequence(aGeomPropVec)));
uno::Reference<container::XNamed> xNamed(xShape, uno::UNO_QUERY);
- xNamed->setName(SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK());
+ xNamed->setName(sWatermark);
xLockable->removeActionLock();
}
}