From 1b02ba03bd62a712e15c15384a3d105d2c088120 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Tue, 13 Feb 2018 21:49:57 +0900 Subject: shapes: don't use "GraphicURL" property, always use "Graphic" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tomaž Vajngerl --- oox/source/export/drawingml.cxx | 33 ++++++++++++++++++++++++--------- oox/source/export/shapes.cxx | 19 +++++++++++++++++-- 2 files changed, 41 insertions(+), 11 deletions(-) (limited to 'oox') diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index d56077c5240a..0503a088faf7 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1325,18 +1325,16 @@ void DrawingML::WritePattFill(const Reference& rXPropSet, const cs mpFS->endElementNS( XML_a , XML_pattFill ); } -void DrawingML::WriteSrcRect( const Reference< XPropertySet >& rXPropSet, const OUString& rURL ) +void DrawingML::WriteGraphicCropProperties(uno::Reference const & rXPropSet, Size const & rOriginalSize, MapMode const & rMapMode) { - GraphicObject aGraphicObject = GraphicObject::CreateGraphicObjectFromURL(rURL); - Size aOriginalSize = aGraphicObject.GetPrefSize(); - const MapMode& rMapMode = aGraphicObject.GetPrefMapMode(); + if (GetProperty(rXPropSet, "GraphicCrop")) + { + Size aOriginalSize(rOriginalSize); - // GraphicCrop is in mm100, so in case the original size is in pixels, convert it over. - if (rMapMode.GetMapUnit() == MapUnit::MapPixel) - aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aOriginalSize, MapMode(MapUnit::Map100thMM)); + // GraphicCrop is in mm100, so in case the original size is in pixels, convert it over. + if (rMapMode.GetMapUnit() == MapUnit::MapPixel) + aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aOriginalSize, MapMode(MapUnit::Map100thMM)); - if ( GetProperty( rXPropSet, "GraphicCrop" ) ) - { css::text::GraphicCrop aGraphicCropStruct; mAny >>= aGraphicCropStruct; @@ -1352,6 +1350,23 @@ void DrawingML::WriteSrcRect( const Reference< XPropertySet >& rXPropSet, const } } +void DrawingML::WriteSrcRect(const uno::Reference& rxPropertySet, const OUString& rURL) +{ + GraphicObject aGraphicObject = GraphicObject::CreateGraphicObjectFromURL(rURL); + Size aOriginalSize = aGraphicObject.GetPrefSize(); + const MapMode& rMapMode = aGraphicObject.GetPrefMapMode(); + WriteGraphicCropProperties(rxPropertySet, aOriginalSize, rMapMode); +} + +void DrawingML::WriteSrcRectXGraphic(uno::Reference const & rxPropertySet, + uno::Reference const & rxGraphic) +{ + Graphic aGraphic(rxGraphic); + Size aOriginalSize = aGraphic.GetPrefSize(); + const MapMode& rMapMode = aGraphic.GetPrefMapMode(); + WriteGraphicCropProperties(rxPropertySet, aOriginalSize, rMapMode); +} + void DrawingML::WriteStretch( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, const OUString& rURL ) { mpFS->startElementNS( XML_a, XML_stretch, FSEND ); diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 8199221686f3..e922a3bce934 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -1098,13 +1098,20 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape SAL_INFO("oox.shape", "graphicObject without text"); OUString sGraphicURL; + uno::Reference xGraphic; OUString sMediaURL; + Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY ); bool bHasGraphicURL = xShapeProps.is() && xShapeProps->getPropertySetInfo()->hasPropertyByName("GraphicURL") && (xShapeProps->getPropertyValue("GraphicURL") >>= sGraphicURL); + + if (xShapeProps.is() && xShapeProps->getPropertySetInfo()->hasPropertyByName("Graphic")) + xShapeProps->getPropertyValue("Graphic") >>= xGraphic; + + bool bHasAnyGraphic = bHasGraphicURL || xGraphic.is(); bool bHasMediaURL = xShapeProps.is() && xShapeProps->getPropertySetInfo()->hasPropertyByName("MediaURL") && (xShapeProps->getPropertyValue("MediaURL") >>= sMediaURL); - if (!pGraphic && !bHasGraphicURL && !bHasMediaURL) + if (!pGraphic && !bHasAnyGraphic && !bHasMediaURL) { SAL_INFO("oox.shape", "no graphic or media URL found"); return; @@ -1158,8 +1165,14 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape pFS->startElementNS( mnXmlNamespace, XML_blipFill, FSEND ); - if (pGraphic || bHasGraphicURL) + if (xGraphic.is()) + { + WriteXGraphicBlip(xShapeProps, xGraphic, false); + } + else if (pGraphic || bHasGraphicURL) + { WriteBlip(xShapeProps, sGraphicURL, false, pGraphic); + } else if (bHasMediaURL) { Reference rGraphic; @@ -1172,6 +1185,8 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape if (bHasGraphicURL) WriteSrcRect(xShapeProps, sGraphicURL); + else if (xGraphic.is()) + WriteSrcRectXGraphic(xShapeProps, xGraphic); // now we stretch always when we get pGraphic (when changing that // behavior, test n#780830 for regression, where the OLE sheet might get tiled -- cgit