xref: /trunk/main/vcl/inc/vcl/gdimtf.hxx (revision bb18ee55)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_GDIMTF_HXX
25 #define _SV_GDIMTF_HXX
26 
27 #include <vcl/dllapi.h>
28 #include <tools/gen.hxx>
29 #include <tools/list.hxx>
30 #include <tools/link.hxx>
31 #include <tools/string.hxx>
32 #include <vcl/mapmod.hxx>
33 
34 class OutputDevice;
35 class ImpLabelList;
36 class MetaAction;
37 class SvStream;
38 class Color;
39 class BitmapEx;
40 class Polygon;
41 class PolyPolygon;
42 class Gradient;
43 
44 // ---------------------
45 // - GDIMetaFile-Types -
46 // ---------------------
47 
48 #define GDI_METAFILE_END                ((sal_uLong)0xFFFFFFFF)
49 #define GDI_METAFILE_LABEL_NOTFOUND     ((sal_uLong)0xFFFFFFFF)
50 
51 #ifndef METAFILE_END
52 #define METAFILE_END					GDI_METAFILE_END
53 #endif
54 
55 #ifndef METAFILE_LABEL_NOTFOUND
56 #define METAFILE_LABEL_NOTFOUND			GDI_METAFILE_LABEL_NOTFOUND
57 #endif
58 
59 // -----------
60 // - Defines -
61 // -----------
62 
63 #define MTF_MIRROR_NONE				0x00000000UL
64 #define MTF_MIRROR_HORZ				0x00000001UL
65 #define MTF_MIRROR_VERT				0x00000002UL
66 
67 // ---------
68 // - Enums -
69 // ---------
70 
71 enum MtfConversion
72 {
73     MTF_CONVERSION_NONE = 0,
74     MTF_CONVERSION_1BIT_THRESHOLD = 1,
75     MTF_CONVERSION_8BIT_GREYS = 2
76 };
77 
78 // -----------------------------
79 // - Color conversion routines -
80 // -----------------------------
81 
82 //#if 0 // _SOLAR__PRIVATE
83 
84 typedef Color (*ColorExchangeFnc)( const Color& rColor, const void* pColParam );
85 typedef BitmapEx (*BmpExchangeFnc)( const BitmapEx& rBmpEx, const void* pBmpParam );
86 
87 //#endif // __PRIVATE
88 
89 // ---------------
90 // - GDIMetaFile -
91 // ---------------
92 
93 class VCL_DLLPUBLIC GDIMetaFile : protected List
94 {
95 private:
96 
97     MapMode         aPrefMapMode;
98     Size            aPrefSize;
99     Link            aHookHdlLink;
100     GDIMetaFile*    pPrev;
101     GDIMetaFile*    pNext;
102     OutputDevice*   pOutDev;
103     ImpLabelList*   pLabelList;
104     sal_Bool            bPause;
105     sal_Bool            bRecord;
106 
107 //#if 0 // _SOLAR__PRIVATE
108 
109 	SAL_DLLPRIVATE static Color    ImplColAdjustFnc( const Color& rColor, const void* pColParam );
110 	SAL_DLLPRIVATE static BitmapEx ImplBmpAdjustFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
111 
112 	SAL_DLLPRIVATE static Color	   ImplColConvertFnc( const Color& rColor, const void* pColParam );
113 	SAL_DLLPRIVATE static BitmapEx ImplBmpConvertFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
114 
115 	SAL_DLLPRIVATE static Color	   ImplColMonoFnc( const Color& rColor, const void* pColParam );
116 	SAL_DLLPRIVATE static BitmapEx ImplBmpMonoFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
117 
118 	SAL_DLLPRIVATE static Color	   ImplColReplaceFnc( const Color& rColor, const void* pColParam );
119 	SAL_DLLPRIVATE static BitmapEx ImplBmpReplaceFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
120 
121 	SAL_DLLPRIVATE void			   ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pColParam,
122                                                        BmpExchangeFnc pFncBmp, const void* pBmpParam );
123 
124     SAL_DLLPRIVATE Point           ImplGetRotatedPoint( const Point& rPt, const Point& rRotatePt,
125                                                         const Size& rOffset, double fSin, double fCos );
126     SAL_DLLPRIVATE Polygon         ImplGetRotatedPolygon( const Polygon& rPoly, const Point& rRotatePt,
127                                                           const Size& rOffset, double fSin, double fCos );
128     SAL_DLLPRIVATE PolyPolygon     ImplGetRotatedPolyPolygon( const PolyPolygon& rPoly, const Point& rRotatePt,
129                                                               const Size& rOffset, double fSin, double fCos );
130     SAL_DLLPRIVATE void            ImplAddGradientEx( GDIMetaFile&          rMtf,
131                                                       const OutputDevice&   rMapDev,
132                                                       const PolyPolygon&    rPolyPoly,
133                                                       const Gradient&	  	rGrad 		);
134 
135 //#endif // __PRIVATE
136 
137 protected:
138 
139     virtual void    Linker( OutputDevice* pOut, sal_Bool bLink );
140     virtual long    Hook();
141 
142 public:
143                     GDIMetaFile();
144 					GDIMetaFile( const GDIMetaFile& rMtf );
145     virtual			~GDIMetaFile();
146 
147     using List::operator==;
148     using List::operator!=;
149     GDIMetaFile&    operator=( const GDIMetaFile& rMtf );
150 	sal_Bool			operator==( const GDIMetaFile& rMtf ) const;
operator !=(const GDIMetaFile & rMtf) const151 	sal_Bool			operator!=( const GDIMetaFile& rMtf ) const { return !( *this == rMtf ); }
152 
153     void            Clear();
154 	sal_Bool		IsEqual( const GDIMetaFile& rMtf ) const;
155     sal_Bool            Mirror( sal_uLong nMirrorFlags );
156     void            Move( long nX, long nY );
157     // additional Move method getting specifics how to handle MapMode( MAP_PIXEL )
158     void            Move( long nX, long nY, long nDPIX, long nDPIY );
159     void            Scale( double fScaleX, double fScaleY );
160     void            Scale( const Fraction& rScaleX, const Fraction& rScaleY );
161     void            Rotate( long nAngle10 );
162     void            Clip( const Rectangle& );
163     /* get the bound rect of the contained actions
164      * caveats:
165      * - clip actions will limit the contained actions,
166      *   but the current clipregion of the passed OutputDevice will not
167      * - coordinates of actions will be transformed to preferred mapmode
168      * - the returned rectangle is relative to the preferred mapmode of the metafile
169     */
170     Rectangle       GetBoundRect( OutputDevice& i_rReference, Rectangle* pHairline = 0 ) const;
171 
172 	void			Adjust( short nLuminancePercent = 0, short nContrastPercent = 0,
173 							short nChannelRPercent = 0, short nChannelGPercent = 0,
174 							short nChannelBPercent = 0, double fGamma = 1.0, sal_Bool bInvert = sal_False );
175 	void			Convert( MtfConversion eConversion );
176     void			ReplaceColors( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
177     void			ReplaceColors( const Color* pSearchColors, const Color* rReplaceColors,
178 								   sal_uLong nColorCount, sal_uLong* pTols = NULL );
179 
180     GDIMetaFile     GetMonochromeMtf( const Color& rCol ) const;
181 
182     void            Record( OutputDevice* pOutDev );
IsRecord() const183     sal_Bool            IsRecord() const { return bRecord; }
184 
185     void            Play( GDIMetaFile& rMtf, sal_uLong nPos = GDI_METAFILE_END );
186     void            Play( OutputDevice* pOutDev, sal_uLong nPos = GDI_METAFILE_END );
187     void            Play( OutputDevice* pOutDev, const Point& rPos,
188                           const Size& rSize, sal_uLong nPos = GDI_METAFILE_END );
189 
190     void            Pause( sal_Bool bPause );
IsPause() const191     sal_Bool            IsPause() const { return bPause; }
192 
193     void            Stop();
194 
195     void            WindStart();
196     void            WindEnd();
197     void            Wind( sal_uLong nAction );
198     void            WindPrev();
199     void            WindNext();
200 
GetActionCount() const201     sal_uLong           GetActionCount() const { return Count(); }
202     void            AddAction( MetaAction* pAction );
203     void            AddAction( MetaAction* pAction, sal_uLong nPos );
204     void 			RemoveAction( sal_uLong nPos );
205     MetaAction*     CopyAction( sal_uLong nPos ) const;
GetCurAction() const206     MetaAction*     GetCurAction() const { return (MetaAction*) GetCurObject(); }
GetAction(sal_uLong nAction) const207     MetaAction*     GetAction( sal_uLong nAction ) const { return (MetaAction*) GetObject( nAction ); }
FirstAction()208     MetaAction*     FirstAction() {	return (MetaAction*) First(); }
NextAction()209     MetaAction*     NextAction() { 	return (MetaAction*) Next(); }
ReplaceAction(MetaAction * pAction,sal_uLong nAction)210     MetaAction*     ReplaceAction( MetaAction* pAction, sal_uLong nAction ) { return (MetaAction*) Replace( pAction, nAction ); }
211 
212     sal_uLong           GetActionPos( const String& rLabel );
213     sal_Bool            InsertLabel( const String& rLabel, sal_uLong nActionPos );
214     void            RemoveLabel( const String& rLabel );
215     void            RenameLabel( const String& rLabel, const String& rNewLabel );
216     sal_uLong           GetLabelCount() const;
217     String          GetLabel( sal_uLong nLabel );
218 
219     sal_Bool            SaveStatus();
220 
GetPrefSize() const221     const Size&     GetPrefSize() const { return aPrefSize; }
SetPrefSize(const Size & rSize)222     void            SetPrefSize( const Size& rSize ) { aPrefSize = rSize; }
223 
GetPrefMapMode() const224     const MapMode&  GetPrefMapMode() const { return aPrefMapMode; }
SetPrefMapMode(const MapMode & rMapMode)225     void            SetPrefMapMode( const MapMode& rMapMode ) { aPrefMapMode = rMapMode; }
226 
SetHookHdl(const Link & rLink)227     void            SetHookHdl( const Link& rLink ) { aHookHdlLink = rLink; }
GetHookHdl() const228     const Link&     GetHookHdl() const { return aHookHdlLink; }
229 
230 	sal_uLong			GetChecksum() const;
231     sal_uLong           GetSizeBytes() const;
232 
233 	// Methoden zum Lesen und Schreiben des neuen Formats;
234 	// die Read-Methode kann auch das alte Format lesen
235 	SvStream&		Read( SvStream& rIStm );
236 	SvStream&		Write( SvStream& rOStm );
237 
238 	// Stream-Operatoren schreiben das alte Format (noch)
239 	// und lesen sowohl das alte wie auch das neue Format
240     friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, GDIMetaFile& rGDIMetaFile );
241     friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const GDIMetaFile& rGDIMetaFile );
242 
243 	sal_Bool           CreateThumbnail( sal_uInt32 nMaximumExtent, BitmapEx& rBmpEx, const BitmapEx* pOverlay = NULL, const Rectangle* pOverlayRect = NULL ) const;
244 };
245 
246 #endif // _SV_GDIMTF_HXX
247