Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SV_GDIMTF_HXX
30 : : #define _SV_GDIMTF_HXX
31 : :
32 : : #include <vcl/dllapi.h>
33 : : #include <tools/gen.hxx>
34 : : #include <tools/link.hxx>
35 : : #include <vcl/mapmod.hxx>
36 : : #include <vector>
37 : :
38 : : class OutputDevice;
39 : : class MetaAction;
40 : : class MetaCommentAction;
41 : : class SvStream;
42 : : class Color;
43 : : class BitmapEx;
44 : : class Polygon;
45 : : class PolyPolygon;
46 : : class Gradient;
47 : :
48 : : // ---------------------
49 : : // - GDIMetaFile-Types -
50 : : // ---------------------
51 : :
52 : : #define GDI_METAFILE_END ((size_t)0xFFFFFFFF)
53 : : #define GDI_METAFILE_LABEL_NOTFOUND ((size_t)0xFFFFFFFF)
54 : :
55 : : #ifndef METAFILE_END
56 : : #define METAFILE_END GDI_METAFILE_END
57 : : #endif
58 : :
59 : : #ifndef METAFILE_LABEL_NOTFOUND
60 : : #define METAFILE_LABEL_NOTFOUND GDI_METAFILE_LABEL_NOTFOUND
61 : : #endif
62 : :
63 : : // -----------
64 : : // - Defines -
65 : : // -----------
66 : :
67 : : #define MTF_MIRROR_NONE 0x00000000UL
68 : : #define MTF_MIRROR_HORZ 0x00000001UL
69 : : #define MTF_MIRROR_VERT 0x00000002UL
70 : :
71 : : // -----------------------------
72 : : // - Write flags for streaming -
73 : : // -----------------------------
74 : :
75 : : #define GDIMETAFILE_WRITE_DEFAULT 0x00000000
76 : : #define GDIMETAFILE_WRITE_REPLACEMENT_RENDERGRAPHIC 0x00000001
77 : :
78 : : typedef sal_uInt32 GDIMetaFileWriteFlags;
79 : :
80 : : // ---------
81 : : // - Enums -
82 : : // ---------
83 : :
84 : : enum MtfConversion
85 : : {
86 : : MTF_CONVERSION_NONE = 0,
87 : : MTF_CONVERSION_1BIT_THRESHOLD = 1,
88 : : MTF_CONVERSION_8BIT_GREYS = 2
89 : : };
90 : :
91 : : // -----------------------------
92 : : // - Color conversion routines -
93 : : // -----------------------------
94 : :
95 : : typedef Color (*ColorExchangeFnc)( const Color& rColor, const void* pColParam );
96 : : typedef BitmapEx (*BmpExchangeFnc)( const BitmapEx& rBmpEx, const void* pBmpParam );
97 : :
98 : :
99 : : // ---------------
100 : : // - GDIMetaFile -
101 : : // ---------------
102 : :
103 : : class VCL_DLLPUBLIC GDIMetaFile
104 : : {
105 : : private:
106 : : ::std::vector< MetaAction* > aList;
107 : : size_t nCurrentActionElement;
108 : :
109 : : MapMode aPrefMapMode;
110 : : Size aPrefSize;
111 : : Link aHookHdlLink;
112 : : GDIMetaFile* pPrev;
113 : : GDIMetaFile* pNext;
114 : : OutputDevice* pOutDev;
115 : : sal_Bool bPause;
116 : : sal_Bool bRecord;
117 : : sal_Bool bUseCanvas;
118 : :
119 : :
120 : : SAL_DLLPRIVATE static Color ImplColAdjustFnc( const Color& rColor, const void* pColParam );
121 : : SAL_DLLPRIVATE static BitmapEx ImplBmpAdjustFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
122 : :
123 : : SAL_DLLPRIVATE static Color ImplColConvertFnc( const Color& rColor, const void* pColParam );
124 : : SAL_DLLPRIVATE static BitmapEx ImplBmpConvertFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
125 : :
126 : : SAL_DLLPRIVATE static Color ImplColMonoFnc( const Color& rColor, const void* pColParam );
127 : : SAL_DLLPRIVATE static BitmapEx ImplBmpMonoFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
128 : :
129 : : SAL_DLLPRIVATE static Color ImplColReplaceFnc( const Color& rColor, const void* pColParam );
130 : : SAL_DLLPRIVATE static BitmapEx ImplBmpReplaceFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
131 : :
132 : : SAL_DLLPRIVATE void ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pColParam,
133 : : BmpExchangeFnc pFncBmp, const void* pBmpParam );
134 : :
135 : : SAL_DLLPRIVATE Point ImplGetRotatedPoint( const Point& rPt, const Point& rRotatePt,
136 : : const Size& rOffset, double fSin, double fCos );
137 : : SAL_DLLPRIVATE Polygon ImplGetRotatedPolygon( const Polygon& rPoly, const Point& rRotatePt,
138 : : const Size& rOffset, double fSin, double fCos );
139 : : SAL_DLLPRIVATE PolyPolygon ImplGetRotatedPolyPolygon( const PolyPolygon& rPoly, const Point& rRotatePt,
140 : : const Size& rOffset, double fSin, double fCos );
141 : : SAL_DLLPRIVATE void ImplAddGradientEx( GDIMetaFile& rMtf,
142 : : const OutputDevice& rMapDev,
143 : : const PolyPolygon& rPolyPoly,
144 : : const Gradient& rGrad );
145 : : SAL_DLLPRIVATE bool ImplPlayWithRenderer( OutputDevice* pOut, const Point& rPos, Size rDestSize );
146 : : SAL_DLLPRIVATE void ImplDelegate2PluggableRenderer( const MetaCommentAction* pAct, OutputDevice* pOut );
147 : :
148 : :
149 : : protected:
150 : :
151 : : virtual void Linker( OutputDevice* pOut, sal_Bool bLink );
152 : : virtual long Hook();
153 : :
154 : : public:
155 : : GDIMetaFile();
156 : : GDIMetaFile( const GDIMetaFile& rMtf );
157 : : virtual ~GDIMetaFile();
158 : :
159 : : GDIMetaFile& operator=( const GDIMetaFile& rMtf );
160 : : sal_Bool operator==( const GDIMetaFile& rMtf ) const;
161 : : sal_Bool operator!=( const GDIMetaFile& rMtf ) const { return !( *this == rMtf ); }
162 : :
163 : : void Clear();
164 : : sal_Bool Mirror( sal_uLong nMirrorFlags );
165 : : void Move( long nX, long nY );
166 : : // additional Move method getting specifics how to handle MapMode( MAP_PIXEL )
167 : : void Move( long nX, long nY, long nDPIX, long nDPIY );
168 : : void Scale( double fScaleX, double fScaleY );
169 : : void Scale( const Fraction& rScaleX, const Fraction& rScaleY );
170 : : void Rotate( long nAngle10 );
171 : : void Clip( const Rectangle& );
172 : : /* get the bound rect of the contained actions
173 : : * caveats:
174 : : * - clip actions will limit the contained actions,
175 : : * but the current clipregion of the passed OutputDevice will not
176 : : * - coordinates of actions will be transformed to preferred mapmode
177 : : * - the returned rectangle is relative to the preferred mapmode of the metafile
178 : : */
179 : : Rectangle GetBoundRect( OutputDevice& i_rReference );
180 : :
181 : : void Adjust( short nLuminancePercent = 0, short nContrastPercent = 0,
182 : : short nChannelRPercent = 0, short nChannelGPercent = 0,
183 : : short nChannelBPercent = 0, double fGamma = 1.0,
184 : : sal_Bool bInvert = sal_False
185 : : );
186 : :
187 : : void Convert( MtfConversion eConversion );
188 : : void ReplaceColors( const Color* pSearchColors, const Color* rReplaceColors,
189 : : sal_uLong nColorCount, sal_uLong* pTols = NULL );
190 : :
191 : : GDIMetaFile GetMonochromeMtf( const Color& rCol ) const;
192 : :
193 : : void Record( OutputDevice* pOutDev );
194 : 7285 : sal_Bool IsRecord() const { return bRecord; }
195 : :
196 : : void Play( GDIMetaFile& rMtf, size_t nPos = GDI_METAFILE_END );
197 : : void Play( OutputDevice* pOutDev, size_t nPos = GDI_METAFILE_END );
198 : : void Play( OutputDevice* pOutDev, const Point& rPos,
199 : : const Size& rSize, size_t nPos = GDI_METAFILE_END );
200 : :
201 : : void Pause( sal_Bool bPause );
202 : 438 : sal_Bool IsPause() const { return bPause; }
203 : :
204 : : void Stop();
205 : :
206 : : void WindStart();
207 : : void WindPrev();
208 : :
209 : : size_t GetActionSize() const;
210 : :
211 : : void AddAction( MetaAction* pAction );
212 : : void AddAction( MetaAction* pAction, size_t nPos );
213 : : void RemoveAction( size_t nPos );
214 : : void push_back( MetaAction* pAction );
215 : :
216 : : MetaAction* FirstAction();
217 : : MetaAction* NextAction();
218 : : MetaAction* GetAction( size_t nAction ) const;
219 : 11083 : MetaAction* GetCurAction() const { return GetAction( nCurrentActionElement ); }
220 : : MetaAction* ReplaceAction( MetaAction* pAction, size_t nAction );
221 : :
222 : 2124 : const Size& GetPrefSize() const { return aPrefSize; }
223 : 7149 : void SetPrefSize( const Size& rSize ) { aPrefSize = rSize; }
224 : :
225 : 13652 : const MapMode& GetPrefMapMode() const { return aPrefMapMode; }
226 : 7149 : void SetPrefMapMode( const MapMode& rMapMode ) { aPrefMapMode = rMapMode; }
227 : :
228 : : void SetHookHdl( const Link& rLink ) { aHookHdlLink = rLink; }
229 : : const Link& GetHookHdl() const { return aHookHdlLink; }
230 : :
231 : : sal_uLong GetChecksum() const;
232 : : sal_uLong GetSizeBytes() const;
233 : :
234 : : // Methods for reading and writing the new formats;
235 : : // the Read method also reads the old format
236 : : SvStream& Read( SvStream& rIStm );
237 : : SvStream& Write( SvStream& rOStm, GDIMetaFileWriteFlags = GDIMETAFILE_WRITE_DEFAULT );
238 : :
239 : : // Stream-operators write (still) the old format
240 : : // and read both the old and the new format
241 : : friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, GDIMetaFile& rGDIMetaFile );
242 : : friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const GDIMetaFile& rGDIMetaFile );
243 : :
244 : : sal_Bool CreateThumbnail( sal_uInt32 nMaximumExtent, BitmapEx& rBmpEx, const BitmapEx* pOverlay = NULL, const Rectangle* pOverlayRect = NULL ) const;
245 : :
246 : : void UseCanvas( sal_Bool _bUseCanvas );
247 : 67 : sal_Bool GetUseCanvas() const { return bUseCanvas; }
248 : : };
249 : :
250 : : /** Create a special metaaction that delegates rendering to specified
251 : : service.
252 : :
253 : : This factory function creates a MetaCommentAction that delegates
254 : : rendering to the specified services, once played back in the
255 : : metafile.
256 : :
257 : : @param rRendererServiceName
258 : : Renderer service. Gets an awt::XGraphic on instantiation
259 : :
260 : : @param rGraphicServiceName
261 : : Graphic service. Gets the raw data on instantiation
262 : :
263 : : @param pData
264 : : Raw data. Gets copied
265 : :
266 : : @param nDataSize
267 : : Length, in byte, of raw data
268 : : */
269 : : MetaCommentAction* makePluggableRendererAction( const rtl::OUString& rRendererServiceName,
270 : : const rtl::OUString& rGraphicServiceName,
271 : : const void* pData,
272 : : sal_uInt32 nDataSize );
273 : :
274 : : #endif // _SV_GDIMTF_HXX
275 : :
276 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|