summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-02-12 12:06:10 +0100
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-02-12 13:20:31 +0100
commit682ab832522b1349f1714bcb16f6e83468ea2920 (patch)
tree4371361c2a94bb85cd9cb458db9a90022d271460
parentb16f90f33143e6c8c9e8e2fa9cc55797b5bbff12 (diff)
drawingML export\import: cropping of shape's fill texture
In Writer shapes had no cropping property so far. With this commit this is introduced as a FillProperty and has the same type as the cropping used for pictures (Picture context menu > Picture > Crop). Layout and UI will be an other step. On the UI it would be placed on the Shape context menu -> Area, when Bitmap is selected as fill type. Note: In case of picture/graphic, cropping property is imported from and exported to a:srcRect instead of a:fillRect. Change-Id: Idc1ed2d40cb20b6992e94f14e7e4d853e1f55d02
-rw-r--r--include/oox/export/drawingml.hxx4
-rw-r--r--include/svx/unoshprp.hxx3
-rw-r--r--offapi/com/sun/star/drawing/FillProperties.idl10
-rw-r--r--oox/source/drawingml/fillproperties.cxx18
-rw-r--r--oox/source/export/drawingml.cxx36
-rw-r--r--oox/source/export/shapes.cxx2
-rw-r--r--sw/qa/extras/ooxmlexport/data/dml-shape-fillbitmapcrop.docxbin0 -> 33037 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx26
-rw-r--r--sw/qa/extras/ooxmlimport/data/dml-shape-fillbitmapcrop.docxbin0 -> 33037 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx24
10 files changed, 112 insertions, 11 deletions
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 36d94a648cb7..570048633111 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -143,12 +143,12 @@ public:
OUString sURLPropName, sal_Int32 nXmlNamespace );
void WriteSrcRect( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, const OUString& );
void WriteOutline( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
- void WriteStretch();
+ void WriteStretch( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, const OUString& rURL );
void WriteLinespacing( ::com::sun::star::style::LineSpacing& rLineSpacing );
OUString WriteBlip( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
OUString& rURL, bool bRelPathToMedia = false , const Graphic *pGraphic=NULL );
- void WriteBlipMode( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
+ void WriteBlipMode( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, const OUString& rURL );
void WriteShapeTransformation( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > rXShape,
sal_Int32 nXmlNamespace, sal_Bool bFlipH = false, sal_Bool bFlipV = false, sal_Bool bSuppressRotation = false );
diff --git a/include/svx/unoshprp.hxx b/include/svx/unoshprp.hxx
index 8c2641b45945..9ce517b256db 100644
--- a/include/svx/unoshprp.hxx
+++ b/include/svx/unoshprp.hxx
@@ -258,7 +258,8 @@
{ OUString(UNO_NAME_FILL_TRANSPARENCE), XATTR_FILLTRANSPARENCE, ::getCppuType((const sal_Int16*)0) , 0, 0}, \
{ OUString("FillTransparenceGradient"), XATTR_FILLFLOATTRANSPARENCE, ::getCppuType((const ::com::sun::star::awt::Gradient*)0), 0, MID_FILLGRADIENT}, \
{ OUString("FillTransparenceGradientName"), XATTR_FILLFLOATTRANSPARENCE, ::getCppuType((const OUString*)0), 0, MID_NAME }, \
- { OUString(UNO_NAME_FILLCOLOR_2), XATTR_SECONDARYFILLCOLOR, ::getCppuType((const sal_Int32*)0), 0, 0},
+ { OUString(UNO_NAME_FILLCOLOR_2), XATTR_SECONDARYFILLCOLOR, ::getCppuType((const sal_Int32*)0), 0, 0}, \
+ { OUString(UNO_NAME_GRAPHIC_GRAPHICCROP), SDRATTR_GRAFCROP , ::getCppuType((const ::com::sun::star::text::GraphicCrop*)0), 0, 0 },
#define EDGERADIUS_PROPERTIES \
{ OUString(UNO_NAME_EDGERADIUS), SDRATTR_ECKENRADIUS , ::getCppuType((const sal_Int32*)0) , 0, SFX_METRIC_ITEM},
diff --git a/offapi/com/sun/star/drawing/FillProperties.idl b/offapi/com/sun/star/drawing/FillProperties.idl
index eee9592e1339..77a99e08c936 100644
--- a/offapi/com/sun/star/drawing/FillProperties.idl
+++ b/offapi/com/sun/star/drawing/FillProperties.idl
@@ -209,6 +209,16 @@ published service FillProperties
*/
[optional, property] boolean FillBitmapTile;
+ /** contains the cropping of the object.
+
+ If the property #FillBitmapMode is set to BitmapMode::STRETCH,
+ this is the cropping, otherwise it is empty.
+
+ @see com::sun::star::text::GraphicCrop
+ @since LibreOffice 4.3
+ */
+ [optional, property] com::sun::star::text::GraphicCrop GraphicCrop;
+
};
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index 4e6d8e1ccf81..080ab3b1c473 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -456,6 +456,24 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetY, nTileOffsetY );
}
}
+ else if ( eBitmapMode == BitmapMode_STRETCH && maBlipProps.moFillRect.has() )
+ {
+ geometry::IntegerRectangle2D aFillRect( maBlipProps.moFillRect.get() );
+ awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
+ if ( aOriginalSize.Width && aOriginalSize.Height )
+ {
+ text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
+ if ( aFillRect.X1 )
+ aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X1 ) / 100000 );
+ if ( aFillRect.Y1 )
+ aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y1 ) / 100000 );
+ if ( aFillRect.X2 )
+ aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 );
+ if ( aFillRect.Y2 )
+ aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 );
+ rPropMap[ PROP_GraphicCrop ] <<= aGraphCrop;
+ }
+ }
}
}
break;
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 050b9319e009..a96ecdd9b7eb 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -818,7 +818,7 @@ OUString DrawingML::WriteBlip( Reference< XPropertySet > rXPropSet, OUString& rU
return sRelId;
}
-void DrawingML::WriteBlipMode( Reference< XPropertySet > rXPropSet )
+void DrawingML::WriteBlipMode( Reference< XPropertySet > rXPropSet, const OUString& rURL )
{
BitmapMode eBitmapMode( BitmapMode_NO_REPEAT );
if (GetProperty( rXPropSet, "FillBitmapMode" ) )
@@ -831,7 +831,7 @@ void DrawingML::WriteBlipMode( Reference< XPropertySet > rXPropSet )
mpFS->singleElementNS( XML_a, XML_tile, FSEND );
break;
case BitmapMode_STRETCH:
- WriteStretch();
+ WriteStretch( rXPropSet, rURL );
break;
default:
;
@@ -869,13 +869,13 @@ void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sBi
WriteBlip( rXPropSet, sBitmapURL, bRelPathToMedia );
if( bWriteMode )
- WriteBlipMode( rXPropSet );
+ WriteBlipMode( rXPropSet, sBitmapURL );
else if( GetProperty( rXPropSet, "FillBitmapStretch" ) ) {
bool bStretch = false;
mAny >>= bStretch;
if( bStretch )
- WriteStretch();
+ WriteStretch( rXPropSet, sBitmapURL );
}
mpFS->endElementNS( nXmlNamespace, XML_blipFill );
}
@@ -902,10 +902,34 @@ void DrawingML::WriteSrcRect( Reference< XPropertySet > rXPropSet, const OUStrin
}
}
-void DrawingML::WriteStretch()
+void DrawingML::WriteStretch( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, const OUString& rURL )
{
mpFS->startElementNS( XML_a, XML_stretch, FSEND );
- mpFS->singleElementNS( XML_a, XML_fillRect, FSEND );
+
+ bool bCrop = false;
+ if ( GetProperty( rXPropSet, "GraphicCrop" ) )
+ {
+ ::com::sun::star::text::GraphicCrop aGraphicCropStruct;
+ mAny >>= aGraphicCropStruct;
+
+ if ( (0 != aGraphicCropStruct.Left) || (0 != aGraphicCropStruct.Top) || (0 != aGraphicCropStruct.Right) || (0 != aGraphicCropStruct.Bottom) )
+ {
+ Size aOriginalSize( GraphicObject::CreateGraphicObjectFromURL( rURL ).GetPrefSize() );
+ mpFS->singleElementNS( XML_a, XML_fillRect,
+ XML_l, I32S(((aGraphicCropStruct.Left) * 100000)/aOriginalSize.Width()),
+ XML_t, I32S(((aGraphicCropStruct.Top) * 100000)/aOriginalSize.Height()),
+ XML_r, I32S(((aGraphicCropStruct.Right) * 100000)/aOriginalSize.Width()),
+ XML_b, I32S(((aGraphicCropStruct.Bottom) * 100000)/aOriginalSize.Height()),
+ FSEND );
+ bCrop = true;
+ }
+ }
+
+ if( !bCrop )
+ {
+ mpFS->singleElementNS( XML_a, XML_fillRect, FSEND );
+ }
+
mpFS->endElementNS( XML_a, XML_stretch );
}
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index f50cab451890..18d6c362df5f 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -518,7 +518,7 @@ void ShapeExport::WriteGraphicObjectShapePart( Reference< XShape > xShape, const
mAny >>= bStretch;
if ( pGraphic || bStretch )
- WriteStretch();
+ pFS->singleElementNS( XML_a, XML_stretch, FSEND );
pFS->endElementNS( mnXmlNamespace, XML_blipFill );
diff --git a/sw/qa/extras/ooxmlexport/data/dml-shape-fillbitmapcrop.docx b/sw/qa/extras/ooxmlexport/data/dml-shape-fillbitmapcrop.docx
new file mode 100644
index 000000000000..6c401bae9399
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/dml-shape-fillbitmapcrop.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 9bdbe36e2e08..cdab9c15f347 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -109,7 +109,8 @@ protected:
"math-mso2k7.docx",
"ImageCrop.docx",
"test_GIF_ImageCrop.docx",
- "test_PNG_ImageCrop.docx"
+ "test_PNG_ImageCrop.docx",
+ "dml-shape-fillbitmapcrop.docx"
};
std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist));
@@ -2940,6 +2941,29 @@ DECLARE_OOXMLEXPORT_TEST(testDMLTextFrameVertAdjust, "dml-textframe-vertadjust.d
xFrame.set(getTextFrameByName("Rectangle 3"), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_BOTTOM, getProperty<drawing::TextVerticalAdjust>(xFrame, "TextVerticalAdjust"));
}
+
+DECLARE_OOXMLEXPORT_TEST(testDMLShapeFillBitmapCrop, "dml-shape-fillbitmapcrop.docx")
+{
+ // Test the new GraphicCrop property which is introduced to define
+ // cropping of shapes filled with a picture in stretch mode.
+
+ // 1st shape has some cropping
+ text::GraphicCrop aGraphicCropStruct = getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop");
+
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 454 ), aGraphicCropStruct.Left );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 367 ), aGraphicCropStruct.Right );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( -454 ), aGraphicCropStruct.Top );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( -367 ), aGraphicCropStruct.Bottom );
+
+ // 2nd shape has no cropping
+ aGraphicCropStruct = getProperty<text::GraphicCrop>(getShape(2), "GraphicCrop");
+
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Left );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Right );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Top );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Bottom );
+
+}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/extras/ooxmlimport/data/dml-shape-fillbitmapcrop.docx b/sw/qa/extras/ooxmlimport/data/dml-shape-fillbitmapcrop.docx
new file mode 100644
index 000000000000..6c401bae9399
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/dml-shape-fillbitmapcrop.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 91c5ede584c0..8195558a545f 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -52,6 +52,7 @@
#include <vcl/svapp.hxx>
#include <unotools/fltrcfg.hxx>
#include <comphelper/sequenceashashmap.hxx>
+#include <com/sun/star/text/GraphicCrop.hpp>
#include <bordertest.hxx>
@@ -1789,6 +1790,29 @@ DECLARE_OOXMLIMPORT_TEST(testDMLGroupShapeParaAdjust, "dml-groupshape-paraadjust
// 7th line has no adjustment
CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty<sal_Int16>(getRun(getParagraphOfText(7, xText), 1), "ParaAdjust"));
}
+
+DECLARE_OOXMLIMPORT_TEST(testDMLShapeFillBitmapCrop, "dml-shape-fillbitmapcrop.docx")
+{
+ // The same test can be found in ooxmlexport, but some rouding made on crop values so we can't test import and
+ // export with the same values.
+
+ // 1st shape has some cropping
+ text::GraphicCrop aGraphicCropStruct = getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop");
+
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 455 ), aGraphicCropStruct.Left );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 368 ), aGraphicCropStruct.Right );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( -455 ), aGraphicCropStruct.Top );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( -368 ), aGraphicCropStruct.Bottom );
+
+ // 2nd shape has no cropping
+ aGraphicCropStruct = getProperty<text::GraphicCrop>(getShape(2), "GraphicCrop");
+
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Left );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Right );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Top );
+ CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Bottom );
+
+}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();