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