1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SV_GDIMTF_HXX
21 #define _SV_GDIMTF_HXX
23 #include <vcl/dllapi.h>
24 #include <tools/gen.hxx>
25 #include <tools/link.hxx>
26 #include <vcl/mapmod.hxx>
31 class MetaCommentAction
;
39 // ---------------------
40 // - GDIMetaFile-Types -
41 // ---------------------
43 #define GDI_METAFILE_END ((size_t)0xFFFFFFFF)
44 #define GDI_METAFILE_LABEL_NOTFOUND ((size_t)0xFFFFFFFF)
47 #define METAFILE_END GDI_METAFILE_END
50 #ifndef METAFILE_LABEL_NOTFOUND
51 #define METAFILE_LABEL_NOTFOUND GDI_METAFILE_LABEL_NOTFOUND
54 #define MTF_MIRROR_NONE 0x00000000UL
55 #define MTF_MIRROR_HORZ 0x00000001UL
56 #define MTF_MIRROR_VERT 0x00000002UL
60 MTF_CONVERSION_NONE
= 0,
61 MTF_CONVERSION_1BIT_THRESHOLD
= 1,
62 MTF_CONVERSION_8BIT_GREYS
= 2
65 // -----------------------------
66 // - Color conversion routines -
67 // -----------------------------
69 typedef Color (*ColorExchangeFnc
)( const Color
& rColor
, const void* pColParam
);
70 typedef BitmapEx (*BmpExchangeFnc
)( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
72 class VCL_DLLPUBLIC GDIMetaFile
75 ::std::vector
< MetaAction
* > aList
;
76 size_t nCurrentActionElement
;
83 OutputDevice
* pOutDev
;
89 SAL_DLLPRIVATE
static Color
ImplColAdjustFnc( const Color
& rColor
, const void* pColParam
);
90 SAL_DLLPRIVATE
static BitmapEx
ImplBmpAdjustFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
92 SAL_DLLPRIVATE
static Color
ImplColConvertFnc( const Color
& rColor
, const void* pColParam
);
93 SAL_DLLPRIVATE
static BitmapEx
ImplBmpConvertFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
95 SAL_DLLPRIVATE
static Color
ImplColMonoFnc( const Color
& rColor
, const void* pColParam
);
96 SAL_DLLPRIVATE
static BitmapEx
ImplBmpMonoFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
98 SAL_DLLPRIVATE
static Color
ImplColReplaceFnc( const Color
& rColor
, const void* pColParam
);
99 SAL_DLLPRIVATE
static BitmapEx
ImplBmpReplaceFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
101 SAL_DLLPRIVATE
void ImplExchangeColors( ColorExchangeFnc pFncCol
, const void* pColParam
,
102 BmpExchangeFnc pFncBmp
, const void* pBmpParam
);
104 SAL_DLLPRIVATE Point
ImplGetRotatedPoint( const Point
& rPt
, const Point
& rRotatePt
,
105 const Size
& rOffset
, double fSin
, double fCos
);
106 SAL_DLLPRIVATE Polygon
ImplGetRotatedPolygon( const Polygon
& rPoly
, const Point
& rRotatePt
,
107 const Size
& rOffset
, double fSin
, double fCos
);
108 SAL_DLLPRIVATE PolyPolygon
ImplGetRotatedPolyPolygon( const PolyPolygon
& rPoly
, const Point
& rRotatePt
,
109 const Size
& rOffset
, double fSin
, double fCos
);
110 SAL_DLLPRIVATE
void ImplAddGradientEx( GDIMetaFile
& rMtf
,
111 const OutputDevice
& rMapDev
,
112 const PolyPolygon
& rPolyPoly
,
113 const Gradient
& rGrad
);
114 SAL_DLLPRIVATE
bool ImplPlayWithRenderer( OutputDevice
* pOut
, const Point
& rPos
, Size rLogicDestSize
);
115 SAL_DLLPRIVATE
void ImplDelegate2PluggableRenderer( const MetaCommentAction
* pAct
, OutputDevice
* pOut
);
120 virtual void Linker( OutputDevice
* pOut
, sal_Bool bLink
);
125 GDIMetaFile( const GDIMetaFile
& rMtf
);
126 virtual ~GDIMetaFile();
128 GDIMetaFile
& operator=( const GDIMetaFile
& rMtf
);
129 sal_Bool
operator==( const GDIMetaFile
& rMtf
) const;
130 sal_Bool
operator!=( const GDIMetaFile
& rMtf
) const { return !( *this == rMtf
); }
133 sal_Bool
Mirror( sal_uLong nMirrorFlags
);
134 void Move( long nX
, long nY
);
135 // additional Move method getting specifics how to handle MapMode( MAP_PIXEL )
136 void Move( long nX
, long nY
, long nDPIX
, long nDPIY
);
137 void Scale( double fScaleX
, double fScaleY
);
138 void Scale( const Fraction
& rScaleX
, const Fraction
& rScaleY
);
139 void Rotate( long nAngle10
);
140 void Clip( const Rectangle
& );
141 /* get the bound rect of the contained actions
143 * - clip actions will limit the contained actions,
144 * but the current clipregion of the passed OutputDevice will not
145 * - coordinates of actions will be transformed to preferred mapmode
146 * - the returned rectangle is relative to the preferred mapmode of the metafile
148 Rectangle
GetBoundRect( OutputDevice
& i_rReference
, Rectangle
* pHairline
= 0 ) const;
150 void Adjust( short nLuminancePercent
= 0, short nContrastPercent
= 0,
151 short nChannelRPercent
= 0, short nChannelGPercent
= 0,
152 short nChannelBPercent
= 0, double fGamma
= 1.0,
153 sal_Bool bInvert
= sal_False
156 void Convert( MtfConversion eConversion
);
157 void ReplaceColors( const Color
* pSearchColors
, const Color
* rReplaceColors
,
158 sal_uLong nColorCount
, sal_uLong
* pTols
= NULL
);
160 GDIMetaFile
GetMonochromeMtf( const Color
& rCol
) const;
162 void Record( OutputDevice
* pOutDev
);
163 sal_Bool
IsRecord() const { return bRecord
; }
165 void Play( GDIMetaFile
& rMtf
, size_t nPos
= GDI_METAFILE_END
);
166 void Play( OutputDevice
* pOutDev
, size_t nPos
= GDI_METAFILE_END
);
167 void Play( OutputDevice
* pOutDev
, const Point
& rPos
,
168 const Size
& rSize
, size_t nPos
= GDI_METAFILE_END
);
170 void Pause( sal_Bool bPause
);
171 sal_Bool
IsPause() const { return bPause
; }
178 size_t GetActionSize() const;
180 void AddAction( MetaAction
* pAction
);
181 void AddAction( MetaAction
* pAction
, size_t nPos
);
182 void RemoveAction( size_t nPos
);
183 void push_back( MetaAction
* pAction
);
185 MetaAction
* FirstAction();
186 MetaAction
* NextAction();
187 MetaAction
* GetAction( size_t nAction
) const;
188 MetaAction
* GetCurAction() const { return GetAction( nCurrentActionElement
); }
190 * @param pAction takes ownership
192 MetaAction
* ReplaceAction( MetaAction
* pAction
, size_t nAction
);
194 const Size
& GetPrefSize() const { return aPrefSize
; }
195 void SetPrefSize( const Size
& rSize
) { aPrefSize
= rSize
; }
197 const MapMode
& GetPrefMapMode() const { return aPrefMapMode
; }
198 void SetPrefMapMode( const MapMode
& rMapMode
) { aPrefMapMode
= rMapMode
; }
200 void SetHookHdl( const Link
& rLink
) { aHookHdlLink
= rLink
; }
201 const Link
& GetHookHdl() const { return aHookHdlLink
; }
203 sal_uLong
GetChecksum() const;
204 sal_uLong
GetSizeBytes() const;
206 // Methods for reading and writing the new formats;
207 // the Read method also reads the old format
208 SvStream
& Read( SvStream
& rIStm
);
209 SvStream
& Write( SvStream
& rOStm
);
211 // Stream-operators write (still) the old format
212 // and read both the old and the new format
213 friend VCL_DLLPUBLIC SvStream
& operator>>( SvStream
& rIStm
, GDIMetaFile
& rGDIMetaFile
);
214 friend VCL_DLLPUBLIC SvStream
& operator<<( SvStream
& rOStm
, const GDIMetaFile
& rGDIMetaFile
);
216 sal_Bool
CreateThumbnail( sal_uInt32 nMaximumExtent
, BitmapEx
& rBmpEx
, const BitmapEx
* pOverlay
= NULL
, const Rectangle
* pOverlayRect
= NULL
) const;
218 void UseCanvas( sal_Bool _bUseCanvas
);
219 sal_Bool
GetUseCanvas() const { return bUseCanvas
; }
222 /** Create a special metaaction that delegates rendering to specified
225 This factory function creates a MetaCommentAction that delegates
226 rendering to the specified services, once played back in the
229 @param rRendererServiceName
230 Renderer service. Gets an awt::XGraphic on instantiation
232 @param rGraphicServiceName
233 Graphic service. Gets the raw data on instantiation
236 Raw data. Gets copied
239 Length, in byte, of raw data
241 MetaCommentAction
* makePluggableRendererAction( const OUString
& rRendererServiceName
,
242 const OUString
& rGraphicServiceName
,
244 sal_uInt32 nDataSize
);
246 #endif // _SV_GDIMTF_HXX
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */