Bump version to 24.04.3.4
[LibreOffice.git] / cppcanvas / source / inc / implrenderer.hxx
blob1f367280598f2b3483d693ea463dc0baa412f7bf
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 <utility>
27 #include <vcl/metaactiontypes.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 <osl/diagnose.h>
37 #include <memory>
38 #include <span>
39 #include <vector>
41 class GDIMetaFile;
42 class VirtualDevice;
43 class Gradient;
44 namespace tools { class Rectangle; }
45 namespace vcl { class Font; }
46 namespace tools { class PolyPolygon; }
47 class Point;
48 class MetaCommentAction;
50 namespace basegfx {
51 class B2DPolyPolygon;
52 class B2DPolygon;
55 namespace cppcanvas::internal
57 struct OutDevState;
58 struct ActionFactoryParameters;
59 struct XForm;
61 // state stack of OutputDevice, to correctly handle
62 // push/pop actions
63 class VectorOfOutDevStates
65 public:
66 OutDevState& getState();
67 const OutDevState& getState() const;
68 void pushState(vcl::PushFlags nFlags);
69 void popState();
70 void clearStateStack();
71 private:
72 std::vector< OutDevState > m_aStates;
75 // EMF+
76 // Transformation matrix (used for Affine Transformation)
77 // [ eM11, eM12, eDx ]
78 // [ eM21, eM22, eDy ]
79 // [ 0, 0, 1 ]
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)
84 struct XForm
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.
92 XForm()
94 SetIdentity ();
97 void SetIdentity ()
99 eM11 = eM22 = 1.0f;
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" );
108 rXForm = XForm();
110 else
112 rIn.ReadFloat( rXForm.eM11 ).ReadFloat( rXForm.eM12 ).ReadFloat( rXForm.eM21 ).ReadFloat( rXForm.eM22 )
113 .ReadFloat( rXForm.eDx ).ReadFloat( rXForm.eDy );
115 return rIn;
119 // EMF+
121 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
123 public:
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.
139 struct MtfAction
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;
156 private:
157 ImplRenderer(const ImplRenderer&) = delete;
158 ImplRenderer& operator=( const ImplRenderer& ) = delete;
160 static void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
161 const ActionFactoryParameters& rParms,
162 bool bIntersect );
164 static void updateClipping( const ::tools::Rectangle& rClipRect,
165 const ActionFactoryParameters& rParms,
166 bool bIntersect );
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,
195 int nIndex,
196 int nLength,
197 KernArraySpan pCharWidths,
198 std::span<const sal_Bool> pKashidaArray,
199 const ActionFactoryParameters& rParms,
200 bool bSubsettable );
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;
209 /* EMF+ */
210 XForm aBaseTransform;
211 /* EMF+ emf header info */
212 sal_Int32 nFrameLeft;
213 sal_Int32 nFrameTop;
214 sal_Int32 nFrameRight;
215 sal_Int32 nFrameBottom;
216 sal_Int32 nPixX;
217 sal_Int32 nPixY;
218 sal_Int32 nMmX;
219 sal_Int32 nMmY;
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 ) :
231 mrStates(rStates),
232 mrCanvas(rCanvas),
233 mrVDev(rVDev),
234 mrParms(rParms),
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: */