summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-02-13 21:49:57 +0900
committerTomaž Vajngerl <quikee@gmail.com>2018-02-14 07:47:26 +0100
commit1b02ba03bd62a712e15c15384a3d105d2c088120 (patch)
treeb46f383c7ea60de65dbbede5b658a7babd813610 /xmloff
parent733d77570771e2536d5ce1f18ba82f68ac6c22ee (diff)
shapes: don't use "GraphicURL" property, always use "Graphic"
With GraphicURL property on shapes (XShape) we transported the external or internal URL to the model, which also included the GraphicObject uniqueID style URLs. This changes that - now we always use "Graphic" property and transfer XGraphic to and from graphic filters. "Graphic" property is already present for XShape so it wasn't needed to add it. Filters changed are: OOXML (oox), ODF (xmloff), RTF and binary MS (esherex). Also start using originURL on Graphic which now transports the URL of the external (linked) graphic/image if it was created that way. Change-Id: Ic338c60b7cfaaae354cf1e1ca3ae7a6373220230 Reviewed-on: https://gerrit.libreoffice.org/49648 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/xmlmultiimagehelper.hxx1
-rw-r--r--xmloff/source/core/xmlexp.cxx23
-rw-r--r--xmloff/source/core/xmlimp.cxx44
-rw-r--r--xmloff/source/core/xmlmultiimagehelper.cxx52
-rw-r--r--xmloff/source/draw/shapeexport.cxx82
-rw-r--r--xmloff/source/draw/ximpshap.cxx66
-rw-r--r--xmloff/source/draw/ximpshap.hxx2
7 files changed, 196 insertions, 74 deletions
diff --git a/xmloff/inc/xmlmultiimagehelper.hxx b/xmloff/inc/xmlmultiimagehelper.hxx
index ee2df0f53c74..2b29835c2f26 100644
--- a/xmloff/inc/xmlmultiimagehelper.hxx
+++ b/xmloff/inc/xmlmultiimagehelper.hxx
@@ -34,6 +34,7 @@ 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<css::graphic::XGraphic> getGraphicFromImportContext(const SvXMLImportContext& rContext) const;
public:
MultiImageImportHelper();
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index a3015b8903ef..7f5df92e5875 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -27,6 +27,7 @@
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <osl/mutex.hxx>
#include <tools/urlobj.hxx>
+#include <vcl/graph.hxx>
#include <comphelper/genericpropertyset.hxx>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/io/XInputStream.hpp>
@@ -1884,19 +1885,27 @@ OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectUR
OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString const & rRequestedName)
{
- OUString sInternalURL;
+ OUString sURL;
- uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY);
+ Graphic aGraphic(rxGraphic);
+ OUString aOriginURL = aGraphic.getOriginURL();
- if (mxGraphicResolver.is() && xGraphicStorageHandler.is())
+ if (!aOriginURL.isEmpty())
{
- if (!(getExportFlags() & SvXMLExportFlags::EMBEDDED))
+ sURL = GetRelativeReference(aOriginURL);
+ }
+ else
+ {
+ uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY);
+ if (mxGraphicResolver.is() && xGraphicStorageHandler.is())
{
- sInternalURL = xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestedName);
+ if (!(getExportFlags() & SvXMLExportFlags::EMBEDDED))
+ {
+ sURL = xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestedName);
+ }
}
}
-
- return sInternalURL;
+ return sURL;
}
Reference< XInputStream > SvXMLExport::GetEmbeddedGraphicObjectStream( const OUString& rGraphicObjectURL )
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 5203cdc4d751..c77193ba38cb 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -23,6 +23,7 @@
#include <tools/diagnose_ex.h>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <tools/urlobj.hxx>
+#include <vcl/graph.hxx>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmluconv.hxx>
@@ -45,6 +46,7 @@
#include <com/sun/star/document/XBinaryStreamResolver.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/document/XGraphicStorageHandler.hpp>
+#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/xml/sax/XLocator.hpp>
#include <com/sun/star/xml/sax/FastParser.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
@@ -57,6 +59,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/documentconstants.hxx>
#include <comphelper/storagehelper.hxx>
+#include <comphelper/propertysequence.hxx>
#include <unotools/fontcvt.hxx>
#include <o3tl/make_unique.hxx>
#include <xmloff/fasttokenhandler.hxx>
@@ -1353,14 +1356,47 @@ bool SvXMLImport::IsPackageURL( const OUString& rURL ) const
return true;
}
-css::uno::Reference<css::graphic::XGraphic> SvXMLImport::loadGraphicByURL(const OUString& rURL)
+uno::Reference<graphic::XGraphic> SvXMLImport::loadGraphicByURL(OUString const & rURL)
{
- css::uno::Reference<css::graphic::XGraphic> xGraphic;
+ uno::Reference<graphic::XGraphic> xGraphic;
uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY);
- if (IsPackageURL(rURL) && xGraphicStorageHandler.is())
+ if (xGraphicStorageHandler.is())
{
- xGraphic = xGraphicStorageHandler->loadGraphic(rURL);
+ if (IsPackageURL(rURL))
+ {
+ xGraphic = xGraphicStorageHandler->loadGraphic(rURL);
+ }
+ else
+ {
+ uno::Reference<graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(GetComponentContext()));
+ OUString const & rAbsoluteURL = GetAbsoluteReference(rURL);
+ uno::Sequence<beans::PropertyValue> aLoadProperties(comphelper::InitPropertySequence(
+ {
+ { "URL", uno::makeAny(rAbsoluteURL) }
+ }));
+
+ xGraphic = xProvider->queryGraphic(aLoadProperties);
+ if (xGraphic.is())
+ {
+ Graphic aGraphic(xGraphic);
+ aGraphic.setOriginURL(rAbsoluteURL);
+ printf ("URL %s\n", rAbsoluteURL.toUtf8().getStr());
+ }
+ }
+ }
+
+ return xGraphic;
+}
+
+uno::Reference<graphic::XGraphic> SvXMLImport::loadGraphicFromBase64(uno::Reference<io::XOutputStream> const & rxOutputStream)
+{
+ uno::Reference<graphic::XGraphic> xGraphic;
+ uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY);
+
+ if (xGraphicStorageHandler.is())
+ {
+ xGraphic = xGraphicStorageHandler->loadGraphicFromOutputStream(rxOutputStream);
}
return xGraphic;
diff --git a/xmloff/source/core/xmlmultiimagehelper.cxx b/xmloff/source/core/xmlmultiimagehelper.cxx
index 3d7725a3b24f..83cee5bbae2a 100644
--- a/xmloff/source/core/xmlmultiimagehelper.cxx
+++ b/xmloff/source/core/xmlmultiimagehelper.cxx
@@ -26,7 +26,7 @@ using namespace ::com::sun::star;
namespace
{
- sal_uInt32 getQualityIndex(const OUString& rString)
+ OUString getMimeTypeForURL(const OUString& rString)
{
OUString sMimeType;
if (rString.startsWith("vnd.sun.star.GraphicObject"))
@@ -42,45 +42,48 @@ namespace
else
{
SAL_WARN("xmloff", "Unknown image source: " << rString);
- return 0;
}
+ return sMimeType;
+ }
+ sal_uInt32 getQualityIndex(const OUString& rMimeType)
+ {
// pixel formats first
- if(sMimeType == "image/bmp")
+ if (rMimeType == "image/bmp")
{
return 10;
}
- if(sMimeType == "image/gif")
+ if (rMimeType == "image/gif")
{
return 20;
}
- if(sMimeType == "image/jpeg")
+ if (rMimeType == "image/jpeg")
{
return 30;
}
- if(sMimeType == "image/png")
+ if (rMimeType == "image/png")
{
return 40;
}
// vector formats, prefer always
- if(sMimeType == "image/x-svm")
+ if (rMimeType == "image/x-svm")
{
return 1000;
}
- if(sMimeType == "image/x-wmf")
+ if (rMimeType == "image/x-wmf")
{
return 1010;
}
- if(sMimeType == "image/x-emf")
+ if (rMimeType == "image/x-emf")
{
return 1020;
}
- if(sMimeType == "application/pdf")
+ if (rMimeType == "application/pdf")
{
return 1030;
}
- if(sMimeType == "image/svg+xml")
+ if (rMimeType == "image/svg+xml")
{
return 1040;
}
@@ -111,10 +114,26 @@ SvXMLImportContextRef MultiImageImportHelper::solveMultipleImages()
for(std::vector<SvXMLImportContextRef>::size_type a = 0; a < maImplContextVector.size(); a++)
{
- const OUString aStreamURL(getGraphicURLFromImportContext(*maImplContextVector[a].get()));
- const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL));
+ const SvXMLImportContext& rContext = *maImplContextVector[a].get();
+
+ sal_uInt32 nNewQuality = 0;
+
+ uno::Reference<graphic::XGraphic> xGraphic(getGraphicFromImportContext(rContext));
+ if (xGraphic.is())
+ {
+ OUString sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForXGraphic(xGraphic);
+ nNewQuality = getQualityIndex(sMimeType);
+ }
+ else
+ {
+ const OUString aStreamURL(getGraphicURLFromImportContext(rContext));
+ if (!aStreamURL.isEmpty())
+ {
+ nNewQuality = getQualityIndex(getMimeTypeForURL(aStreamURL));
+ }
+ }
- if(nNewQuality > nBestQuality)
+ if (nNewQuality > nBestQuality)
{
nBestQuality = nNewQuality;
nIndexOfPreferred = a;
@@ -156,4 +175,9 @@ void MultiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportCo
maImplContextVector.emplace_back(const_cast< SvXMLImportContext* >(&rSvXMLImportContext));
}
+uno::Reference<graphic::XGraphic> MultiImageImportHelper::getGraphicFromImportContext(const SvXMLImportContext& /*rContext*/) const
+{
+ return uno::Reference<graphic::XGraphic>();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx
index 81293655dea7..b1b5ea0e1537 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -2307,6 +2307,33 @@ void XMLShapeExport::ImpExportPolygonShape(
}
+namespace
+{
+
+OUString getNameFromStreamURL(OUString const & rURL)
+{
+ const OUString sPackageURL("vnd.sun.star.Package:");
+
+ OUString sResult;
+
+ if (rURL.match(sPackageURL))
+ {
+ OUString sRequestedName = rURL.copy(sPackageURL.getLength());
+ sal_Int32 nLastIndex = sRequestedName.lastIndexOf('/') + 1;
+ if ((nLastIndex > 0) && (nLastIndex < sRequestedName.getLength()))
+ sRequestedName = sRequestedName.copy(nLastIndex);
+ nLastIndex = sRequestedName.lastIndexOf('.');
+ if (nLastIndex >= 0)
+ sRequestedName = sRequestedName.copy(0, nLastIndex);
+ if (!sRequestedName.isEmpty())
+ sResult = sRequestedName;
+ }
+
+ return sResult;
+}
+
+} // end anonymous namespace
+
void XMLShapeExport::ImpExportGraphicObjectShape(
const uno::Reference< drawing::XShape >& xShape,
XmlShapeType eShapeType, XMLShapeExportFlags nFeatures, awt::Point* pRefPoint)
@@ -2320,8 +2347,6 @@ void XMLShapeExport::ImpExportGraphicObjectShape(
// Transformation
ImpExportNewTrans(xPropSet, nFeatures, pRefPoint);
- OUString sImageURL;
-
if(eShapeType == XmlShapeTypePresGraphicObjectShape)
bIsEmptyPresObj = ImpExportPresentationAttributes( xPropSet, GetXMLToken(XML_PRESENTATION_GRAPHIC) );
@@ -2331,53 +2356,56 @@ void XMLShapeExport::ImpExportGraphicObjectShape(
const bool bSaveBackwardsCompatible = bool( mrExport.getExportFlags() & SvXMLExportFlags::SAVEBACKWARDCOMPATIBLE );
+ OUString sImageURL;
+ uno::Reference<graphic::XGraphic> xGraphic;
+
if( !bIsEmptyPresObj || bSaveBackwardsCompatible )
{
if( !bIsEmptyPresObj )
{
OUString aStreamURL;
-
xPropSet->getPropertyValue("GraphicStreamURL") >>= aStreamURL;
+
+ OUString sRequestedName = getNameFromStreamURL(aStreamURL);
+
xPropSet->getPropertyValue("GraphicURL") >>= sImageURL;
- OUString aResolveURL( sImageURL );
- const OUString sPackageURL( "vnd.sun.star.Package:" );
+ uno::Any aGraphicAny = xPropSet->getPropertyValue("Graphic");
+ if (aGraphicAny.has<uno::Reference<graphic::XGraphic>>())
+ xGraphic = aGraphicAny.get<uno::Reference<graphic::XGraphic>>();
+
+ OUString aStoredURL;
- // trying to preserve the filename for embedded images which already have its stream inside the package
- bool bIsEmbeddedImageWithExistingStreamInPackage = false;
- if ( aStreamURL.match( sPackageURL ) )
+ if (xGraphic.is())
{
- bIsEmbeddedImageWithExistingStreamInPackage = true;
-
- OUString sRequestedName = aStreamURL.copy( sPackageURL.getLength() );
- sal_Int32 nLastIndex = sRequestedName.lastIndexOf( '/' ) + 1;
- if ( ( nLastIndex > 0 ) && ( nLastIndex < sRequestedName.getLength() ) )
- sRequestedName = sRequestedName.copy( nLastIndex );
- nLastIndex = sRequestedName.lastIndexOf( '.' );
- if ( nLastIndex >= 0 )
- sRequestedName = sRequestedName.copy( 0, nLastIndex );
- if ( !sRequestedName.isEmpty() )
- {
+ aStoredURL = mrExport.AddEmbeddedXGraphic(xGraphic, sRequestedName);
+ }
+ else
+ {
+ OUString aResolveURL(sImageURL);
+ if (!sRequestedName.isEmpty())
aResolveURL += "?requestedName=" + sRequestedName;
- }
+
+ aStoredURL = mrExport.AddEmbeddedGraphicObject(aResolveURL);
}
- const OUString aStr = mrExport.AddEmbeddedGraphicObject( aResolveURL );
- mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aStr );
+ mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aStoredURL);
- if( !aStr.isEmpty() )
+ if (!aStoredURL.isEmpty())
{
+ const OUString sPackageURL("vnd.sun.star.Package:");
+
// apply possible changed stream URL to embedded image object
- if ( bIsEmbeddedImageWithExistingStreamInPackage )
+ if (!sRequestedName.isEmpty())
{
OUString newStreamURL = sPackageURL;
- if ( aStr[0] == '#' )
+ if (aStoredURL[0] == '#')
{
- newStreamURL += aStr.copy( 1, aStr.getLength() - 1 );
+ newStreamURL += aStoredURL.copy(1, aStoredURL.getLength() - 1);
}
else
{
- newStreamURL += aStr;
+ newStreamURL += aStoredURL;
}
if (newStreamURL != aStreamURL)
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 4ccdb68d5ff1..187262720251 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -2402,15 +2402,10 @@ void SdXMLGraphicObjectShapeContext::StartElement( const css::uno::Reference< cs
{
if( !maURL.isEmpty() )
{
- uno::Any aAny;
- aAny <<= GetImport().ResolveGraphicObjectURL( maURL, GetImport().isGraphicLoadOnDemandSupported() );
- try
- {
- xPropset->setPropertyValue("GraphicURL", aAny );
- xPropset->setPropertyValue("GraphicStreamURL", aAny );
- }
- catch (const lang::IllegalArgumentException&)
+ uno::Reference<graphic::XGraphic> xGraphic = GetImport().loadGraphicByURL(maURL);
+ if (xGraphic.is())
{
+ xPropset->setPropertyValue("Graphic", uno::makeAny(xGraphic));
}
}
}
@@ -2439,23 +2434,15 @@ void SdXMLGraphicObjectShapeContext::StartElement( const css::uno::Reference< cs
void SdXMLGraphicObjectShapeContext::EndElement()
{
- if( mxBase64Stream.is() )
+ if (mxBase64Stream.is())
{
- OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream ) );
- if( !sURL.isEmpty() )
+ uno::Reference<graphic::XGraphic> xGraphic(GetImport().loadGraphicFromBase64(mxBase64Stream));
+ if (xGraphic.is())
{
- try
- {
- uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
- if(xProps.is())
- {
- const uno::Any aAny( uno::makeAny( sURL ) );
- xProps->setPropertyValue("GraphicURL", aAny );
- xProps->setPropertyValue("GraphicStreamURL", aAny );
- }
- }
- catch (const lang::IllegalArgumentException&)
+ uno::Reference<beans::XPropertySet> xProperties(mxShape, uno::UNO_QUERY);
+ if (xProperties.is())
{
+ xProperties->setPropertyValue("Graphic", uno::makeAny(xGraphic));
}
}
}
@@ -3365,6 +3352,41 @@ void SdXMLFrameShapeContext::removeGraphicFromImportContext(const SvXMLImportCon
}
}
+namespace
+{
+uno::Reference<beans::XPropertySet> getGraphicPropertySetFromImportContext(const SvXMLImportContext& rContext)
+{
+ uno::Reference<beans::XPropertySet> aPropertySet;
+ const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast<const SdXMLGraphicObjectShapeContext*>(&rContext);
+
+ if (pSdXMLGraphicObjectShapeContext)
+ aPropertySet.set(pSdXMLGraphicObjectShapeContext->getShape(), uno::UNO_QUERY);
+
+ return aPropertySet;
+}
+
+} // end anonymous namespace
+
+uno::Reference<graphic::XGraphic> SdXMLFrameShapeContext::getGraphicFromImportContext(const SvXMLImportContext& rContext) const
+{
+ uno::Reference<graphic::XGraphic> xGraphic;
+ try
+ {
+ const uno::Reference<beans::XPropertySet> xPropertySet = getGraphicPropertySetFromImportContext(rContext);
+
+ if (xPropertySet.is())
+ {
+ xPropertySet->getPropertyValue("Graphic") >>= xGraphic;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION_WHEN("Error in cleanup of multiple graphic object import.");
+ }
+
+ return xGraphic;
+}
+
OUString SdXMLFrameShapeContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const
{
OUString aRetval;
diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx
index 950d8645aae8..c6376719c637 100644
--- a/xmloff/source/draw/ximpshap.hxx
+++ b/xmloff/source/draw/ximpshap.hxx
@@ -550,6 +550,8 @@ protected:
virtual OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const override;
virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) override;
+ css::uno::Reference<css::graphic::XGraphic> getGraphicFromImportContext(const SvXMLImportContext& rContext) const override;
+
public:
SdXMLFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,