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_CPPCANVAS_SOURCE_INC_IMPLRENDERER_HXX
21 #define INCLUDED_CPPCANVAS_SOURCE_INC_IMPLRENDERER_HXX
23 #include <sal/config.h>
25 #include <basegfx/vector/b2dsize.hxx>
26 #include <sal/types.h>
27 #include <tools/stream.hxx>
28 #include <cppcanvas/renderer.hxx>
29 #include <cppcanvas/canvas.hxx>
31 #include "canvasgraphichelper.hxx"
33 #include "outdevstate.hxx"
35 #include <com/sun/star/rendering/FontRequest.hpp>
36 #include <com/sun/star/rendering/StrokeAttributes.hpp>
37 #include <osl/diagnose.h>
38 #include <osl/endian.h>
47 namespace tools
{ class Rectangle
; }
48 namespace vcl
{ class Font
; }
49 namespace tools
{ class PolyPolygon
; }
51 class MetaCommentAction
;
64 struct ActionFactoryParameters
;
67 // state stack of OutputDevice, to correctly handle
69 class VectorOfOutDevStates
72 OutDevState
& getState();
73 const OutDevState
& getState() const;
74 void pushState(PushFlags nFlags
);
76 void clearStateStack();
78 std::vector
< OutDevState
> m_aStates
;
82 // Transformation matrix (used for Affine Transformation)
83 // [ eM11, eM12, eDx ]
84 // [ eM21, eM22, eDy ]
86 // that consists of a linear map (eM11, eM12, eM21, eM22)
87 // More info: https://en.wikipedia.org/wiki/Linear_map
88 // followed by a translation (eDx, eDy)
92 float eM11
; // M1,1 value in the matrix. Increases or decreases the size of the pixels horizontally.
93 float eM12
; // M1,2 value in the matrix. This effectively angles the X axis up or down.
94 float eM21
; // M2,1 value in the matrix. This effectively angles the Y axis left or right.
95 float eM22
; // M2,2 value in the matrix. Increases or decreases the size of the pixels vertically.
96 float eDx
; // Delta x (Dx) value in the matrix. Moves the whole coordinate system horizontally.
97 float eDy
; // Delta y (Dy) value in the matrix. Moves the whole coordinate system vertically.
106 eDx
= eDy
= eM12
= eM21
= 0.0f
;
109 friend SvStream
& ReadXForm( SvStream
& rIn
, XForm
& rXForm
)
111 if ( sizeof( float ) != 4 )
113 OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
118 rIn
.ReadFloat( rXForm
.eM11
).ReadFloat( rXForm
.eM12
).ReadFloat( rXForm
.eM21
).ReadFloat( rXForm
.eM22
)
119 .ReadFloat( rXForm
.eDx
).ReadFloat( rXForm
.eDy
);
127 class ImplRenderer
: public virtual Renderer
, protected CanvasGraphicHelper
130 ImplRenderer( const CanvasSharedPtr
& rCanvas
,
131 const GDIMetaFile
& rMtf
,
132 const Parameters
& rParms
);
134 virtual ~ImplRenderer() override
;
136 virtual bool draw() const override
;
137 virtual bool drawSubset( sal_Int32 nStartIndex
,
138 sal_Int32 nEndIndex
) const override
;
139 virtual ::basegfx::B2DRange
getSubsetArea( sal_Int32 nStartIndex
,
140 sal_Int32 nEndIndex
) const override
;
143 // element of the Renderer's action vector. Need to be
144 // public, since some functors need it, too.
147 MtfAction( const std::shared_ptr
<Action
>& rAction
,
148 sal_Int32 nOrigIndex
) :
150 mnOrigIndex( nOrigIndex
)
154 std::shared_ptr
<Action
> mpAction
;
155 sal_Int32 mnOrigIndex
;
158 // prefetched and prepared canvas actions
159 // (externally not visible)
160 typedef std::vector
< MtfAction
> ActionVector
;
163 ImplRenderer(const ImplRenderer
&) = delete;
164 ImplRenderer
& operator=( const ImplRenderer
& ) = delete;
166 static void updateClipping( const ::basegfx::B2DPolyPolygon
& rClipPoly
,
167 const ActionFactoryParameters
& rParms
,
170 static void updateClipping( const ::tools::Rectangle
& rClipRect
,
171 const ActionFactoryParameters
& rParms
,
174 static css::uno::Reference
<
175 css::rendering::XCanvasFont
> createFont( double& o_rFontRotation
,
176 const vcl::Font
& rFont
,
177 const ActionFactoryParameters
& rParms
);
178 void createActions( GDIMetaFile
& rMtf
,
179 const ActionFactoryParameters
& rParms
,
180 bool bSubsettableActions
);
181 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon
& rPolyPoly
,
182 const ActionFactoryParameters
& rParms
);
183 bool createFillAndStroke( const ::basegfx::B2DPolygon
& rPoly
,
184 const ActionFactoryParameters
& rParms
);
185 static void skipContent( GDIMetaFile
& rMtf
,
186 const char* pCommentString
,
187 sal_Int32
& io_rCurrActionIndex
);
189 static bool isActionContained( GDIMetaFile
& rMtf
,
190 const char* pCommentString
,
191 MetaActionType nType
);
193 void createGradientAction( const ::tools::PolyPolygon
& rPoly
,
194 const ::Gradient
& rGradient
,
195 const ActionFactoryParameters
& rParms
,
196 bool bIsPolygonRectangle
,
197 bool bSubsettableActions
);
199 void createTextAction( const ::Point
& rStartPoint
,
200 const OUString
& rString
,
203 const long* pCharWidths
,
204 const ActionFactoryParameters
& rParms
,
207 bool getSubsetIndices( sal_Int32
& io_rStartIndex
,
208 sal_Int32
& io_rEndIndex
,
209 ActionVector::const_iterator
& o_rRangeBegin
,
210 ActionVector::const_iterator
& o_rRangeEnd
) const;
212 ActionVector maActions
;
215 XForm aBaseTransform
;
216 /* EMF+ emf header info */
217 sal_Int32 nFrameLeft
;
219 sal_Int32 nFrameRight
;
220 sal_Int32 nFrameBottom
;
228 /// Common parameters when creating actions
229 struct ActionFactoryParameters
231 ActionFactoryParameters( VectorOfOutDevStates
& rStates
,
232 const CanvasSharedPtr
& rCanvas
,
233 ::VirtualDevice
& rVDev
,
234 const Renderer::Parameters
& rParms
,
235 sal_Int32
& io_rCurrActionIndex
) :
240 mrCurrActionIndex(io_rCurrActionIndex
)
243 VectorOfOutDevStates
& mrStates
;
244 const CanvasSharedPtr
& mrCanvas
;
245 ::VirtualDevice
& mrVDev
;
246 const Renderer::Parameters
& mrParms
;
247 sal_Int32
& mrCurrActionIndex
;
252 #endif // INCLUDED_CPPCANVAS_SOURCE_INC_IMPLRENDERER_HXX
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */