Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_GDIMTF_HXX
21 : #define INCLUDED_VCL_GDIMTF_HXX
22 :
23 : #include <vcl/dllapi.h>
24 : #include <tools/gen.hxx>
25 : #include <tools/link.hxx>
26 : #include <vcl/mapmod.hxx>
27 : #include <vcl/bitmap.hxx>
28 : #include <vcl/vclptr.hxx>
29 : #include <vector>
30 :
31 : class OutputDevice;
32 : class MetaAction;
33 : class MetaCommentAction;
34 : class SvStream;
35 : class Color;
36 : class BitmapEx;
37 : class Polygon;
38 : namespace tools { class PolyPolygon; }
39 : class Gradient;
40 :
41 :
42 : // - GDIMetaFile-Types -
43 :
44 :
45 : #define GDI_METAFILE_END ((size_t)0xFFFFFFFF)
46 : #define GDI_METAFILE_LABEL_NOTFOUND ((size_t)0xFFFFFFFF)
47 :
48 : #ifndef METAFILE_END
49 : #define METAFILE_END GDI_METAFILE_END
50 : #endif
51 :
52 : #ifndef METAFILE_LABEL_NOTFOUND
53 : #define METAFILE_LABEL_NOTFOUND GDI_METAFILE_LABEL_NOTFOUND
54 : #endif
55 :
56 : enum MtfConversion
57 : {
58 : MTF_CONVERSION_NONE = 0,
59 : MTF_CONVERSION_1BIT_THRESHOLD = 1,
60 : MTF_CONVERSION_8BIT_GREYS = 2
61 : };
62 :
63 :
64 : // - Color conversion routines -
65 :
66 :
67 : typedef Color (*ColorExchangeFnc)( const Color& rColor, const void* pColParam );
68 : typedef BitmapEx (*BmpExchangeFnc)( const BitmapEx& rBmpEx, const void* pBmpParam );
69 :
70 : class VCL_DLLPUBLIC GDIMetaFile
71 : {
72 : private:
73 : ::std::vector< MetaAction* > aList;
74 : size_t nCurrentActionElement;
75 :
76 : MapMode aPrefMapMode;
77 : Size aPrefSize;
78 : Link<> aHookHdlLink;
79 : GDIMetaFile* pPrev;
80 : GDIMetaFile* pNext;
81 : VclPtr<OutputDevice> pOutDev;
82 : bool bPause;
83 : bool bRecord;
84 : bool bUseCanvas;
85 :
86 :
87 : SAL_DLLPRIVATE static Color ImplColAdjustFnc( const Color& rColor, const void* pColParam );
88 : SAL_DLLPRIVATE static BitmapEx ImplBmpAdjustFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
89 :
90 : SAL_DLLPRIVATE static Color ImplColConvertFnc( const Color& rColor, const void* pColParam );
91 : SAL_DLLPRIVATE static BitmapEx ImplBmpConvertFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
92 :
93 : SAL_DLLPRIVATE static Color ImplColMonoFnc( const Color& rColor, const void* pColParam );
94 : SAL_DLLPRIVATE static BitmapEx ImplBmpMonoFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
95 :
96 : SAL_DLLPRIVATE static Color ImplColReplaceFnc( const Color& rColor, const void* pColParam );
97 : SAL_DLLPRIVATE static BitmapEx ImplBmpReplaceFnc( const BitmapEx& rBmpEx, const void* pBmpParam );
98 :
99 : SAL_DLLPRIVATE void ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pColParam,
100 : BmpExchangeFnc pFncBmp, const void* pBmpParam );
101 :
102 : SAL_DLLPRIVATE Point ImplGetRotatedPoint( const Point& rPt, const Point& rRotatePt,
103 : const Size& rOffset, double fSin, double fCos );
104 : SAL_DLLPRIVATE Polygon ImplGetRotatedPolygon( const Polygon& rPoly, const Point& rRotatePt,
105 : const Size& rOffset, double fSin, double fCos );
106 : SAL_DLLPRIVATE tools::PolyPolygon ImplGetRotatedPolyPolygon( const tools::PolyPolygon& rPoly, const Point& rRotatePt,
107 : const Size& rOffset, double fSin, double fCos );
108 : SAL_DLLPRIVATE void ImplAddGradientEx( GDIMetaFile& rMtf,
109 : const OutputDevice& rMapDev,
110 : const tools::PolyPolygon& rPolyPoly,
111 : const Gradient& rGrad );
112 :
113 : SAL_DLLPRIVATE bool ImplPlayWithRenderer( OutputDevice* pOut, const Point& rPos, Size rLogicDestSize );
114 : SAL_DLLPRIVATE void ImplDelegate2PluggableRenderer( const MetaCommentAction* pAct, OutputDevice* pOut );
115 :
116 :
117 : protected:
118 :
119 : void Linker( OutputDevice* pOut, bool bLink );
120 : long Hook();
121 :
122 : public:
123 : GDIMetaFile();
124 : GDIMetaFile( const GDIMetaFile& rMtf );
125 : virtual ~GDIMetaFile();
126 :
127 : GDIMetaFile& operator=( const GDIMetaFile& rMtf );
128 : bool operator==( const GDIMetaFile& rMtf ) const;
129 : bool operator!=( const GDIMetaFile& rMtf ) const { return !( *this == rMtf ); }
130 :
131 : void Clear();
132 : bool Mirror( BmpMirrorFlags nMirrorFlags );
133 : void Move( long nX, long nY );
134 : // additional Move method getting specifics how to handle MapMode( MAP_PIXEL )
135 : void Move( long nX, long nY, long nDPIX, long nDPIY );
136 : void Scale( double fScaleX, double fScaleY );
137 : void Scale( const Fraction& rScaleX, const Fraction& rScaleY );
138 : void Rotate( long nAngle10 );
139 : void Clip( const Rectangle& );
140 : /* get the bound rect of the contained actions
141 : * caveats:
142 : * - clip actions will limit the contained actions,
143 : * but the current clipregion of the passed OutputDevice will not
144 : * - coordinates of actions will be transformed to preferred mapmode
145 : * - the returned rectangle is relative to the preferred mapmode of the metafile
146 : */
147 : Rectangle GetBoundRect( OutputDevice& i_rReference, Rectangle* pHairline = 0 ) const;
148 :
149 : void Adjust( short nLuminancePercent = 0, short nContrastPercent = 0,
150 : short nChannelRPercent = 0, short nChannelGPercent = 0,
151 : short nChannelBPercent = 0, double fGamma = 1.0,
152 : bool bInvert = false, bool msoBrightness = false );
153 :
154 : void Convert( MtfConversion eConversion );
155 : void ReplaceColors( const Color* pSearchColors, const Color* rReplaceColors,
156 : sal_uLong nColorCount, sal_uLong* pTols = NULL );
157 :
158 : GDIMetaFile GetMonochromeMtf( const Color& rCol ) const;
159 :
160 : void Record( OutputDevice* pOutDev );
161 8612 : bool IsRecord() const { return bRecord; }
162 :
163 : void Play( GDIMetaFile& rMtf, size_t nPos = GDI_METAFILE_END );
164 : void Play( OutputDevice* pOutDev, size_t nPos = GDI_METAFILE_END );
165 : void Play( OutputDevice* pOutDev, const Point& rPos,
166 : const Size& rSize, size_t nPos = GDI_METAFILE_END );
167 :
168 : void Pause( bool bPause );
169 3583 : bool IsPause() const { return bPause; }
170 :
171 : void Stop();
172 :
173 : void WindStart();
174 : void WindPrev();
175 :
176 : size_t GetActionSize() const;
177 :
178 : void AddAction( MetaAction* pAction );
179 : void AddAction( MetaAction* pAction, size_t nPos );
180 : void RemoveAction( size_t nPos );
181 : void push_back( MetaAction* pAction );
182 : /**
183 : * @param pAction takes ownership
184 : */
185 : MetaAction* ReplaceAction( MetaAction* pAction, size_t nAction );
186 :
187 : MetaAction* FirstAction();
188 : MetaAction* NextAction();
189 : MetaAction* GetAction( size_t nAction ) const;
190 13029 : MetaAction* GetCurAction() const { return GetAction( nCurrentActionElement ); }
191 :
192 5895 : const Size& GetPrefSize() const { return aPrefSize; }
193 6854 : void SetPrefSize( const Size& rSize ) { aPrefSize = rSize; }
194 :
195 8004 : const MapMode& GetPrefMapMode() const { return aPrefMapMode; }
196 6853 : void SetPrefMapMode( const MapMode& rMapMode ) { aPrefMapMode = rMapMode; }
197 :
198 : void SetHookHdl( const Link<>& rLink ) { aHookHdlLink = rLink; }
199 : const Link<>& GetHookHdl() const { return aHookHdlLink; }
200 :
201 : sal_uLong GetChecksum() const;
202 : sal_uLong GetSizeBytes() const;
203 :
204 : // Methods for reading and writing the new formats;
205 : // the Read method also reads the old format
206 : SvStream& Read( SvStream& rIStm );
207 : SvStream& Write( SvStream& rOStm );
208 :
209 : // Stream-operators write (still) the old format
210 : // and read both the old and the new format
211 : friend VCL_DLLPUBLIC SvStream& ReadGDIMetaFile( SvStream& rIStm, GDIMetaFile& rGDIMetaFile );
212 : friend VCL_DLLPUBLIC SvStream& WriteGDIMetaFile( SvStream& rOStm, const GDIMetaFile& rGDIMetaFile );
213 :
214 : /// Creates an antialiased thumbnail, with maximum width or height of nMaximumExtent.
215 : bool CreateThumbnail(BitmapEx& rBitmapEx,
216 : sal_uInt32 nMaximumExtent = 256,
217 : BmpConversion nColorConversion = BMP_CONVERSION_24BIT,
218 : BmpScaleFlag nScaleFlag = BmpScaleFlag::BestQuality) const;
219 :
220 : void UseCanvas( bool _bUseCanvas );
221 132 : bool GetUseCanvas() const { return bUseCanvas; }
222 : };
223 :
224 : /** Create a special metaaction that delegates rendering to specified
225 : service.
226 :
227 : This factory function creates a MetaCommentAction that delegates
228 : rendering to the specified services, once played back in the
229 : metafile.
230 :
231 : @param rRendererServiceName
232 : Renderer service. Gets an awt::XGraphic on instantiation
233 :
234 : @param rGraphicServiceName
235 : Graphic service. Gets the raw data on instantiation
236 :
237 : @param pData
238 : Raw data. Gets copied
239 :
240 : @param nDataSize
241 : Length, in byte, of raw data
242 : */
243 : MetaCommentAction* makePluggableRendererAction( const OUString& rRendererServiceName,
244 : const OUString& rGraphicServiceName,
245 : const void* pData,
246 : sal_uInt32 nDataSize );
247 :
248 : #endif // INCLUDED_VCL_GDIMTF_HXX
249 :
250 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|