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 <vcl/mapmod.hxx>
26 #include <vcl/bitmap.hxx>
27 #include <vcl/vclptr.hxx>
32 class MetaCommentAction
;
43 #define GDI_METAFILE_END ((size_t)0xFFFFFFFF)
44 #define GDI_METAFILE_LABEL_NOTFOUND ((size_t)0xFFFFFFFF)
46 enum class MtfConversion
53 typedef Color (*ColorExchangeFnc
)( const Color
& rColor
, const void* pColParam
);
54 typedef BitmapEx (*BmpExchangeFnc
)( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
56 class VCL_DLLPUBLIC GDIMetaFile final
59 ::std::vector
< MetaAction
* > m_aList
;
60 size_t m_nCurrentActionElement
;
62 MapMode m_aPrefMapMode
;
66 VclPtr
<OutputDevice
> m_pOutDev
;
72 SAL_DLLPRIVATE
static Color
ImplColAdjustFnc( const Color
& rColor
, const void* pColParam
);
73 SAL_DLLPRIVATE
static BitmapEx
ImplBmpAdjustFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
75 SAL_DLLPRIVATE
static Color
ImplColConvertFnc( const Color
& rColor
, const void* pColParam
);
76 SAL_DLLPRIVATE
static BitmapEx
ImplBmpConvertFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
78 SAL_DLLPRIVATE
static Color
ImplColMonoFnc( const Color
& rColor
, const void* pColParam
);
79 SAL_DLLPRIVATE
static BitmapEx
ImplBmpMonoFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
81 SAL_DLLPRIVATE
static Color
ImplColReplaceFnc( const Color
& rColor
, const void* pColParam
);
82 SAL_DLLPRIVATE
static BitmapEx
ImplBmpReplaceFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
84 SAL_DLLPRIVATE
void ImplExchangeColors( ColorExchangeFnc pFncCol
, const void* pColParam
,
85 BmpExchangeFnc pFncBmp
, const void* pBmpParam
);
87 SAL_DLLPRIVATE
static Point
ImplGetRotatedPoint( const Point
& rPt
, const Point
& rRotatePt
,
88 const Size
& rOffset
, double fSin
, double fCos
);
89 SAL_DLLPRIVATE
static tools::Polygon
ImplGetRotatedPolygon( const tools::Polygon
& rPoly
, const Point
& rRotatePt
,
90 const Size
& rOffset
, double fSin
, double fCos
);
91 SAL_DLLPRIVATE
static tools::PolyPolygon
ImplGetRotatedPolyPolygon( const tools::PolyPolygon
& rPoly
, const Point
& rRotatePt
,
92 const Size
& rOffset
, double fSin
, double fCos
);
93 SAL_DLLPRIVATE
static void ImplAddGradientEx( GDIMetaFile
& rMtf
,
94 const OutputDevice
& rMapDev
,
95 const tools::PolyPolygon
& rPolyPoly
,
96 const Gradient
& rGrad
);
98 SAL_DLLPRIVATE
bool ImplPlayWithRenderer( OutputDevice
* pOut
, const Point
& rPos
, Size rLogicDestSize
);
100 void Linker( OutputDevice
* pOut
, bool bLink
);
104 GDIMetaFile( const GDIMetaFile
& rMtf
);
107 GDIMetaFile
& operator=( const GDIMetaFile
& rMtf
);
108 bool operator==( const GDIMetaFile
& rMtf
) const;
109 bool operator!=( const GDIMetaFile
& rMtf
) const { return !( *this == rMtf
); }
112 bool Mirror( BmpMirrorFlags nMirrorFlags
);
113 void Move( long nX
, long nY
);
114 // additional Move method getting specifics how to handle MapMode( MapUnit::MapPixel )
115 void Move( long nX
, long nY
, long nDPIX
, long nDPIY
);
116 void Scale( double fScaleX
, double fScaleY
);
117 void Scale( const Fraction
& rScaleX
, const Fraction
& rScaleY
);
118 void Rotate( long nAngle10
);
119 void Clip( const tools::Rectangle
& );
120 /* get the bound rect of the contained actions
122 * - clip actions will limit the contained actions,
123 * but the current clipregion of the passed OutputDevice will not
124 * - coordinates of actions will be transformed to preferred mapmode
125 * - the returned rectangle is relative to the preferred mapmode of the metafile
127 tools::Rectangle
GetBoundRect( OutputDevice
& i_rReference
, tools::Rectangle
* pHairline
= nullptr ) const;
129 void Adjust( short nLuminancePercent
, short nContrastPercent
,
130 short nChannelRPercent
= 0, short nChannelGPercent
= 0,
131 short nChannelBPercent
= 0, double fGamma
= 1.0,
132 bool bInvert
= false, bool msoBrightness
= false );
134 void Convert( MtfConversion eConversion
);
135 void ReplaceColors( const Color
* pSearchColors
, const Color
* rReplaceColors
,
136 sal_uLong nColorCount
);
138 GDIMetaFile
GetMonochromeMtf( const Color
& rCol
) const;
140 void Record( OutputDevice
* pOutDev
);
141 bool IsRecord() const { return m_bRecord
; }
143 void Play( GDIMetaFile
& rMtf
);
144 void Play( OutputDevice
* pOutDev
, size_t nPos
= GDI_METAFILE_END
);
145 void Play( OutputDevice
* pOutDev
, const Point
& rPos
,
148 void Pause( bool bPause
);
149 bool IsPause() const { return m_bPause
; }
156 size_t GetActionSize() const;
158 void AddAction( MetaAction
* pAction
);
159 void AddAction( MetaAction
* pAction
, size_t nPos
);
160 void RemoveAction( size_t nPos
);
161 void push_back( MetaAction
* pAction
);
163 * @param pAction takes ownership
164 * @param nAction the action to replace
166 MetaAction
* ReplaceAction( MetaAction
* pAction
, size_t nAction
);
168 MetaAction
* FirstAction();
169 MetaAction
* NextAction();
170 MetaAction
* GetAction( size_t nAction
) const;
171 MetaAction
* GetCurAction() const { return GetAction( m_nCurrentActionElement
); }
173 const Size
& GetPrefSize() const { return m_aPrefSize
; }
174 void SetPrefSize( const Size
& rSize
) { m_aPrefSize
= rSize
; }
176 const MapMode
& GetPrefMapMode() const { return m_aPrefMapMode
; }
177 void SetPrefMapMode( const MapMode
& rMapMode
) { m_aPrefMapMode
= rMapMode
; }
180 BitmapChecksum
GetChecksum() const;
181 sal_uLong
GetSizeBytes() const;
183 // Methods for reading and writing the new formats;
184 // the Read method also reads the old format
185 SvStream
& Read( SvStream
& rIStm
);
186 SvStream
& Write( SvStream
& rOStm
);
188 // Stream-operators write (still) the old format
189 // and read both the old and the new format
190 friend VCL_DLLPUBLIC SvStream
& ReadGDIMetaFile( SvStream
& rIStm
, GDIMetaFile
& rGDIMetaFile
);
191 friend VCL_DLLPUBLIC SvStream
& WriteGDIMetaFile( SvStream
& rOStm
, const GDIMetaFile
& rGDIMetaFile
);
193 /// Creates an antialiased thumbnail
194 bool CreateThumbnail(BitmapEx
& rBitmapEx
,
195 BmpConversion nColorConversion
= BmpConversion::N24Bit
,
196 BmpScaleFlag nScaleFlag
= BmpScaleFlag::BestQuality
) const;
198 void UseCanvas( bool _bUseCanvas
);
199 bool GetUseCanvas() const { return m_bUseCanvas
; }
202 #endif // INCLUDED_VCL_GDIMTF_HXX
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */