sw/qa/extras/htmlexport/data/tdf162426_image_with_wrap_none.fodt | 20 ++++++++++ sw/qa/extras/htmlexport/htmlexport.cxx | 16 ++++++++ sw/source/filter/html/htmlflywriter.cxx | 8 +++- sw/source/filter/html/wrthtml.hxx | 2 + 4 files changed, 45 insertions(+), 1 deletion(-)
New commits: commit 9555b793082db56ff5b61708bbbd4d4a088ccf4b Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Aug 11 13:57:07 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Aug 11 15:17:57 2024 +0200 tdf#162426: make sure to only output new tags after all attributes were written In commit 03fe839d6e76ed8b1dfb65093ab59a8904852ff6 (html export: rework image output to use HTML writer, 2014-09-22), optional export of linebreak tag was implemented in the end of SwHTMLWriter::writeFrameFormatOptions. But it is called in the middle of img arrtibutes output in OutHTML_ImageStart; so when br was output, all following img attributes got discarded. This makes writing the tag a separate function with appropriate name, which is called after all attributes are already written. Change-Id: I2a7df56e73150d93c565a7240c047b09f3336641 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171722 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/htmlexport/data/tdf162426_image_with_wrap_none.fodt b/sw/qa/extras/htmlexport/data/tdf162426_image_with_wrap_none.fodt new file mode 100644 index 000000000000..9dc1f13101bd --- /dev/null +++ b/sw/qa/extras/htmlexport/data/tdf162426_image_with_wrap_none.fodt @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:style style:name="Graphics" style:family="graphic"/> + </office:styles> + <office:automatic-styles> + <style:style style:name="fr1" style:family="graphic" style:parent-style-name="Graphics"> + <style:graphic-properties style:wrap="none"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:text> + <text:p><draw:frame draw:style-name="fr1" text:anchor-type="char" svg:y="0" svg:width="1cm" svg:height="1cm"><draw:image draw:mime-type="image/png"> + <office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==</office:binary-data> + </draw:image> + </draw:frame></text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 5de5ef5f155f..df5d90c30855 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -3432,6 +3432,22 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_162282) CPPUNIT_ASSERT_EQUAL(correctData, emfData); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_162426) +{ + // Given a document with an image with style:wrap="none": + createSwDoc("tdf162426_image_with_wrap_none.fodt"); + // Before the fix, an assertion failed in HtmlWriter::attribute when exporting to HTML : + ExportToHTML(); + + xmlDocUniquePtr pDoc = parseXml(maTempFile); + CPPUNIT_ASSERT(pDoc); + + // Before the fix, the 'border' attribute was written after the 'img' tag was already closed, + // so without the asserion, this would fail with + // - In <>, XPath '/html/body/p/img' no attribute 'border' exist + assertXPath(pDoc, "/html/body/p/img"_ostr, "border"_ostr, u"0"_ustr); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index a98aab4d429f..31fabc882de3 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -999,7 +999,11 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma } } } +} +void SwHTMLWriter::writeFrameSurroundTag(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, + HtmlFrmOpts nFrameOptions) +{ if (mbReqIF) return; @@ -1011,7 +1015,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma RndStdIds nAnchorId = rFrameFormat.GetAnchor().GetAnchorId(); if (RndStdIds::FLY_AT_PARA != nAnchorId && RndStdIds::FLY_AT_CHAR != nAnchorId) return; - const SwFormatSurround* pSurround = rItemSet.GetItemIfSet( RES_SURROUND ); + const SwFormatSurround* pSurround = rFrameFormat.GetAttrSet().GetItemIfSet(RES_SURROUND); if (!pSurround) return; @@ -1456,6 +1460,8 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const S rHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_usemap, "#" + aIMapName); } + rWrt.writeFrameSurroundTag(rHtml, rFrameFormat, nFrameOpts); + if (bReplacement) { OUString aAltText = rAlternateText; diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 0b518a29c448..734a86e55566 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -516,6 +516,8 @@ public: void writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, const OUString& rAltText, HtmlFrmOpts nFrameOpts); + void writeFrameSurroundTag(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, HtmlFrmOpts nFrameOpts); + /// Writes the formatting for tables. void OutCSS1_TableFrameFormatOptions( const SwFrameFormat& rFrameFormat );