[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - 2 commits - svx/source sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 21 08:29:44 UTC 2021
svx/source/xoutdev/_xoutbmp.cxx | 6 ++-
sw/qa/extras/htmlimport/data/ole-img-svg.xhtml | 7 +++
sw/qa/extras/htmlimport/data/ole-img.xhtml | 7 +++
sw/qa/extras/htmlimport/data/ole2.gif |binary
sw/qa/extras/htmlimport/data/ole2.svg | 3 +
sw/qa/extras/htmlimport/htmlimport.cxx | 48 +++++++++++++++++++++++++
sw/source/filter/html/htmlflywriter.cxx | 24 ++++++++++++
sw/source/filter/html/htmlplug.cxx | 24 +++++++++++-
sw/source/filter/html/swhtml.cxx | 6 +++
9 files changed, 122 insertions(+), 3 deletions(-)
New commits:
commit 4c952bfe5748ba89764ff1c0b58e15ad47e82f1e
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Jul 20 17:13:36 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jul 21 10:29:08 2021 +0200
sw XHTML import, improved <object> handling for images: support more formats
This was working for only png and gif in the past, handle more formats:
- bmp
- jpg
- emf
- svg
- wmf
- tif
(cherry picked from commit f3b2fc2276ee8a7f64e73d9975d0143d1696362c)
Conflicts:
svx/source/xoutdev/_xoutbmp.cxx
Change-Id: I2af42157428550977f0abab88f2ed728636d2a02
diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx
index 15123e853484..5bc11f752aba 100644
--- a/svx/source/xoutdev/_xoutbmp.cxx
+++ b/svx/source/xoutdev/_xoutbmp.cxx
@@ -136,7 +136,11 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName,
{
const bool bIsSvg(rFilterName.equalsIgnoreAsciiCase("svg") && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getVectorGraphicDataType());
const bool bIsWmf(rFilterName.equalsIgnoreAsciiCase("wmf") && VectorGraphicDataType::Wmf == rVectorGraphicDataPtr->getVectorGraphicDataType());
- const bool bIsEmf(rFilterName.equalsIgnoreAsciiCase("emf") && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getVectorGraphicDataType());
+ bool bIsEmf(rFilterName.equalsIgnoreAsciiCase("emf") && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getVectorGraphicDataType());
+ if (!bIsEmf)
+ {
+ bIsEmf = rGraphic.GetGfxLink().IsEMF();
+ }
const bool bIsPdf(rFilterName.equalsIgnoreAsciiCase("pdf") && VectorGraphicDataType::Pdf == rVectorGraphicDataPtr->getVectorGraphicDataType());
if (bIsSvg || bIsWmf || bIsEmf || bIsPdf)
diff --git a/sw/qa/extras/htmlimport/data/ole-img-svg.xhtml b/sw/qa/extras/htmlimport/data/ole-img-svg.xhtml
new file mode 100644
index 000000000000..2e063937ff20
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/ole-img-svg.xhtml
@@ -0,0 +1,7 @@
+<reqif-xhtml:div>
+<reqif-xhtml:p>
+<reqif-xhtml:object data="ole2.svg" type="image/svg+xml">
+ <reqif-xhtml:object data="ole2.png" type="image/png"></reqif-xhtml:object>
+</reqif-xhtml:object>
+</reqif-xhtml:p>
+</reqif-xhtml:div>
diff --git a/sw/qa/extras/htmlimport/data/ole2.svg b/sw/qa/extras/htmlimport/data/ole2.svg
new file mode 100644
index 000000000000..552a1cf5afaf
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/ole2.svg
@@ -0,0 +1,3 @@
+<svg width="400" height="110">
+ <rect width="300" height="100" style="fill:none;stroke-width:3;stroke:rgb(0,0,0)" />
+</svg>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 72eec15a87ff..1241bfec3b04 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -465,6 +465,30 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImg)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
}
+CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImgSvg)
+{
+ // Given an XHTML with an <object> (containing SVG) and an inner <object> (containing PNG, to be
+ // ignored):
+ uno::Sequence<beans::PropertyValue> aLoadProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ };
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-img-svg.xhtml";
+
+ // When loading the document:
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties);
+
+ // Then make sure the result is a single Writer image:
+ uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xObjects(xSupplier->getGraphicObjects(),
+ uno::UNO_QUERY);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 0
+ // - Actual : 1
+ // i.e. the image was not imported as a Writer image (but as an OLE object).
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
+}
+
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 847dae7cb93b..2e19d5395796 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1965,6 +1965,30 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF
if (!rGraphic.isAvailable())
const_cast<Graphic&>(rGraphic).makeAvailable();
+ if (rHTMLWrt.mbReqIF && bWritePNGFallback)
+ {
+ // ReqIF: force native data if possible.
+ const std::shared_ptr<VectorGraphicData>& pVectorGraphicData = rGraphic.getVectorGraphicData();
+ if (pVectorGraphicData && pVectorGraphicData->getVectorGraphicDataType() == VectorGraphicDataType::Svg)
+ {
+ aFilterName = "svg";
+ }
+ else if (rGraphic.GetGfxLink().IsEMF())
+ {
+ aFilterName = "emf";
+ aMimeType = "image/x-emf"; // avoid image/x-wmf
+ }
+ else if (pVectorGraphicData && pVectorGraphicData->getVectorGraphicDataType() == VectorGraphicDataType::Wmf)
+ {
+ aFilterName = "wmf";
+ }
+ else if (rGraphic.GetGfxLink().GetType() == GfxLinkType::NativeTif)
+ {
+ aFilterName = "tif";
+ aMimeType = "image/tiff"; // avoid image/x-vclgraphic
+ }
+ }
+
ErrCode nErr = XOutBitmap::WriteGraphic( rGraphic, aGraphicURL,
aFilterName, nFlags, &aMM100Size );
if( nErr )
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index ace9726a3530..c2fc7b9c5a18 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -437,6 +437,12 @@ bool SwHTMLParser::InsertEmbed()
static const std::set<std::u16string_view> vAllowlist = {
u"image/png",
u"image/gif",
+ u"image/x-MS-bmp",
+ u"image/jpeg",
+ u"image/x-wmf",
+ u"image/svg+xml",
+ u"image/tiff",
+ u"image/x-emf",
};
if (vAllowlist.find(aType) != vAllowlist.end() && m_aEmbeds.empty())
commit 01d64185981cde17a4033ec0d69a8f57896933b1
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Jul 19 16:24:41 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jul 21 08:57:53 2021 +0200
sw XHTML import: improve handling of <object> with images
The reqif/xhtml export can map images to a pair of <object> elements:
the outer one contains the real image and the inner one contains a PNG
fallback. We used to import this back to OLE objects, except for PNG,
which has a single <object> element.
Improve this by allowing the pair of <object> elements as well: if the
outer type is GIF, then map this to an image and ignore the inner PNG.
(cherry picked from commit 87f6a73fd136ae3d342d09426a27fbde7dbe0fce)
Change-Id: I5c56720cf6a054208cd0478a54bdac15ffece9aa
diff --git a/sw/qa/extras/htmlimport/data/ole-img.xhtml b/sw/qa/extras/htmlimport/data/ole-img.xhtml
new file mode 100644
index 000000000000..798787290c18
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/ole-img.xhtml
@@ -0,0 +1,7 @@
+<reqif-xhtml:div>
+<reqif-xhtml:p>
+<reqif-xhtml:object data="ole2.gif" type="image/gif">
+ <reqif-xhtml:object data="ole2.png" type="image/png"></reqif-xhtml:object>
+</reqif-xhtml:object>
+</reqif-xhtml:p>
+</reqif-xhtml:div>
diff --git a/sw/qa/extras/htmlimport/data/ole2.gif b/sw/qa/extras/htmlimport/data/ole2.gif
new file mode 100644
index 000000000000..19e9785e527c
Binary files /dev/null and b/sw/qa/extras/htmlimport/data/ole2.gif differ
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index fe323ca2592c..72eec15a87ff 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -441,6 +441,30 @@ CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testHiddenTextframe)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), xDrawPage->getCount());
}
+CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImg)
+{
+ // Given an XHTML with an <object> (containing GIF) and an inner <object> (containing PNG, to be
+ // ignored):
+ uno::Sequence<beans::PropertyValue> aLoadProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ };
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-img.xhtml";
+
+ // When loading the document:
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties);
+
+ // Then make sure the result is a single Writer image:
+ uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xObjects(xSupplier->getGraphicObjects(),
+ uno::UNO_QUERY);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 0
+ // - Actual : 1
+ // i.e. the image was not imported as a Writer image (but as an OLE object).
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount());
+}
+
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 4c7e90758f1d..ace9726a3530 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -434,9 +434,17 @@ bool SwHTMLParser::InsertEmbed()
aCmdLst.Append( rOption.GetTokenString(), rOption.GetString() );
}
- if (aType == "image/png" && m_aEmbeds.empty())
- // Toplevel <object> for PNG -> that's an image, not an OLE object.
+ static const std::set<std::u16string_view> vAllowlist = {
+ u"image/png",
+ u"image/gif",
+ };
+
+ if (vAllowlist.find(aType) != vAllowlist.end() && m_aEmbeds.empty())
+ {
+ // Toplevel <object> for an image format -> that's an image, not an OLE object.
+ m_aEmbeds.push(nullptr);
return false;
+ }
SfxItemSet aItemSet( m_xDoc->GetAttrPool(), m_pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
@@ -488,6 +496,12 @@ bool SwHTMLParser::InsertEmbed()
{
// Nested XHTML <object> element: points to replacement graphic.
SwOLENode* pOLENode = m_aEmbeds.top();
+ if (!pOLENode)
+ {
+ // <object> is mapped to an image -> ignore replacement graphic.
+ return true;
+ }
+
svt::EmbeddedObjectRef& rObj = pOLENode->GetOLEObj().GetObject();
Graphic aGraphic;
if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE)
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 940642a816d4..63dd5fa55b80 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -1533,6 +1533,12 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
// The text token is inside an OLE object, which means
// alternate text.
SwOLENode* pOLENode = m_aEmbeds.top();
+ if (!pOLENode)
+ {
+ // <object> is mapped to an image -> ignore.
+ break;
+ }
+
if (SwFlyFrameFormat* pFormat
= dynamic_cast<SwFlyFrameFormat*>(pOLENode->GetFlyFormat()))
{
More information about the Libreoffice-commits
mailing list