[Libreoffice-commits] core.git: 2 commits - include/oox include/svx offapi/com oox/source sw/qa
Zolnai Tamás
tamas.zolnai at collabora.com
Wed Feb 12 04:26:54 PST 2014
include/oox/export/drawingml.hxx | 4 -
include/svx/unoshprp.hxx | 3
offapi/com/sun/star/drawing/FillProperties.idl | 10 ++
oox/source/drawingml/fillproperties.cxx | 18 ++++
oox/source/export/drawingml.cxx | 36 +++++++--
oox/source/export/shapes.cxx | 2
oox/source/shape/ShapeContextHandler.cxx | 2
sw/qa/extras/ooxmlexport/data/dml-shape-fillbitmapcrop.docx |binary
sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 26 ++++++
sw/qa/extras/ooxmlimport/data/dml-shape-fillbitmapcrop.docx |binary
sw/qa/extras/ooxmlimport/data/picture-with-schemecolor.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 47 ++++++++++++
12 files changed, 136 insertions(+), 12 deletions(-)
New commits:
commit 2efd433478cf4820b308b20cf42595345e023af2
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Tue Feb 11 18:35:38 2014 +0100
drawingML import: picture with scheme color
Theme fragment must be loaded for pictures too.
Change-Id: If4c412926319df2beaecfc120065bd011fc3eb57
diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx
index 34ddd3d..eeb70ae 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -272,7 +272,7 @@ void SAL_CALL ShapeContextHandler::startFastElement
mpThemePtr.reset(new Theme());
- if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) || Element == WPS_TOKEN(wsp) || Element == WPG_TOKEN(wgp))
+ if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) || Element == WPS_TOKEN(wsp) || Element == WPG_TOKEN(wgp) || PPT_TOKEN( pic ))
{
// Parse the theme relation, if available; the diagram won't have colors without it.
if (!msRelationFragmentPath.isEmpty())
diff --git a/sw/qa/extras/ooxmlimport/data/picture-with-schemecolor.docx b/sw/qa/extras/ooxmlimport/data/picture-with-schemecolor.docx
new file mode 100644
index 0000000..bfee0e1
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/picture-with-schemecolor.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 8195558..15c3fdf 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1813,6 +1813,29 @@ DECLARE_OOXMLIMPORT_TEST(testDMLShapeFillBitmapCrop, "dml-shape-fillbitmapcrop.d
CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), aGraphicCropStruct.Bottom );
}
+
+DECLARE_OOXMLIMPORT_TEST(testPictureWithSchemeColor, "picture-with-schemecolor.docx")
+{
+ // At the start of the document, a picture which has a color specified with a color scheme, lost
+ // it's color during import.
+ uno::Reference<beans::XPropertySet> xImage(getShape(1), uno::UNO_QUERY);
+ uno::Reference<graphic::XGraphic> xGraphic = getProperty<uno::Reference<graphic::XGraphic> >(xImage, "Graphic");
+ uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(341), xBitmap->getSize().Width );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(181), xBitmap->getSize().Height );
+
+ // Check some bits of the bitmap which change when color is imported.
+ const uno::Sequence< sal_Int8 > aDIB = xBitmap->getDIB();
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(-91), aDIB[54] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(110), aDIB[55] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(49), aDIB[56] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(-36), aDIB[96] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(-57), aDIB[97] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(-80), aDIB[98] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(-91), aDIB[135] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(110), aDIB[136] );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int8>(49), aDIB[137] );
+}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
commit 682ab832522b1349f1714bcb16f6e83468ea2920
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Wed Feb 12 12:06:10 2014 +0100
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
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 36d94a6..5700486 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 8c2641b..9ce517b 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 eee9592..77a99e0 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 4e6d8e1..080ab3b 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 050b931..a96ecdd 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 f50cab4..18d6c36 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 0000000..6c401ba
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/dml-shape-fillbitmapcrop.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 9bdbe36..cdab9c1 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 0000000..6c401ba
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/dml-shape-fillbitmapcrop.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 91c5ede..8195558 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();
More information about the Libreoffice-commits
mailing list