[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa

2023-03-02 Thread Mike Kaganski (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |   16 
 1 file changed, 8 insertions(+), 8 deletions(-)

New commits:
commit aa634cb115ec4efb61017aae6699744666a7c31f
Author: Mike Kaganski 
AuthorDate: Fri Mar 3 09:45:16 2023 +0300
Commit: Mike Kaganski 
CommitDate: Fri Mar 3 06:46:41 2023 +

tdf#153923: modify the unit test for the 7.0 branch

Test the ReqIF here.

Change-Id: Ief6703546398aa63812512f85a3185e5aceb405e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148155
Tested-by: Mike Kaganski 
Reviewed-by: Mike Kaganski 

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 1326fbb48dc5..b6cc08282287 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2328,22 +2328,22 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testSectionDir)
 assertXPath(pXmlDoc, "//reqif-xhtml:div[@id='mysect']", "style", "dir: 
ltr");
 }
 
-CPPUNIT_TEST_FIXTURE(HtmlExportTest, testTdf153923)
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf153923)
 {
 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"TableWithIndent.fodt";
 mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {});
-uno::Reference xStorable(mxComponent, 
uno::UNO_QUERY_THROW);
-uno::Sequence aStoreProperties = {
-comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)"))
-};
-xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
 
-htmlDocUniquePtr pDoc = parseHtml(maTempFile);
+// When exporting to (reqif-)xhtml:
+ExportToReqif();
+
+SvMemoryStream aStream;
+WrapReqifFromTempFile(aStream);
+xmlDocUniquePtr pDoc = parseXmlStream();
 // Without the fix in place, this would fail
 CPPUNIT_ASSERT(pDoc);
 
 // The 'dd' tag was not closed
-assertXPath(pDoc, "/html/body//dd");
+assertXPath(pDoc, "//reqif-xhtml:dd");
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2023-03-02 Thread Mike Kaganski (via logerrit)
 sw/qa/extras/htmlexport/data/TableWithIndent.fodt |   22 ++
 sw/qa/extras/htmlexport/htmlexport.cxx|   18 ++
 sw/source/filter/html/htmltabw.cxx|   10 ++
 3 files changed, 50 insertions(+)

New commits:
commit 2561cb3f97f9c58051a609873de6af175e529b42
Author: Mike Kaganski 
AuthorDate: Thu Mar 2 16:15:16 2023 +0300
Commit: Mike Kaganski 
CommitDate: Fri Mar 3 06:17:17 2023 +

tdf#153923: close 'dd' tag properly

Change-Id: I4ae3b23c616fc2ea40a5fdf8640bf5db0bb371ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148122
Tested-by: Jenkins
Reviewed-by: Noel Grandin 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148153
Tested-by: Mike Kaganski 
Reviewed-by: Mike Kaganski 

diff --git a/sw/qa/extras/htmlexport/data/TableWithIndent.fodt 
b/sw/qa/extras/htmlexport/data/TableWithIndent.fodt
new file mode 100644
index ..5daaa75e8e24
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/TableWithIndent.fodt
@@ -0,0 +1,22 @@
+
+
+
+ 
+  
+   
+  
+ 
+ 
+  
+   
+
+
+ 
+  
+ 
+
+   
+   
+  
+ 
+
\ No newline at end of file
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 19e40fb1c256..1326fbb48dc5 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2328,6 +2328,24 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSectionDir)
 assertXPath(pXmlDoc, "//reqif-xhtml:div[@id='mysect']", "style", "dir: 
ltr");
 }
 
+CPPUNIT_TEST_FIXTURE(HtmlExportTest, testTdf153923)
+{
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"TableWithIndent.fodt";
+mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {});
+uno::Reference xStorable(mxComponent, 
uno::UNO_QUERY_THROW);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)"))
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+htmlDocUniquePtr pDoc = parseHtml(maTempFile);
+// Without the fix in place, this would fail
+CPPUNIT_ASSERT(pDoc);
+
+// The 'dd' tag was not closed
+assertXPath(pDoc, "/html/body//dd");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmltabw.cxx 
b/sw/source/filter/html/htmltabw.cxx
index 1150b72d5320..debf5d3d0e3a 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -1059,6 +1059,7 @@ Writer& OutHTML_SwTableNode( Writer& rWrt, SwTableNode & 
rNode,
 if( rHTMLWrt.m_bLFPossible )
 rHTMLWrt.OutNewLine();
 HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + 
OOO_STRING_SVTOOLS_HTML_dd );
+rHTMLWrt.IncIndentLevel();
 }
 
 // eFlyHoriOri and eTabHoriOri now only contain the values of
@@ -1185,6 +1186,15 @@ Writer& OutHTML_SwTableNode( Writer& rWrt, SwTableNode & 
rNode,
 // move Pam behind the table
 rHTMLWrt.m_pCurrentPam->GetPoint()->nNode = *rNode.EndOfSectionNode();
 
+if (nNewDefListLvl)
+{
+rHTMLWrt.DecIndentLevel();
+if (rHTMLWrt.m_bLFPossible)
+rHTMLWrt.OutNewLine();
+// close the dd element
+HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), rHTMLWrt.GetNamespace() + 
OOO_STRING_SVTOOLS_HTML_dd, false);
+}
+
 if( bPreserveForm )
 {
 rHTMLWrt.m_bPreserveForm = false;


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2023-01-13 Thread Miklos Vajna (via logerrit)
 sw/qa/filter/html/html.cxx |   37 +++
 sw/source/filter/html/htmltabw.cxx |   49 +++--
 2 files changed, 78 insertions(+), 8 deletions(-)

New commits:
commit ccec05262ad389dd3d50ff75499ae8e5a877fc0f
Author: Miklos Vajna 
AuthorDate: Thu Jan 12 13:57:16 2023 +0100
Commit: Miklos Vajna 
CommitDate: Fri Jan 13 10:54:51 2023 +0100

sw HTML export: fix invalid HTML when all cells of a row have the same 
rowspan

The bugdoc has a table with 2 columns and 2 rows, but both the A1 and
the A2 cell has rowspan=2, so there are only covered cells in the second
row. It seems there is no valid HTML markup to express this Writer doc
model.

What HTML seems to suggest instead is to simply decrease the amount of
rowspan attribute values and then the empty  elements can be simply
skipped.

This fixes the

Row 2 of a row group established by a tbody element has no cells 
beginning on it.

from the w3c HTML validator.

Note that you can't create such problematic tables on the UI: the UI
will delete the row only containing covered cells for you when the last
cell gets merged. Such documents can be created by importers, though.

(cherry picked from commit a2fb3a135425bbc14375e1edfcc1e09a41d760f9)

Conflicts:
sw/source/filter/html/htmltabw.cxx

Change-Id: Ice4fa3636e8b780d374f3d319b198da9f5e0

diff --git a/sw/qa/filter/html/html.cxx b/sw/qa/filter/html/html.cxx
index f3b31efa7fe6..ef44aa39817a 100644
--- a/sw/qa/filter/html/html.cxx
+++ b/sw/qa/filter/html/html.cxx
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 
 #include 
 #include 
@@ -33,7 +34,7 @@ const char DATA_DIRECTORY[] = "/sw/qa/filter/html/data/";
  * Keep using the various sw_import/export suites for multiple filter 
calls inside a single
  * test.
  */
-class Test : public SwModelTestBase
+class Test : public SwModelTestBase, public HtmlTestTools
 {
 };
 
@@ -181,6 +182,40 @@ CPPUNIT_TEST_FIXTURE(Test, testTableCellFloatValueType)
 assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:td", "sdval");
 assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:td", "sdnum");
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTableRowSpanInAllCells)
+{
+// Given a document with a 2x2 table, A1:A2 and B1:B2 is merged:
+loadURL("private:factory/swriter", nullptr);
+auto pTextDocument = dynamic_cast(mxComponent.get());
+SwDoc* pDoc = pTextDocument->GetDocShell()->GetDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
+pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2);
+pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
+SwTableNode* pTableNode = 
pWrtShell->GetCursor()->GetNode().FindTableNode();
+SwTable& rTable = pTableNode->GetTable();
+auto pBox = const_cast(rTable.GetTableBox("A1"));
+pBox->setRowSpan(2);
+pBox = const_cast(rTable.GetTableBox("B1"));
+pBox->setRowSpan(2);
+pBox = const_cast(rTable.GetTableBox("A2"));
+pBox->setRowSpan(-1);
+pBox = const_cast(rTable.GetTableBox("B2"));
+pBox->setRowSpan(-1);
+
+// When exporting to HTML:
+save("HTML (StarWriter)", maTempFile);
+
+// Then make sure that the output is simplified to valid HTML, by omitting 
the rowspan attribute
+// & the empty  element:
+htmlDocUniquePtr pHtmlDoc = parseHtml(maTempFile);
+// Without the accompanying fix in place, this test would have failed with:
+// - XPath '//tr[1]/td[1]' unexpected 'rowspan' attribute
+// i.e. a combination of rowspan + empty  was emitted.
+assertXPathNoAttribute(pHtmlDoc, "//tr[1]/td[1]", "rowspan");
+assertXPath(pHtmlDoc, "//tr", 1);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmltabw.cxx 
b/sw/source/filter/html/htmltabw.cxx
index 73c1e1336e98..5cdbb8a5c205 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -63,12 +63,20 @@ class SwHTMLWrtTable : public SwWriteTable
 static void Pixelize( sal_uInt16& rValue );
 void PixelizeBorders();
 
+/// Writes a single table cell.
+///
+/// bCellRowSpan decides if the cell's row span should be written or not.
 void OutTableCell( SwHTMLWriter& rWrt, const SwWriteTableCell *pCell,
-   bool bOutVAlign ) const;
+   bool bOutVAlign,
+   bool bCellRowSpan ) const;
 
+/// Writes a single table row.
+///
+/// rSkipRows decides if the next N rows should be skipped or written.
 void OutTableCells( SwHTMLWriter& rWrt,
 const SwWriteTableCells& rCells,
-const SvxBrushItem *pBrushItem ) const;
+const SvxBrushItem *pBrushItem,
+sal_uInt16& rSkipRows ) const;
 
 virtual bool 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2023-01-06 Thread Miklos Vajna (via logerrit)
 sw/qa/filter/html/html.cxx |   37 +
 sw/source/filter/html/htmltabw.cxx |2 +-
 2 files changed, 38 insertions(+), 1 deletion(-)

New commits:
commit 90441a276d14441f3f0c325f89338c535f6bdfbe
Author: Miklos Vajna 
AuthorDate: Thu Jan 5 13:56:23 2023 +0100
Commit: Miklos Vajna 
CommitDate: Fri Jan 6 10:04:14 2023 +0100

sw XHTML export: avoid sdnum and sdval attributes on table cells

These are not valid in XHTML, as the reqif validator points it out:

ERROR at 239: [XSD] cvc-complex-type.3.2.2: Attribute 'sdval' is not 
allowed to appear in element 'td'.
ERROR at 239: [XSD] cvc-complex-type.3.2.2: Attribute 'sdnum' is not 
allowed to appear in element 'td'.

The actual cell contents is already there, so just omit this unwanted
metadata in the XHTML case.

(cherry picked from commit b4c3291630610d38270d7d8ccda5f810b3e05d63)

Change-Id: I68804dd2ce45b0579287aeccbb550b174859f7ba

diff --git a/sw/qa/filter/html/html.cxx b/sw/qa/filter/html/html.cxx
index 5fb02c46e2c4..f3b31efa7fe6 100644
--- a/sw/qa/filter/html/html.cxx
+++ b/sw/qa/filter/html/html.cxx
@@ -16,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 namespace
 {
@@ -144,6 +147,40 @@ CPPUNIT_TEST_FIXTURE(Test, testSvmImageExport)
 // i.e. we wrote both GIF and PNG, not just PNG for SVM images.
 assertXPath(pXmlDoc, "//reqif-xhtml:object", "type", "image/png");
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTableCellFloatValueType)
+{
+// Given a document with a single table cell, its cell value is set to 
double:
+loadURL("private:factory/swriter", nullptr);
+auto pTextDocument = dynamic_cast(mxComponent.get());
+SwDoc* pDoc = pTextDocument->GetDocShell()->GetDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
+pWrtShell->InsertTable(aTableOptions, 1, 1);
+pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
+SwTableNode* pTableNode = 
pWrtShell->GetCursor()->GetNode().FindTableNode();
+SwTable& rTable = pTableNode->GetTable();
+auto pBox = const_cast(rTable.GetTableBox("A1"));
+SwFrameFormat* pBoxFormat = pBox->ClaimFrameFormat();
+SwAttrSet aSet(pBoxFormat->GetAttrSet());
+SwTableBoxValue aBoxValue(42.0);
+aSet.Put(aBoxValue);
+pBoxFormat->GetDoc()->SetAttr(aSet, *pBoxFormat);
+
+// When exporting to XHTML:
+setFilterOptions("xhtmlns=reqif-xhtml");
+save("HTML (StarWriter)", maTempFile);
+
+// Then make sure that the sdval attribute is omitted, which is not in the 
XHTML spec:
+SvMemoryStream aStream;
+WrapReqifFromTempFile(aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+// Without the accompanying fix in place, this test would have failed with:
+// - XPath '//reqif-xhtml:td' unexpected 'sdval' attribute
+// i.e. sdval was written in XHTML mode.
+assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:td", "sdval");
+assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:td", "sdnum");
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmltabw.cxx 
b/sw/source/filter/html/htmltabw.cxx
index 81a7daf570a0..73c1e1336e98 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -455,7 +455,7 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
 nNumFormat = 
pBox->GetFrameFormat()->GetTableBoxNumFormat().GetValue();
 }
 
-if( bNumFormat || bValue )
+if ((bNumFormat || bValue) && !rWrt.mbXHTML)
 {
 sOut.append(HTMLOutFuncs::CreateTableDataOptionsValNum(bValue, nValue,
 nNumFormat, *rWrt.m_pDoc->GetNumberFormatter(), rWrt.m_eDestEnc,


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-12-13 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/uno/uno.cxx |   43 +++
 sw/source/uibase/uno/unotxvw.cxx |5 
 2 files changed, 48 insertions(+)

New commits:
commit bee4c51ff8bd3b86ce16440153b88b316ce482fd
Author: Miklos Vajna 
AuthorDate: Tue Dec 13 12:31:11 2022 +0100
Commit: Miklos Vajna 
CommitDate: Wed Dec 14 08:51:52 2022 +0100

sw, createTextRangeByPixelPosition(): fix crash with at-page anchored images

When createTextRangeByPixelPosition() was called with a position that is
inside an at-page anchored image, we crashed.

The problem is that in general we can't create an XTextRange for a
graphic node. We already tried to return the anchor position for graphic
nodes since 2302ebefb2e25878e8fe1e64d208f265f87d5b9b (sw,
createTextRangeByPixelPosition(): fix crash when the position is an
image, 2022-11-22), but that fixed the problem only in case
GetContentAnchor() gave us a doc model position.

Fix the problem by returning an empty reference in the "graphic node but
no content anchor" case, that is still better for at-page and at-frame
anchored images than a crash.

A follow-up change could be to add a new API that has a more generic
return type (similar to how getSelection() returns `any`) and then
return the image itself, not its anchor in the image case. That approach
would work for at-page and at-frame anchored images as well.

(cherry picked from commit 41071f58415927b257eab66b2674d521607bdee5)

Conflicts:
sw/qa/uibase/uno/uno.cxx

Change-Id: If850ec945c24052568230a83da2ae2aa004b4265

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index 8085798d8f4d..540917c1744a 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -95,6 +95,49 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, 
testCreateTextRangeByPixelPositionGraphic)
 CPPUNIT_ASSERT_EQUAL(aAnchorPos, *aPaM.GetPoint());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, 
testCreateTextRangeByPixelPositionAtPageGraphic)
+{
+// Given a document with an at-page anchored image:
+mxComponent = loadFromDesktop("private:factory/swriter", 
"com.sun.star.text.TextDocument");
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextGraphic(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xTextGraphic->setPropertyValue("AnchorType", 
uno::Any(text::TextContentAnchorType_AT_PAGE));
+xTextGraphic->setPropertyValue("AnchorPageNo", 
uno::Any(static_cast(1)));
+xTextGraphic->setPropertyValue("Width", 
uno::Any(static_cast(1)));
+xTextGraphic->setPropertyValue("Height", 
uno::Any(static_cast(1)));
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBodyText = xTextDocument->getText();
+uno::Reference xCursor(xBodyText->createTextCursor());
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xBodyText->insertTextContent(xCursor, xTextContent, false);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+SwDocShell* pDocShell = pDoc->GetDocShell();
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+SwRootFrame* pLayout = pWrtShell->GetLayout();
+SwFrame* pPage = pLayout->GetLower();
+SwSortedObjs& rDrawObjs = *pPage->GetDrawObjs();
+SwAnchoredObject* pAnchored = rDrawObjs[0];
+Point aLogic = pAnchored->GetObjRect().Center();
+SwView* pView = pDocShell->GetView();
+SwEditWin& rEditWin = pView->GetEditWin();
+Point aPixel = rEditWin.LogicToPixel(aLogic);
+
+// When asking for the doc model pos of the image's anchor by pixel 
position:
+uno::Reference xModel(mxComponent, uno::UNO_QUERY);
+uno::Reference xControllers = 
xModel->getControllers();
+uno::Reference 
xController(xControllers->nextElement(),
+ 
uno::UNO_QUERY);
+awt::Point aPoint(aPixel.getX(), aPixel.getY());
+// Without the accompanying fix in place, this test would have crashed.
+uno::Reference xTextRange
+= xController->createTextRangeByPixelPosition(aPoint);
+
+// Then make sure that the result is empty, since the image is at-page 
anchored:
+CPPUNIT_ASSERT(!xTextRange.is());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index 821ec11fe934..b4086cdef474 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -543,6 +543,11 @@ SwXTextView::createTextRangeByPixelPosition(const 
awt::Point& rPixelPosition)
 {
 aPosition = *pAnchor;
 }
+else
+{
+// Page-anchored graphics have no anchor.
+return {};
+}
 }
 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-12-12 Thread Miklos Vajna (via logerrit)
 sw/qa/core/layout/data/page-remove-fly-table.odt |binary
 sw/qa/core/layout/layout.cxx |   40 +++
 sw/source/core/layout/flylay.cxx |   11 ++
 3 files changed, 51 insertions(+)

New commits:
commit ee9e7a6645dca3d79d784fdda8dd1cd003f1b998
Author: Miklos Vajna 
AuthorDate: Fri Dec 9 16:52:48 2022 +0100
Commit: Miklos Vajna 
CommitDate: Mon Dec 12 10:00:27 2022 +0100

sw layout: invalidate margins of body content when moving a fly from page

The (simplified) bugdoc has 9 pages, and once the ToC is updated, the
two tables below the (only) bookmark in the document has a 5879 twips
gap between them for no reason. Adding a new paragraph to the second
table "fixes" the incremental layout.

What seems to happen is that there is an anchored image on page 8, but
the layout decides that it doesn't fit there so it gets moved to page 9.
Before this move happens, SwTabFrame::Format() handles the outer of the
nested table below the unwanted gap and its CalcFlyOffsets() notices
that a large upper margin is wanted so that the table wraps around the
anchored image. Later the image gets moved to the next page, but the
removal doesn't invalidate the print area of the table with the large
top margin, so the unwanted gap appears.

Fix the problem by looking at the old page in SwPageFrame::MoveFly() and
walking through the immediate children of the body frame: if the frame
print area is invalidated, then SetYMargins() is called from
SwTabFrame::Format(), which also invalidates the size of the outer table
frame, so it will use Shrink() to have a correct size.

This appears to be a regression from commit
b9ef71476fd70bc13f50ebe80390e0730d1b7afb (tdf#134298 sw: layout: remove
left-over page frame without content, 2020-11-13).

(cherry picked from commit cf2c070de2bafeec3b476c6bff7bb4ac87ba46db)

Conflicts:
sw/qa/core/layout/layout.cxx

Change-Id: I0424d9eea4d8a030959f8534985950c7efad4686

diff --git a/sw/qa/core/layout/data/page-remove-fly-table.odt 
b/sw/qa/core/layout/data/page-remove-fly-table.odt
new file mode 100644
index ..6aaf230966ef
Binary files /dev/null and b/sw/qa/core/layout/data/page-remove-fly-table.odt 
differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 4cc7390d63f9..1f8e2e8e5482 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -10,8 +10,16 @@
 #include 
 
 #include 
+#include 
+#include 
 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 static char const DATA_DIRECTORY[] = "/sw/qa/core/layout/data/";
 
@@ -164,6 +172,38 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, 
testKeepwithnextFullheight)
 assertXPath(pXmlDoc, "//page[2]/body/txt/anchored/fly", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testPageRemoveFlyTable)
+{
+// Given a document with a ToC and several tables, one table marked with a 
bookmark:
+load(DATA_DIRECTORY, "page-remove-fly-table.odt");
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwDocShell* pShell = pTextDoc->GetDocShell();
+SwDoc* pDoc = pShell->GetDoc();
+
+// When updating the ToC and incrementally formatting the document:
+SwView* pView = pDoc->GetDocShell()->GetView();
+SfxDispatcher& rDispatcher = *pView->GetViewFrame()->GetDispatcher();
+rDispatcher.Execute(FN_UPDATE_TOX);
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Reformat();
+
+// Then make sure that the 2nd table below the bookmark has no unwanted 
top margin:
+pWrtShell->GotoMark("test");
+pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false);
+pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false);
+SwPaM* pCursor = pWrtShell->GetCursor();
+SwTextNode* pTextNode = pCursor->GetPoint()->nNode.GetNode().GetTextNode();
+SwFrame* pTextFrame = pTextNode->getLayoutFrame(nullptr);
+SwTabFrame* pInnerTable = pTextFrame->FindTabFrame();
+SwTabFrame* pOuterTable = pInnerTable->GetUpper()->FindTabFrame();
+long nActual = pOuterTable->getFramePrintArea().Top();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 0
+// - Actual  : 5879
+// i.e. the bad table had a large, unwanted/leftover top margin.
+CPPUNIT_ASSERT_EQUAL(static_cast(0), nActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index 72d673b224d4..b8f586938454 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -987,6 +987,17 @@ void SwPageFrame::MoveFly( SwFlyFrame *pToMove, 
SwPageFrame *pDest )
 {
 m_pSortedObjs.reset();
 }
+
+// Removing a fly from 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-10-18 Thread Miklos Vajna (via logerrit)
 sw/qa/core/doc/doc.cxx   |   86 +++
 sw/source/core/doc/docbm.cxx |   21 +-
 2 files changed, 104 insertions(+), 3 deletions(-)

New commits:
commit 61c467d0ccd97b8d69d6085e25e5e3f3395f2201
Author: Miklos Vajna 
AuthorDate: Tue Oct 18 09:22:29 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Oct 18 11:56:07 2022 +0200

sw: fix crash on deleting a bookmark with active selection listeners

The document had a registered selection listener that created UNO
cursors (bookmarks) in its selectionChanged() callback. Once an UNO API
user tried to delete a bookmark, Writer crashed.

What happens is that sw::mark::MarkManager::deleteMark() created an
iterator pointing to an element of m_vAllMarks, then called
sw::mark::Bookmark::DeregisterFromDoc(), which indirectly calls
SwXTextView::NotifySelChanged(), which invokes UNO selection listeners,
which are allowed to create UNO cursors, which modify m_vAllMarks,
invalidating the iterator.

Fix the problem by first creating a non-const iterator based on ppMark,
then conditionally invoke DeregisterFromDoc(). If DeregisterFromDoc() is
called, then update the iterator based on pMark, so it is valid by the
time we erase the bookmark from m_vAllMarks.

This was not the problem when erasing the same mark from m_vBookmarks,
as in that case the iterator creation and the erase() both happen before
the de-registration.

(cherry picked from commit e9861d8e0138028c17e93fec277125e7752439bd)

Conflicts:
sw/qa/core/doc/doc.cxx
sw/source/core/doc/docbm.cxx

Change-Id: Iaae95ec9c3038e8ee3b84408094844d0ff678213

diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index 59a73751308d..1cefc11e55c9 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -9,6 +9,8 @@
 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -110,6 +112,90 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, 
testImageHyperlinkStyle)
 CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
 }
 
+namespace
+{
+/// This selection listener calls getAnchor() on selection change, which 
creates UNO cursors and is
+/// invoked in the middle of a bookmark deletion.
+struct SelectionChangeListener : public 
cppu::WeakImplHelper
+{
+uno::Reference m_xBookmarks;
+std::vector> m_aAnchors;
+
+public:
+SelectionChangeListener(const uno::Reference& 
xBookmarks);
+// view::XSelectionChangeListener
+void SAL_CALL selectionChanged(const lang::EventObject& rEvent) override;
+
+// lang::XEventListener
+void SAL_CALL disposing(const lang::EventObject& rSource) override;
+};
+}
+
+SelectionChangeListener::SelectionChangeListener(
+const uno::Reference& xBookmarks)
+: m_xBookmarks(xBookmarks)
+{
+}
+
+void SelectionChangeListener::selectionChanged(const lang::EventObject& 
/*rEvent*/)
+{
+uno::Sequence aElementNames = m_xBookmarks->getElementNames();
+for (const auto& rName : aElementNames)
+{
+uno::Reference 
xTextContent(m_xBookmarks->getByName(rName),
+uno::UNO_QUERY);
+m_aAnchors.push_back(xTextContent->getAnchor());
+}
+}
+
+void SelectionChangeListener::disposing(const lang::EventObject& /*rSource*/) 
{}
+
+CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testBookmarkDeleteListeners)
+{
+// Given a document with 2 bookmarks:
+createDoc();
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+{
+xText->insertString(xCursor, "test", /*bAbsorb=*/false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBookmark(
+xFactory->createInstance("com.sun.star.text.Bookmark"), 
uno::UNO_QUERY);
+uno::Reference xBookmarkNamed(xBookmark, 
uno::UNO_QUERY);
+xBookmarkNamed->setName("mybookmark");
+xText->insertTextContent(xCursor, xBookmark, /*bAbsorb=*/true);
+}
+{
+xCursor->gotoEnd(/*bExpand=*/false);
+xText->insertString(xCursor, "test2", /*bAbsorb=*/false);
+xCursor->goLeft(4, /*bExpand=*/true);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBookmark(
+xFactory->createInstance("com.sun.star.text.Bookmark"), 
uno::UNO_QUERY);
+uno::Reference xBookmarkNamed(xBookmark, 
uno::UNO_QUERY);
+xBookmarkNamed->setName("mybookmark2");
+xText->insertTextContent(xCursor, xBookmark, /*bAbsorb=*/true);
+}
+uno::Reference xBookmarksSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBookmarks = 
xBookmarksSupplier->getBookmarks();
+
+// When registering a selection listener that creates uno marks:
+uno::Reference 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-09-27 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   78 +---
 sw/qa/filter/html/html.cxx  |   39 
 sw/qa/inc/swmodeltestbase.hxx   |   13 +
 sw/source/filter/html/htmlflywriter.cxx |7 ++
 4 files changed, 91 insertions(+), 46 deletions(-)

New commits:
commit 6627358f67ac71eac6b5e13c08f8a1bd89954399
Author: Miklos Vajna 
AuthorDate: Mon Sep 26 15:40:29 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Sep 27 11:09:40 2022 +0200

sw HTML export: fix PNG export of Writer images containing metafiles

We attempted to export SVM metafiles as SVM+PNG, but then the SVM was
turned into GIF. A GIF+PNG pair is not useful, just write PNG.

This is similar to commit c8a9396e5695675ffe92935a9ba40354fc76ed79 (sw
XHTML / reqif export: fix PNG export of shapes, 2021-06-03), which did
the same for non-SdrGrafObj shapes.

(cherry picked from commit 92259b092e7271a638c2f88d7565983dfe49f0b1)

Conflicts:
sw/qa/inc/swmodeltestbase.hxx
sw/qa/unit/swmodeltestbase.cxx

Change-Id: I1a0ab266473787d263573b4813dc19426e272435

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 442feecaa145..19e40fb1c256 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -183,20 +183,6 @@ public:
 m_eUnit(FieldUnit::NONE)
 {}
 
-/**
- * Wraps a reqif-xhtml fragment into an XHTML file, so an XML parser can
- * parse it.
- */
-static void wrapFragment(const utl::TempFile& rTempFile, SvMemoryStream& 
rStream)
-{
-rStream.WriteCharPtr(
-"http://www.w3.org/1999/xhtml\;>\n");
-SvFileStream aFileStream(rTempFile.GetURL(), StreamMode::READ);
-rStream.WriteStream(aFileStream);
-rStream.WriteCharPtr("\n");
-rStream.Seek(0);
-}
-
 /// Wraps an RTF fragment into a complete RTF file, so an RTF parser can 
handle it.
 static void wrapRtfFragment(const OUString& rURL, SvMemoryStream& rStream)
 {
@@ -279,7 +265,7 @@ public:
 OUString SwHtmlDomExportTest::GetOlePath()
 {
 SvMemoryStream aStream;
-HtmlExportTest::wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 CPPUNIT_ASSERT(pDoc);
 OUString aOlePath = getXPath(
@@ -295,7 +281,7 @@ OUString SwHtmlDomExportTest::GetOlePath()
 OUString SwHtmlDomExportTest::GetPngPath()
 {
 SvMemoryStream aStream;
-HtmlExportTest::wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 CPPUNIT_ASSERT(pDoc);
 OUString aPngPath = getXPath(
@@ -787,7 +773,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqIfTableHeight)
 
 // Then make sure that the explicit cell height is omitted from the output:
 SvMemoryStream aStream;
-HtmlExportTest::wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 // Without the accompanying fix in place, this test would have failed, 
explicit height was
 // written, which is not valid reqif-xhtml.
@@ -847,7 +833,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOle2, 
"reqif-ole2.xhtml")
 {
 // Check that the replacement graphic is exported at RTF level.
 SvMemoryStream aStream;
-wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 CPPUNIT_ASSERT(pDoc);
 // Get the path of the RTF data.
@@ -919,7 +905,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTransparentImageReqIf)
 };
 xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
 SvMemoryStream aStream;
-HtmlExportTest::wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 CPPUNIT_ASSERT(pDoc);
 
@@ -936,7 +922,7 @@ DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, 
"reqif-ole-nodata.odt")
 {
 // This failed, io::IOException was thrown during the filter() call.
 SvMemoryStream aStream;
-wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 CPPUNIT_ASSERT(pDoc);
 
@@ -951,7 +937,7 @@ DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, 
"reqif-ole-nodata.odt")
 DECLARE_HTMLEXPORT_TEST(testNoLangReqIf, "reqif-no-lang.odt")
 {
 SvMemoryStream aStream;
-wrapFragment(maTempFile, aStream);
+WrapReqifFromTempFile(aStream);
 xmlDocUniquePtr pDoc = parseXmlStream();
 CPPUNIT_ASSERT(pDoc);
 
@@ -1003,7 +989,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testBlockQuoteReqIf)
 aMediaDescriptor["FilterOptions"] <<= OUString("xhtmlns=reqif-xhtml");
 xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
 SvMemoryStream aStream;
-

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-08-31 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/data/paint-ole-bitmap-format.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx   |   33 +++
 sw/source/filter/html/htmlreqifreader.cxx|6 ++
 3 files changed, 39 insertions(+)

New commits:
commit b33fe3f5435745daf04758675750033468ac6b3c
Author: Miklos Vajna 
AuthorDate: Tue Aug 30 15:00:19 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Aug 31 15:40:12 2022 +0200

sw reqif/xhtml export: fix invalid pixel formats of graphics exported as OLE

When exporting a Writer document to reqif-xhtml in ExportImagesAsOLE
mode with something like:

soffice.bin --convert-to 'xhtml:HTML 
(StarWriter):{"XhtmlNs":{"type":"string","value":"reqif-xhtml"},"ExportImagesAsOLE":{"type":"boolean","value":"true"}}'
 test.odt

images are exported as ms paint ole objects instead of plain images.

This happens in WrapGraphicInRtf(), using GraphicConverter::Export()
where we just specify we want a BMP output. This usually works, but not
when the bitmap format is something exotic where we try to keep that
format in BMP, but ms paint can't handle it. When this happens, we get
an RPC_E_SERVERFAULT error from OleRun() in OleComponent::RunObject(),
which doesn't say much, except that ms paint failed to read the byte
array we handed out.

Fix the problem by ensuring that if a graphic is exported as OLE data,
then it always has the 24bit pixel format.

Interestingly a 8bit BMP can be opened in ms paint manually, but not
when embedding it as OLE object.

(cherry picked from commit 13219c632b7ec154ba882a715cf890b54f10b146)

Change-Id: I2285bf67c4528cde208ae9fba42ece56822f5403

diff --git a/sw/qa/extras/htmlexport/data/paint-ole-bitmap-format.odt 
b/sw/qa/extras/htmlexport/data/paint-ole-bitmap-format.odt
new file mode 100644
index ..d83b89459773
Binary files /dev/null and 
b/sw/qa/extras/htmlexport/data/paint-ole-bitmap-format.odt differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 9d2aed175a66..442feecaa145 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -1266,6 +1267,38 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifOle1Paint)
 CPPUNIT_ASSERT_EQUAL(OString("PBrush"), aClassName);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PaintBitmapFormat)
+{
+// Given a document with a 8bpp bitmap:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"paint-ole-bitmap-format.odt";
+mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {});
+
+// When exporting to reqif-xhtml with ExportImagesAsOLE enabled:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+comphelper::makePropertyValue("ExportImagesAsOLE", true),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure the resulting bitmap is 24bpp:
+OUString aRtfUrl = GetOlePath();
+SvMemoryStream aOle1;
+ParseOle1FromRtfUrl(aRtfUrl, aOle1);
+OLE1Reader aOle1Reader(aOle1);
+Bitmap aBitmap;
+SvMemoryStream aMemory;
+aMemory.WriteBytes(aOle1Reader.m_aNativeData.data(), 
aOle1Reader.m_aNativeData.size());
+aMemory.Seek(0);
+CPPUNIT_ASSERT(ReadDIB(aBitmap, aMemory, true));
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 24
+// - Actual  : 8
+// i.e. it was not a pixel format ms paint could handle in OLE mode.
+CPPUNIT_ASSERT_EQUAL(static_cast(24), aBitmap.GetBitCount());
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testMultiParaListItem)
 {
 // Create a document with 3 list items: A, B and D.
diff --git a/sw/source/filter/html/htmlreqifreader.cxx 
b/sw/source/filter/html/htmlreqifreader.cxx
index a091183b9f69..894b78d99d20 100644
--- a/sw/source/filter/html/htmlreqifreader.cxx
+++ b/sw/source/filter/html/htmlreqifreader.cxx
@@ -550,6 +550,12 @@ bool WrapGraphicInRtf(const Graphic& rGraphic, const 
SwFrameFormat& rFormat, SvS
 BitmapEx aBitmapEx = rGraphic.GetBitmapEx();
 Bitmap aBitmap = 
aBitmapEx.GetBitmap(/*aTransparentReplaceColor=*/COL_WHITE);
 
+if (aBitmap.GetBitCount() != 24)
+{
+// More exotic pixel formats cause trouble for ms paint.
+aBitmap.Convert(BmpConversion::N24Bit);
+}
+
 if (GraphicConverter::Export(aNativeData, BitmapEx(aBitmap), 
ConvertDataFormat::BMP)
 != ERRCODE_NONE)
 {


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-08-18 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlimport/data/ole-data2.xhtml |   12 
 sw/qa/extras/htmlimport/htmlimport.cxx   |   25 +
 sw/source/filter/html/htmlgrin.cxx   |1 +
 3 files changed, 38 insertions(+)

New commits:
commit 47fa0fbb17bbe4f3edda9ad1563225a488bfb8a7
Author: Miklos Vajna 
AuthorDate: Wed Aug 17 10:32:16 2022 +0200
Commit: Miklos Vajna 
CommitDate: Thu Aug 18 15:50:39 2022 +0200

sw XHTML import: fix unexpected link on image

The trouble was that once an image got a pending link applied, the
remaining images also got that link in case they didn't have an own
link.

This was a problem since commit 56769d3982e6afb075cb6d833662f066437fab6a
(sw XHTML import: handle non-image, non-RTF objects as clickable images,
2022-05-24), the pending URL is not updated after it's applied.

Fix the problem by clearing the pending URL, since we know that one
pending URL is always applied just once.

(cherry picked from commit ee3ebda2be3965584d12b52c007fb047d624b64c)

Change-Id: I0a363330fbcc1dec95f90f56dc7c420249769e2a

diff --git a/sw/qa/extras/htmlimport/data/ole-data2.xhtml 
b/sw/qa/extras/htmlimport/data/ole-data2.xhtml
new file mode 100644
index ..0eb180e6ca63
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/ole-data2.xhtml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx 
b/sw/qa/extras/htmlimport/htmlimport.cxx
index 326af44fb298..b3b47c06f9cb 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -516,6 +516,31 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData)
 CPPUNIT_ASSERT(getProperty(xShape, 
"HyperLinkURL").endsWith("/data.ole"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData2)
+{
+// Given an XHTML with 2 objects: the first has a link, the second does 
not have:
+uno::Sequence aLoadProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+};
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"ole-data2.xhtml";
+
+// When loading the document:
+mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", 
aLoadProperties);
+
+// Then make sure that the second image doesn't have a link set:
+uno::Reference xSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference 
xObjects(xSupplier->getGraphicObjects(),
+ uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(static_cast(2), xObjects->getCount());
+uno::Reference xShape = getShape(1);
+CPPUNIT_ASSERT(getProperty(xShape, 
"HyperLinkURL").endsWith("/data.ole"));
+xShape = getShape(2);
+// Without the accompanying fix in place, this test would have failed, the 
link from the 1st
+// image leaked to the 2nd image.
+CPPUNIT_ASSERT(getProperty(xShape, "HyperLinkURL").isEmpty());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlgrin.cxx 
b/sw/source/filter/html/htmlgrin.cxx
index 2a8e8c46dc13..b1bd3d445265 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -871,6 +871,7 @@ IMAGE_SETEVENT:
 // image.
 SwFormatURL aURL(pFlyFormat->GetURL());
 aURL.SetURL(m_aEmbedURL, bIsMap);
+m_aEmbedURL.clear();
 pFlyFormat->SetFormatAttr(aURL);
 }
 


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-07-27 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |5 ++---
 sw/source/filter/html/wrthtml.cxx  |8 
 2 files changed, 10 insertions(+), 3 deletions(-)

New commits:
commit b9d4e9c3c10f0d76ecf83dbd259ba6e5544836e9
Author: Miklos Vajna 
AuthorDate: Tue Jul 26 13:47:54 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jul 27 13:41:24 2022 +0200

sw reqif-xhtml export: fix duplicated bookmark names in fragments

The problem was that exporting multiple documents to reqif fragments and
then combining them to a single document resulted in non-unique bookmark
identifiers, even if they were unique in the original source documents.

Writer already tries to ensure unique bookmark names, but if the export
result is not a full document on its own, this is not enough. On the
other hand, bookmarks in these fragments are almost always used
unintentionally.

Fix the problem by keeping the bookmark output in the HTML/XHTML case,
but disable it for ReqIF.

Note that we disable unique anchors in general, so this fixes the same
problem with section anchors as well.

(cherry picked from commit 4e6327c673075ab4a44f497a06a8dbf759c1a72a)

Change-Id: Ib47d1589fa08d205b7904e21656c937bfbca0a2f

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 851d8409b549..9d2aed175a66 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -620,9 +620,8 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
 // This was "" instead of CSS + namespace prefix was missing.
 CPPUNIT_ASSERT(aStream.indexOf("") != -1);
+// This was '': non-unique bookmark name in reqif 
fragment.
+CPPUNIT_ASSERT_EQUAL(static_cast(-1), 
aStream.indexOf(" has to be unique inside the whole document, but
+// we only write a fragment, so we can't ensure the ID is indeed
+// unique. Just don't write anchors in the ReqIF case.
+return;
+}
+
 OStringBuffer sOut;
 sOut.append("<" + GetNamespace() + OOO_STRING_SVTOOLS_HTML_anchor " ");
 if (!mbXHTML)


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-07-22 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |   24 
 sw/source/filter/html/css1atr.cxx  |   11 +++
 sw/source/filter/html/css1kywd.cxx |1 +
 sw/source/filter/html/css1kywd.hxx |1 +
 sw/source/filter/html/wrthtml.cxx  |7 +--
 5 files changed, 42 insertions(+), 2 deletions(-)

New commits:
commit 7a8665b51f911835a593cfe754c3e10b6cdab662
Author: Miklos Vajna 
AuthorDate: Thu Jul 21 15:40:58 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Jul 22 13:22:34 2022 +0200

sw XHTML export: fix writing of section direction

The XHTML export behavior was the same as the HTML one for section text
direction, the  markup was used.

This shares code with the HTML filter, but it's not valid in
reqif-xhtml, while the CSS markup would be fine: .

Fix the problem by keeping the behavior unchanged for HTML, but switch
to inline CSS for XHTML.

The other similar attribute was "id", but that's fine even in XHTML.

(cherry picked from commit 3b7c18a579f3165c9d425d172d697f8978d6cd84)

Change-Id: I5797c90f9cf957dec7fc4074dd6e79dce11fada7

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 1d03d107fd09..851d8409b549 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2286,6 +2286,30 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio)
 assertXPath(pDoc, "/html/body/p/img", "height", "auto");
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSectionDir)
+{
+// Given a document with a section:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("test");
+pWrtShell->SelAll();
+SwSectionData aSectionData(SectionType::Content, "mysect");
+pWrtShell->InsertSection(aSectionData);
+
+// When exporting to (reqif-)xhtml:
+ExportToReqif();
+
+// Then make sure CSS is used to export the text direction of the section:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+// Without the accompanying fix in place, this test would have failed with:
+// - XPath '//reqif-xhtml:div[@id='mysect']' no attribute 'style' exist
+// i.e. the dir="ltr" HTML attribute was used instead.
+assertXPath(pXmlDoc, "//reqif-xhtml:div[@id='mysect']", "style", "dir: 
ltr");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/css1atr.cxx 
b/sw/source/filter/html/css1atr.cxx
index 18ee264324f6..8a0bc881e1c8 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -2143,6 +2143,17 @@ void SwHTMLWriter::OutCSS1_SectionFormatOptions( const 
SwFrameFormat& rFrameForm
 if( SfxItemState::SET==rItemSet.GetItemState( RES_BACKGROUND, false, 
 ) )
 OutCSS1_SvxBrush( *this, *pItem, sw::Css1Background::Section, nullptr 
);
 
+if (mbXHTML)
+{
+SvxFrameDirection nDir = GetHTMLDirection(rFrameFormat.GetAttrSet());
+OString sConvertedDirection = convertDirection(nDir);
+if (!sConvertedDirection.isEmpty())
+{
+OutCSS1_Property(sCSS1_P_dir, sConvertedDirection.getStr(), 
nullptr,
+ sw::Css1Background::Section);
+}
+}
+
 if (pCol)
 {
 OString 
sColumnCount(OString::number(static_cast(pCol->GetNumCols(;
diff --git a/sw/source/filter/html/css1kywd.cxx 
b/sw/source/filter/html/css1kywd.cxx
index f8914dedb274..c0299e28c958 100644
--- a/sw/source/filter/html/css1kywd.cxx
+++ b/sw/source/filter/html/css1kywd.cxx
@@ -197,6 +197,7 @@ const char* const sCSS1_P_height = "height";
 const char* const sCSS1_P_float = "float";
 
 const char* const sCSS1_P_column_count = "column-count";
+const char* const sCSS1_P_dir = "dir";
 
 // Strings for positioning
 
diff --git a/sw/source/filter/html/css1kywd.hxx 
b/sw/source/filter/html/css1kywd.hxx
index 7c0e326fd86a..c4609c5659b1 100644
--- a/sw/source/filter/html/css1kywd.hxx
+++ b/sw/source/filter/html/css1kywd.hxx
@@ -200,6 +200,7 @@ extern const char* const sCSS1_P_height;
 extern const char* const sCSS1_P_float;
 
 extern const char* const sCSS1_P_column_count;
+extern const char* const sCSS1_P_dir;
 
 // Strings for positioning
 
diff --git a/sw/source/filter/html/wrthtml.cxx 
b/sw/source/filter/html/wrthtml.cxx
index 238dbf36060a..8aeaf9c32fac 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -715,9 +715,12 @@ static void lcl_html_OutSectionStartTag( SwHTMLWriter& 
rHTMLWrt,
 sOut.append('\"');
 }
 
-SvxFrameDirection nDir = rHTMLWrt.GetHTMLDirection( rFormat.GetAttrSet() );
 rHTMLWrt.Strm().WriteOString( sOut.makeStringAndClear() );
-

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-06-17 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   41 
 sw/source/filter/html/htmlatr.cxx   |   12 +++--
 sw/source/filter/html/htmlnumwriter.cxx |4 ++-
 sw/source/filter/html/wrthtml.hxx   |3 +-
 4 files changed, 56 insertions(+), 4 deletions(-)

New commits:
commit eb0cd13590ae93410d831e689922c263ea75face
Author: Miklos Vajna 
AuthorDate: Thu Jun 16 15:55:23 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Jun 17 08:50:48 2022 +0200

sw HTML export, XHTML mode: fix lost  with a list header + item

There is a general mismatch between XHTML and Writer lists: XHTML can
only contain list items (for ordered or unordered lists), while Writer
can contain list headers and list items. List headers have no bullet or
number at the start, list items are the normal text nodes.

Commit 8c2607ae3ce143586e623532b8ae5288277ec3ac (sw HTML export, XHTML
mode: fix lost  when last list item is not numbered, 2022-02-21)
fixed the list item end side of this problem: if all text nodes in a
list are headers, then don't write ul/ol at all, otherwise end list
headers with  as well to make sure the output XML is valid.
However, this created a mis-match, the starting  for list headers in
a list which have non-header text nodes at as was not adapted.

Fix the problem by extending OutHTML_SwFormat() so list headers in a
list with non-header text nodes always have a  and , and this
condition is the same on the start/end side.

Calculating if at least one text node is non-header in a list may not be
cheap, so reuse the already calculated info from
OutHTML_NumberBulletListStart() in OutHTML_SwFormat().

(cherry picked from commit b2bee5a4db5552c4d408800908ca717b4ea2564a)

Change-Id: I3817a489f16166fc5b4c33ee64e2283c41a4402c

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 7b9128e8d32a..1d03d107fd09 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1512,6 +1512,47 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testPartiallyNumberedList)
 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeaderAndItem)
+{
+// Given a document with a list, first para is not numbered, but the 
second is:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("not numbered");
+SwDoc* pDoc = pWrtShell->GetDoc();
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+pWrtShell->SplitNode();
+pWrtShell->Insert2("numbered");
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+}
+
+// When exporting to ReqIF:
+ExportToReqif();
+
+// Then make sure the output is well-formed xhtml:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+// Without the accompanying fix in place, this test would have failed:
+// Entity: line 3: parser error : Opening and ending tag mismatch: ol line 
3 and li
+// not 
numbered
+CPPUNIT_ASSERT(pXmlDoc);
+// Make sure that in case the list has a header and an item, then both are 
wrapped in an 
+// element.
+assertXPath(pXmlDoc,
+
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin)
 {
 // Given a document with some text, para style set to Quotations, no 
bottom margin:
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index 8f8d0c1fa080..24ae4cbc1713 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -686,11 +686,12 @@ static void OutHTML_SwFormat( Writer& rWrt, const 
SwFormat& rFormat,
 if( nNewDefListLvl != rHWrt.m_nDefListLvl )
 rHWrt.OutAndSetDefList( nNewDefListLvl );
 
+bool bAtLeastOneNumbered = false;
 // if necessary, start a bulleted or numbered list
 if( rInfo.bInNumberBulletList )
 {
 OSL_ENSURE( !rHWrt.m_nDefListLvl, "DL cannot be inside OL!" );
-OutHTML_NumberBulletListStart( rHWrt, aNumInfo );
+OutHTML_NumberBulletListStart( rHWrt, aNumInfo, 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-05-18 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   34 +
 sw/source/filter/html/htmlflywriter.cxx |   50 
 2 files changed, 78 insertions(+), 6 deletions(-)

New commits:
commit cd5f5cbcc71e4dd403539f65b578a3256121f377
Author: Miklos Vajna 
AuthorDate: Tue May 17 16:11:25 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed May 18 09:41:10 2022 +0200

sw HTML export: avoid pixel height when height is scale and width is 
relative

Commit b17180a84cb4561b8a7bbf9e2281c91fffd56f87 (write out image size in
html export for 'keep ratio' images, 2021-06-29) changed the sw HTML
export to write the layout size of images in case one dimension is "keep
ratio" and the other is some more concrete value.

This is useful in case that other dimension is a fixed value, because
"keep ratio" on the UI only means to keep the ratio as the size changes,
it does not mean that the ratio will be the original ratio of the
bitmap. However, it's problematic to write this layout size of the "keep
ratio" dimension when the other dimension is relative, as this will mean
the image's aspect ratio will change if the user resizes the browser
window.

Fix the problem by extending the way we write the "height" and "width"
of fly frames:

1) Write a percentage in case of relative sizes

2) Write an explicit "auto" (or just omit the attribute in XHTML mode)
   in case the size is "keep ratio" and the other dimension is a
   relative size

3) Write the layout size in other cases (fixed size or "keep ratio", but
   the other dimension is a fixed size)

Note that HTML itself has no concept of relative sizes where 100% is not
the parent's size (e.g. page, not paragraph) and also has no concept of
keeping an aspect ratio which is not the aspect ratio of the bitmap, so
those cases remain unchanged.

(cherry picked from commit 9e3eee88338c45424b24040f731083f9f59cfbe2)

Change-Id: Ic5c7dc4d697160eff81e960a2f7d335fb78ab7c0

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 5569c1205557..8e78b288566f 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2207,6 +2207,40 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTableBackground)
 assertXPathNoAttribute(pXmlDoc, 
"//reqif-xhtml:table[2]/reqif-xhtml:tr[1]", "bgcolor");
 }
 
+CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio)
+{
+// Given a document with an image: width is relative, height is "keep 
ratio":
+loadURL("private:factory/swriter", nullptr);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextGraphic(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xTextGraphic->setPropertyValue("AnchorType",
+   
uno::Any(text::TextContentAnchorType_AS_CHARACTER));
+xTextGraphic->setPropertyValue("RelativeWidth", 
uno::Any(static_cast(42)));
+xTextGraphic->setPropertyValue("IsSyncHeightToWidth", uno::Any(true));
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBodyText = xTextDocument->getText();
+uno::Reference xCursor(xBodyText->createTextCursor());
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xBodyText->insertTextContent(xCursor, xTextContent, false);
+
+// When exporting to HTML:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure that the width is not a fixed size, that would break on 
resizing the browser
+// window:
+htmlDocUniquePtr pDoc = parseHtml(maTempFile);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: auto
+// - Actual  : 2
+// i.e. a static (CSS pixel) height was written.
+assertXPath(pDoc, "/html/body/p/img", "height", "auto");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 2e19d5395796..01553a363c82 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -990,22 +990,60 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& 
aHtml, const SwFrameForma
 ((nPercentWidth && nPercentWidth!=255) || aPixelSz.Width()) )
 {
 OString sWidth;
-if (nPercentWidth && nPercentWidth != 255)
-sWidth = 
OString::number(static_cast(nPercentWidth)) + "%";
+if (nPercentWidth)
+{
+if (nPercentWidth == 255)
+{
+ 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-04-08 Thread Miklos Vajna (via logerrit)
 sw/qa/core/doc/doc.cxx|   28 
 sw/source/core/doc/docfly.cxx |2 +-
 2 files changed, 29 insertions(+), 1 deletion(-)

New commits:
commit 0983dca4d64f3099c9cfe6341e9c219ea37e9aa5
Author: Miklos Vajna 
AuthorDate: Thu Apr 7 16:59:32 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 8 16:44:23 2022 +0200

sw: keep URL when applying frame style on images

It seems that the intention is to reset properties which are possible to
set in a style when applying a style. For example the paragraph
alignment can be defined in a paragraph style, so reset that on style
apply.

URLs on frames can't be defined for frame styles, so it looks incorrect
to reset the URL of a frame/image on style apply, fix this.

(cherry picked from commit 97c18cf32a9a3088b5a51e2b0d535d8caf5daca8)

Conflicts:
sw/qa/core/doc/doc.cxx

Change-Id: Ie3a57b654cf06b9512b25d2dc103d15cd83727b7

diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index a8489e01a274..59a73751308d 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -82,6 +82,34 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, 
testTextboxTextRotateAngle)
 ErrorRegistry::Reset();
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testImageHyperlinkStyle)
+{
+// Given a document with an image with a hyperlink:
+loadURL("private:factory/swriter", nullptr);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xDocument(mxComponent, uno::UNO_QUERY);
+uno::Reference xText = xDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+uno::Reference xImage(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xImage, /*bAbsorb=*/false);
+uno::Reference xImageProps(xImage, uno::UNO_QUERY);
+OUString aExpected = "http://www.example.com;;
+xImageProps->setPropertyValue("HyperLinkURL", uno::makeAny(aExpected));
+
+// When applying a frame style on it:
+xImageProps->setPropertyValue("FrameStyleName", 
uno::makeAny(OUString("Frame")));
+
+// Then make sure that the hyperlink is not lost:
+auto aActual = getProperty(xImageProps, "HyperLinkURL");
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: http://www.example.com
+// - Actual  :
+// i.e. the link was lost, even if the frame style dialog doesn't allow 
specifying a link on
+// frames.
+CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx
index e435920da879..b5aa5465cdc8 100644
--- a/sw/source/core/doc/docfly.cxx
+++ b/sw/source/core/doc/docfly.cxx
@@ -700,7 +700,7 @@ bool SwDoc::SetFrameFormatToFly( SwFrameFormat& rFormat, 
SwFrameFormat& rNewForm
 rFormat.ResetFormatAttr( RES_PRINT, RES_SURROUND );
 rFormat.ResetFormatAttr( RES_LR_SPACE, RES_UL_SPACE );
 rFormat.ResetFormatAttr( RES_BACKGROUND, RES_COL );
-rFormat.ResetFormatAttr( RES_URL, RES_EDIT_IN_READONLY );
+rFormat.ResetFormatAttr( RES_EDIT_IN_READONLY );
 
 if( !bFrameSz )
 rFormat.SetFormatAttr( aFrameSz );


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-02-23 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |   27 +++
 sw/source/filter/html/wrthtml.cxx  |   11 +--
 2 files changed, 32 insertions(+), 6 deletions(-)

New commits:
commit 2bd52c78a707d4229543e3b00e706176f7ca2367
Author: Miklos Vajna 
AuthorDate: Tue Feb 22 17:06:39 2022 +0100
Commit: Miklos Vajna 
CommitDate: Wed Feb 23 11:31:10 2022 +0100

sw HTML export: handle LeadingTabWidth without FilterOptions

LeadingTabWidth is meant to be useful for plain HTML as well, but the
old code only considered it when FilterOptions was set (typically to
enable th XHTML mode).

Thanks Stephan Bergmann for noticing that the u"" SAL_NEWLINE_STRING
"\xa0\xa0 test" form would not work with MSVC.

(cherry picked from commit 89667371e2c773760e7f7496590f55e7da062cb7)

Change-Id: I89a8b266d9a0f543f6022d82cf043bda4e6e639f

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index ccb45601d738..f55002c04a3d 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2139,6 +2139,33 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTab)
 assertXPathContent(pXmlDoc, "//reqif-xhtml:p[3]", u"thi \t rd");
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTabHTML)
+{
+// Given a document with leading tabs:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("\t test");
+
+// When exporting to plain HTML, using LeadingTabWidth=2:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("LeadingTabWidth", 
static_cast(2)),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure that leading tabs are replaced with 2 nbsps:
+htmlDocUniquePtr pHtmlDoc = parseHtml(maTempFile);
+CPPUNIT_ASSERT(pHtmlDoc);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: test
+// - Actual  : test
+// i.e. the leading tab was not replaced by 2 nbsps.
+assertXPathContent(pHtmlDoc, "/html/body/p", SAL_NEWLINE_STRING u"\xa0\xa0 
test");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/wrthtml.cxx 
b/sw/source/filter/html/wrthtml.cxx
index b665bd7bb503..4f003dbdc115 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -187,12 +187,11 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium)
 return;
 
 const SfxPoolItem* pItem;
-if (pSet->GetItemState( SID_FILE_FILTEROPTIONS, true,  ) != 
SfxItemState::SET)
-return;
-
-
-const OUString sFilterOptions = static_cast(pItem)->GetValue();
-SetupFilterOptions(sFilterOptions);
+if (pSet->GetItemState(SID_FILE_FILTEROPTIONS, true, ) == 
SfxItemState::SET)
+{
+const OUString sFilterOptions = static_cast(pItem)->GetValue();
+SetupFilterOptions(sFilterOptions);
+}
 
 SetupFilterFromPropertyValues(rMedium.GetArgs());
 }


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-02-22 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   42 +
 sw/source/filter/html/htmlnumwriter.cxx |   46 ++--
 2 files changed, 69 insertions(+), 19 deletions(-)

New commits:
commit 44660b663a1ae8046818117f5fe3db10d68e2e2f
Author: Miklos Vajna 
AuthorDate: Mon Feb 21 16:38:51 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Feb 22 11:19:54 2022 +0100

sw HTML export, XHTML mode: fix lost  when last list item is not 
numbered

This went wrong in 013a4f1f5c9ea5fb511568c53a7e76d1b365a65d (sw XHTML
export: fix handling of list labels, 2021-05-13), where we started to
assume that in case the last paragraph of a list is not numbered, then
the entire list is not numbered. This lead to loosing the  for an
 in case the list starts with a numbered paragraph, but ends with a
non-numbered one.

Fix the problem by (if necessary) looking back till the start of the
list to see if any paragraph is numbered: that ensures that the  and
 is always in sync.

This fixes the new problem and keeps the old problem fixed at the same
time.

(cherry picked from commit 8c2607ae3ce143586e623532b8ae5288277ec3ac)

Conflicts:
sw/source/filter/html/htmlnumwriter.cxx

Change-Id: I7d347b37a40dcc727c2080bf8279e33c3ad147e9

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 5064abc3f7a5..ccb45601d738 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1469,6 +1469,48 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testListHeading)
 assertXPathContent(pXmlDoc, 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "list header");
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testPartiallyNumberedList)
+{
+// Given a document with a list, first para is numbered, second is not:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("list header");
+SwDoc* pDoc = pWrtShell->GetDoc();
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+}
+pWrtShell->Insert2("numbered");
+pWrtShell->SplitNode();
+pWrtShell->Insert2("not numbered");
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+
+// When exporting to ReqIF:
+ExportToReqif();
+
+// Then make sure the output is well-formed xhtml:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+CPPUNIT_ASSERT(pXmlDoc);
+// Without the accompanying fix in place, this test would have failed:
+// - expected: ..
+// - actual  : ..
+// because a  without a matching  is not well-formed, and the 
 was omitted because
+// the second para was not numbered.
+assertXPath(pXmlDoc,
+
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin)
 {
 // Given a document with some text, para style set to Quotations, no 
bottom margin:
diff --git a/sw/source/filter/html/htmlnumwriter.cxx 
b/sw/source/filter/html/htmlnumwriter.cxx
index 3360750ecfd9..f338251c0211 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -321,25 +321,10 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
 bool bSameRule = rNextInfo.GetNumRule() == rInfo.GetNumRule();
 bool bListEnd = !bSameRule || rNextInfo.GetDepth() < rInfo.GetDepth() || 
rNextInfo.IsRestart();
 
-if (rWrt.mbXHTML)
-{
-// XHTML  for the list item content.
-if ((bListEnd && rInfo.IsNumbered()) || (!bListEnd && 
rNextInfo.IsNumbered()))
-{
-HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(),
-   rWrt.GetNamespace() + 
OOO_STRING_SVTOOLS_HTML_li, false);
-}
-}
-
-if (!bListEnd)
-{
-return rWrt;
-}
-
+std::optional oAtLeastOneNumbered;
 if (rWrt.mbXHTML && !rInfo.IsNumbered())
 {
-// If the list only consisted of non-numbered text nodes, then don't 
end the list.
-bool bAtLeastOneNumbered = false;
+oAtLeastOneNumbered = false;
 sal_uLong nPos = rWrt.m_pCurrentPam->GetPoint()->nNode.GetIndex() - 1;
 SwNumRule* pNumRule = nullptr;

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2022-02-14 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |   82 +++--
 sw/source/filter/html/htmlatr.cxx  |   18 ---
 sw/source/filter/html/htmltab.cxx  |6 ++
 3 files changed, 76 insertions(+), 30 deletions(-)

New commits:
commit fb035e08ff759c06bab9839d41be89de6ba61ad2
Author: Miklos Vajna 
AuthorDate: Fri Feb 11 16:18:26 2022 +0100
Commit: Miklos Vajna 
CommitDate: Mon Feb 14 15:23:16 2022 +0100

sw XHTML / ReqIF filter: avoid adding and removing s for trailing s

The sw/ HTML export writes two s for a  in the doc model at the
end of a paragraph, because the last  would be ignored by browsers.
But then the import ignores all s at the end of paragraphs, so the
import and the export are not a 1:1 mapping; but at least the layout of
the exported HTML is close to the Writer layout.

ReqIF focuses on the preserving the semantics of the doc model instead:
it already doesn't open the document in "web view", and it's not
expected that the number of s change on import or export.

Fix the problem by disabling both the import and the export tweaks in
the ReqIF case.

It would perhaps make sense to do this in general, but for users who
only care about the export layout (and never import the result again),
that would be probably a regression, so don't change this
unconditionally for now.

(cherry picked from commit b86679ea6bd2bb053c3822c4642a62a49e381909)

Conflicts:
sw/qa/extras/htmlexport/htmlexport.cxx

Change-Id: Iabd4a462185493c1ece0352069077e04c293816b

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index f95884620b55..eff7bda22037 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -268,6 +268,8 @@ public:
 void ParseOle1FromRtfUrl(const OUString& rRtfUrl, SvMemoryStream& rOle1);
 /// Export using the C++ HTML export filter, with xhtmlns=reqif-xhtml.
 void ExportToReqif();
+/// Import using the C++ HTML import filter, with xhtmlns=reqif-xhtml.
+void ImportFromReqif(const OUString& rUrl);
 };
 
 OUString SwHtmlDomExportTest::GetOlePath()
@@ -322,6 +324,15 @@ void SwHtmlDomExportTest::ExportToReqif()
 xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
 }
 
+void SwHtmlDomExportTest::ImportFromReqif(const OUString& rUrl)
+{
+uno::Sequence aLoadProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+};
+mxComponent = loadFromDesktop(rUrl, "com.sun.star.text.TextDocument", 
aLoadProperties);
+}
+
 char const DATA_DIRECTORY[] = "/sw/qa/extras/htmlexport/data/";
 
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo81276, "fdo81276.html")
@@ -700,11 +711,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfPngImg)
 };
 
 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"reqif-png-img.xhtml";
-uno::Sequence aLoadProperties = {
-comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
-comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
-};
-mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", 
aLoadProperties);
+ImportFromReqif(aURL);
 verify(/*bExported=*/false);
 uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
 uno::Sequence aStoreProperties = {
@@ -714,8 +721,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfPngImg)
 };
 xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
 mxComponent->dispose();
-mxComponent
-= loadFromDesktop(maTempFile.GetURL(), 
"com.sun.star.text.TextDocument", aLoadProperties);
+ImportFromReqif(maTempFile.GetURL());
 verify(/*bExported=*/true);
 }
 
@@ -1011,12 +1017,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testRTFOLEMimeType)
 {
 // Import a document with an embedded object.
 OUString aType("test/rtf");
-uno::Sequence aLoadProperties = {
-comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
-comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
-};
 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"reqif-ole-data.xhtml";
-mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", 
aLoadProperties);
+ImportFromReqif(aURL);
 
 // Export it.
 uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
@@ -1185,12 +1187,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifOle1PDF)
 // Now import this back and check the ODT result.
 mxComponent->dispose();
 mxComponent.clear();
-uno::Sequence aLoadProperties = {
-comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
-

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-10-14 Thread Miklos Vajna (via logerrit)
 sw/qa/core/unocore/data/graphic.png  |binary
 sw/qa/core/unocore/unocore.cxx   |   26 ++
 sw/source/core/unocore/unocrsrhelper.cxx |3 ++-
 3 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 0fb7a4324aac356856e215e6c19521cb6871bc77
Author: Miklos Vajna 
AuthorDate: Wed Oct 13 17:00:30 2021 +0200
Commit: Miklos Vajna 
CommitDate: Thu Oct 14 12:06:33 2021 +0200

sw: fix corrupted proxy object for SwGrfNode via the view cursor UNO API

Creating an SwXTextFrame for a graphic node will result in a wrapper
that has no underlying SwTextNode, as the downcast from SwNode fails in
SwXParagraphEnumerationImpl::NextElement_Impl(). This is certainly not
intended, similar code in SwFmDrawPage::CreateShape() handles the text
node, graphic node and OLE node cases separately.

To make this more problematic, this corrupted wrapper can be still alive
by the time we try to save to ODT, but the wrapper without an underlying
SwTextNode will be unable to enumerat the paragraphs of the text frame,
so it throws, making it impossible to save the document.

Fix this by limiting the TextFrame property of the cursor to actual text
frames any returning an empty reference in other cases.

If there is a need to access graphic or OLE frames via that API, then
dedicated properties can be added to expose those different nodes.

(cherry picked from commit a399b05401fc35ebba4dbd07504fae4a609b3614)

Conflicts:
sw/qa/core/unocore/unocore.cxx

Change-Id: I5e97a826271b0d8a1bf262e43cd8516656b37c3a

diff --git a/sw/qa/core/unocore/data/graphic.png 
b/sw/qa/core/unocore/data/graphic.png
new file mode 100644
index ..fdad35484e7c
Binary files /dev/null and b/sw/qa/core/unocore/data/graphic.png differ
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index a4a39489da60..6ad020077d46 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -42,6 +43,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace ::com::sun::star;
 
@@ -108,6 +110,30 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, flyAtParaAnchor)
 xText->insertTextContent(xAnchor, xFieldmark, false);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testViewCursorTextFrame)
+{
+// Given a document with a graphic and holding a reference to that graphic 
frame:
+mxComponent = loadFromDesktop("private:factory/swriter", 
"com.sun.star.text.TextDocument");
+uno::Sequence aInsertArgs = { 
comphelper::makePropertyValue(
+"FileName", m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"graphic.png") };
+dispatchCommand(mxComponent, ".uno:InsertGraphic", aInsertArgs);
+uno::Reference xModel(mxComponent, uno::UNO_QUERY);
+uno::Reference xTextViewCursorSupplier(
+xModel->getCurrentController(), uno::UNO_QUERY);
+uno::Reference 
xViewCursor(xTextViewCursorSupplier->getViewCursor(),
+uno::UNO_QUERY);
+uno::Reference xFrame;
+xViewCursor->getPropertyValue("TextFrame") >>= xFrame;
+
+// When saving to ODT, then make sure the store doesn't fail:
+uno::Reference xStorable(xModel, uno::UNO_QUERY);
+uno::Sequence aStoreArgs
+= { comphelper::makePropertyValue("FilterName", OUString("writer8")) };
+// Without the accompanying fix in place, this test would have failed with:
+// uno.RuntimeException: "SwXParagraph: disposed or invalid ..."
+xStorable->storeToURL(maTempFile.GetURL(), aStoreArgs);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx 
b/sw/source/core/unocore/unocrsrhelper.cxx
index a82e7a1c2308..6a71158d0c3e 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -631,7 +631,8 @@ bool getCursorPropertyValue(const 
SfxItemPropertySimpleEntry& rEntry
 SwFrameFormat* pFormat;
 if(eType == SwFlyStartNode && nullptr != (pFormat = 
pSttNode->GetFlyFormat()))
 {
-if( pAny )
+// Create a wrapper only for text frames, not for graphic or 
OLE nodes.
+if (pAny && !rPam.GetNode().IsNoTextNode())
 {
 uno::Reference const xFrame(
 SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), 
pFormat));


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-10-12 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   41 
 sw/source/filter/html/htmlnumwriter.cxx |   13 +-
 2 files changed, 53 insertions(+), 1 deletion(-)

New commits:
commit f6db057a505bc2a9fab66004f35b48bc89c72340
Author: Miklos Vajna 
AuthorDate: Mon Oct 11 16:46:21 2021 +0200
Commit: Miklos Vajna 
CommitDate: Tue Oct 12 09:02:50 2021 +0200

sw XHTML export: fix missing  around nested /

This was fine in practice in the HTML case, so make it conditional on
the XHTML flag for now.

(cherry picked from commit 869e554a017d57da14b0c5b1e1f6ce742db316e0)

Conflicts:
sw/source/filter/html/htmlnumwriter.cxx

Change-Id: Ie96357ba78f4a7fae125165c1c4e47c3f5686ddf

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index e5d9b4fdc8b9..f95884620b55 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1984,6 +1984,47 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testOleEmfPreviewToHtml)
 CPPUNIT_ASSERT(aPath.endsWith("gif"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testNestedBullets)
+{
+// Given a documented with nested lists:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("first");
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetAttrListLevel(0);
+}
+pWrtShell->SplitNode();
+pWrtShell->Insert("second");
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetAttrListLevel(1);
+}
+
+// When exporting to xhtml:
+ExportToReqif();
+
+// Then make sure that there is a  between the outer and the inner 
:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+CPPUNIT_ASSERT(pDoc);
+// Without the accompanying fix in place, this test would have failed with:
+// - XPath 
'//reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p' 
not found
+// i.e. the  inside the outer  was missing.
+assertXPathContent(
+pXmlDoc, 
"//reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
+"second");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlnumwriter.cxx 
b/sw/source/filter/html/htmlnumwriter.cxx
index 5b9f484d9995..3360750ecfd9 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -211,11 +211,15 @@ Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt,
 
 rWrt.m_aBulletGrfs[i].clear();
 OString sOut = "<" + rWrt.GetNamespace();
+if (rWrt.mbXHTML && (nPrevDepth != 0 || i != 0))
+{
+sOut += OOO_STRING_SVTOOLS_HTML_li "><" + rWrt.GetNamespace();
+}
 const SwNumFormat& rNumFormat = rInfo.GetNumRule()->Get( i );
 sal_Int16 eType = rNumFormat.GetNumberingType();
 if( SVX_NUM_CHAR_SPECIAL == eType )
 {
-// ordered list: 
+// unordered list: 
 sOut += OString(OOO_STRING_SVTOOLS_HTML_unorderlist);
 
 // determine the type by the bullet character
@@ -319,6 +323,7 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
 
 if (rWrt.mbXHTML)
 {
+// XHTML  for the list item content.
 if ((bListEnd && rInfo.IsNumbered()) || (!bListEnd && 
rNextInfo.IsNumbered()))
 {
 HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(),
@@ -387,6 +392,12 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
 else
 aTag = OOO_STRING_SVTOOLS_HTML_orderlist;
 HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rWrt.GetNamespace() + aTag, 
false );
+if (rWrt.mbXHTML && (nNextDepth != 0 || i != 1))
+{
+HTMLOutFuncs::Out_AsciiTag(
+rWrt.Strm(), rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li,
+/*bOn=*/false);
+}
 rWrt.m_bLFPossible = true;
 }
 


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source test/source

2021-07-09 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   28 
 sw/source/filter/html/htmlflywriter.cxx |4 ++--
 test/source/htmltesttools.cxx   |5 -
 3 files changed, 34 insertions(+), 3 deletions(-)

New commits:
commit 559181f925b5791512408c87ce32e3aed90ecded
Author: Miklos Vajna 
AuthorDate: Thu Jul 8 17:08:06 2021 +0200
Commit: Miklos Vajna 
CommitDate: Fri Jul 9 15:10:46 2021 +0200

tdf#142871 sw HTML export: avoid unwanted inner PNG for images

Regression from commit e76471c5ce725dae9abb6f78b7674c6f77df34f4 (sw
XHTML / reqif export: export non-PNG graphic shapes directly,
2021-06-02), reqif wants to have a PNG fallback for non-PNG pixel
formats, but this is not needed for plain HTML, make this reqif-only.

(cherry picked from commit 2d9580e6a65a2699ff61fc1b0e07f62b4946de84)

Change-Id: I0fc1bc13ad4bf808afbe68407e7db802f910c7a7

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 3dfe581a4858..f1fcc3631dae 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1757,6 +1757,34 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifEmbedShapeAsPNG)
 OUString::number(aPixelSize.getWidth()));
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testShapeAsImageHtml)
+{
+// Given a document with a shape:
+loadURL("private:factory/swriter", nullptr);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xShape(
+xFactory->createInstance("com.sun.star.drawing.RectangleShape"), 
uno::UNO_QUERY);
+xShape->setSize(awt::Size(5080, 2540));
+uno::Reference xDrawPageSupplier(mxComponent, 
uno::UNO_QUERY);
+xDrawPageSupplier->getDrawPage()->add(xShape);
+
+// When exporting to plain HTML:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+mxComponent->dispose();
+
+// Then make sure importing it back results in a clean doc model:
+mxComponent = loadFromDesktop(maTempFile.GetURL());
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected:
+// - Actual  :  />
+// i.e. the output was not well-formed.
+CPPUNIT_ASSERT_EQUAL(OUString(" "), getParagraph(1)->getString());
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedShapeAsPNGCustomDPI)
 {
 // Given a document with a shape:
diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 6f01a5c7008d..847dae7cb93b 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1801,7 +1801,7 @@ static void OutHTML_ImageOLEEnd(SwHTMLWriter& rHTMLWrt)
 static Writer & OutHTML_FrameFormatAsImage( Writer& rWrt, const SwFrameFormat& 
rFrameFormat, bool bPNGFallback)
 {
 SwHTMLWriter& rHTMLWrt = static_cast(rWrt);
-bool bWritePNGFallback = !rHTMLWrt.m_bExportImagesAsOLE && bPNGFallback;
+bool bWritePNGFallback = rHTMLWrt.mbReqIF && 
!rHTMLWrt.m_bExportImagesAsOLE && bPNGFallback;
 
 if (rHTMLWrt.mbSkipImages)
 return rWrt;
@@ -1896,7 +1896,7 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, 
const SwFrameFormat& rF
   bool bInCntnr, bool bPNGFallback )
 {
 SwHTMLWriter& rHTMLWrt = static_cast(rWrt);
-bool bWritePNGFallback = !rHTMLWrt.m_bExportImagesAsOLE && bPNGFallback;
+bool bWritePNGFallback = rHTMLWrt.mbReqIF && 
!rHTMLWrt.m_bExportImagesAsOLE && bPNGFallback;
 
 if (rHTMLWrt.mbSkipImages)
 return rWrt;
diff --git a/test/source/htmltesttools.cxx b/test/source/htmltesttools.cxx
index 9f9a1bbddfc6..d61f07bd3d1b 100644
--- a/test/source/htmltesttools.cxx
+++ b/test/source/htmltesttools.cxx
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 
 #include 
 
@@ -30,7 +31,9 @@ htmlDocUniquePtr HtmlTestTools::parseHtmlStream(SvStream* 
pStream)
 std::unique_ptr pBuffer(new sal_uInt8[nSize + 1]);
 pStream->ReadBytes(pBuffer.get(), nSize);
 pBuffer[nSize] = 0;
-return 
htmlDocUniquePtr(htmlParseDoc(reinterpret_cast(pBuffer.get()), 
nullptr));
+auto pCharBuffer = reinterpret_cast(pBuffer.get());
+SAL_INFO("test", "HtmlTestTools::parseXmlStream: pBuffer is '" << 
pCharBuffer << "'");
+return htmlDocUniquePtr(htmlParseDoc(pCharBuffer, nullptr));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-06-16 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   87 
 sw/source/filter/html/htmlnumwriter.cxx |   10 ++-
 2 files changed, 95 insertions(+), 2 deletions(-)

New commits:
commit 9b4bd79a84353b2630717014d346982c968cc46f
Author: Miklos Vajna 
AuthorDate: Tue Jun 15 14:04:57 2021 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jun 16 10:24:52 2021 +0200

sw XHTML / reqif export: handle multiple lists when detecting header-only 
lists

The case when the list was at the end of the text node section (body
text, table cell, etc) was already handled, this handles when the list
is followed by a different list.

(cherry picked from commit fdf1db0010104294c01c7780d9daba5adf38450b)

Change-Id: I131402cb577bd16814f56a5bd6bcad7c99947dbd

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 750e97594a7d..1fd48f104ed6 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1849,6 +1849,93 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifOleBmpTransparent)
 CPPUNIT_ASSERT_EQUAL(COL_WHITE, nActualColor);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListsHeading)
+{
+// Given a document with lh, lh, li, li, lh and lh nodes:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("list 1, header 1");
+pWrtShell->SplitNode();
+pWrtShell->Insert("list 1, header 2");
+pWrtShell->SplitNode();
+pWrtShell->Insert("list 2, item 1");
+pWrtShell->SplitNode();
+pWrtShell->Insert("list 2, item 2");
+pWrtShell->SplitNode();
+pWrtShell->Insert("list 3, header 1");
+pWrtShell->SplitNode();
+pWrtShell->Insert("list 3, header 2");
+SwDoc* pDoc = pWrtShell->GetDoc();
+pWrtShell->Up(false, 5);
+{
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = 
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+pWrtShell->Down(false, 1);
+{
+SwNode& rNode = 
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+}
+pWrtShell->Down(false, 1);
+{
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = 
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+}
+pWrtShell->Down(false, 1);
+{
+SwNode& rNode = 
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+}
+}
+pWrtShell->Down(false, 1);
+{
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = 
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+pWrtShell->Down(false, 1);
+{
+SwNode& rNode = 
pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+}
+
+// When exporting to ReqIF:
+ExportToReqif();
+
+// Then make sure the output is valid xhtml:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+CPPUNIT_ASSERT(pDoc);
+
+// Without the accompanying fix in place, this test would have failed with:
+// - In <>, XPath '/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p' not 
found
+// Because the headers of list 1 were inside , not directly under 
.
+assertXPathContent(pXmlDoc, 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p",
+   "list 1, header 1");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlnumwriter.cxx 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-06-15 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/data/transparent.png |binary
 sw/qa/extras/htmlexport/htmlexport.cxx   |   48 ++-
 sw/source/filter/html/htmlreqifreader.cxx|8 +++-
 3 files changed, 54 insertions(+), 2 deletions(-)

New commits:
commit 4a0fe3fb336c78bbf1eb74bbe32f27d7d424357c
Author: Miklos Vajna 
AuthorDate: Mon Jun 14 12:09:01 2021 +0200
Commit: Miklos Vajna 
CommitDate: Tue Jun 15 11:08:22 2021 +0200

sw XHTML/reqif export, OLE data for transparent images: avoid black 
background

Once a semi-transparent images is exported to reqif in OLE mode, the
native data is 24bit BMP. This needs some solid color as a background
for the transparent pixels. The OLE presentation data had white, the OLE
native data had black, so this was inconsistent.

Fix the problem by going with white for the native data as well.

(cherry picked from commit 547386eef9b1723812dfdab5aed33e9025a372c6)

Change-Id: I1b5e9ed37369b541425cfcd7f690e1b0bba97ddc

diff --git a/sw/qa/extras/htmlexport/data/transparent.png 
b/sw/qa/extras/htmlexport/data/transparent.png
new file mode 100644
index ..936980b0a19b
Binary files /dev/null and b/sw/qa/extras/htmlexport/data/transparent.png differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 69ba0bd54c36..750e97594a7d 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace
 {
@@ -130,6 +131,7 @@ bool TestReqIfRtfReader::WriteObjectData(SvStream& rOLE)
 struct OLE1Reader
 {
 sal_uInt32 m_nNativeDataSize;
+std::vector m_aNativeData;
 sal_uInt32 m_nPresentationDataSize;
 
 OLE1Reader(SvStream& rStream);
@@ -151,7 +153,8 @@ OLE1Reader::OLE1Reader(SvStream& rStream)
 rStream.SeekRel(nData);
 
 rStream.ReadUInt32(m_nNativeDataSize);
-rStream.SeekRel(m_nNativeDataSize);
+m_aNativeData.resize(m_nNativeDataSize);
+rStream.ReadBytes(m_aNativeData.data(), m_aNativeData.size());
 
 rStream.ReadUInt32(nData); // OLEVersion for presentation data
 CPPUNIT_ASSERT(rStream.good());
@@ -1803,6 +1806,49 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifEmbedShapeAsPNGCustomDPI)
 OUString::number(aPixelSize.getWidth()));
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOleBmpTransparent)
+{
+// Given a document with a transparent image:
+loadURL("private:factory/swriter", nullptr);
+OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"transparent.png";
+uno::Sequence aArgs = {
+comphelper::makePropertyValue("FileName", aImageURL),
+};
+dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
+
+// When exporting to reqif with ExportImagesAsOLE=true:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+comphelper::makePropertyValue("ExportImagesAsOLE", true),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure the transparent pixel turns into white:
+OUString aRtfUrl = GetOlePath();
+SvMemoryStream aRtf;
+HtmlExportTest::wrapRtfFragment(aRtfUrl, aRtf);
+tools::SvRef xReader(new TestReqIfRtfReader(aRtf));
+CPPUNIT_ASSERT(xReader->CallParser() != SvParserState::Error);
+SvMemoryStream aOle1;
+CPPUNIT_ASSERT(xReader->WriteObjectData(aOle1));
+OLE1Reader aOle1Reader(aOle1);
+SvMemoryStream aBitmapStream(aOle1Reader.m_aNativeData.data(), 
aOle1Reader.m_aNativeData.size(),
+ StreamMode::READ);
+Bitmap aBitmap;
+ReadDIB(aBitmap, aBitmapStream, /*bFileHeader=*/true);
+Size aBitmapSize = aBitmap.GetSizePixel();
+BitmapEx aBitmapEx(aBitmap);
+Color nActualColor
+= aBitmapEx.GetPixelColor(aBitmapSize.getWidth() - 1, 
aBitmapSize.getHeight() - 1);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: Color: R:255 G:255 B:255 A:0
+// - Actual  : Color: R:0 G:0 B:0 A:0
+// i.e. the bitmap without an alpha channel was black, not white.
+CPPUNIT_ASSERT_EQUAL(COL_WHITE, nActualColor);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlreqifreader.cxx 
b/sw/source/filter/html/htmlreqifreader.cxx
index 8a6101fa93ee..a091183b9f69 100644
--- a/sw/source/filter/html/htmlreqifreader.cxx
+++ b/sw/source/filter/html/htmlreqifreader.cxx
@@ -545,7 +545,13 @@ bool WrapGraphicInRtf(const Graphic& rGraphic, const 
SwFrameFormat& rFormat, SvS
 
 // NativeDataSize
 SvMemoryStream aNativeData;
-if (GraphicConverter::Export(aNativeData, rGraphic, 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-04-30 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/data/reqif-objdata-presentationdatasize.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx  |   35 
++
 sw/source/filter/html/htmlreqifreader.cxx   |4 -
 3 files changed, 37 insertions(+), 2 deletions(-)

New commits:
commit d3ab4fc0ba8e62d4f25caf5d759eb54d3f7ecd94
Author: Miklos Vajna 
AuthorDate: Thu Apr 29 17:21:54 2021 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 30 17:37:22 2021 +0200

sw html/reqif export: fix size of presentation data for "real" OLE2 
embedding

InsertOLE1Header() can either take its OLE1 presentation data (preview)
from OLE2 or from RTF (SwOLENode). The presentation data size we wrote
was incorrect in the OLE2 case case: nPresentationData is the RTF size,
nBytes is the actual buffer size.

In practice this made the embedded object non-editable in Word (when
trying to edit the RTF fragment).

This went wrong in commit 0d027abbc5609b096d2a954e77aa7354a55928ab (sw
reqif-xhtml export, embedded objects: take OLE1 pres data from rtf if
needed, 2020-09-02).

(cherry picked from commit 58607e1c410ee89ddfd47dcd128abfa00e0ac839)

Change-Id: I89019202c9a8b40c1b9a21f611f1190fd50073a5

diff --git 
a/sw/qa/extras/htmlexport/data/reqif-objdata-presentationdatasize.odt 
b/sw/qa/extras/htmlexport/data/reqif-objdata-presentationdatasize.odt
new file mode 100644
index ..231a7c572a3a
Binary files /dev/null and 
b/sw/qa/extras/htmlexport/data/reqif-objdata-presentationdatasize.odt differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 08a21b6b7dd3..3746c3e7e786 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -255,6 +255,8 @@ public:
 OUString GetOlePath();
 /// Parse the ole1 data out of an RTF fragment URL.
 void ParseOle1FromRtfUrl(const OUString& rRtfUrl, SvMemoryStream& rOle1);
+/// Export using the C++ HTML export filter, with xhtmlns=reqif-xhtml.
+void ExportToReqif();
 };
 
 OUString SwHtmlDomExportTest::GetOlePath()
@@ -283,6 +285,16 @@ void SwHtmlDomExportTest::ParseOle1FromRtfUrl(const 
OUString& rRtfUrl, SvMemoryS
 CPPUNIT_ASSERT(rOle1.Tell());
 }
 
+void SwHtmlDomExportTest::ExportToReqif()
+{
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+}
+
 char const DATA_DIRECTORY[] = "/sw/qa/extras/htmlexport/data/";
 
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo81276, "fdo81276.html")
@@ -1354,6 +1366,29 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifAscharObjsize)
 CPPUNIT_ASSERT_EQUAL(static_cast(4116), xReader->GetObjh());
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifObjdataPresentationDataSize)
+{
+// Given a document with an OLE2 embedded object, containing a preview:
+OUString aURL
+= m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"reqif-objdata-presentationdatasize.odt";
+mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {});
+
+// When exporting to ReqIF:
+ExportToReqif();
+
+// Then make sure that the PresentationDataSize in the RTF's objdata blob 
is correct:
+OUString aRtfUrl = GetOlePath();
+SvMemoryStream aOle1;
+ParseOle1FromRtfUrl(aRtfUrl, aOle1);
+OLE1Reader aOle1Reader(aOle1);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 565994
+// - Actual  : 330240 (Linux)
+// - Actual  : 566034 (Windows, when Word is installed)
+// because PresentationData was taken from the OLE2 stream but its size 
was taken from RTF.
+CPPUNIT_ASSERT_EQUAL(static_cast(565994), 
aOle1Reader.m_nPresentationDataSize);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlreqifreader.cxx 
b/sw/source/filter/html/htmlreqifreader.cxx
index a59f56ee40ee..47cf2341e1e5 100644
--- a/sw/source/filter/html/htmlreqifreader.cxx
+++ b/sw/source/filter/html/htmlreqifreader.cxx
@@ -341,8 +341,8 @@ OString InsertOLE1Header(SvStream& rOle2, SvStream& rOle1, 
sal_uInt32& nWidth, s
 rOle1.WriteUInt32(nWidth);
 // Height.
 rOle1.WriteUInt32(nHeight * -1);
-// PresentationDataSize
-rOle1.WriteUInt32(8 + nPresentationData);
+// PresentationDataSize: size of (reserved fields + pBytes).
+rOle1.WriteUInt32(8 + nBytes);
 // Reserved1-4.
 rOle1.WriteUInt16(0x0008);
 rOle1.WriteUInt16(0x31b1);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-04-16 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx|   38 ++
 sw/source/filter/html/htmlplug.cxx|4 -
 sw/source/filter/html/htmlreqifreader.cxx |7 ++-
 sw/source/filter/html/htmlreqifreader.hxx |4 +
 5 files changed, 48 insertions(+), 5 deletions(-)

New commits:
commit a4b426d4cd246fc9a5faf2a89cad0ebdc0a18847
Author: Miklos Vajna 
AuthorDate: Fri Apr 16 10:14:05 2021 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 16 17:16:08 2021 +0200

sw html/reqif export: fix size of embedded object

We used to write the size of the underlying OLE object, which may or may
not match the user-configured size. The PNG preview was correct, which
works with the size from the SwFormatFlyCnt ("as-char formatting"). Do
the same when writing the "object size" (i.e. \objw and \objh in the RTF
snippet).

(cherry picked from commit 21cd910d144b14ead358bccd1146650806346eb5)

Change-Id: I7e240c1e115846c17b0945376b0de02d19769100

diff --git a/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt 
b/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt
new file mode 100644
index ..6028b54a4190
Binary files /dev/null and 
b/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 5e1264fcadb4..08a21b6b7dd3 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -48,10 +48,14 @@ public:
 TestReqIfRtfReader(SvStream& rStream);
 void NextToken(int nToken) override;
 bool WriteObjectData(SvStream& rOLE);
+long GetObjw() const { return m_nObjw; }
+long GetObjh() const { return m_nObjh; }
 
 private:
 bool m_bInObjData = false;
 OStringBuffer m_aHex;
+long m_nObjw = 0;
+long m_nObjh = 0;
 };
 
 TestReqIfRtfReader::TestReqIfRtfReader(SvStream& rStream)
@@ -73,6 +77,12 @@ void TestReqIfRtfReader::NextToken(int nToken)
 case RTF_OBJDATA:
 m_bInObjData = true;
 break;
+case RTF_OBJW:
+m_nObjw = nTokenValue;
+break;
+case RTF_OBJH:
+m_nObjh = nTokenValue;
+break;
 }
 }
 
@@ -1316,6 +1326,34 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifOle1PresDataWmfOnly)
 CPPUNIT_ASSERT_EQUAL(static_cast(135660), 
aOle1Reader.m_nPresentationDataSize);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifAscharObjsize)
+{
+// Given a document with an as-char anchored embedded object:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"reqif-aschar-objsize.odt";
+mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {});
+
+// When exporting to reqif-xhtml:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure that the RTF snippet has the correct aspect ratio:
+OUString aRtfUrl = GetOlePath();
+SvMemoryStream aRtf;
+HtmlExportTest::wrapRtfFragment(aRtfUrl, aRtf);
+tools::SvRef xReader(new TestReqIfRtfReader(aRtf));
+CPPUNIT_ASSERT(xReader->CallParser() != SvParserState::Error);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 7344
+// - Actual  : 2836
+// i.e. the aspect ratio was 1:1, while the PNG aspect ratio was correctly 
not 1:1.
+CPPUNIT_ASSERT_EQUAL(static_cast(7344), xReader->GetObjw());
+CPPUNIT_ASSERT_EQUAL(static_cast(4116), xReader->GetObjh());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlplug.cxx 
b/sw/source/filter/html/htmlplug.cxx
index 525b3b0ea175..5fd6b3e54d7b 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -1549,7 +1549,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, 
const SwFrameFormat& rFrame
 if (xStream.is())
 {
 std::unique_ptr 
pStream(utl::UcbStreamHelper::CreateStream(xStream));
-if (SwReqIfReader::WrapOleInRtf(*pStream, aOutStream, *pOLENd))
+if (SwReqIfReader::WrapOleInRtf(*pStream, aOutStream, *pOLENd, 
rFrameFormat))
 {
 // Data always wrapped in RTF.
 aFileType = aRTFType;
@@ -1568,7 +1568,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, 
const SwFrameFormat& rFrame
 aOLEExp.ExportOLEObject(rOLEObj.GetObject(), *pStorage);
 pStorage->Commit();
 aMemory.Seek(0);
-if 

[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source

2021-03-25 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |   33 +
 sw/source/filter/html/htmltabw.cxx |6 ++
 2 files changed, 39 insertions(+)

New commits:
commit 833de9c3dbf52adaa2e62d0e5f624dce9ec0113d
Author: Miklos Vajna 
AuthorDate: Wed Mar 24 16:38:18 2021 +0100
Commit: Miklos Vajna 
CommitDate: Thu Mar 25 13:49:49 2021 +0100

sw reqif-xhtml export: fix unexpected height for 

The ReqIF validator complains about this, similar to the already
disabled width.

(cherry picked from commit ab6a7a9addfc059d8f1fbeaa6c601229d420)

Change-Id: I05137a9dcc7e94bffe92269e98d310724a144b24

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 6fdf15730dde..5e1264fcadb4 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -684,6 +684,39 @@ DECLARE_HTMLEXPORT_TEST(testReqIfTable2, 
"reqif-table2.odt")
 CPPUNIT_ASSERT(aStream.indexOf("") != -1);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfTableHeight)
+{
+// Given a document with a table in it, with an explicit row height:
+loadURL("private:factory/swriter", nullptr);
+uno::Sequence aTableProperties = {
+comphelper::makePropertyValue("Rows", static_cast(1)),
+comphelper::makePropertyValue("Columns", static_cast(1)),
+};
+dispatchCommand(mxComponent, ".uno:InsertTable", aTableProperties);
+uno::Reference xTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference 
xTables(xTablesSupplier->getTextTables(),
+uno::UNO_QUERY);
+uno::Reference xTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+uno::Reference xRow(xTable->getRows()->getByIndex(0), 
uno::UNO_QUERY);
+xRow->setPropertyValue("Height", 
uno::makeAny(static_cast(1000)));
+
+// When exporting to reqif-xhtml:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+comphelper::makePropertyValue("FilterOptions", 
OUString("xhtmlns=reqif-xhtml")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure that the explicit cell height is omitted from the output:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pDoc = parseXmlStream();
+// Without the accompanying fix in place, this test would have failed, 
explicit height was
+// written, which is not valid reqif-xhtml.
+assertXPathNoAttribute(pDoc, "//reqif-xhtml:td", "height");
+}
+
 DECLARE_HTMLEXPORT_TEST(testXHTMLUseCSS, "xhtml-css.odt")
 {
 SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
diff --git a/sw/source/filter/html/htmltabw.cxx 
b/sw/source/filter/html/htmltabw.cxx
index f7d5951ae585..1febebd9ff34 100644
--- a/sw/source/filter/html/htmltabw.cxx
+++ b/sw/source/filter/html/htmltabw.cxx
@@ -380,6 +380,12 @@ void SwHTMLWrtTable::OutTableCell( SwHTMLWriter& rWrt,
 sOut.append("\"");
 }
 
+if (rWrt.mbReqIF)
+{
+// ReqIF implies strict XHTML: no height for .
+nHeight = 0;
+}
+
 if( nHeight )
 {
 sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - sw/qa sw/source vcl/source

2021-03-18 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt |binary
 sw/qa/extras/htmlexport/htmlexport.cxx  |   93 +---
 sw/source/filter/html/htmlreqifreader.cxx   |   11 +-
 vcl/source/filter/wmf/wmfwr.cxx |8 +
 4 files changed, 80 insertions(+), 32 deletions(-)

New commits:
commit 42d20c2ab73615a8b43957b9f0203bbe9e879d3d
Author: Miklos Vajna 
AuthorDate: Wed Mar 17 17:30:52 2021 +0100
Commit: Miklos Vajna 
CommitDate: Thu Mar 18 11:53:56 2021 +0100

sw reqif-xhtml export: make sure OLE1 preview is WMF-only

reqif-xhtml has previews for embedded objects at 4 levels:

- png preview
- RTF preview
- OLE1 preview
- OLE2 preview

The OLE1 preview has to be a WMF one, and in case our WMF export tries
to inject EMF into it, Word will refuse to open the embedded object. So
add a new flag to allow opting out of the EMF embedding for reqif-xhtml
export purposes.

The other option would be what Word does to just omit the OLE1 preview,
but then this would break reqif-xhtml consumers who take the preview
from the OLE1 data.

(cherry picked from commit 5c7255d3a98568a2965f840b76371cf03eb0d99a)

Change-Id: Ia8d4626aefb6309743c9f4023f289c9a7b872035

diff --git a/sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt 
b/sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt
new file mode 100644
index ..9bcca729bc52
Binary files /dev/null and 
b/sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index e2a7e5eb6a60..6fdf15730dde 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -109,6 +109,43 @@ bool TestReqIfRtfReader::WriteObjectData(SvStream& rOLE)
 rOLE.WriteStream(aStream);
 return true;
 }
+
+/// Parser for [MS-OLEDS] 2.2.5 EmbeddedObject, aka OLE1.
+struct OLE1Reader
+{
+sal_uInt32 m_nNativeDataSize;
+sal_uInt32 m_nPresentationDataSize;
+
+OLE1Reader(SvStream& rStream);
+};
+
+OLE1Reader::OLE1Reader(SvStream& rStream)
+{
+// Skip ObjectHeader, see [MS-OLEDS] 2.2.4.
+rStream.Seek(0);
+sal_uInt32 nData;
+rStream.ReadUInt32(nData); // OLEVersion
+rStream.ReadUInt32(nData); // FormatID
+rStream.ReadUInt32(nData); // ClassName
+rStream.SeekRel(nData);
+rStream.ReadUInt32(nData); // TopicName
+rStream.SeekRel(nData);
+rStream.ReadUInt32(nData); // ItemName
+rStream.SeekRel(nData);
+
+rStream.ReadUInt32(m_nNativeDataSize);
+rStream.SeekRel(m_nNativeDataSize);
+
+rStream.ReadUInt32(nData); // OLEVersion for presentation data
+CPPUNIT_ASSERT(rStream.good());
+rStream.ReadUInt32(nData); // FormatID
+rStream.ReadUInt32(nData); // ClassName
+rStream.SeekRel(nData);
+rStream.ReadUInt32(nData); // Width
+rStream.ReadUInt32(nData); // Height
+rStream.ReadUInt32(nData); // PresentationDataSize
+m_nPresentationDataSize = nData;
+}
 }
 
 class HtmlExportTest : public SwModelTestBase, public HtmlTestTools
@@ -1024,25 +1061,14 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifOle1PDF)
 ParseOle1FromRtfUrl(aRtfUrl, aOle1);
 
 // Check the content of the ole1 data.
-// Skip ObjectHeader, see [MS-OLEDS] 2.2.4.
-aOle1.Seek(0);
-sal_uInt32 nData;
-aOle1.ReadUInt32(nData); // OLEVersion
-aOle1.ReadUInt32(nData); // FormatID
-aOle1.ReadUInt32(nData); // ClassName
-aOle1.SeekRel(nData);
-aOle1.ReadUInt32(nData); // TopicName
-aOle1.SeekRel(nData);
-aOle1.ReadUInt32(nData); // ItemName
-aOle1.SeekRel(nData);
-aOle1.ReadUInt32(nData); // NativeDataSize
+OLE1Reader aOle1Reader(aOle1);
 
 // Without the accompanying fix in place, this test would have failed with:
 // - Expected: 39405
 // - Actual  : 43008
 // i.e. we did not work with the Ole10Native stream, rather created an 
OLE1 wrapper around the
 // OLE1-in-OLE2 data, resulting in additional size.
-CPPUNIT_ASSERT_EQUAL(static_cast(0x99ed), nData);
+CPPUNIT_ASSERT_EQUAL(static_cast(0x99ed), 
aOle1Reader.m_nNativeDataSize);
 
 // Now import this back and check the ODT result.
 mxComponent->dispose();
@@ -1228,26 +1254,33 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifOle1PresDataNoOle2)
 ParseOle1FromRtfUrl(aRtfUrl, aOle1);
 
 // Check the content of the ole1 data.
-// Skip ObjectHeader, see [MS-OLEDS] 2.2.4.
-aOle1.Seek(0);
-sal_uInt32 nData;
-aOle1.ReadUInt32(nData); // OLEVersion
-aOle1.ReadUInt32(nData); // FormatID
-aOle1.ReadUInt32(nData); // ClassName
-aOle1.SeekRel(nData);
-aOle1.ReadUInt32(nData); // TopicName
-aOle1.SeekRel(nData);
-aOle1.ReadUInt32(nData); // ItemName
-aOle1.SeekRel(nData);
-aOle1.ReadUInt32(nData); // NativeDataSize
-aOle1.SeekRel(nData);
-
-aOle1.ReadUInt32(nData); // OLEVersion for