22#include <com/sun/star/awt/XDevice.hpp>
23#include <com/sun/star/frame/Desktop.hpp>
24#include <com/sun/star/drawing/FillStyle.hpp>
25#include <com/sun/star/drawing/BitmapMode.hpp>
26#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
27#include <com/sun/star/presentation/XPresentationPage.hpp>
28#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
41 static DeviceInfo aDeviceInfo;
42 if( !aDeviceInfo.Width )
46 Reference< XDesktop2 > xDesktop = Desktop::create( rxFact );
47 Reference< XFrame >
xFrame( xDesktop->getActiveFrame() );
48 Reference< XWindow > xWindow(
xFrame->getContainerWindow() );
49 Reference< XDevice > xDevice( xWindow, UNO_QUERY_THROW );
50 aDeviceInfo = xDevice->getInfo();
64 auto aIter = std::find_if(rGraphicEntities.begin(), rGraphicEntities.end(),
66 return rGraphicEntity.maUser[ 0 ].mxGraphic == rUser.mxGraphic;
68 if ( aIter == rGraphicEntities.end() )
71 rGraphicEntities.push_back( aEntity );
77 if ( rUser.
maLogicalSize.Height > aIter->maLogicalSize.Height )
79 aIter->maUser.push_back( rUser );
83static void ImpAddGraphicEntity(
const Reference< XComponentContext >& rxMSF, Reference< XShape >
const & rxShape,
const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities )
85 Reference< XGraphic > xGraphic;
86 Reference< XPropertySet > xShapePropertySet( rxShape, UNO_QUERY_THROW );
87 if ( !(xShapePropertySet->getPropertyValue(
"Graphic" ) >>= xGraphic) )
90 text::GraphicCrop aGraphicCropLogic( 0, 0, 0, 0 );
96 xShapePropertySet->getPropertyValue(
"GraphicCrop" ) >>= aGraphicCropLogic;
97 awt::Size aLogicalSize( rxShape->getSize() );
100 if ( aGraphicCropLogic.Left || aGraphicCropLogic.Right || aGraphicCropLogic.Top || aGraphicCropLogic.Bottom )
103 if ( aSize100thMM.Width && aSize100thMM.Height )
105 awt::Size aCropSize( aSize100thMM.Width - ( aGraphicCropLogic.Left + aGraphicCropLogic.Right ),
106 aSize100thMM.Height - ( aGraphicCropLogic.Top + aGraphicCropLogic.Bottom ));
107 if ( aCropSize.Width && aCropSize.Height )
109 awt::Size aNewLogSize(
static_cast< sal_Int32
>(
static_cast< double >( aSize100thMM.Width * aLogicalSize.Width ) / aCropSize.Width ),
110 static_cast< sal_Int32
>(
static_cast< double >( aSize100thMM.Height * aLogicalSize.Height ) / aCropSize.Height ) );
111 aLogicalSize = aNewLogSize;
117 ImpAddEntity( rGraphicEntities, rGraphicSettings, aUser );
120static void ImpAddFillBitmapEntity(
const Reference< XComponentContext >& rxMSF,
const Reference< XPropertySet >& rxPropertySet,
const awt::Size& rLogicalSize,
121 std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities,
const GraphicSettings& rGraphicSettings,
const Reference< XPropertySet >& rxPagePropertySet )
126 if ( rxPropertySet->getPropertyValue(
"FillStyle" ) >>= eFillStyle )
128 if ( eFillStyle == FillStyle_BITMAP )
130 Reference< XBitmap > xFillBitmap;
131 if ( rxPropertySet->getPropertyValue(
"FillBitmap" ) >>= xFillBitmap )
133 Reference< XGraphic > xGraphic( xFillBitmap, UNO_QUERY_THROW );
134 awt::Size aLogicalSize( rLogicalSize );
135 Reference< XPropertySetInfo > axPropSetInfo( rxPropertySet->getPropertySetInfo() );
136 if ( axPropSetInfo.is() )
138 if ( axPropSetInfo->hasPropertyByName(
"FillBitmapMode" ) )
141 if ( rxPropertySet->getPropertyValue(
"FillBitmapMode" ) >>= eBitmapMode )
143 if ( ( eBitmapMode == BitmapMode_REPEAT ) || ( eBitmapMode == BitmapMode_NO_REPEAT ) )
145 bool bLogicalSize =
false;
146 awt::Size aSize( 0, 0 );
147 if ( ( rxPropertySet->getPropertyValue(
"FillBitmapLogicalSize" ) >>= bLogicalSize )
148 && ( rxPropertySet->getPropertyValue(
"FillBitmapSizeX" ) >>= aSize.Width )
149 && ( rxPropertySet->getPropertyValue(
"FillBitmapSizeY" ) >>= aSize.Height ) )
153 if ( !aSize.Width || !aSize.Height )
156 if ( aSize100thMM.Width && aSize100thMM.Height )
157 aLogicalSize = aSize100thMM;
160 aLogicalSize = aSize;
164 aLogicalSize.Width = sal::static_int_cast< sal_Int32 >( (
static_cast< double >( aLogicalSize.Width ) * aSize.Width ) / -100.0 );
165 aLogicalSize.Height = sal::static_int_cast< sal_Int32 >( (
static_cast< double >( aLogicalSize.Height ) * aSize.Height ) / -100.0 );
178 ImpAddEntity( rGraphicEntities, rGraphicSettings, aUser );
188static void ImpCollectBackgroundGraphic(
const Reference< XComponentContext >& rxMSF,
const Reference< XDrawPage >& rxDrawPage,
const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities )
192 awt::Size aLogicalSize( 28000, 21000 );
193 Reference< XPropertySet > xPropertySet( rxDrawPage, UNO_QUERY_THROW );
194 xPropertySet->getPropertyValue(
"Width" ) >>= aLogicalSize.Width;
195 xPropertySet->getPropertyValue(
"Height" ) >>= aLogicalSize.Height;
197 Reference< XPropertySet > xBackgroundPropSet;
198 if ( xPropertySet->getPropertyValue(
"Background" ) >>= xBackgroundPropSet )
199 ImpAddFillBitmapEntity( rxMSF, xBackgroundPropSet, aLogicalSize, rGraphicEntities, rGraphicSettings, xPropertySet );
206static void ImpCollectGraphicObjects(
const Reference< XComponentContext >& rxMSF,
const Reference< XShapes >& rxShapes,
const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicEntities )
208 for ( sal_Int32
i = 0;
i < rxShapes->getCount();
i++ )
212 Reference< XShape > xShape( rxShapes->getByIndex(
i ), UNO_QUERY_THROW );
213 const OUString sShapeType( xShape->getShapeType() );
214 if ( sShapeType ==
"com.sun.star.drawing.GroupShape" )
216 Reference< XShapes > xShapes( xShape, UNO_QUERY_THROW );
221 if ( sShapeType ==
"com.sun.star.drawing.GraphicObjectShape" ||
222 sShapeType ==
"com.sun.star.presentation.GraphicObjectShape" )
226 Reference< XPropertySet > xEmptyPagePropSet;
227 Reference< XPropertySet > xShapePropertySet( xShape, UNO_QUERY_THROW );
228 awt::Size aLogicalSize( xShape->getSize() );
229 ImpAddFillBitmapEntity( rxMSF, xShapePropertySet, aLogicalSize, rGraphicEntities, rGraphicSettings, xEmptyPagePropSet );
239 awt::Size aSize100thMM( 0, 0 );
240 Reference< XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW );
241 if ( xGraphicPropertySet->getPropertyValue(
"Size100thMM" ) >>= aSize100thMM )
243 if ( !aSize100thMM.Width && !aSize100thMM.Height )
245 awt::Size aSourceSizePixel( 0, 0 );
246 if ( xGraphicPropertySet->getPropertyValue(
"SizePixel" ) >>= aSourceSizePixel )
249 if ( rDeviceInfo.PixelPerMeterX && rDeviceInfo.PixelPerMeterY )
251 aSize100thMM.Width =
static_cast< sal_Int32
>( ( aSourceSizePixel.Width * 100000.0 ) / rDeviceInfo.PixelPerMeterX );
252 aSize100thMM.Height =
static_cast< sal_Int32
>( ( aSourceSizePixel.Height * 100000.0 ) / rDeviceInfo.PixelPerMeterY );
261 const GraphicSettings& rGraphicSettings, std::vector< GraphicCollector::GraphicEntity >& rGraphicList )
266 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
267 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
268 for (
i = 0;
i < xDrawPages->getCount();
i++ )
270 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex(
i ), UNO_QUERY_THROW );
274 Reference< XPresentationPage > xPresentationPage( xDrawPage, UNO_QUERY_THROW );
275 Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() );
279 Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
280 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
281 for (
i = 0;
i < xMasterPages->getCount();
i++ )
283 Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex(
i ), UNO_QUERY_THROW );
288 for(
auto& rGraphic : rGraphicList )
292 if ( rGraphic.mbRemoveCropArea )
294 std::vector< GraphicCollector::GraphicUser >::iterator aGUIter( rGraphic.maUser.begin() );
295 while( rGraphic.mbRemoveCropArea && ( aGUIter != rGraphic.maUser.end() ) )
297 if ( aGUIter->maGraphicCropLogic.Left || aGUIter->maGraphicCropLogic.Top
298 || aGUIter->maGraphicCropLogic.Right || aGUIter->maGraphicCropLogic.Bottom )
300 if ( aGUIter == rGraphic.maUser.begin() )
301 rGraphic.maGraphicCropLogic = aGUIter->maGraphicCropLogic;
302 else if ( ( rGraphic.maGraphicCropLogic.Left != aGUIter->maGraphicCropLogic.Left )
303 || ( rGraphic.maGraphicCropLogic.Top != aGUIter->maGraphicCropLogic.Top )
304 || ( rGraphic.maGraphicCropLogic.Right != aGUIter->maGraphicCropLogic.Right )
305 || ( rGraphic.maGraphicCropLogic.Bottom != aGUIter->maGraphicCropLogic.Bottom ) )
307 rGraphic.mbRemoveCropArea =
false;
311 rGraphic.mbRemoveCropArea =
false;
315 if ( !rGraphic.mbRemoveCropArea )
316 rGraphic.maGraphicCropLogic = text::GraphicCrop( 0, 0, 0, 0 );
326 for ( sal_Int32
i = 0;
i < rxShapes->getCount();
i++ )
330 Reference< XShape > xShape( rxShapes->getByIndex(
i ), UNO_QUERY_THROW );
331 const OUString sShapeType( xShape->getShapeType() );
332 if ( sShapeType ==
"com.sun.star.drawing.GroupShape" )
334 Reference< XShapes > xShapes( xShape, UNO_QUERY_THROW );
339 if ( sShapeType ==
"com.sun.star.drawing.GraphicObjectShape" ||
340 sShapeType ==
"com.sun.star.presentation.GraphicObjectShape" )
346 Reference< XPropertySet > xShapePropertySet( xShape, UNO_QUERY_THROW );
348 if ( xShapePropertySet->getPropertyValue(
"FillStyle" ) >>= eFillStyle )
350 if ( eFillStyle == FillStyle_BITMAP )
363 const Reference< XDrawPage >& rxDrawPage, sal_Int32& rnGraphics )
367 awt::Size aLogicalSize( 28000, 21000 );
368 Reference< XPropertySet > xPropertySet( rxDrawPage, UNO_QUERY_THROW );
369 xPropertySet->getPropertyValue(
"Width" ) >>= aLogicalSize.Width;
370 xPropertySet->getPropertyValue(
"Height" ) >>= aLogicalSize.Height;
372 Reference< XPropertySet > xBackgroundPropSet;
373 if ( xPropertySet->getPropertyValue(
"Background" ) >>= xBackgroundPropSet )
376 if ( xBackgroundPropSet->getPropertyValue(
"FillStyle" ) >>= eFillStyle )
378 if ( eFillStyle == FillStyle_BITMAP )
396 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
397 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
398 for (
i = 0;
i < xDrawPages->getCount();
i++ )
400 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex(
i ), UNO_QUERY_THROW );
404 Reference< XPresentationPage > xPresentationPage( xDrawPage, UNO_QUERY_THROW );
405 Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() );
409 Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
410 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
411 for (
i = 0;
i < xMasterPages->getCount();
i++ )
413 Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex(
i ), UNO_QUERY_THROW );
static css::awt::Size GetOriginalSize(const css::uno::Reference< css::uno::XComponentContext > &rxMSF, const css::uno::Reference< css::graphic::XGraphic > &rxGraphic)
static void CollectGraphics(const css::uno::Reference< css::uno::XComponentContext > &rxMSF, const css::uno::Reference< css::frame::XModel > &rxModel, const GraphicSettings &rGraphicSettings, std::vector< GraphicEntity > &io_rGraphicList)
static const css::awt::DeviceInfo & GetDeviceInfo(const css::uno::Reference< css::uno::XComponentContext > &rxFact)
static void CountGraphics(const css::uno::Reference< css::uno::XComponentContext > &rxMSF, const css::uno::Reference< css::frame::XModel > &rxModel, const GraphicSettings &rGraphicSettings, sal_Int32 &rGraphics)
static void ImpCollectBackgroundGraphic(const Reference< XComponentContext > &rxMSF, const Reference< XDrawPage > &rxDrawPage, const GraphicSettings &rGraphicSettings, std::vector< GraphicCollector::GraphicEntity > &rGraphicEntities)
static void ImpAddEntity(std::vector< GraphicCollector::GraphicEntity > &rGraphicEntities, const GraphicSettings &rGraphicSettings, const GraphicCollector::GraphicUser &rUser)
static void ImpAddGraphicEntity(const Reference< XComponentContext > &rxMSF, Reference< XShape > const &rxShape, const GraphicSettings &rGraphicSettings, std::vector< GraphicCollector::GraphicEntity > &rGraphicEntities)
static void ImpAddFillBitmapEntity(const Reference< XComponentContext > &rxMSF, const Reference< XPropertySet > &rxPropertySet, const awt::Size &rLogicalSize, std::vector< GraphicCollector::GraphicEntity > &rGraphicEntities, const GraphicSettings &rGraphicSettings, const Reference< XPropertySet > &rxPagePropertySet)
static void ImpCountBackgroundGraphic(const Reference< XDrawPage > &rxDrawPage, sal_Int32 &rnGraphics)
static void ImpCountGraphicObjects(const Reference< XComponentContext > &rxMSF, const Reference< XShapes > &rxShapes, const GraphicSettings &rGraphicSettings, sal_Int32 &rnGraphics)
static void ImpCollectGraphicObjects(const Reference< XComponentContext > &rxMSF, const Reference< XShapes > &rxShapes, const GraphicSettings &rGraphicSettings, std::vector< GraphicCollector::GraphicEntity > &rGraphicEntities)
enum SAL_DLLPUBLIC_RTTI FillStyle
css::uno::Reference< css::beans::XPropertySet > mxPagePropertySet
css::text::GraphicCrop maGraphicCropLogic
css::uno::Reference< css::graphic::XGraphic > mxGraphic
css::awt::Size maLogicalSize
css::uno::Reference< css::drawing::XShape > mxShape
css::uno::Reference< css::beans::XPropertySet > mxPropertySet
bool mbEmbedLinkedGraphics
Reference< XFrame > xFrame