From 27008aa028cde8d270e898c5743a9fe5c7701dab Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 5 Mar 2018 20:44:08 +0900 Subject: xmloff: convert XMLTextParagraphExport to get rid of "GraphicURL" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I10cc1115bfe628dc296b67b75e386e1a2e4a6c46 Reviewed-on: https://gerrit.libreoffice.org/50789 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- xmloff/inc/xmlmultiimagehelper.hxx | 4 +- xmloff/source/core/xmlmultiimagehelper.cxx | 39 +++------ xmloff/source/draw/ximpshap.cxx | 10 +-- xmloff/source/draw/ximpshap.hxx | 5 +- xmloff/source/text/XMLTextFrameContext.cxx | 44 +++++++--- xmloff/source/text/XMLTextFrameContext.hxx | 5 +- xmloff/source/text/txtparae.cxx | 126 ++++++++++++++++------------- 7 files changed, 125 insertions(+), 108 deletions(-) (limited to 'xmloff') diff --git a/xmloff/inc/xmlmultiimagehelper.hxx b/xmloff/inc/xmlmultiimagehelper.hxx index 2b29835c2f26..90a279c083d2 100644 --- a/xmloff/inc/xmlmultiimagehelper.hxx +++ b/xmloff/inc/xmlmultiimagehelper.hxx @@ -32,9 +32,9 @@ private: protected: /// helper to get the created xShape instance, override this - virtual OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const = 0; virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) = 0; - virtual css::uno::Reference getGraphicFromImportContext(const SvXMLImportContext& rContext) const; + virtual OUString getGraphicPackageURLFromImportContext(const SvXMLImportContext& rContext) const = 0; + virtual css::uno::Reference getGraphicFromImportContext(const SvXMLImportContext& rContext) const = 0; public: MultiImageImportHelper(); diff --git a/xmloff/source/core/xmlmultiimagehelper.cxx b/xmloff/source/core/xmlmultiimagehelper.cxx index 83cee5bbae2a..6acf7b30ed28 100644 --- a/xmloff/source/core/xmlmultiimagehelper.cxx +++ b/xmloff/source/core/xmlmultiimagehelper.cxx @@ -29,19 +29,10 @@ namespace OUString getMimeTypeForURL(const OUString& rString) { OUString sMimeType; - if (rString.startsWith("vnd.sun.star.GraphicObject")) + if (rString.startsWith("vnd.sun.star.Package")) { - sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageUrl(rString); - } - else if (rString.startsWith("vnd.sun.star.Package")) - { - sMimeType - = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension(OUStringToOString( - rString.copy(rString.lastIndexOf(".") + 1), RTL_TEXTENCODING_ASCII_US)); - } - else - { - SAL_WARN("xmloff", "Unknown image source: " << rString); + OString aExtension = OUStringToOString(rString.copy(rString.lastIndexOf(".") + 1), RTL_TEXTENCODING_ASCII_US); + sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension(aExtension); } return sMimeType; } @@ -116,23 +107,22 @@ SvXMLImportContextRef MultiImageImportHelper::solveMultipleImages() { const SvXMLImportContext& rContext = *maImplContextVector[a].get(); - sal_uInt32 nNewQuality = 0; - uno::Reference xGraphic(getGraphicFromImportContext(rContext)); - if (xGraphic.is()) + OUString sMimeType; + + const OUString aStreamURL(getGraphicPackageURLFromImportContext(rContext)); + if (!aStreamURL.isEmpty()) { - OUString sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForXGraphic(xGraphic); - nNewQuality = getQualityIndex(sMimeType); + sMimeType = getMimeTypeForURL(aStreamURL); } else { - const OUString aStreamURL(getGraphicURLFromImportContext(rContext)); - if (!aStreamURL.isEmpty()) - { - nNewQuality = getQualityIndex(getMimeTypeForURL(aStreamURL)); - } + uno::Reference xGraphic(getGraphicFromImportContext(rContext)); + if (xGraphic.is()) + sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForXGraphic(xGraphic); } + sal_uInt32 nNewQuality = getQualityIndex(sMimeType); if (nNewQuality > nBestQuality) { nBestQuality = nNewQuality; @@ -175,9 +165,4 @@ void MultiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportCo maImplContextVector.emplace_back(const_cast< SvXMLImportContext* >(&rSvXMLImportContext)); } -uno::Reference MultiImageImportHelper::getGraphicFromImportContext(const SvXMLImportContext& /*rContext*/) const -{ - return uno::Reference(); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index 187262720251..5e59db4fafcb 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -3387,7 +3387,7 @@ uno::Reference SdXMLFrameShapeContext::getGraphicFromImportCo return xGraphic; } -OUString SdXMLFrameShapeContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const +OUString SdXMLFrameShapeContext::getGraphicPackageURLFromImportContext(const SvXMLImportContext& rContext) const { OUString aRetval; const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast< const SdXMLGraphicObjectShapeContext* >(&rContext); @@ -3398,15 +3398,9 @@ OUString SdXMLFrameShapeContext::getGraphicURLFromImportContext(const SvXMLImpor { const uno::Reference< beans::XPropertySet > xPropSet(pSdXMLGraphicObjectShapeContext->getShape(), uno::UNO_QUERY_THROW); - if(xPropSet.is()) + if (xPropSet.is()) { xPropSet->getPropertyValue("GraphicStreamURL") >>= aRetval; - - if(!aRetval.getLength()) - { - // it maybe a link, try GraphicURL - xPropSet->getPropertyValue("GraphicURL") >>= aRetval; - } } } catch( uno::Exception& ) diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx index c6376719c637..30f5b149ad9f 100644 --- a/xmloff/source/draw/ximpshap.hxx +++ b/xmloff/source/draw/ximpshap.hxx @@ -547,9 +547,8 @@ private: protected: /// helper to get the created xShape instance, needs to be overridden - virtual OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const override; - virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) override; - + void removeGraphicFromImportContext(const SvXMLImportContext& rContext) override; + OUString getGraphicPackageURLFromImportContext(const SvXMLImportContext& rContext) const override; css::uno::Reference getGraphicFromImportContext(const SvXMLImportContext& rContext) const override; public: diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx index 0580c1a70915..786461819d89 100644 --- a/xmloff/source/text/XMLTextFrameContext.cxx +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -660,20 +660,19 @@ void XMLTextFrameContext_Impl::Create() "neither URL nor base64 image data given" ); rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); - if( !sHRef.isEmpty() ) + uno::Reference xGraphic; + if (!sHRef.isEmpty()) { - bool bForceLoad = xTxtImport->IsInsertMode() || - xTxtImport->IsBlockMode() || - xTxtImport->IsStylesOnlyMode() || - xTxtImport->IsOrganizerMode(); - sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad ); + xGraphic = GetImport().loadGraphicByURL(sHRef); } - else if( xBase64Stream.is() ) + else if (xBase64Stream.is()) { - sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ); + xGraphic = GetImport().loadGraphicFromBase64(xBase64Stream); xBase64Stream = nullptr; } - xPropSet->setPropertyValue( "GraphicURL", Any(sHRef) ); + + if (xGraphic.is()) + xPropSet->setPropertyValue("Graphic", Any(xGraphic)); // filter name xPropSet->setPropertyValue( "GraphicFilter", Any(sFilterName) ); @@ -763,18 +762,41 @@ void XMLTextFrameContext::removeGraphicFromImportContext(const SvXMLImportContex } } -OUString XMLTextFrameContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const +OUString XMLTextFrameContext::getGraphicPackageURLFromImportContext(const SvXMLImportContext& rContext) const { const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext); if(pXMLTextFrameContext_Impl) { - return pXMLTextFrameContext_Impl->GetHRef(); + return "vnd.sun.star.Package:" + pXMLTextFrameContext_Impl->GetHRef(); } return OUString(); } +css::uno::Reference XMLTextFrameContext::getGraphicFromImportContext(const SvXMLImportContext& rContext) const +{ + uno::Reference xGraphic; + + const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast(&rContext); + + if (pXMLTextFrameContext_Impl) + { + try + { + const uno::Reference& xPropertySet = pXMLTextFrameContext_Impl->GetPropSet(); + + if (xPropertySet.is()) + { + xPropertySet->getPropertyValue("Graphic") >>= xGraphic; + } + } + catch (uno::Exception&) + {} + } + return xGraphic; +} + bool XMLTextFrameContext_Impl::CreateIfNotThere() { if( !xPropSet.is() && diff --git a/xmloff/source/text/XMLTextFrameContext.hxx b/xmloff/source/text/XMLTextFrameContext.hxx index 2d11b287ec30..e3c570c477fe 100644 --- a/xmloff/source/text/XMLTextFrameContext.hxx +++ b/xmloff/source/text/XMLTextFrameContext.hxx @@ -59,8 +59,9 @@ class XMLTextFrameContext : public SvXMLImportContext, public MultiImageImportHe protected: /// helper to get the created xShape instance, needs to be overridden - virtual OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const override; - virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) override; + void removeGraphicFromImportContext(const SvXMLImportContext& rContext) override; + OUString getGraphicPackageURLFromImportContext(const SvXMLImportContext& rContext) const override; + css::uno::Reference getGraphicFromImportContext(const SvXMLImportContext& rContext) const override; public: diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index ebf533781b45..c23ddb2bfa98 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -3103,84 +3103,100 @@ void XMLTextParagraphExport::_exportTextGraphic( // original content SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_DRAW, XML_FRAME, false, true); - // replacement graphic for backwards compatibility, but - // only for SVG and metafiles currently - uno::Reference xReplacementGraphic; - rPropSet->getPropertyValue("ReplacementGraphic") >>= xReplacementGraphic; + { + // xlink:href + uno::Reference xGraphic; + rPropSet->getPropertyValue("Graphic") >>= xGraphic; - // xlink:href - OUString sOrigURL; - rPropSet->getPropertyValue("GraphicURL") >>= sOrigURL; - OUString sURL(GetExport().AddEmbeddedGraphicObject( sOrigURL )); + OUString sInternalURL; + OUString sOutMimeType; - // If there still is no url, then graphic is empty - if( !sURL.isEmpty() ) - { - GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sURL ); - GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); - GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); - GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, - XML_ONLOAD ); - } + if (xGraphic.is()) + { + sInternalURL = GetExport().AddEmbeddedXGraphic(xGraphic, sOutMimeType); + } - // draw:filter-name - OUString sGrfFilter; - rPropSet->getPropertyValue( sGraphicFilter ) >>= sGrfFilter; - if( !sGrfFilter.isEmpty() ) - GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME, - sGrfFilter ); + // If there still is no url, then graphic is empty + if (!sInternalURL.isEmpty()) + { + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sInternalURL); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD); + } - // Add mimetype to make it easier for readers to get the base64 image type right, tdf#109202 - // do we have a hard export image filter set? then that's our mimetype - OUString aSourceMimeType = GetExport().GetImageFilterName(); - // otherwise determine mimetype from graphic - if ( aSourceMimeType.isEmpty() ) - aSourceMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageUrl(sOrigURL); - else // !aSourceMimeType.isEmpty() - { - const OString aExt( OUStringToOString( aSourceMimeType, RTL_TEXTENCODING_ASCII_US ) ); - aSourceMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension( aExt ); - } + // draw:filter-name + OUString sGrfFilter; + rPropSet->getPropertyValue( sGraphicFilter ) >>= sGrfFilter; + if( !sGrfFilter.isEmpty() ) + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME, + sGrfFilter ); - if (GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012) - { - GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aSourceMimeType); - } + if (GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012) + { + if (sOutMimeType.isEmpty()) + { + GetExport().GetGraphicMimeTypeFromStream(xGraphic, sOutMimeType); + } + if (!sOutMimeType.isEmpty()) + { + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", sOutMimeType); + } + } - { - SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW, - XML_IMAGE, false, true ); // optional office:binary-data - GetExport().AddEmbeddedGraphicObjectAsBase64( sOrigURL ); + if (xGraphic.is()) + { + SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, false, true ); + GetExport().AddEmbeddedXGraphicAsBase64(xGraphic); + } } - //Resolves: fdo#62461 put preferred image first above, followed by - //fallback here - if (xReplacementGraphic.is()) { - OUString aMimeType; - const OUString sHref = GetExport().AddEmbeddedXGraphic(xReplacementGraphic, aMimeType); + // replacement graphic for backwards compatibility, but + // only for SVG and metafiles currently + uno::Reference xReplacementGraphic; + rPropSet->getPropertyValue("ReplacementGraphic") >>= xReplacementGraphic; - if (aMimeType.isEmpty()) - GetExport().GetGraphicMimeTypeFromStream(xReplacementGraphic, aMimeType); + OUString sInternalURL; + OUString sOutMimeType; + + //Resolves: fdo#62461 put preferred image first above, followed by + //fallback here + if (xReplacementGraphic.is()) + { + sInternalURL = GetExport().AddEmbeddedXGraphic(xReplacementGraphic, sOutMimeType); + } // If there is no url, then graphic is empty - if (!sHref.isEmpty()) + if (!sInternalURL.isEmpty()) { - GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sHref); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sInternalURL); GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE); GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED); GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD); } - if (!aMimeType.isEmpty()) - GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aMimeType); + if (GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012) + { + if (sOutMimeType.isEmpty()) + { + GetExport().GetGraphicMimeTypeFromStream(xReplacementGraphic, sOutMimeType); + } + if (!sOutMimeType.isEmpty()) + { + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", sOutMimeType); + } + } - SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, true, true); // optional office:binary-data - GetExport().AddEmbeddedXGraphicAsBase64(xReplacementGraphic); + if (xReplacementGraphic.is()) + { + SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, true, true); + GetExport().AddEmbeddedXGraphicAsBase64(xReplacementGraphic); + } } // script:events -- cgit