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 INCLUDED_VCL_GDIMTF_HXX
21 #define INCLUDED_VCL_GDIMTF_HXX
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>
33 class MetaCommentAction
;
38 namespace tools
{ class PolyPolygon
; }
42 // - GDIMetaFile-Types -
45 #define GDI_METAFILE_END ((size_t)0xFFFFFFFF)
46 #define GDI_METAFILE_LABEL_NOTFOUND ((size_t)0xFFFFFFFF)
49 #define METAFILE_END GDI_METAFILE_END
52 #ifndef METAFILE_LABEL_NOTFOUND
53 #define METAFILE_LABEL_NOTFOUND GDI_METAFILE_LABEL_NOTFOUND
58 MTF_CONVERSION_NONE
= 0,
59 MTF_CONVERSION_1BIT_THRESHOLD
= 1,
60 MTF_CONVERSION_8BIT_GREYS
= 2
64 // - Color conversion routines -
67 typedef Color (*ColorExchangeFnc
)( const Color
& rColor
, const void* pColParam
);
68 typedef BitmapEx (*BmpExchangeFnc
)( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
70 class VCL_DLLPUBLIC GDIMetaFile
73 ::std::vector
< MetaAction
* > aList
;
74 size_t nCurrentActionElement
;
81 VclPtr
<OutputDevice
> pOutDev
;
87 SAL_DLLPRIVATE
static Color
ImplColAdjustFnc( const Color
& rColor
, const void* pColParam
);
88 SAL_DLLPRIVATE
static BitmapEx
ImplBmpAdjustFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
90 SAL_DLLPRIVATE
static Color
ImplColConvertFnc( const Color
& rColor
, const void* pColParam
);
91 SAL_DLLPRIVATE
static BitmapEx
ImplBmpConvertFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
93 SAL_DLLPRIVATE
static Color
ImplColMonoFnc( const Color
& rColor
, const void* pColParam
);
94 SAL_DLLPRIVATE
static BitmapEx
ImplBmpMonoFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
96 SAL_DLLPRIVATE
static Color
ImplColReplaceFnc( const Color
& rColor
, const void* pColParam
);
97 SAL_DLLPRIVATE
static BitmapEx
ImplBmpReplaceFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
99 SAL_DLLPRIVATE
void ImplExchangeColors( ColorExchangeFnc pFncCol
, const void* pColParam
,
100 BmpExchangeFnc pFncBmp
, const void* pBmpParam
);
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
);
113 SAL_DLLPRIVATE
bool ImplPlayWithRenderer( OutputDevice
* pOut
, const Point
& rPos
, Size rLogicDestSize
);
114 SAL_DLLPRIVATE
void ImplDelegate2PluggableRenderer( const MetaCommentAction
* pAct
, OutputDevice
* pOut
);
119 void Linker( OutputDevice
* pOut
, bool bLink
);
124 GDIMetaFile( const GDIMetaFile
& rMtf
);
125 virtual ~GDIMetaFile();
127 GDIMetaFile
& operator=( const GDIMetaFile
& rMtf
);
128 bool operator==( const GDIMetaFile
& rMtf
) const;
129 bool operator!=( const GDIMetaFile
& rMtf
) const { return !( *this == rMtf
); }
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
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
147 Rectangle
GetBoundRect( OutputDevice
& i_rReference
, Rectangle
* pHairline
= 0 ) const;
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 );
154 void Convert( MtfConversion eConversion
);
155 void ReplaceColors( const Color
* pSearchColors
, const Color
* rReplaceColors
,
156 sal_uLong nColorCount
, sal_uLong
* pTols
= NULL
);
158 GDIMetaFile
GetMonochromeMtf( const Color
& rCol
) const;
160 void Record( OutputDevice
* pOutDev
);
161 bool IsRecord() const { return bRecord
; }
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
);
168 void Pause( bool bPause
);
169 bool IsPause() const { return bPause
; }
176 size_t GetActionSize() const;
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
);
183 * @param pAction takes ownership
185 MetaAction
* ReplaceAction( MetaAction
* pAction
, size_t nAction
);
187 MetaAction
* FirstAction();
188 MetaAction
* NextAction();
189 MetaAction
* GetAction( size_t nAction
) const;
190 MetaAction
* GetCurAction() const { return GetAction( nCurrentActionElement
); }
192 const Size
& GetPrefSize() const { return aPrefSize
; }
193 void SetPrefSize( const Size
& rSize
) { aPrefSize
= rSize
; }
195 const MapMode
& GetPrefMapMode() const { return aPrefMapMode
; }
196 void SetPrefMapMode( const MapMode
& rMapMode
) { aPrefMapMode
= rMapMode
; }
198 void SetHookHdl( const Link
<>& rLink
) { aHookHdlLink
= rLink
; }
199 const Link
<>& GetHookHdl() const { return aHookHdlLink
; }
201 BitmapChecksum
GetChecksum() const;
202 sal_uLong
GetSizeBytes() const;
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
);
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
);
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;
220 void UseCanvas( bool _bUseCanvas
);
221 bool GetUseCanvas() const { return bUseCanvas
; }
224 /** Create a special metaaction that delegates rendering to specified
227 This factory function creates a MetaCommentAction that delegates
228 rendering to the specified services, once played back in the
231 @param rRendererServiceName
232 Renderer service. Gets an awt::XGraphic on instantiation
234 @param rGraphicServiceName
235 Graphic service. Gets the raw data on instantiation
238 Raw data. Gets copied
241 Length, in byte, of raw data
243 MetaCommentAction
* makePluggableRendererAction( const OUString
& rRendererServiceName
,
244 const OUString
& rGraphicServiceName
,
246 sal_uInt32 nDataSize
);
248 #endif // INCLUDED_VCL_GDIMTF_HXX
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */