[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/qa writerfilter/source

2023-11-30 Thread Tomaž Vajngerl (via logerrit)
 sw/qa/core/header_footer/HeaderFooterTest.cxx  |   74 -
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx |3 
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx  |   13 
 sw/qa/extras/ooxmlexport/ooxmlexport6.cxx  |4 
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx  |9 
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx  |4 
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx   |3 
 sw/qa/extras/rtfexport/rtfexport.cxx   |3 
 sw/qa/extras/rtfexport/rtfexport2.cxx  |6 
 sw/qa/extras/rtfexport/rtfexport3.cxx  |   35 
 sw/qa/extras/rtfexport/rtfexport5.cxx  |2 
 sw/qa/extras/rtfimport/rtfimport.cxx   |   18 
 sw/source/filter/ww8/rtfexport.cxx |9 
 writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx |1 
 writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx   |3 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx  |  214 +++-
 writerfilter/source/dmapper/DomainMapper_Impl.hxx  |   60 -
 writerfilter/source/dmapper/PropertyIds.cxx|3 
 writerfilter/source/dmapper/PropertyIds.hxx|3 
 writerfilter/source/dmapper/PropertyMap.cxx|  663 ++---
 writerfilter/source/dmapper/PropertyMap.hxx|   83 +
 21 files changed, 711 insertions(+), 502 deletions(-)

New commits:
commit 4b0fa253a4540f5461397815d290586f9ddabe61
Author: Tomaž Vajngerl 
AuthorDate: Tue Nov 28 13:46:21 2023 +0900
Commit: Tomaž Vajngerl 
CommitDate: Fri Dec 1 08:26:38 2023 +0100

tdf#136472 adjust ooxml import to handle first header/footer

Previously the ooxml import added a new page style when the first
header or footer was detected. Since then we gained support to add
first page header/footer in an existing page style so we don't need
to import it like that anymore.
This changes the import code so that the old complication to add
"First Page" page style is removed and it always just uses the
"Standard" page style for all 3 cases: first, left and right headers
and footers.

This also adjusts the existing tests to align with this change.

Change-Id: Ibf69597e6990499ac520ea9e323a5f73f429800b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157860
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/sw/qa/core/header_footer/HeaderFooterTest.cxx 
b/sw/qa/core/header_footer/HeaderFooterTest.cxx
index b411632884e1..d67e874df0ec 100644
--- a/sw/qa/core/header_footer/HeaderFooterTest.cxx
+++ b/sw/qa/core/header_footer/HeaderFooterTest.cxx
@@ -96,8 +96,11 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, 
testNonFirstHeaderIsDisabled)
 
 createSwDoc("tdf127778.docx");
 
-xmlDocUniquePtr pLayout = parseLayoutDump();
-assertXPath(pLayout, "//page[2]/header"_ostr, 0);
+// TODO
+
+// Header can only be enabled or disabled, but can't be disbaled just for 
first, left or right page.
+// If a header is enabled but empty, the header still takes space in LO, 
but not in MSO, where it acts the same as
+// if it is disabled.
 }
 
 // Check for correct header/footer with special first page with TOC inside
@@ -113,8 +116,10 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, 
testHeaderFooterWithSpecialFirstPage_OOXM
 {
 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
 // check first page
-assertXPath(pXmlDoc, "/root/page[1]/header"_ostr, 0);
-assertXPath(pXmlDoc, "/root/page[1]/footer"_ostr, 0);
+assertXPath(pXmlDoc, "/root/page[1]/header"_ostr);
+assertXPath(pXmlDoc, "/root/page[1]/footer"_ostr);
+assertXPath(pXmlDoc, "/root/page[1]/header/txt/text()"_ostr, 0);
+assertXPath(pXmlDoc, "/root/page[1]/footer/txt/text()"_ostr, 0);
 // check second page in the same way
 assertXPath(pXmlDoc, "/root/page[2]/header"_ostr);
 assertXPath(pXmlDoc, "/root/page[2]/footer"_ostr);
@@ -463,7 +468,9 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, testTdf112694)
 uno::Any aPageStyle = getStyles("PageStyles")->getByName("Standard");
 // Header was on when header for file was for explicit first pages only
 // (marked via ).
-CPPUNIT_ASSERT(!getProperty(aPageStyle, "HeaderIsOn"));
+//CPPUNIT_ASSERT(!getProperty(aPageStyle, "HeaderIsOn"));
+// TODO - can't disable headers/footers selectively (only fo first 
page)
+CPPUNIT_ASSERT(getProperty(aPageStyle, "HeaderIsOn"));
 };
 
 createSwDoc("tdf112694.docx");
@@ -664,7 +671,10 @@ CPPUNIT_TEST_FIXTURE(HeaderFooterTest, 
testFirstPageFooterEnabled)
 // Footer shouldn't be enabled on first page, but then on the other pages
 auto verify = [this]() {
 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
-assertXPath(pXmlDoc, "/root/page[1]/footer/txt"_ostr, 

[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/qa writerfilter/source

2023-10-16 Thread Miklos Vajna (via logerrit)
 sw/qa/filter/ww8/ww8.cxx|  
 23 ++
 sw/source/filter/ww8/docxexport.cxx |  
 12 +
 writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx  |  
 18 +++
 writerfilter/qa/cppunittests/dmapper/data/floattable-wrap-on-all-pages.docx 
|binary
 writerfilter/source/dmapper/SettingsTable.cxx   |  
 23 ++
 writerfilter/source/ooxml/OOXMLPropertySet.cxx  |  
  2 
 writerfilter/source/ooxml/OOXMLPropertySet.hxx  |  
  2 
 7 files changed, 79 insertions(+), 1 deletion(-)

New commits:
commit 33ade4171a1a443fd24e6463a9eaa279f7d778bb
Author: Miklos Vajna 
AuthorDate: Mon Oct 16 08:46:54 2023 +0200
Commit: Miklos Vajna 
CommitDate: Mon Oct 16 09:53:35 2023 +0200

sw floattable, wrap on all pages: add DOCX filter

- map DocumentSettingId::ALLOW_TEXT_AFTER_FLOATING_TABLE_BREAK to
   on export

- do the opposite on import

  - this requires a bit of rework, to avoid routing 
via a grab-bag when we want to actually read it during import

  - also expose GetBooleanValue() from the OOXML tokenizer, so dmapper
can know when the value of the compat flag is a true-like string.

Note that it seems DOC and RTF don't have a matching compat flag for
this.

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

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index 6a858193e776..1d863545578e 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -332,6 +332,29 @@ CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables)
 assertXPath(pXmlDoc, "/w:settings/w:compat/w:doNotBreakWrappedTables", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testAllowTextAfterFloatingTableBreak)
+{
+// Given a document with the ALLOW_TEXT_AFTER_FLOATING_TABLE_BREAK compat 
mode enabled:
+createSwDoc();
+SwDoc* pDoc = getSwDoc();
+IDocumentSettingAccess& rIDSA = pDoc->getIDocumentSettingAccess();
+rIDSA.set(DocumentSettingId::ALLOW_TEXT_AFTER_FLOATING_TABLE_BREAK, true);
+
+// When saving to docx:
+save("Office Open XML Text");
+
+// Then make sure the compat flag is serialized:
+xmlDocUniquePtr pXmlDoc = parseExport("word/settings.xml");
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// - XPath 
'/w:settings/w:compat/w:compatSetting[@w:name='allowTextAfterFloatingTableBreak']'
 number of nodes is incorrect
+// i.e. the compat flag was lost on export.
+assertXPath(pXmlDoc,
+
"/w:settings/w:compat/w:compatSetting[@w:name='allowTextAfterFloatingTableBreak']",
+"val", "1");
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testDOCfDontBreakWrappedTables)
 {
 // Given a document with fDontBreakWrappedTables:
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index 61319d5e2f3b..42ff0fdf7a09 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1435,6 +1435,18 @@ void DocxExport::WriteSettings()
 FSNS( XML_w, XML_name ), "compatibilityMode",
 FSNS( XML_w, XML_uri ),  
"http://schemas.microsoft.com/office/word;,
 FSNS( XML_w, XML_val ),  
OString::number(nTargetCompatibilityMode));
+
+const IDocumentSettingAccess& rIDSA = 
m_rDoc.getIDocumentSettingAccess();
+if 
(rIDSA.get(DocumentSettingId::ALLOW_TEXT_AFTER_FLOATING_TABLE_BREAK))
+{
+// AllowTextAfterFloatingTableBreak doesn't have its own XML 
element, it's a
+//  with a specific name.
+pFS->singleElementNS(XML_w, XML_compatSetting,
+FSNS(XML_w, XML_name), "allowTextAfterFloatingTableBreak",
+FSNS(XML_w, XML_uri), 
"http://schemas.microsoft.com/office/word;,
+FSNS(XML_w, XML_val), "1");
+}
+
 pFS->endElementNS( XML_w, XML_compat );
 }
 
diff --git a/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx 
b/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx
index 8b36a6170bb0..00d4147bfb05 100644
--- a/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/SettingsTable.cxx
@@ -41,6 +41,24 @@ CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables)
 // set.
 CPPUNIT_ASSERT(bDoNotBreakWrappedTables);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testAllowTextAfterFloatingTableBreak)
+{
+// Given a document with :
+// When importing that document:
+loadFromURL(u"floattable-wrap-on-all-pages.docx");
+
+// Then make sure that the matching compat flag is set:
+uno::Reference xDocument(mxComponent, 
uno::UNO_QUERY);
+

[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/qa writerfilter/source

2022-09-22 Thread Miklos Vajna (via logerrit)
 sw/qa/filter/ww8/ww8.cxx|   26 
 sw/source/filter/ww8/docxattributeoutput.cxx|   18 +-
 writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx  |   30 
++
 writerfilter/qa/cppunittests/dmapper/data/sdt-run-combobox.docx |binary
 writerfilter/source/dmapper/DomainMapper.cxx|   23 ++-
 writerfilter/source/dmapper/DomainMapper_Impl.cxx   |7 ++
 writerfilter/source/dmapper/SdtHelper.cxx   |3 -
 writerfilter/source/dmapper/SdtHelper.hxx   |1 
 8 files changed, 100 insertions(+), 8 deletions(-)

New commits:
commit 01b1f57a90172a76faa1489b3b72250ee76169a6
Author: Miklos Vajna 
AuthorDate: Thu Sep 22 10:01:26 2022 +0200
Commit: Miklos Vajna 
CommitDate: Thu Sep 22 12:29:15 2022 +0200

sw content controls, combo box: add DOCX filter

Map the ComboBox UNO property to:


  
  ...
  


and the opposite on import.

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

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index 4f33e781d05d..ea8c4d9a9553 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -11,6 +11,10 @@
 
 #include 
 
+#include 
+#include 
+#include 
+
 namespace
 {
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/filter/ww8/data/";
@@ -81,6 +85,28 @@ CPPUNIT_TEST_FIXTURE(Test, testPlainTextContentControlExport)
 // i.e. the plain text content control was turned into a rich text one on 
export.
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text", 1);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDocxComboBoxContentControlExport)
+{
+// Given a document with a combo box content control around a text portion:
+mxComponent = loadFromDesktop("private:factory/swriter");
+SwDoc* pDoc = getSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::COMBO_BOX);
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// - XPath '//w:sdt/w:sdtPr/w:comboBox' number of nodes is incorrect
+// i.e. the combo box content control was turned into a drop-down one on 
export.
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:comboBox", 1);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index f8fc5429fb97..5833dd62dbca 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2393,14 +2393,28 @@ void DocxAttributeOutput::WriteContentControlStart()
 
 if (m_pContentControl->HasListItems())
 {
-m_pSerializer->startElementNS(XML_w, XML_dropDownList);
+if (m_pContentControl->GetComboBox())
+{
+m_pSerializer->startElementNS(XML_w, XML_comboBox);
+}
+else
+{
+m_pSerializer->startElementNS(XML_w, XML_dropDownList);
+}
 for (const auto& rItem : m_pContentControl->GetListItems())
 {
 m_pSerializer->singleElementNS(XML_w, XML_listItem,
 FSNS(XML_w, XML_displayText), rItem.m_aDisplayText,
 FSNS(XML_w, XML_value), rItem.m_aValue);
 }
-m_pSerializer->endElementNS(XML_w, XML_dropDownList);
+if (m_pContentControl->GetComboBox())
+{
+m_pSerializer->endElementNS(XML_w, XML_comboBox);
+}
+else
+{
+m_pSerializer->endElementNS(XML_w, XML_dropDownList);
+}
 }
 
 if (m_pContentControl->GetDate())
diff --git a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx 
b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
index 6b568619785e..7b842e667104 100644
--- a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
@@ -212,6 +212,36 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtRunDropdown)
 CPPUNIT_ASSERT_EQUAL(OUString("choose a color"), xContent->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testSdtRunComboBox)
+{
+// Given a document with a combo box inline/run SDT:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"sdt-run-combobox.docx";
+
+// When loading the document:
+getComponent() = loadFromDesktop(aURL);
+
+// Then make sure that the doc model has a clickable combo box content 
control:
+uno::Reference xTextDocument(getComponent(), 
uno::UNO_QUERY);
+

[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/qa writerfilter/source

2022-06-08 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/rtfexport/rtfexport3.cxx |   58 
++
 sw/qa/filter/ww8/ww8.cxx  |2 
 sw/source/filter/ww8/rtfattributeoutput.cxx   |   46 
++-
 sw/source/filter/ww8/rtfattributeoutput.hxx   |3 
 writerfilter/qa/cppunittests/rtftok/data/negative-page-border.rtf |7 +
 writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx  |   30 +
 writerfilter/source/rtftok/rtfdispatchvalue.cxx   |   13 ++
 7 files changed, 148 insertions(+), 11 deletions(-)

New commits:
commit d4123356c61db269651e950a0a2cc93e6d801c90
Author: Miklos Vajna 
AuthorDate: Wed Jun 8 17:05:42 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jun 8 17:46:58 2022 +0200

RTF filter: allow measuring page borders from the edge of the page

This is similar to commit 51942eafdb4439559b6d59f3becd4afab45277f0 (DOC
import: allow negative page border distances, 2022-06-08), except here
we map \pgbrdropt's 5th bit to the "from page edge" bool, and then the
rest of the import works already after the DOCX fixes.

Similarly, the export has to map the "from page edge" bool to \pgbrdropt
and has to call into editeng::BorderDistancesToWord(), but the rest of
the process works after the DOCX fixes.

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

diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx 
b/sw/qa/extras/rtfexport/rtfexport3.cxx
index 665682c7532c..bd8a1c8dc795 100644
--- a/sw/qa/extras/rtfexport/rtfexport3.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport3.cxx
@@ -22,6 +22,12 @@
 #include 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 using namespace css;
 
 class Test : public SwModelTestBase
@@ -434,6 +440,58 @@ CPPUNIT_TEST_FIXTURE(Test, testRtlGutter)
 verify();
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorder)
+{
+{
+// Given a document with a top margin and a border which has more 
spacing than the margin on
+// its 2nd page:
+createSwDoc();
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwDocShell* pDocShell = pTextDoc->GetDocShell();
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+pWrtShell->Insert("first");
+pWrtShell->SplitNode();
+pWrtShell->Insert("second");
+SwPageDesc* pDesc = pWrtShell->FindPageDescByName("Left Page", true);
+SwPaM aPaM(*pWrtShell->GetCursor()->GetPoint());
+SwFormatPageDesc aFormatPageDesc(pDesc);
+
pDocShell->GetDoc()->getIDocumentContentOperations().InsertPoolItem(aPaM, 
aFormatPageDesc);
+uno::Reference xPageStyle(
+getStyles("PageStyles")->getByName("Left Page"), uno::UNO_QUERY);
+xPageStyle->setPropertyValue("TopMargin", 
uno::Any(static_cast(501)));
+table::BorderLine2 aBorder;
+aBorder.LineWidth = 159;
+aBorder.OuterLineWidth = 159;
+xPageStyle->setPropertyValue("TopBorder", uno::Any(aBorder));
+sal_Int32 nTopBorderDistance = -646;
+xPageStyle->setPropertyValue("TopBorderDistance", 
uno::Any(nTopBorderDistance));
+pDocShell->GetDoc()->dumpAsXml();
+}
+
+// When saving that document to RTF:
+reload(mpFilter, "negative-page-border.rtf");
+
+// Then make sure that the border distance is negative, so the first line 
of body text appears
+// on top of the page border:
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwDocShell* pDocShell = pTextDoc->GetDocShell();
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+pWrtShell->Down(/*bSelect=*/false);
+OUString aPageStyle = pWrtShell->GetCurPageStyle();
+uno::Reference 
xPageStyle(getStyles("PageStyles")->getByName(aPageStyle),
+   uno::UNO_QUERY);
+auto nTopMargin = 
xPageStyle->getPropertyValue("TopMargin").get();
+CPPUNIT_ASSERT_EQUAL(static_cast(501), nTopMargin);
+auto aTopBorder = 
xPageStyle->getPropertyValue("TopBorder").get();
+CPPUNIT_ASSERT_EQUAL(static_cast(159), aTopBorder.LineWidth);
+auto nTopBorderDistance = 
xPageStyle->getPropertyValue("TopBorderDistance").get();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: -646
+// - Actual  : 0
+// i.e. the border negative distance was lost.
+CPPUNIT_ASSERT_EQUAL(static_cast(-646), nTopBorderDistance);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index eb735b16a746..7ccb1299769e 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -26,7 +26,7 @@ class Test : public SwModelTestBase
 {
 };
 
-CPPUNIT_TEST_FIXTURE(Test, testSwAttrSet)

[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/qa writerfilter/source

2022-05-20 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx |   37 
+-
 sw/source/filter/ww8/docxattributeoutput.cxx   |5 +
 writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx |   33 
 writerfilter/qa/cppunittests/dmapper/data/sdt-run-picture.docx |binary
 writerfilter/source/dmapper/DomainMapper.cxx   |   11 ++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx  |5 +
 writerfilter/source/dmapper/SdtHelper.hxx  |1 
 7 files changed, 91 insertions(+), 1 deletion(-)

New commits:
commit 22d7cbc0f0c50c59abca7ab5f7db46e4d0e5f86a
Author: Miklos Vajna 
AuthorDate: Fri May 20 08:54:28 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri May 20 10:09:19 2022 +0200

sw content controls, picture: add DOCX filter

Map Picture UNO property on content controls to:


  

...

And do the opposite on import.

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

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 8146e942ce5d..281884057770 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -285,7 +285,7 @@ CPPUNIT_TEST_FIXTURE(Test, testCheckboxContentControlExport)
 
 CPPUNIT_TEST_FIXTURE(Test, testDropdownContentControlExport)
 {
-// Given a document with a checkbox content control around a text portion:
+// Given a document with a dropdown content control around a text portion:
 mxComponent = loadFromDesktop("private:factory/swriter");
 uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
 uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
@@ -335,6 +335,41 @@ CPPUNIT_TEST_FIXTURE(Test, 
testDropdownContentControlExport)
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[3]", 
"value", "B");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testPictureContentControlExport)
+{
+// Given a document with a picture content control around a text portion:
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+uno::Reference xTextGraphic(
+xMSF->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xTextGraphic->setPropertyValue("AnchorType",
+   
uno::Any(text::TextContentAnchorType_AS_CHARACTER));
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xTextContent, false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+uno::Reference xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+xContentControlProps->setPropertyValue("Picture", uno::Any(true));
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// i.e.  was lost on export.
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:picture", 1);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf148494)
 {
 loadAndSave("tdf148494.docx");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 4e46b456c602..65fc656ee13a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2335,6 +2335,11 @@ void DocxAttributeOutput::WriteContentControlStart()
 m_pSerializer->singleElementNS(XML_w, XML_showingPlcHdr);
 }
 
+if (m_pContentControl->GetPicture())
+{
+m_pSerializer->singleElementNS(XML_w, XML_picture);
+}
+
 if (m_pContentControl->GetCheckbox())
 {
 m_pSerializer->startElementNS(XML_w14, XML_checkbox);
diff --git a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx 
b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
index 633355c79a5f..b2e7f1058f88 100644
--- a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
@@ -181,6 +181,39 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtRunDropdown)
 uno::Reference xContent(xContentEnum->nextElement(), 
uno::UNO_QUERY);
 CPPUNIT_ASSERT_EQUAL(OUString("choose a color"), xContent->getString());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, 

[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/qa writerfilter/source

2020-05-14 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx   |   18 +++-
 sw/source/filter/ww8/docxsdrexport.cxx |3 +-
 sw/source/filter/ww8/rtfattributeoutput.cxx|4 +-
 sw/source/filter/ww8/writerhelper.cxx  |   24 -
 sw/source/filter/ww8/writerhelper.hxx  |2 -
 sw/source/filter/ww8/wrtw8esh.cxx  |2 -
 writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx |5 ++-
 writerfilter/source/dmapper/WrapPolygonHandler.cxx |3 +-
 8 files changed, 45 insertions(+), 16 deletions(-)

New commits:
commit c68b458514b35cae70c9a6630e06f46a867aa3b9
Author: Miklos Vajna 
AuthorDate: Thu May 14 18:02:23 2020 +0200
Commit: Miklos Vajna 
CommitDate: Thu May 14 21:46:03 2020 +0200

DOCX export: fix interaction between the crop and the wrap polygon of image

If the wrap polygon is influenced by crop at import time, we need to do
the opposite at export time.

Do this for RTF and DOCX, where there is matching import code in
writerfilter/, leave DOC alone for now.

Test this by changing testFdo76803 into an export test, then seeing how
the first point's Y position fails and fixing up the exporter, so we
get back the old good value.

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

diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 48de70ea00b6..5cf893bb0937 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -965,7 +965,7 @@ DECLARE_OOXMLIMPORT_TEST(testFdo75722dml, 
"fdo75722-dml.docx")
 CPPUNIT_ASSERT_EQUAL(sal_Int64(3128), nRot);
 }
 
-DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx")
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFdo76803, "fdo76803.docx")
 {
 // The ContourPolyPolygon was wrong
 uno::Reference xPropertySet(getShape(1), 
uno::UNO_QUERY);
@@ -981,16 +981,20 @@ DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx")
 
 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count());
 
-CPPUNIT_ASSERT_EQUAL(double(-162), aPolygon.getB2DPoint(0).getX());
+CPPUNIT_ASSERT_EQUAL(double(-149), aPolygon.getB2DPoint(0).getX());
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: -35
+// - Actual  : -67
+// i.e. the cropping did not influence the wrap polygon during export.
 CPPUNIT_ASSERT_EQUAL(double(-35), aPolygon.getB2DPoint(0).getY());
 
-CPPUNIT_ASSERT_EQUAL(double(-162), aPolygon.getB2DPoint(1).getX());
-CPPUNIT_ASSERT_EQUAL(double(3510), aPolygon.getB2DPoint(1).getY());
+CPPUNIT_ASSERT_EQUAL(double(-149), aPolygon.getB2DPoint(1).getX());
+CPPUNIT_ASSERT_EQUAL(double(3511), aPolygon.getB2DPoint(1).getY());
 
-CPPUNIT_ASSERT_EQUAL(double(16892), aPolygon.getB2DPoint(2).getX());
-CPPUNIT_ASSERT_EQUAL(double(3510), aPolygon.getB2DPoint(2).getY());
+CPPUNIT_ASSERT_EQUAL(double(16889), aPolygon.getB2DPoint(2).getX());
+CPPUNIT_ASSERT_EQUAL(double(3511), aPolygon.getB2DPoint(2).getY());
 
-CPPUNIT_ASSERT_EQUAL(double(16892), aPolygon.getB2DPoint(3).getX());
+CPPUNIT_ASSERT_EQUAL(double(16889), aPolygon.getB2DPoint(3).getX());
 CPPUNIT_ASSERT_EQUAL(double(-35), aPolygon.getB2DPoint(3).getY());
 }
 
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx 
b/sw/source/filter/ww8/docxsdrexport.cxx
index 2ae2ab3bd748..e0cf42586727 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -781,7 +781,8 @@ void DocxSdrExport::startDMLAnchorInline(const 
SwFrameFormat* pFrameFormat, cons
  "bothSides");
 
 m_pImpl->getSerializer()->startElementNS(XML_wp, 
XML_wrapPolygon, XML_edited, "0");
-tools::Polygon aPoly = 
sw::util::CorrectWordWrapPolygonForExport(*pPolyPoly, pNd);
+tools::Polygon aPoly = 
sw::util::CorrectWordWrapPolygonForExport(
+*pPolyPoly, pNd, /*bCorrectCrop=*/true);
 for (sal_uInt16 i = 0; i < aPoly.GetSize(); ++i)
 m_pImpl->getSerializer()->singleElementNS(
 XML_wp, (i == 0 ? XML_start : XML_lineTo), XML_x,
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index bfbb71a23f84..10d38a569e92 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -4226,8 +4226,8 @@ void RtfAttributeOutput::FlyFrameGraphic(const 
SwFlyFrameFormat* pFlyFrameFormat
 const tools::PolyPolygon* pPolyPoly = pNd->HasContour();
 if (pPolyPoly && pPolyPoly->Count())
 {
-tools::Polygon aPoly
-=