Bump version to 21.06.18.1
[LibreOffice.git] / cppcanvas / source / inc / implrenderer.hxx
blob4b432f8982601128829265200c4080e6a088a7ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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"
31 #include "action.hxx"
32 #include "outdevstate.hxx"
34 #include <osl/diagnose.h>
36 #include <memory>
37 #include <vector>
39 class GDIMetaFile;
40 class VirtualDevice;
41 class Gradient;
42 namespace tools { class Rectangle; }
43 namespace vcl { class Font; }
44 namespace tools { class PolyPolygon; }
45 class Point;
46 class MetaCommentAction;
48 namespace basegfx {
49 class B2DPolyPolygon;
50 class B2DPolygon;
53 namespace cppcanvas::internal
55 struct OutDevState;
56 struct ActionFactoryParameters;
57 struct XForm;
59 // state stack of OutputDevice, to correctly handle
60 // push/pop actions
61 class VectorOfOutDevStates
63 public:
64 OutDevState& getState();
65 const OutDevState& getState() const;
66 void pushState(PushFlags nFlags);
67 void popState();
68 void clearStateStack();
69 private:
70 std::vector< OutDevState > m_aStates;
73 // EMF+
74 // Transformation matrix (used for Affine Transformation)
75 // [ eM11, eM12, eDx ]
76 // [ eM21, eM22, eDy ]
77 // [ 0, 0, 1 ]
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)
82 struct XForm
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.
90 XForm()
92 SetIdentity ();
95 void SetIdentity ()
97 eM11 = eM22 = 1.0f;
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" );
106 rXForm = XForm();
108 else
110 rIn.ReadFloat( rXForm.eM11 ).ReadFloat( rXForm.eM12 ).ReadFloat( rXForm.eM21 ).ReadFloat( rXForm.eM22 )
111 .ReadFloat( rXForm.eDx ).ReadFloat( rXForm.eDy );
113 return rIn;
117 // EMF+
119 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
121 public:
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.
137 struct MtfAction
139 MtfAction( const std::shared_ptr<Action>& rAction,
140 sal_Int32 nOrigIndex ) :
141 mpAction( rAction ),
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;
154 private:
155 ImplRenderer(const ImplRenderer&) = delete;
156 ImplRenderer& operator=( const ImplRenderer& ) = delete;
158 static void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
159 const ActionFactoryParameters& rParms,
160 bool bIntersect );
162 static void updateClipping( const ::tools::Rectangle& rClipRect,
163 const ActionFactoryParameters& rParms,
164 bool bIntersect );
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,
193 int nIndex,
194 int nLength,
195 const tools::Long* pCharWidths,
196 const ActionFactoryParameters& rParms,
197 bool bSubsettable );
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;
206 /* EMF+ */
207 XForm aBaseTransform;
208 /* EMF+ emf header info */
209 sal_Int32 nFrameLeft;
210 sal_Int32 nFrameTop;
211 sal_Int32 nFrameRight;
212 sal_Int32 nFrameBottom;
213 sal_Int32 nPixX;
214 sal_Int32 nPixY;
215 sal_Int32 nMmX;
216 sal_Int32 nMmY;
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 ) :
228 mrStates(rStates),
229 mrCanvas(rCanvas),
230 mrVDev(rVDev),
231 mrParms(rParms),
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: */