1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef GRAPHICCOLLECTOR_HXX
29 #define GRAPHICCOLLECTOR_HXX
30 
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <com/sun/star/awt/DeviceInfo.hpp>
33 #include <com/sun/star/text/GraphicCrop.hpp>
34 #include <com/sun/star/drawing/XShape.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/awt/Size.hpp>
37 #include <com/sun/star/graphic/XGraphic.hpp>
38 #include <com/sun/star/frame/XModel.hpp>
39 #include <vector>
40 
41 
42 struct GraphicSettings
43 {
44 	sal_Bool	mbJPEGCompression;
45 	sal_Int32	mnJPEGQuality;
46 	sal_Bool	mbRemoveCropArea;
47 	sal_Int32	mnImageResolution;
48 	sal_Bool	mbEmbedLinkedGraphics;
49 
50 	GraphicSettings( sal_Bool bJPEGCompression, sal_Int32 nJPEGQuality, sal_Bool bRemoveCropArea,
51 						sal_Int32 nImageResolution, sal_Bool bEmbedLinkedGraphics )
52 	: mbJPEGCompression( bJPEGCompression )
53 	, mnJPEGQuality( nJPEGQuality )
54 	, mbRemoveCropArea( bRemoveCropArea )
55 	, mnImageResolution( nImageResolution )
56 	, mbEmbedLinkedGraphics( bEmbedLinkedGraphics ) {};
57 };
58 
59 class GraphicCollector
60 {
61 	public:
62 
63 	struct GraphicUser
64 	{
65 		com::sun::star::uno::Reference< com::sun::star::drawing::XShape >		mxShape;			// if mbFillBitmap is false the xShape has
66 		com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >	mxPropertySet;		// to be used otherwise the PropertySet
67 		com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >	mxPagePropertySet;
68 		rtl::OUString						maGraphicURL;
69 		rtl::OUString						maGraphicStreamURL;
70 		com::sun::star::text::GraphicCrop	maGraphicCropLogic;
71 		com::sun::star::awt::Size			maLogicalSize;
72 		sal_Bool							mbFillBitmap;
73 
74 		GraphicUser() : mxShape(), maGraphicCropLogic( 0, 0, 0, 0 ), mbFillBitmap( sal_False ) {};
75 	};
76 
77 	struct GraphicEntity
78 	{
79 		com::sun::star::awt::Size						maLogicalSize;							// the biggest logical size the graphic will be displayed
80 		sal_Bool										mbRemoveCropArea;						//
81 		com::sun::star::text::GraphicCrop				maGraphicCropLogic;
82 		std::vector< GraphicUser >						maUser;
83 
84 		GraphicEntity( const GraphicUser& rUser )
85 			: maLogicalSize( rUser.maLogicalSize ), mbRemoveCropArea( sal_False ), maGraphicCropLogic( 0, 0, 0, 0 ) { maUser.push_back( rUser ); };
86 	};
87 
88 	static const com::sun::star::awt::DeviceInfo& GetDeviceInfo( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxFact );
89 	static com::sun::star::awt::Size GetOriginalSize( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxMSF,
90 				const com::sun::star::uno::Reference< com::sun::star::graphic::XGraphic >& rxGraphic );
91 
92 	// collecting graphic instances, the downside of this method is that every graphic is swapped in
93 	static void CollectGraphics( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxMSF, const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel,
94 		const GraphicSettings& rGraphicSettings, std::vector< GraphicEntity >& io_rGraphicList );
95 	// counting graphics without swapping in graphics
96 	static void CountGraphics( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxMSF, const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel,
97 		const GraphicSettings& rGraphicSettings, sal_Int32& rGraphics );
98 };
99 
100 // --------------------
101 // - GRAPHICCOLLECTOR -
102 // --------------------
103 
104 
105 #endif // GRAPHICCOLLECTOR_HXX
106