[Libreoffice-commits] core.git: sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Mar 9 15:09:00 UTC 2018
sw/qa/extras/htmlexport/data/reqif-png-img.xhtml | 4 ++++
sw/qa/extras/htmlexport/htmlexport.cxx | 9 +++++++++
sw/source/filter/html/htmlgrin.cxx | 13 ++++++++++++-
sw/source/filter/html/htmlplug.cxx | 20 +++++++++++++-------
sw/source/filter/html/swhtml.cxx | 3 ++-
sw/source/filter/html/swhtml.hxx | 2 +-
6 files changed, 41 insertions(+), 10 deletions(-)
New commits:
commit 68c542cfa888f1aa03a08bfc13163c0f2f0c3a75
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Mar 9 15:14:36 2018 +0100
sw XHTML import: PNG <object> is an image
The previous scheme was:
<object data="..." type="...">
<object data="..." type="image/png">alternate text</object>
</object>
Support also the case when the inner <object> is standalone, like:
<object data="..." type="image/png">alternate text</object>
Change-Id: I2dec2770ee3c1c538bcf26f6ff12c6e8f5969563
Reviewed-on: https://gerrit.libreoffice.org/51003
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml b/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml
new file mode 100644
index 000000000000..f31795e35224
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml
@@ -0,0 +1,4 @@
+<reqif-xhtml:div><reqif-xhtml:br/>
+ <reqif-xhtml:object data="reqif-ole-img.png" type="image/png">OLE Object</reqif-xhtml:object>
+</reqif-xhtml:div>
+
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index f65b0014e799..1fcb66d5e4b7 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -402,6 +402,15 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty<OUString>(xObject, "Title").trim());
}
+DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml")
+{
+ uno::Reference<container::XNamed> xShape(getShape(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xShape.is());
+
+ // This was Object1, PNG without fallback was imported as OLE object.
+ CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xShape->getName());
+}
+
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 3c6d5022bfc0..dfa5f63976a4 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -306,6 +306,7 @@ void SwHTMLParser::InsertImage()
// and now analyze
OUString sAltNm, aId, aClass, aStyle, aMap, sHTMLGrfName;
OUString sGrfNm;
+ OUString aGraphicData;
sal_Int16 eVertOri = text::VertOrientation::TOP;
sal_Int16 eHoriOri = text::HoriOrientation::NONE;
bool bWidthProvided=false, bHeightProvided=false;
@@ -344,6 +345,11 @@ void SwHTMLParser::InsertImage()
if( !InternalImgToPrivateURL(sGrfNm) )
sGrfNm = INetURLObject::GetAbsURL( m_sBaseURL, sGrfNm );
break;
+ case HtmlOptionId::DATA:
+ aGraphicData = rOption.GetString();
+ if (!InternalImgToPrivateURL(aGraphicData))
+ aGraphicData = INetURLObject::GetAbsURL(m_sBaseURL, aGraphicData);
+ break;
case HtmlOptionId::ALIGN:
eVertOri =
rOption.GetEnum( aHTMLImgVAlignTable,
@@ -427,6 +433,9 @@ IMAGE_SETEVENT:
}
}
+ if (sGrfNm.isEmpty() && !aGraphicData.isEmpty())
+ sGrfNm = aGraphicData;
+
if( sGrfNm.isEmpty() )
return;
@@ -469,8 +478,10 @@ IMAGE_SETEVENT:
sGrfNm.clear();
}
}
- else if (m_sBaseURL.isEmpty()) // sBaseURL is empty if the source is clipboard
+ else if (m_sBaseURL.isEmpty() || !aGraphicData.isEmpty())
{
+ // sBaseURL is empty if the source is clipboard
+ // aGraphicData is non-empty for <object data="..."> -> not a linked graphic.
if (ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aGraphicURL))
sGrfNm.clear();
}
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 7ad6b589e2b3..8f39db95bbb4 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -293,7 +293,7 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace,
}
}
-void SwHTMLParser::InsertEmbed()
+bool SwHTMLParser::InsertEmbed()
{
OUString aURL, aType, aName, aAlt, aId, aStyle, aClass;
OUString aData;
@@ -382,6 +382,10 @@ void 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.
+ return false;
+
SfxItemSet aItemSet( m_xDoc->GetAttrPool(), m_pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
if( HasStyleOptions( aStyle, aId, aClass ) )
@@ -422,7 +426,7 @@ void SwHTMLParser::InsertEmbed()
// do not insert plugin if it has neither URL nor type
bool bHasType = !aType.isEmpty();
if( !bHasURL && !bHasType && !bHasData )
- return;
+ return true;
if (!m_aEmbeds.empty())
{
@@ -431,7 +435,7 @@ void SwHTMLParser::InsertEmbed()
svt::EmbeddedObjectRef& rObj = pOLENode->GetOLEObj().GetObject();
Graphic aGraphic;
if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE)
- return;
+ return true;
rObj.SetGraphic(aGraphic, aType);
@@ -448,7 +452,7 @@ void SwHTMLParser::InsertEmbed()
SwFrameFormat* pFormat = pOLENode->GetFlyFormat();
if (!pFormat)
- return;
+ return true;
SwAttrSet aAttrSet(pFormat->GetAttrSet());
aAttrSet.ClearItem(RES_CNTNT);
@@ -456,7 +460,7 @@ void SwHTMLParser::InsertEmbed()
SwFormatFrameSize aFrameSize(ATT_FIX_SIZE, aTwipSize.Width(), aTwipSize.Height());
aAttrSet.Put(aFrameSize);
pOLENode->GetDoc()->SetFlyFrameAttr(*pFormat, aAttrSet);
- return;
+ return true;
}
// create the plug-in
@@ -559,13 +563,15 @@ void SwHTMLParser::InsertEmbed()
}
if (!bHasData)
- return;
+ return true;
SwOLENode* pOLENode = pNoTextNd->GetOLENode();
if (!pOLENode)
- return;
+ return true;
m_aEmbeds.push(pOLENode);
+
+ return true;
}
#if HAVE_FEATURE_JAVA
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index d196c718921e..0b0cecace0f0 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -1418,7 +1418,8 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
case HtmlTokenId::OBJECT_ON:
if (m_bXHTML)
{
- InsertEmbed();
+ if (!InsertEmbed())
+ InsertImage();
break;
}
#if HAVE_FEATURE_JAVA
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 911042defa20..8b9c9505d366 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -735,7 +735,7 @@ private:
// the actual insert methods for <IMG>, <EMBED>, <APPLET> and <PARAM>
void InsertImage(); // htmlgrin.cxx
- void InsertEmbed(); // htmlplug.cxx
+ bool InsertEmbed(); // htmlplug.cxx
#if HAVE_FEATURE_JAVA
void NewObject(); // htmlplug.cxx
More information about the Libreoffice-commits
mailing list