summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-12-18 13:12:50 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2020-12-22 06:37:22 +0100
commit3d7c90b45c607fe560bacd8f57de0966a93edb4d (patch)
tree57f8b9a77b0b13182b54dc192cf2249ee149e8a6
parentb5a02acda8396c108e21e72fc830cc41a0bc890c (diff)
tdf#138953: use original (cropped, but unrotated) object size in spPr
This not only fixes the regression from b226383a83e41bbced9fc2a02dc09a449401ec97, but also makes the written size more correct than before, when it was slightly larger compared to original object size. Corrected unit test for tdf#116371 reflect that: the object in ODT is 241.78 mm x 240.61 mm. It previously was exported as 241.88 x 240.70; now the exported size is closer: 241.79 x 240.63. Change-Id: Ibfe85c7cd98c089e58af8d7f3848990af8e1100f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107957 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit 3dc2e629b247873bfbd3190c11152d8d2bab1a03) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107996
-rw-r--r--sw/qa/extras/ooxmlexport/data/croppedAndRotated.odtbin0 -> 11188 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport13.cxx4
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport16.cxx14
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx42
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx3
5 files changed, 45 insertions, 18 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/croppedAndRotated.odt b/sw/qa/extras/ooxmlexport/data/croppedAndRotated.odt
new file mode 100644
index 000000000000..825db09da8bf
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/croppedAndRotated.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index daaecd43df9f..a9ea821e1700 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -610,8 +610,8 @@ DECLARE_OOXMLEXPORT_TEST(testTdf116371, "tdf116371.odt")
auto xShape(getShape(1));
CPPUNIT_ASSERT_DOUBLES_EQUAL(4700.0, getProperty<double>(xShape, "RotateAngle"), 10);
auto frameRect = getProperty<awt::Rectangle>(xShape, "FrameRect");
- CPPUNIT_ASSERT_EQUAL(sal_Int32(24070), frameRect.Height);
- CPPUNIT_ASSERT_EQUAL(sal_Int32(24188), frameRect.Width);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(24063), frameRect.Height);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(24179), frameRect.Width);
}
DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFrameSizeExport, "floating-tables-anchor.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index 174f2f0f7330..e12804e58289 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -38,6 +38,20 @@ DECLARE_OOXMLEXPORT_TEST(testTdf138892_noNumbering, "tdf138892_noNumbering.docx"
CPPUNIT_ASSERT_MESSAGE("Para3: <blank line>", getProperty<OUString>(getParagraph(3), "NumberingStyleName").isEmpty());
}
+DECLARE_OOXMLEXPORT_TEST(testTdf138953, "croppedAndRotated.odt")
+{
+ CPPUNIT_ASSERT_EQUAL(1, getShapes());
+ CPPUNIT_ASSERT_EQUAL(1, getPages());
+ // Make sure the rotation is exported correctly, and size not distorted
+ auto xShape(getShape(1));
+ CPPUNIT_ASSERT_EQUAL(27000.0, getProperty<double>(xShape, "RotateAngle"));
+ auto frameRect = getProperty<css::awt::Rectangle>(xShape, "FrameRect");
+ // Before the fix, original object size (i.e., before cropping) was written to spPr in OOXML,
+ // and the resulting object size was much larger than should be.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(12961), frameRect.Height);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(8664), frameRect.Width);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 534ba9b4f8bf..fd304e9f4fe9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4837,13 +4837,12 @@ void DocxAttributeOutput::DefaultStyle()
/* Writes <a:srcRect> tag back to document.xml if a file contains a cropped image.
* NOTE : Tested on images of type JPEG,EMF/WMF,BMP, PNG and GIF.
*/
-void DocxAttributeOutput::WriteSrcRect(const SdrObject* pSdrObj, const SwFrameFormat* pFrameFormat )
+void DocxAttributeOutput::WriteSrcRect(
+ const css::uno::Reference<css::beans::XPropertySet>& xShapePropSet,
+ const SwFrameFormat* pFrameFormat)
{
- uno::Reference< drawing::XShape > xShape( const_cast<SdrObject*>(pSdrObj)->getUnoShape(), uno::UNO_QUERY );
- uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
-
uno::Reference<graphic::XGraphic> xGraphic;
- xPropSet->getPropertyValue("Graphic") >>= xGraphic;
+ xShapePropSet->getPropertyValue("Graphic") >>= xGraphic;
const Graphic aGraphic(xGraphic);
Size aOriginalSize(aGraphic.GetPrefSize());
@@ -4856,7 +4855,7 @@ void DocxAttributeOutput::WriteSrcRect(const SdrObject* pSdrObj, const SwFrameFo
}
css::text::GraphicCrop aGraphicCropStruct;
- xPropSet->getPropertyValue( "GraphicCrop" ) >>= aGraphicCropStruct;
+ xShapePropSet->getPropertyValue("GraphicCrop") >>= aGraphicCropStruct;
sal_Int32 nCropL = aGraphicCropStruct.Left;
sal_Int32 nCropR = aGraphicCropStruct.Right;
sal_Int32 nCropT = aGraphicCropStruct.Top;
@@ -5023,7 +5022,6 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
rtl::Reference<sax_fastparser::FastAttributeList> xFrameAttributes(
FastSerializerHelper::createAttrList());
- Size aSize = rSize;
if (pGrfNode)
{
const SwAttrSet& rSet = pGrfNode->GetSwAttrSet();
@@ -5037,10 +5035,27 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
// RES_GRFATR_ROTATION is in 10ths of degree; convert to 100ths for macro
sal_uInt32 mOOXMLRot = oox::drawingml::ExportRotateClockwisify(nRot*10);
xFrameAttributes->add(XML_rot, OString::number(mOOXMLRot));
- aSize = pGrfNode->GetTwipSize();
}
}
+ css::uno::Reference<css::beans::XPropertySet> xShapePropSet;
+ if (pSdrObj)
+ {
+ css::uno::Reference<css::drawing::XShape> xShape(
+ const_cast<SdrObject*>(pSdrObj)->getUnoShape(), css::uno::UNO_QUERY);
+ xShapePropSet.set(xShape, css::uno::UNO_QUERY);
+ assert(xShapePropSet);
+ }
+
+ Size aSize = rSize;
+ // We need the original (cropped, but unrotated) size of object. So prefer the object data,
+ // and only use passed frame size as fallback.
+ if (xShapePropSet)
+ {
+ if (css::awt::Size val; xShapePropSet->getPropertyValue("Size") >>= val)
+ aSize = Size(convertMm100ToTwip(val.Width), convertMm100ToTwip(val.Height));
+ }
+
m_rExport.SdrExporter().startDMLAnchorInline(pFrameFormat, aSize);
// picture description (used for pic:cNvPr later too)
@@ -5054,11 +5069,9 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
m_pSerializer->startElementNS( XML_wp, XML_docPr, docPrAttrListRef );
OUString sURL, sRelId;
- if(pSdrObj)
+ if (xShapePropSet)
{
- uno::Reference< drawing::XShape > xShape( const_cast<SdrObject*>(pSdrObj)->getUnoShape(), uno::UNO_QUERY );
- uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
- xPropSet->getPropertyValue("HyperLinkURL") >>= sURL;
+ xShapePropSet->getPropertyValue("HyperLinkURL") >>= sURL;
if(!sURL.isEmpty())
{
if (sURL.startsWith("#") && sURL.indexOf(' ') != -1 && !sURL.endsWith("|outline") && !sURL.endsWith("|table") &&
@@ -5137,9 +5150,8 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
}
m_pSerializer->endElementNS( XML_a, XML_blip );
- if (pSdrObj){
- WriteSrcRect(pSdrObj, pFrameFormat);
- }
+ if (xShapePropSet)
+ WriteSrcRect(xShapePropSet, pFrameFormat);
m_pSerializer->startElementNS(XML_a, XML_stretch);
m_pSerializer->singleElementNS(XML_a, XML_fillRect);
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index cfc6eae89f12..7dcee3406f96 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -402,7 +402,8 @@ private:
///
/// @see WriteOLE2Obj()
void FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrameFormat* pOLEFrameFormat, SwOLENode* pOLENode, const SdrObject* pSdrObj = nullptr);
- void WriteSrcRect( const SdrObject* pSdrObj, const SwFrameFormat* pFrameFormat );
+ void WriteSrcRect(const css::uno::Reference<css::beans::XPropertySet>& xShapePropSet,
+ const SwFrameFormat* pFrameFormat);
void WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rNode, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat, const sal_Int8 nFormulaAlignment);
bool WriteOLEChart( const SdrObject* pSdrObj, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat);
bool WriteOLEMath( const SwOLENode& rNode, const sal_Int8 nAlign );