1  /**************************************************************
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   *************************************************************/
21  
22  
23  
24  #ifndef _CPPCANVAS_IMPLRENDERER_HXX
25  #define _CPPCANVAS_IMPLRENDERER_HXX
26  
27  #include <sal/types.h>
28  
29  #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
30  #include <boost/shared_ptr.hpp>
31  #endif
32  #include <cppcanvas/renderer.hxx>
33  #include <cppcanvas/canvas.hxx>
34  
35  #include <canvasgraphichelper.hxx>
36  #include <action.hxx>
37  
38  #include <vector>
39  
40  class GDIMetaFile;
41  class VirtualDevice;
42  class Gradient;
43  class BitmapEx;
44  class MapMode;
45  class Size;
46  
47  namespace basegfx {
48      class B2DPolyPolygon;
49      class B2DPolygon;
50  }
51  
52  namespace cppcanvas
53  {
54  
55      namespace internal
56      {
57          struct OutDevState;
58          struct ActionFactoryParameters;
59  
60          // state stack of OutputDevice, to correctly handle
61          // push/pop actions
62          typedef ::std::vector< OutDevState >	VectorOfOutDevStates;
63  
64          class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
65          {
66          public:
67              ImplRenderer( const CanvasSharedPtr&	rCanvas,
68                            const GDIMetaFile&		rMtf,
69                            const Parameters& 		rParms );
70              ImplRenderer( const CanvasSharedPtr&	rCanvas,
71                            const BitmapEx&			rBmpEx,
72                            const Parameters& 		rParms );
73  
74              virtual ~ImplRenderer();
75  
76              virtual bool 				draw() const;
77              virtual bool 				drawSubset( sal_Int32	nStartIndex,
78                                                      sal_Int32	nEndIndex ) const;
79              virtual ::basegfx::B2DRange getSubsetArea( sal_Int32	nStartIndex,
80                                                         sal_Int32	nEndIndex ) const;
81  
82  
83              // element of the Renderer's action vector. Need to be
84              // public, since some functors need it, too.
85              struct MtfAction
86              {
MtfActioncppcanvas::internal::ImplRenderer::MtfAction87                  MtfAction( const ActionSharedPtr& 	rAction,
88                             sal_Int32				nOrigIndex ) :
89                      mpAction( rAction ),
90                      mnOrigIndex( nOrigIndex )
91                  {
92                  }
93  
94                  ActionSharedPtr mpAction;
95                  sal_Int32		mnOrigIndex;
96              };
97  
98              // prefetched and prepared canvas actions
99              // (externally not visible)
100              typedef ::std::vector< MtfAction > 		ActionVector;
101  
102  
103          private:
104              // default: disabled copy/assignment
105              ImplRenderer(const ImplRenderer&);
106              ImplRenderer& operator=( const ImplRenderer& );
107  
108              void updateClipping( const ::basegfx::B2DPolyPolygon&   rClipPoly,
109                                   const ActionFactoryParameters&     rParms,
110                                   bool                               bIntersect );
111  
112              void updateClipping( const ::Rectangle&                 rClipRect,
113                                   const ActionFactoryParameters&     rParms,
114                                   bool                               bIntersect );
115  
116              ::com::sun::star::uno::Reference<
117                  ::com::sun::star::rendering::XCanvasFont > createFont( double&                         o_rFontRotation,
118                                                                         const ::Font&                   rFont,
119                                                                         const ActionFactoryParameters&  rParms ) const;
120              bool createActions( GDIMetaFile&                    rMtf,
121                                  const ActionFactoryParameters&  rParms,
122                                  bool                            bSubsettableActions );
123              bool createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly,
124                                        const ActionFactoryParameters&   rParms );
125              bool createFillAndStroke( const ::basegfx::B2DPolygon&   rPoly,
126                                        const ActionFactoryParameters& rParms );
127              void skipContent( GDIMetaFile& rMtf,
128                                const char*  pCommentString,
129                                sal_Int32&   io_rCurrActionIndex ) const;
130  
131              bool isActionContained( GDIMetaFile& rMtf,
132                                      const char*  pCommentString,
133                                      sal_uInt16       nType ) const;
134  
135              void createGradientAction( const ::PolyPolygon&           rPoly,
136                                         const ::Gradient&              rGradient,
137                                         const ActionFactoryParameters& rParms,
138                                         bool                           bIsPolygonRectangle,
139                                         bool                           bSubsettableActions );
140  
141              void createTextAction( const ::Point&                 rStartPoint,
142                                     const String                   rString,
143                                     int                            nIndex,
144                                     int                            nLength,
145                                     const sal_Int32*               pCharWidths,
146                                     const ActionFactoryParameters& rParms,
147                                     bool                           bSubsettable );
148  
149              bool getSubsetIndices( sal_Int32&                    io_rStartIndex,
150                                     sal_Int32&                    io_rEndIndex,
151                                     ActionVector::const_iterator& o_rRangeBegin,
152                                     ActionVector::const_iterator& o_rRangeEnd ) const;
153  
154  
155              ActionVector maActions;
156          };
157  
158  
159          /// Common parameters when creating actions
160          struct ActionFactoryParameters
161          {
ActionFactoryParameterscppcanvas::internal::ActionFactoryParameters162              ActionFactoryParameters( VectorOfOutDevStates&       rStates,
163                                       const CanvasSharedPtr&      rCanvas,
164                                       ::VirtualDevice&            rVDev,
165                                       const Renderer::Parameters& rParms,
166                                       sal_Int32&                  io_rCurrActionIndex ) :
167                  mrStates(rStates),
168                  mrCanvas(rCanvas),
169                  mrVDev(rVDev),
170                  mrParms(rParms),
171                  mrCurrActionIndex(io_rCurrActionIndex)
172              {}
173  
174              VectorOfOutDevStates&       mrStates;
175              const CanvasSharedPtr&      mrCanvas;
176              ::VirtualDevice&            mrVDev;
177              const Renderer::Parameters& mrParms;
178              sal_Int32&                  mrCurrActionIndex;
179          };
180      }
181  }
182  
183  #endif /* _CPPCANVAS_IMPLRENDERER_HXX */
184