[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - sw/qa writerfilter/source

2022-04-01 Thread Justin Luth (via logerrit)
 sw/qa/extras/ooxmlexport/data/tdf147861_customField.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport16.cxx   |   19 +++
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx|2 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx|   25 ++-
 writerfilter/source/dmapper/DomainMapper_Impl.hxx|4 ++
 5 files changed, 48 insertions(+), 2 deletions(-)

New commits:
commit 5f265a90b0c635826ca59a7726a85c639098e0bf
Author: Justin Luth 
AuthorDate: Sat Mar 12 11:11:01 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 1 08:34:03 2022 +0200

tdf#147861 writerfilter: use GetFieldResult, not current DocProperty

Import DOCX and RTF DocProperty fields as "fixed" if the displayed
text does not match the File - Properties - Custom variable's content.

Otherwise LO will automatically update the field and show the wrong
contents (because MS Word requires the user to manually refresh via F9).

(cherry picked from commit c4cb1d1dd581a5f120d9cf8b1d4274ec38f3eabe)

Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
writerfilter/source/dmapper/DomainMapper_Impl.cxx

Change-Id: Id5d3d0794e81b13465c5e824f1e994f563e62c1c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132347
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/data/tdf147861_customField.docx 
b/sw/qa/extras/ooxmlexport/data/tdf147861_customField.docx
new file mode 100644
index ..70071fa7e8a3
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf147861_customField.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index d71c466258c3..042f4c825adb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -253,6 +254,24 @@ DECLARE_OOXMLEXPORT_TEST(testCommentDoneModel, 
"CommentDone.docx")
 }
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf147861_customField, 
"tdf147861_customField.docx")
+{
+// These should each be specific values, not a shared DocProperty
+getParagraph(1, "CustomEditedTitle"); // edited
+// A couple of nulls at the end of the string thwarted all attemps at an 
"equals" comparison.
+CPPUNIT_ASSERT(getParagraph(2)->getString().startsWith(" INSERT Custom 
Title here"));
+getParagraph(3, "My Title"); // edited
+
+// Verify that these are fields, and not just plain text
+uno::Reference xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+auto xFieldsAccess(xTextFieldsSupplier->getTextFields());
+uno::Reference 
xFields(xFieldsAccess->createEnumeration());
+uno::Reference xField(xFields->nextElement(), 
uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(OUString("CustomEditedTitle"), 
xField->getPresentation(false));
+// The " (fixed)" part is unnecessary, but it must be consistent across a 
round-trip
+CPPUNIT_ASSERT_EQUAL(OUString("DocInformation:Title (fixed)"), 
xField->getPresentation(true));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index f95920b7a9dc..523f4dda51fb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -160,7 +160,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo49940, "fdo49940.docx")
 DECLARE_OOXMLEXPORT_TEST(testFdo74745, "fdo74745.docx")
 {
 uno::Reference paragraph = getParagraph(3);
-CPPUNIT_ASSERT_EQUAL(OUString("09/02/14"), paragraph->getString());
+CPPUNIT_ASSERT_EQUAL(OUString("09/02/2014"), paragraph->getString());
 }
 
 DECLARE_OOXMLEXPORT_TEST(testFdo81486, "fdo81486.docx")
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index accf1148f916..51b704b8a2e8 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4160,6 +4160,11 @@ void 
FieldContext::SetTextField(uno::Reference const& xTextFie
 m_xTextField = xTextField;
 }
 
+void FieldContext::CacheVariableValue(const uno::Any& rAny)
+{
+rAny >>= m_sVariableValue;
+}
+
 void FieldContext::AppendCommand(const OUString& rPart)
 {
 m_sCommand += rPart;
@@ -4793,6 +4798,9 @@ void DomainMapper_Impl::handleAuthor
 }
 }
 }
+else
+
pContext->CacheVariableValue(xUserDefinedProps->getPropertyValue(rFirstParam));
+
 OUString sServiceName("com.sun.star.text.TextField.");
 bool bIsCustomField = false;
 if(sFieldServiceName.isEmpty())
@@ -6406,7 +6414,22 @@ void DomainMapper_Impl::SetFieldResult(OUString const& 
rResult)
 getPropertyName(bHasContent && sValue.isEmpty()? 
PROP_CONTENT : 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - sw/qa writerfilter/source

2022-01-28 Thread Attila Szűcs (via logerrit)
 sw/qa/extras/ooxmlexport/data/tdf119952_negativeMargins.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx   |   83 +++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |   38 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx|   63 
 writerfilter/source/dmapper/DomainMapper_Impl.hxx|3 
 writerfilter/source/dmapper/PropertyMap.cxx  |   78 --
 writerfilter/source/dmapper/PropertyMap.hxx  |7 
 7 files changed, 190 insertions(+), 82 deletions(-)

New commits:
commit 4a539a150d5f9f606aabca11633f2c7104fb2a13
Author: Attila Szűcs 
AuthorDate: Fri Jun 25 10:37:47 2021 +0200
Commit: Miklos Vajna 
CommitDate: Fri Jan 28 18:18:07 2022 +0100

tdf#119952 DOCX import: fix negative page margins

DOCX body text can overlap with header/footer, if top/bottom
page margin is negative. To support this, convert header/footer
text content to textbox anchored to header/footer, if needed.

Note: possible improvements:

1) Skip this hack, if the header is small enough to not overlap with
the body, calculate only the height of the header at the import time.

2) This hack does not fix the case when the top of the header
is under the top of the body. (A problem in DOC import, too.)
This could be achieved by repositioning the dummy header to the top,
and lower the textbox by the same amount. (This would still not
resolve the extreme situation, when the body start from 0 mm
(in LibreOffice, header must be at least 1 mm).

3) Import of VertOrientation::BOTTOM property seems to be bad,
or at least the footer loses this property after a DOCX round-trip,
resulting bad footer position.

4) after a round-trip, the 1 mm height of the dummy header
increases to 1 line height. Also the "Autofit height" and
"Use dynamic spacing" settings are changed, likely related
to their missing DOCX export.

Co-authored-by: Tibor Nagy (NISZ)

(cherry picked from commit d656191ec308d4280b93c7169372e543a255d108)

Change-Id: I8319c93c6c5a980878ee9956c8ab2953da60409e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129102
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/data/tdf119952_negativeMargins.docx 
b/sw/qa/extras/ooxmlexport/data/tdf119952_negativeMargins.docx
new file mode 100644
index ..9b5a98d3f1aa
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf119952_negativeMargins.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index 1638d93cf878..4523b19e5311 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -1424,6 +1424,89 @@ DECLARE_OOXMLEXPORT_TEST(testTdf124678_case2, 
"tdf124678_with_leading_paragraph.
 CPPUNIT_ASSERT_EQUAL_MESSAGE("Second page header text", 
OUString("HEADER"), parseDump("/root/page[2]/header/txt"));
 }
 
+static bool lcl_nearEqual(const sal_Int32 nNumber1, const sal_Int32 nNumber2, 
sal_Int32 nMaxDiff = 5)
+{
+return std::abs(nNumber1 - nNumber2) < nMaxDiff;
+}
+
+DECLARE_OOXMLEXPORT_TEST(testTdf119952_negativeMargins, 
"tdf119952_negativeMargins.docx")
+{
+// With negative margins (in MS Word) one can set up header (or footer) 
that overlaps with the body.
+// LibreOffice unable to display that, so when importing negative margins,
+// the header (or footer) converted to a flyframe, anchored to the header..
+// that can overlap with the body, and will appear like in Word.
+// This conversion modifies the document [i.e. replacing header text with 
a textbox...]
+// but its DOCX export looks the same, as the original document in Word, 
too.
+xmlDocUniquePtr pDump = parseLayoutDump();
+
+//Check layout positions / sizes
+sal_Int32 nLeftHead = getXPath(pDump, "//page[1]/header/infos/bounds", 
"left").toInt32();
+sal_Int32 nLeftBody = getXPath(pDump, "//page[1]/body/infos/bounds", 
"left").toInt32();
+sal_Int32 nLeftFoot = getXPath(pDump, "//page[1]/footer/infos/bounds", 
"left").toInt32();
+sal_Int32 nLeftHFly = getXPath(pDump, 
"//page[1]/header/txt/anchored/fly/infos/bounds", "left").toInt32();
+sal_Int32 nLeftFFly = getXPath(pDump, 
"//page[1]/footer/txt/anchored/fly/infos/bounds", "left").toInt32();
+
+sal_Int32 nTopHead = getXPath(pDump, "//page[1]/header/infos/bounds", 
"top").toInt32();
+sal_Int32 nTopBody = getXPath(pDump, "//page[1]/body/infos/bounds", 
"top").toInt32();
+sal_Int32 nTopFoot = getXPath(pDump, "//page[1]/footer/infos/bounds", 
"top").toInt32();
+sal_Int32 nTopHFly = getXPath(pDump, 
"//page[1]/header/txt/anchored/fly/infos/bounds", "top").toInt32();
+sal_Int32 nTopFFly = getXPath(pDump, 
"//page[1]/footer/txt/anchored/fly/infos/bounds", "top").toInt32();
+
+

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - sw/qa writerfilter/source

2022-01-26 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx|3 ++-
 sw/qa/extras/ooxmlexport/ooxmlexport6.cxx |8 
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx |   12 +---
 writerfilter/source/dmapper/GraphicImport.cxx |7 ++-
 4 files changed, 13 insertions(+), 17 deletions(-)

New commits:
commit 3973c5dc82b49b563c2534ca0cb3aa9a6a2c9d58
Author: Miklos Vajna 
AuthorDate: Mon Sep 20 19:56:37 2021 +0200
Commit: Henry Castro 
CommitDate: Wed Jan 26 12:39:42 2022 +0100

tdf#143591 DOCX import: handle anchored objects as at-char

This partially reverts cc8f8ae55f681755f5da3bf64e4c30bb713f0383 (DOCX
drawingML shape import: wp:anchor's behindDoc attribute, 2013-11-19), it
seems to be more important to be consistent with the DOC import than
with the VML import which is no longer used for DOCX shapes crated with
Word >= 2010.

Change-Id: I631da010bce1b4d3c392645e0ae3797a03665a42
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122367
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128927
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Henry Castro 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 47307b49789e..6e789cabaa26 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -151,7 +151,8 @@ DECLARE_OOXMLEXPORT_TEST(testWpsOnly, "wps-only.docx")
 // Document has wp:anchor, not wp:inline, so handle it accordingly.
 uno::Reference xShape = getShape(1);
 text::TextContentAnchorType eValue = 
getProperty(xShape, "AnchorType");
-CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_PARAGRAPH, eValue);
+// Word only as as-char and at-char, so at-char is our only choice.
+CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, eValue);
 
 // Check position, it was 0. This is a shape, so use getPosition(), not a 
property.
 CPPUNIT_ASSERT_EQUAL(oox::drawingml::convertEmuToHmm(671830), 
xShape->getPosition().X);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
index cc63f77e5c56..08728107fc15 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
@@ -697,13 +697,13 @@ 
DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testSmartArtAnchoredInline, "fdo73227.docx")
 
 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
 assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","id","1");
-assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","name","Diagram1");
+assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[1]/wp:anchor/wp:docPr","name","Picture 
1");
 
-assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr","id","2");
+assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr","id","3");
 assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr","name","10-Point
 Star 3");
 
-assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","id","3");
-assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","name","Picture 
1");
+assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","id","2");
+assertXPath(pXmlDoc, 
"/w:document/w:body/w:p/w:r/w:drawing[2]/wp:anchor/wp:docPr","name","Diagram2");
 }
 
 DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFdo65833, "fdo65833.docx")
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 43608c5bd136..9082916fcdb8 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -423,15 +423,13 @@ DECLARE_OOXMLIMPORT_TEST(testTextCopy, "text-copy.docx")
 uno::Reference xPageStyle(
 getStyles("PageStyles")->getByName(aPageStyleName), uno::UNO_QUERY);
 auto xHeaderText = getProperty>(xPageStyle, 
"HeaderText");
-uno::Reference xHeaderPara(
-getParagraphOfText(1, xHeaderText), uno::UNO_QUERY);
-uno::Reference xHeaderShapes
-= 
xHeaderPara->createContentEnumeration("com.sun.star.text.TextContent");
+uno::Reference xHeaderPara = getParagraphOfText(1, 
xHeaderText);
+auto aTextPortionType = getProperty(getRun(xHeaderPara, 1), 
"TextPortionType");
 // Without the accompanying fix in place, this test would have failed with:
-// assertion failed
-// - Expression: xHeaderShapes->hasMoreElements()
+// - Expected: Frame
+// - Actual  : Text
 // i.e. the second page's header had no anchored shapes.
-CPPUNIT_ASSERT(xHeaderShapes->hasMoreElements());
+CPPUNIT_ASSERT_EQUAL(OUString("Frame"), aTextPortionType);
 }