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>
27 #include <vcl/metaactiontypes.hxx>
28 #include <cppcanvas/renderer.hxx>
29 #include <cppcanvas/canvas.hxx>
31 #include "canvasgraphichelper.hxx"
33 #include "outdevstate.hxx"
35 #include <osl/diagnose.h>
44 namespace tools
{ class Rectangle
; }
45 namespace vcl
{ class Font
; }
46 namespace tools
{ class PolyPolygon
; }
48 class MetaCommentAction
;
55 namespace cppcanvas::internal
58 struct ActionFactoryParameters
;
61 // state stack of OutputDevice, to correctly handle
63 class VectorOfOutDevStates
66 OutDevState
& getState();
67 const OutDevState
& getState() const;
68 void pushState(vcl::PushFlags nFlags
);
70 void clearStateStack();
72 std::vector
< OutDevState
> m_aStates
;
76 // Transformation matrix (used for Affine Transformation)
77 // [ eM11, eM12, eDx ]
78 // [ eM21, eM22, eDy ]
80 // that consists of a linear map (eM11, eM12, eM21, eM22)
81 // More info: https://en.wikipedia.org/wiki/Linear_map
82 // followed by a translation (eDx, eDy)
86 float eM11
; // M1,1 value in the matrix. Increases or decreases the size of the pixels horizontally.
87 float eM12
; // M1,2 value in the matrix. This effectively angles the X axis up or down.
88 float eM21
; // M2,1 value in the matrix. This effectively angles the Y axis left or right.
89 float eM22
; // M2,2 value in the matrix. Increases or decreases the size of the pixels vertically.
90 float eDx
; // Delta x (Dx) value in the matrix. Moves the whole coordinate system horizontally.
91 float eDy
; // Delta y (Dy) value in the matrix. Moves the whole coordinate system vertically.
100 eDx
= eDy
= eM12
= eM21
= 0.0f
;
103 friend SvStream
& ReadXForm( SvStream
& rIn
, XForm
& rXForm
)
105 if ( sizeof( float ) != 4 )
107 OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
112 rIn
.ReadFloat( rXForm
.eM11
).ReadFloat( rXForm
.eM12
).ReadFloat( rXForm
.eM21
).ReadFloat( rXForm
.eM22
)
113 .ReadFloat( rXForm
.eDx
).ReadFloat( rXForm
.eDy
);
121 class ImplRenderer
: public virtual Renderer
, protected CanvasGraphicHelper
124 ImplRenderer( const CanvasSharedPtr
& rCanvas
,
125 const GDIMetaFile
& rMtf
,
126 const Parameters
& rParms
);
128 virtual ~ImplRenderer() override
;
130 virtual bool draw() const override
;
131 virtual bool drawSubset( sal_Int32 nStartIndex
,
132 sal_Int32 nEndIndex
) const override
;
133 virtual ::basegfx::B2DRange
getSubsetArea( sal_Int32 nStartIndex
,
134 sal_Int32 nEndIndex
) const override
;
137 // element of the Renderer's action vector. Need to be
138 // public, since some functors need it, too.
141 MtfAction( std::shared_ptr
<Action
> xAction
,
142 sal_Int32 nOrigIndex
) :
143 mpAction(std::move( xAction
)),
144 mnOrigIndex( nOrigIndex
)
148 std::shared_ptr
<Action
> mpAction
;
149 sal_Int32 mnOrigIndex
;
152 // prefetched and prepared canvas actions
153 // (externally not visible)
154 typedef std::vector
< MtfAction
> ActionVector
;
157 ImplRenderer(const ImplRenderer
&) = delete;
158 ImplRenderer
& operator=( const ImplRenderer
& ) = delete;
160 static void updateClipping( const ::basegfx::B2DPolyPolygon
& rClipPoly
,
161 const ActionFactoryParameters
& rParms
,
164 static void updateClipping( const ::tools::Rectangle
& rClipRect
,
165 const ActionFactoryParameters
& rParms
,
168 static css::uno::Reference
<
169 css::rendering::XCanvasFont
> createFont( double& o_rFontRotation
,
170 const vcl::Font
& rFont
,
171 const ActionFactoryParameters
& rParms
);
172 void createActions( GDIMetaFile
& rMtf
,
173 const ActionFactoryParameters
& rParms
,
174 bool bSubsettableActions
);
175 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon
& rPolyPoly
,
176 const ActionFactoryParameters
& rParms
);
177 bool createFillAndStroke( const ::basegfx::B2DPolygon
& rPoly
,
178 const ActionFactoryParameters
& rParms
);
179 static void skipContent( GDIMetaFile
& rMtf
,
180 const char* pCommentString
,
181 sal_Int32
& io_rCurrActionIndex
);
183 static bool isActionContained( GDIMetaFile
& rMtf
,
184 const char* pCommentString
,
185 MetaActionType nType
);
187 void createGradientAction( const ::tools::PolyPolygon
& rPoly
,
188 const ::Gradient
& rGradient
,
189 const ActionFactoryParameters
& rParms
,
190 bool bIsPolygonRectangle
,
191 bool bSubsettableActions
);
193 void createTextAction( const ::Point
& rStartPoint
,
194 const OUString
& rString
,
197 KernArraySpan pCharWidths
,
198 std::span
<const sal_Bool
> pKashidaArray
,
199 const ActionFactoryParameters
& rParms
,
202 bool getSubsetIndices( sal_Int32
& io_rStartIndex
,
203 sal_Int32
& io_rEndIndex
,
204 ActionVector::const_iterator
& o_rRangeBegin
,
205 ActionVector::const_iterator
& o_rRangeEnd
) const;
207 ActionVector maActions
;
210 XForm aBaseTransform
;
211 /* EMF+ emf header info */
212 sal_Int32 nFrameLeft
;
214 sal_Int32 nFrameRight
;
215 sal_Int32 nFrameBottom
;
223 /// Common parameters when creating actions
224 struct ActionFactoryParameters
226 ActionFactoryParameters( VectorOfOutDevStates
& rStates
,
227 const CanvasSharedPtr
& rCanvas
,
228 ::VirtualDevice
& rVDev
,
229 const Renderer::Parameters
& rParms
,
230 sal_Int32
& io_rCurrActionIndex
) :
235 mrCurrActionIndex(io_rCurrActionIndex
)
238 VectorOfOutDevStates
& mrStates
;
239 const CanvasSharedPtr
& mrCanvas
;
240 ::VirtualDevice
& mrVDev
;
241 const Renderer::Parameters
& mrParms
;
242 sal_Int32
& mrCurrActionIndex
;
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */