1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CPPCANVAS_RENDERER_MTFTOOLS_HXX
29 #define _CPPCANVAS_RENDERER_MTFTOOLS_HXX
30 
31 #include <action.hxx>
32 #include <cppcanvas/canvas.hxx>
33 
34 
35 class VirtualDevice;
36 class Point;
37 class Size;
38 
39 namespace basegfx
40 {
41     class B2DVector;
42     class B2DPoint;
43 }
44 namespace com { namespace sun { namespace star { namespace rendering
45 {
46     struct RenderState;
47 } } } }
48 
49 
50 namespace cppcanvas
51 {
52     namespace internal
53     {
54         struct OutDevState;
55     }
56 
57     namespace tools
58     {
59         /** Init render state from OutDevState
60 
61         	This method initializes the given render state object,
62         	sets up the transformation and the clip from the
63         	OutDevState.
64          */
65         void initRenderState( ::com::sun::star::rendering::RenderState&	renderState,
66                               const ::cppcanvas::internal::OutDevState&			outdevState );
67 
68         /** Calc output offset relative to baseline
69 
70         	The XCanvas API always renders text relative to its
71         	baseline. This method calculates an offset in logical
72         	coordinates, depending on the OutDevState's
73         	textReferencePoint and the font currently set, to offset
74         	the text from the baseline.
75 
76             @param outdevState
77             State to take textReferencePoint from
78 
79             @param rVDev
80             VDev to obtain font metrics from.
81          */
82         ::Size getBaselineOffset( const ::cppcanvas::internal::OutDevState&	outdevState,
83                                   const VirtualDevice&						rVDev );
84 
85         /** Construct a matrix that converts from logical to pixel
86             coordinate system.
87 
88             This method calculates a matrix that approximates the
89             VirtualDevice's LogicToPixel conversion (disregarding any
90             offset components, thus the 'linear' in the method name -
91             the returned matrix is guaranteed to be linear).
92 
93             @param o_rMatrix
94             This matrix will receive the calculated transform, and is
95             also returned from this method.
96 
97             @return the calculated transformation matrix.
98          */
99         ::basegfx::B2DHomMatrix& calcLogic2PixelLinearTransform( ::basegfx::B2DHomMatrix&	o_rMatrix,
100                                                                  const VirtualDevice& 		rVDev );
101 
102         /** Construct a matrix that converts from logical to pixel
103             coordinate system.
104 
105             This method calculates a matrix that approximates the
106             VirtualDevice's LogicToPixel conversion.
107 
108             @param o_rMatrix
109             This matrix will receive the calculated transform, and is
110             also returned from this method.
111 
112             @return the calculated transformation matrix.
113          */
114         ::basegfx::B2DHomMatrix& calcLogic2PixelAffineTransform( ::basegfx::B2DHomMatrix&	o_rMatrix,
115                                                                  const VirtualDevice& 		rVDev );
116 
117         /** This method modifies the clip, to cancel the given
118             transformation.
119 
120             As the clip is relative to the render state
121             transformation, offsetting or scaling the render state
122             must modify the clip, to keep it at the same position
123             relative to the primitive at hand
124 
125             @param o_rRenderState
126             Render state to change the clip in
127 
128             @param rOutdevState
129             Input state. Is used to retrieve the original clip from
130 
131             @param rOffset
132             The clip is offsetted by the negative of this value.
133 
134             @param pScaling
135             The clip is inversely scaled by this value (if given)
136 
137             @param pRotation
138             The clip is inversely rotated by this value (if given)
139 
140             @return true, if the clip has changed, false if not
141          */
142         bool modifyClip( ::com::sun::star::rendering::RenderState&			o_rRenderState,
143                          const struct ::cppcanvas::internal::OutDevState&	rOutdevState,
144                          const CanvasSharedPtr&								rCanvas,
145                          const ::Point&										rOffset,
146                          const ::basegfx::B2DVector*						pScaling,
147                          const double*                                      pRotation );
148 
149         /** This method modifies the clip, to cancel the given
150             transformation.
151 
152             As the clip is relative to the render state
153             transformation, offsetting or scaling the render state
154             must modify the clip, to keep it at the same position
155             relative to the primitive at hand
156 
157             @param o_rRenderState
158             Render state to change the clip in
159 
160             @param rOutdevState
161             Input state. Is used to retrieve the original clip from
162 
163             @param rOffset
164             The clip is offsetted by the negative of this value.
165 
166             @param pScaling
167             The clip is inversely scaled by this value (if given)
168 
169             @param pRotation
170             The clip is inversely rotated by this value (if given)
171 
172             @return true, if the clip has changed, false if not
173          */
174         bool modifyClip( ::com::sun::star::rendering::RenderState&			o_rRenderState,
175                          const struct ::cppcanvas::internal::OutDevState&	rOutdevState,
176                          const CanvasSharedPtr&								rCanvas,
177                          const ::basegfx::B2DPoint&							rOffset,
178                          const ::basegfx::B2DVector*						pScaling,
179                          const double*                                      pRotation );
180 
181         /** This method modifies the clip, to cancel the given
182             transformation.
183 
184             As the clip is relative to the render state
185             transformation, transforming the render state further must
186             modify the clip, to keep it at the same position relative
187             to the primitive at hand
188 
189             @param o_rRenderState
190             Render state to change the clip in
191 
192             @param rOutdevState
193             Input state. Is used to retrieve the original clip from
194 
195             @param rTransform
196             The clip is transformed by the inverse of this value.
197 
198             @return true, if the clip has changed, false if not
199          */
200         bool modifyClip( ::com::sun::star::rendering::RenderState&			o_rRenderState,
201                          const struct ::cppcanvas::internal::OutDevState&	rOutdevState,
202                          const CanvasSharedPtr&								rCanvas,
203                          const ::basegfx::B2DHomMatrix&						rTransform );
204 
205         struct TextLineInfo
206         {
207             TextLineInfo( const double& rLineHeight,
208                           const double& rOverlineHeight,
209                           const double& rOverlineOffset,
210                           const double& rUnderlineOffset,
211                           const double& rStrikeoutOffset,
212                           sal_Int8		nOverlineStyle,
213                           sal_Int8		nUnderlineStyle,
214                           sal_Int8		nStrikeoutStyle ) :
215                 mnLineHeight( rLineHeight ),
216                 mnOverlineHeight( rOverlineHeight ),
217                 mnOverlineOffset( rOverlineOffset ),
218                 mnUnderlineOffset( rUnderlineOffset ),
219                 mnStrikeoutOffset( rStrikeoutOffset ),
220                 mnOverlineStyle( nOverlineStyle ),
221                 mnUnderlineStyle( nUnderlineStyle ),
222                 mnStrikeoutStyle( nStrikeoutStyle )
223             {
224             }
225 
226             double 		mnLineHeight;
227             double 		mnOverlineHeight;
228             double 		mnOverlineOffset;
229             double 		mnUnderlineOffset;
230             double 		mnStrikeoutOffset;
231             sal_Int8	mnOverlineStyle;
232             sal_Int8	mnUnderlineStyle;
233             sal_Int8	mnStrikeoutStyle;
234         };
235 
236         /** Transform given bounds to device coordinate system.
237          */
238         ::basegfx::B2DRange calcDevicePixelBounds( const ::basegfx::B2DRange& 						rBounds,
239                                                    const ::com::sun::star::rendering::ViewState&	viewState,
240                                                    const ::com::sun::star::rendering::RenderState&	renderState );
241 
242         /** Generate text underline/strikeout info struct from OutDev
243             state.
244          */
245         TextLineInfo createTextLineInfo( const ::VirtualDevice& 					rVDev,
246                                          const ::cppcanvas::internal::OutDevState&	rState );
247 
248         /** Create a poly-polygon representing the given combination
249             of overline, strikeout and underline.
250 
251             @param rStartOffset
252             Offset in X direction, where the underline starts
253 
254             @param rLineWidth
255             Width of the line of text to overline/strikeout/underline
256 
257             @param rTextLineInfo
258             Common info needed for overline/strikeout/underline generation
259          */
260         ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const double&			rStartOffset,
261                                                               const double&			rLineWidth,
262                                                               const TextLineInfo&	rTextLineInfo );
263 
264         ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const ::basegfx::B2DPoint rStartPos,
265                                                               const double&				rLineWidth,
266                                                               const TextLineInfo&		rTextLineInfo );
267     }
268 }
269 
270 #endif /* _CPPCANVAS_RENDERER_MTFTOOLS_HXX */
271