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 .
22 #include <sal/config.h>
24 #include <sal/types.h>
25 #include <tools/stream.hxx>
26 #include <vcl/metaactiontypes.hxx>
27 #include <cppcanvas/renderer.hxx>
28 #include <cppcanvas/canvas.hxx>
30 #include "canvasgraphichelper.hxx"
32 #include "outdevstate.hxx"
34 #include <osl/diagnose.h>
42 namespace tools
{ class Rectangle
; }
43 namespace vcl
{ class Font
; }
44 namespace tools
{ class PolyPolygon
; }
46 class MetaCommentAction
;
53 namespace cppcanvas::internal
56 struct ActionFactoryParameters
;
59 // state stack of OutputDevice, to correctly handle
61 class VectorOfOutDevStates
64 OutDevState
& getState();
65 const OutDevState
& getState() const;
66 void pushState(PushFlags nFlags
);
68 void clearStateStack();
70 std::vector
< OutDevState
> m_aStates
;
74 // Transformation matrix (used for Affine Transformation)
75 // [ eM11, eM12, eDx ]
76 // [ eM21, eM22, eDy ]
78 // that consists of a linear map (eM11, eM12, eM21, eM22)
79 // More info: https://en.wikipedia.org/wiki/Linear_map
80 // followed by a translation (eDx, eDy)
84 float eM11
; // M1,1 value in the matrix. Increases or decreases the size of the pixels horizontally.
85 float eM12
; // M1,2 value in the matrix. This effectively angles the X axis up or down.
86 float eM21
; // M2,1 value in the matrix. This effectively angles the Y axis left or right.
87 float eM22
; // M2,2 value in the matrix. Increases or decreases the size of the pixels vertically.
88 float eDx
; // Delta x (Dx) value in the matrix. Moves the whole coordinate system horizontally.
89 float eDy
; // Delta y (Dy) value in the matrix. Moves the whole coordinate system vertically.
98 eDx
= eDy
= eM12
= eM21
= 0.0f
;
101 friend SvStream
& ReadXForm( SvStream
& rIn
, XForm
& rXForm
)
103 if ( sizeof( float ) != 4 )
105 OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
110 rIn
.ReadFloat( rXForm
.eM11
).ReadFloat( rXForm
.eM12
).ReadFloat( rXForm
.eM21
).ReadFloat( rXForm
.eM22
)
111 .ReadFloat( rXForm
.eDx
).ReadFloat( rXForm
.eDy
);
119 class ImplRenderer
: public virtual Renderer
, protected CanvasGraphicHelper
122 ImplRenderer( const CanvasSharedPtr
& rCanvas
,
123 const GDIMetaFile
& rMtf
,
124 const Parameters
& rParms
);
126 virtual ~ImplRenderer() override
;
128 virtual bool draw() const override
;
129 virtual bool drawSubset( sal_Int32 nStartIndex
,
130 sal_Int32 nEndIndex
) const override
;
131 virtual ::basegfx::B2DRange
getSubsetArea( sal_Int32 nStartIndex
,
132 sal_Int32 nEndIndex
) const override
;
135 // element of the Renderer's action vector. Need to be
136 // public, since some functors need it, too.
139 MtfAction( const std::shared_ptr
<Action
>& rAction
,
140 sal_Int32 nOrigIndex
) :
142 mnOrigIndex( nOrigIndex
)
146 std::shared_ptr
<Action
> mpAction
;
147 sal_Int32 mnOrigIndex
;
150 // prefetched and prepared canvas actions
151 // (externally not visible)
152 typedef std::vector
< MtfAction
> ActionVector
;
155 ImplRenderer(const ImplRenderer
&) = delete;
156 ImplRenderer
& operator=( const ImplRenderer
& ) = delete;
158 static void updateClipping( const ::basegfx::B2DPolyPolygon
& rClipPoly
,
159 const ActionFactoryParameters
& rParms
,
162 static void updateClipping( const ::tools::Rectangle
& rClipRect
,
163 const ActionFactoryParameters
& rParms
,
166 static css::uno::Reference
<
167 css::rendering::XCanvasFont
> createFont( double& o_rFontRotation
,
168 const vcl::Font
& rFont
,
169 const ActionFactoryParameters
& rParms
);
170 void createActions( GDIMetaFile
& rMtf
,
171 const ActionFactoryParameters
& rParms
,
172 bool bSubsettableActions
);
173 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon
& rPolyPoly
,
174 const ActionFactoryParameters
& rParms
);
175 bool createFillAndStroke( const ::basegfx::B2DPolygon
& rPoly
,
176 const ActionFactoryParameters
& rParms
);
177 static void skipContent( GDIMetaFile
& rMtf
,
178 const char* pCommentString
,
179 sal_Int32
& io_rCurrActionIndex
);
181 static bool isActionContained( GDIMetaFile
& rMtf
,
182 const char* pCommentString
,
183 MetaActionType nType
);
185 void createGradientAction( const ::tools::PolyPolygon
& rPoly
,
186 const ::Gradient
& rGradient
,
187 const ActionFactoryParameters
& rParms
,
188 bool bIsPolygonRectangle
,
189 bool bSubsettableActions
);
191 void createTextAction( const ::Point
& rStartPoint
,
192 const OUString
& rString
,
195 const tools::Long
* pCharWidths
,
196 const ActionFactoryParameters
& rParms
,
199 bool getSubsetIndices( sal_Int32
& io_rStartIndex
,
200 sal_Int32
& io_rEndIndex
,
201 ActionVector::const_iterator
& o_rRangeBegin
,
202 ActionVector::const_iterator
& o_rRangeEnd
) const;
204 ActionVector maActions
;
207 XForm aBaseTransform
;
208 /* EMF+ emf header info */
209 sal_Int32 nFrameLeft
;
211 sal_Int32 nFrameRight
;
212 sal_Int32 nFrameBottom
;
220 /// Common parameters when creating actions
221 struct ActionFactoryParameters
223 ActionFactoryParameters( VectorOfOutDevStates
& rStates
,
224 const CanvasSharedPtr
& rCanvas
,
225 ::VirtualDevice
& rVDev
,
226 const Renderer::Parameters
& rParms
,
227 sal_Int32
& io_rCurrActionIndex
) :
232 mrCurrActionIndex(io_rCurrActionIndex
)
235 VectorOfOutDevStates
& mrStates
;
236 const CanvasSharedPtr
& mrCanvas
;
237 ::VirtualDevice
& mrVDev
;
238 const Renderer::Parameters
& mrParms
;
239 sal_Int32
& mrCurrActionIndex
;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */