LibreOffice Module cppcanvas (master) 1
implrenderer.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <sal/types.h>
25#include <o3tl/span.hxx>
26#include <tools/stream.hxx>
27#include <utility>
30#include <cppcanvas/canvas.hxx>
31
33#include "action.hxx"
34#include "outdevstate.hxx"
35
36#include <osl/diagnose.h>
37
38#include <memory>
39#include <vector>
40
41class GDIMetaFile;
42class VirtualDevice;
43class Gradient;
44namespace tools { class Rectangle; }
45namespace vcl { class Font; }
46namespace tools { class PolyPolygon; }
47class Point;
49
50namespace basegfx {
51 class B2DPolyPolygon;
52 class B2DPolygon;
53}
54
55namespace cppcanvas::internal
56 {
57 struct OutDevState;
58 struct ActionFactoryParameters;
59 struct XForm;
60
61 // state stack of OutputDevice, to correctly handle
62 // push/pop actions
64 {
65 public:
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;
73 };
74
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)
83
84 struct XForm
85 {
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.
93 {
94 SetIdentity ();
95 }
96
98 {
99 eM11 = eM22 = 1.0f;
100 eDx = eDy = eM12 = eM21 = 0.0f;
101 }
102
103 friend SvStream& ReadXForm( SvStream& rIn, XForm& rXForm )
104 {
105 if ( sizeof( float ) != 4 )
106 {
107 OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
108 rXForm = XForm();
109 }
110 else
111 {
112 rIn.ReadFloat( rXForm.eM11 ).ReadFloat( rXForm.eM12 ).ReadFloat( rXForm.eM21 ).ReadFloat( rXForm.eM22 )
113 .ReadFloat( rXForm.eDx ).ReadFloat( rXForm.eDy );
114 }
115 return rIn;
116 }
117 };
118
119 // EMF+
120
121 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
122 {
123 public:
124 ImplRenderer( const CanvasSharedPtr& rCanvas,
125 const GDIMetaFile& rMtf,
126 const Parameters& rParms );
127
128 virtual ~ImplRenderer() override;
129
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;
135
136
137 // element of the Renderer's action vector. Need to be
138 // public, since some functors need it, too.
140 {
141 MtfAction( std::shared_ptr<Action> xAction,
142 sal_Int32 nOrigIndex ) :
143 mpAction(std::move( xAction )),
144 mnOrigIndex( nOrigIndex )
145 {
146 }
147
148 std::shared_ptr<Action> mpAction;
149 sal_Int32 mnOrigIndex;
150 };
151
152 // prefetched and prepared canvas actions
153 // (externally not visible)
154 typedef std::vector< MtfAction > ActionVector;
155
156 private:
157 ImplRenderer(const ImplRenderer&) = delete;
159
160 static void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
161 const ActionFactoryParameters& rParms,
162 bool bIntersect );
163
164 static void updateClipping( const ::tools::Rectangle& rClipRect,
165 const ActionFactoryParameters& rParms,
166 bool bIntersect );
167
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 );
182
183 static bool isActionContained( GDIMetaFile& rMtf,
184 const char* pCommentString,
185 MetaActionType nType );
186
187 void createGradientAction( const ::tools::PolyPolygon& rPoly,
188 const ::Gradient& rGradient,
189 const ActionFactoryParameters& rParms,
190 bool bIsPolygonRectangle,
191 bool bSubsettableActions );
192
193 void createTextAction( const ::Point& rStartPoint,
194 const OUString& rString,
195 int nIndex,
196 int nLength,
197 KernArraySpan pCharWidths,
198 o3tl::span<const sal_Bool> pKashidaArray,
199 const ActionFactoryParameters& rParms,
200 bool bSubsettable );
201
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;
206
208
209 /* EMF+ */
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;
220 };
221
222
225 {
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)
236 {}
237
243 };
244
245}
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream & ReadFloat(float &rFloat)
virtual bool drawSubset(sal_Int32 nStartIndex, sal_Int32 nEndIndex) const override
Render subset of metafile to given canvas.
static void skipContent(GDIMetaFile &rMtf, const char *pCommentString, sal_Int32 &io_rCurrActionIndex)
virtual bool draw() const override
Render to parent canvas.
bool getSubsetIndices(sal_Int32 &io_rStartIndex, sal_Int32 &io_rEndIndex, ActionVector::const_iterator &o_rRangeBegin, ActionVector::const_iterator &o_rRangeEnd) const
ImplRenderer & operator=(const ImplRenderer &)=delete
ImplRenderer(const CanvasSharedPtr &rCanvas, const GDIMetaFile &rMtf, const Parameters &rParms)
void createGradientAction(const ::tools::PolyPolygon &rPoly, const ::Gradient &rGradient, const ActionFactoryParameters &rParms, bool bIsPolygonRectangle, bool bSubsettableActions)
void createTextAction(const ::Point &rStartPoint, const OUString &rString, int nIndex, int nLength, KernArraySpan pCharWidths, o3tl::span< const sal_Bool > pKashidaArray, const ActionFactoryParameters &rParms, bool bSubsettable)
bool createFillAndStroke(const ::basegfx::B2DPolyPolygon &rPolyPoly, const ActionFactoryParameters &rParms)
static css::uno::Reference< css::rendering::XCanvasFont > createFont(double &o_rFontRotation, const vcl::Font &rFont, const ActionFactoryParameters &rParms)
static bool isActionContained(GDIMetaFile &rMtf, const char *pCommentString, MetaActionType nType)
static void updateClipping(const ::basegfx::B2DPolyPolygon &rClipPoly, const ActionFactoryParameters &rParms, bool bIntersect)
virtual ::basegfx::B2DRange getSubsetArea(sal_Int32 nStartIndex, sal_Int32 nEndIndex) const override
Query bounding box of metafile subset.
ImplRenderer(const ImplRenderer &)=delete
std::vector< MtfAction > ActionVector
void createActions(GDIMetaFile &rMtf, const ActionFactoryParameters &rParms, bool bSubsettableActions)
void pushState(vcl::PushFlags nFlags)
std::vector< OutDevState > m_aStates
MetaActionType
std::shared_ptr< Canvas > CanvasSharedPtr
Parameters for the Renderer.
Definition: renderer.hxx:101
Common parameters when creating actions.
ActionFactoryParameters(VectorOfOutDevStates &rStates, const CanvasSharedPtr &rCanvas, ::VirtualDevice &rVDev, const Renderer::Parameters &rParms, sal_Int32 &io_rCurrActionIndex)
MtfAction(std::shared_ptr< Action > xAction, sal_Int32 nOrigIndex)
friend SvStream & ReadXForm(SvStream &rIn, XForm &rXForm)