[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0-10.0' - sw/qa sw/source
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 12269c021e785b8dca7e57a378d02023f7863d62 Author: Miklos Vajna AuthorDate: Thu Jul 21 15:40:58 2022 +0200 Commit: Miklos Vajna CommitDate: Fri Jul 22 14:55:05 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) Conflicts: sw/qa/extras/htmlexport/htmlexport.cxx Change-Id: I5797c90f9cf957dec7fc4074dd6e79dce11fada7 diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index af92c6e1859c..7e674160c4f8 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -1734,6 +1734,30 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTabHTML) assertXPathContent(pHtmlDoc, "/html/body/p", SAL_NEWLINE_STRING u"\xa0\xa0 test"); } +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(&aStream); +// 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, &pItem ) ) 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 995b1a291f3e..b8a48c2918f3 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -701,9 +701,12 @@ static void lcl_html_OutSectionStartTag( SwHTMLWriter& rHTMLWrt, sOut.append('\"'); } -SvxFrameDirection nDir = rHTMLWrt.GetHTMLDi
[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0-10.0' - sw/qa sw/source
sw/qa/extras/htmlexport/htmlexport.cxx | 42 + sw/source/filter/html/htmlnumwriter.cxx | 45 +++- 2 files changed, 69 insertions(+), 18 deletions(-) New commits: commit c3439e7053d4dafedd87b7128bc2253ff2f9c947 Author: Miklos Vajna AuthorDate: Mon Feb 21 16:38:51 2022 +0100 Commit: Miklos Vajna CommitDate: Tue Feb 22 12:06:20 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 fd9e4ee06583..cf64738d0e40 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -1429,6 +1429,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(&aStream); +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 84ed431699d8..7e2583a48583 100644 --- a/sw/source/filter/html/htmlnumwriter.cxx +++ b/sw/source/filter/html/htmlnumwriter.cxx @@ -314,24 +314,10 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, bool bSameRule = rNextInfo.GetNumRule() == rInfo.GetNumRule(); bool bListEnd = !bSameRule || rNextInfo.GetDepth() < rInfo.GetDepth() || rNextInfo.IsRestart(); -if (rWrt.mbXHTML) -{ -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; while (true) { @@ -349,13 +335,36 @@ Writer& OutHTML_NumberB
[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0-10.0' - sw/qa sw/source
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 296e438f7ac3ea221c0e94e0726c30285c3f2509 Author: Miklos Vajna AuthorDate: Mon Jun 14 12:09:01 2021 +0200 Commit: Miklos Vajna CommitDate: Wed Jun 16 10:19:28 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 50e001c72890..fd9e4ee06583 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -38,6 +38,7 @@ #include #include #include +#include namespace { @@ -129,6 +130,7 @@ bool TestReqIfRtfReader::WriteObjectData(SvStream& rOLE) struct OLE1Reader { sal_uInt32 m_nNativeDataSize; +std::vector m_aNativeData; sal_uInt32 m_nPresentationDataSize; OLE1Reader(SvStream& rStream); @@ -150,7 +152,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()); @@ -1494,6 +1497,49 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifImageToOle) CPPUNIT_ASSERT(aOle1Reader.m_nPresentationDataSize); } +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, ConvertDataFormat::BMP