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/solar.h>
26 #include <vcl/mapmod.hxx>
27 #include <vcl/bitmap.hxx>
28 #include <vcl/vclptr.hxx>
41 struct ImplMetaReadData
;
43 #define GDI_METAFILE_END (size_t(0xFFFFFFFF))
45 enum class MtfConversion
52 typedef Color (*ColorExchangeFnc
)( const Color
& rColor
, const void* pColParam
);
53 typedef BitmapEx (*BmpExchangeFnc
)( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
55 class VCL_DLLPUBLIC GDIMetaFile final
58 ::std::vector
< rtl::Reference
<MetaAction
> > m_aList
;
59 size_t m_nCurrentActionElement
;
61 MapMode m_aPrefMapMode
;
65 VclPtr
<OutputDevice
> m_pOutDev
;
70 // tdf#155479 need to know if it's SVG export
74 SAL_DLLPRIVATE
static Color
ImplColAdjustFnc( const Color
& rColor
, const void* pColParam
);
75 SAL_DLLPRIVATE
static BitmapEx
ImplBmpAdjustFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
77 SAL_DLLPRIVATE
static Color
ImplColConvertFnc( const Color
& rColor
, const void* pColParam
);
78 SAL_DLLPRIVATE
static BitmapEx
ImplBmpConvertFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
80 SAL_DLLPRIVATE
static Color
ImplColMonoFnc( const Color
& rColor
, const void* pColParam
);
81 SAL_DLLPRIVATE
static BitmapEx
ImplBmpMonoFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
83 SAL_DLLPRIVATE
static Color
ImplColReplaceFnc( const Color
& rColor
, const void* pColParam
);
84 SAL_DLLPRIVATE
static BitmapEx
ImplBmpReplaceFnc( const BitmapEx
& rBmpEx
, const void* pBmpParam
);
86 SAL_DLLPRIVATE
void ImplExchangeColors( ColorExchangeFnc pFncCol
, const void* pColParam
,
87 BmpExchangeFnc pFncBmp
, const void* pBmpParam
);
89 SAL_DLLPRIVATE
static Point
ImplGetRotatedPoint( const Point
& rPt
, const Point
& rRotatePt
,
90 const Size
& rOffset
, double fSin
, double fCos
);
91 SAL_DLLPRIVATE
static tools::Polygon
ImplGetRotatedPolygon( const tools::Polygon
& rPoly
, const Point
& rRotatePt
,
92 const Size
& rOffset
, double fSin
, double fCos
);
93 SAL_DLLPRIVATE
static tools::PolyPolygon
ImplGetRotatedPolyPolygon( const tools::PolyPolygon
& rPoly
, const Point
& rRotatePt
,
94 const Size
& rOffset
, double fSin
, double fCos
);
95 SAL_DLLPRIVATE
static void ImplAddGradientEx( GDIMetaFile
& rMtf
,
96 const OutputDevice
& rMapDev
,
97 const tools::PolyPolygon
& rPolyPoly
,
98 const Gradient
& rGrad
);
100 SAL_DLLPRIVATE
bool ImplPlayWithRenderer(OutputDevice
& rOut
, const Point
& rPos
, Size rLogicDestSize
);
102 SAL_DLLPRIVATE
void Linker( OutputDevice
* pOut
, bool bLink
);
106 GDIMetaFile( const GDIMetaFile
& rMtf
);
109 GDIMetaFile
& operator=( const GDIMetaFile
& rMtf
);
110 bool operator==( const GDIMetaFile
& rMtf
) const;
111 bool operator!=( const GDIMetaFile
& rMtf
) const { return !( *this == rMtf
); }
114 SAL_DLLPRIVATE
void Mirror( BmpMirrorFlags nMirrorFlags
);
115 void Move( tools::Long nX
, tools::Long nY
);
116 // additional Move method getting specifics how to handle MapMode( MapUnit::MapPixel )
117 void Move( tools::Long nX
, tools::Long nY
, tools::Long nDPIX
, tools::Long nDPIY
);
118 void ScaleActions(double fScaleX
, double fScaleY
);
119 void Scale( double fScaleX
, double fScaleY
);
120 void Scale( const Fraction
& rScaleX
, const Fraction
& rScaleY
);
121 SAL_DLLPRIVATE
void Rotate( Degree10 nAngle10
);
122 void Clip( const tools::Rectangle
& );
123 bool HasTransparentActions() const;
125 /* get the bound rect of the contained actions
127 * - clip actions will limit the contained actions,
128 * but the current clipregion of the passed OutputDevice will not
129 * - coordinates of actions will be transformed to preferred mapmode
130 * - the returned rectangle is relative to the preferred mapmode of the metafile
132 tools::Rectangle
GetBoundRect( OutputDevice
& i_rReference
) const;
134 void Adjust( short nLuminancePercent
, short nContrastPercent
,
135 short nChannelRPercent
= 0, short nChannelGPercent
= 0,
136 short nChannelBPercent
= 0, double fGamma
= 1.0,
137 bool bInvert
= false, bool msoBrightness
= false );
139 void Convert( MtfConversion eConversion
);
140 void ReplaceColors( const Color
* pSearchColors
, const Color
* rReplaceColors
,
141 sal_uLong nColorCount
);
143 GDIMetaFile
GetMonochromeMtf( const Color
& rCol
) const;
145 void Record( OutputDevice
* pOutDev
);
146 bool IsRecord() const { return m_bRecord
; }
148 void Play(GDIMetaFile
& rMtf
);
149 void Play(OutputDevice
& rOutDev
, size_t nPos
= GDI_METAFILE_END
);
150 void Play(OutputDevice
& rOutDev
, const Point
& rPos
, const Size
& rSize
);
152 void Pause( bool bPause
);
153 bool IsPause() const { return m_bPause
; }
160 size_t GetActionSize() const;
162 void AddAction(const rtl::Reference
<MetaAction
>& pAction
);
163 void AddAction(const rtl::Reference
<MetaAction
>& pAction
, size_t nPos
);
164 SAL_DLLPRIVATE
void push_back(const rtl::Reference
<MetaAction
>& pAction
);
166 * @param nAction the action to replace
168 SAL_DLLPRIVATE
void ReplaceAction( rtl::Reference
<MetaAction
> pAction
, size_t nAction
);
170 MetaAction
* FirstAction();
171 MetaAction
* NextAction();
172 MetaAction
* GetAction( size_t nAction
) const;
173 MetaAction
* GetCurAction() const { return GetAction( m_nCurrentActionElement
); }
175 const Size
& GetPrefSize() const { return m_aPrefSize
; }
176 void SetPrefSize( const Size
& rSize
) { m_aPrefSize
= rSize
; }
178 const MapMode
& GetPrefMapMode() const { return m_aPrefMapMode
; }
179 void SetPrefMapMode( const MapMode
& rMapMode
) { m_aPrefMapMode
= rMapMode
; }
182 SAL_DLLPRIVATE sal_uLong
GetSizeBytes() const;
184 /// Creates an antialiased thumbnail
185 bool CreateThumbnail(BitmapEx
& rBitmapEx
,
186 BmpConversion nColorConversion
= BmpConversion::N24Bit
,
187 BmpScaleFlag nScaleFlag
= BmpScaleFlag::BestQuality
) const;
189 void UseCanvas( bool _bUseCanvas
);
190 bool GetUseCanvas() const { return m_bUseCanvas
; }
193 bool getSVG() const { return m_bSVG
; }
194 void setSVG(bool bNew
) { m_bSVG
= bNew
; }
196 /// Dumps the meta actions as XML in metafile.xml.
197 void dumpAsXml(const char* pFileName
= nullptr) const;
200 #endif // INCLUDED_VCL_GDIMTF_HXX
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */