bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cppcanvas / source / inc / implrenderer.hxx
blobe02b45d20a1a4c7c54447dff6f2c9bdf7085229f
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 #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"
32 #include "action.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>
40 #include <map>
41 #include <memory>
42 #include <vector>
44 class GDIMetaFile;
45 class VirtualDevice;
46 class Gradient;
47 namespace tools { class Rectangle; }
48 namespace vcl { class Font; }
49 namespace tools { class PolyPolygon; }
50 class Point;
51 class MetaCommentAction;
53 namespace basegfx {
54 class B2DPolyPolygon;
55 class B2DPolygon;
58 namespace cppcanvas
61 namespace internal
63 struct OutDevState;
64 struct ActionFactoryParameters;
65 struct XForm;
67 // state stack of OutputDevice, to correctly handle
68 // push/pop actions
69 class VectorOfOutDevStates
71 public:
72 OutDevState& getState();
73 const OutDevState& getState() const;
74 void pushState(PushFlags nFlags);
75 void popState();
76 void clearStateStack();
77 private:
78 std::vector< OutDevState > m_aStates;
81 // EMF+
82 // Transformation matrix (used for Affine Transformation)
83 // [ eM11, eM12, eDx ]
84 // [ eM21, eM22, eDy ]
85 // [ 0, 0, 1 ]
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)
90 struct XForm
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.
98 XForm()
100 SetIdentity ();
103 void SetIdentity ()
105 eM11 = eM22 = 1.0f;
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" );
114 rXForm = XForm();
116 else
118 rIn.ReadFloat( rXForm.eM11 ).ReadFloat( rXForm.eM12 ).ReadFloat( rXForm.eM21 ).ReadFloat( rXForm.eM22 )
119 .ReadFloat( rXForm.eDx ).ReadFloat( rXForm.eDy );
121 return rIn;
125 // EMF+
127 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
129 public:
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.
145 struct MtfAction
147 MtfAction( const std::shared_ptr<Action>& rAction,
148 sal_Int32 nOrigIndex ) :
149 mpAction( rAction ),
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;
162 private:
163 ImplRenderer(const ImplRenderer&) = delete;
164 ImplRenderer& operator=( const ImplRenderer& ) = delete;
166 static void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
167 const ActionFactoryParameters& rParms,
168 bool bIntersect );
170 static void updateClipping( const ::tools::Rectangle& rClipRect,
171 const ActionFactoryParameters& rParms,
172 bool bIntersect );
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,
201 int nIndex,
202 int nLength,
203 const long* pCharWidths,
204 const ActionFactoryParameters& rParms,
205 bool bSubsettable );
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;
214 /* EMF+ */
215 XForm aBaseTransform;
216 /* EMF+ emf header info */
217 sal_Int32 nFrameLeft;
218 sal_Int32 nFrameTop;
219 sal_Int32 nFrameRight;
220 sal_Int32 nFrameBottom;
221 sal_Int32 nPixX;
222 sal_Int32 nPixY;
223 sal_Int32 nMmX;
224 sal_Int32 nMmY;
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 ) :
236 mrStates(rStates),
237 mrCanvas(rCanvas),
238 mrVDev(rVDev),
239 mrParms(rParms),
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: */