1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mtftools.hxx,v $
10 * $Revision: 1.9.16.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CPPCANVAS_RENDERER_MTFTOOLS_HXX
32 #define _CPPCANVAS_RENDERER_MTFTOOLS_HXX
35 #include <cppcanvas/canvas.hxx>
47 namespace com
{ namespace sun
{ namespace star
{ namespace rendering
62 /** Init render state from OutDevState
64 This method initializes the given render state object,
65 sets up the transformation and the clip from the
68 void initRenderState( ::com::sun::star::rendering::RenderState
& renderState
,
69 const ::cppcanvas::internal::OutDevState
& outdevState
);
71 /** Calc output offset relative to baseline
73 The XCanvas API always renders text relative to its
74 baseline. This method calculates an offset in logical
75 coordinates, depending on the OutDevState's
76 textReferencePoint and the font currently set, to offset
77 the text from the baseline.
80 State to take textReferencePoint from
83 VDev to obtain font metrics from.
85 ::Size
getBaselineOffset( const ::cppcanvas::internal::OutDevState
& outdevState
,
86 const VirtualDevice
& rVDev
);
88 /** Construct a matrix that converts from logical to pixel
91 This method calculates a matrix that approximates the
92 VirtualDevice's LogicToPixel conversion (disregarding any
93 offset components, thus the 'linear' in the method name -
94 the returned matrix is guaranteed to be linear).
97 This matrix will receive the calculated transform, and is
98 also returned from this method.
100 @return the calculated transformation matrix.
102 ::basegfx::B2DHomMatrix
& calcLogic2PixelLinearTransform( ::basegfx::B2DHomMatrix
& o_rMatrix
,
103 const VirtualDevice
& rVDev
);
105 /** Construct a matrix that converts from logical to pixel
108 This method calculates a matrix that approximates the
109 VirtualDevice's LogicToPixel conversion.
112 This matrix will receive the calculated transform, and is
113 also returned from this method.
115 @return the calculated transformation matrix.
117 ::basegfx::B2DHomMatrix
& calcLogic2PixelAffineTransform( ::basegfx::B2DHomMatrix
& o_rMatrix
,
118 const VirtualDevice
& rVDev
);
120 /** This method modifies the clip, to cancel the given
123 As the clip is relative to the render state
124 transformation, offsetting or scaling the render state
125 must modify the clip, to keep it at the same position
126 relative to the primitive at hand
128 @param o_rRenderState
129 Render state to change the clip in
132 Input state. Is used to retrieve the original clip from
135 The clip is offsetted by the negative of this value.
138 The clip is inversely scaled by this value (if given)
141 The clip is inversely rotated by this value (if given)
143 @return true, if the clip has changed, false if not
145 bool modifyClip( ::com::sun::star::rendering::RenderState
& o_rRenderState
,
146 const struct ::cppcanvas::internal::OutDevState
& rOutdevState
,
147 const CanvasSharedPtr
& rCanvas
,
148 const ::Point
& rOffset
,
149 const ::basegfx::B2DVector
* pScaling
,
150 const double* pRotation
);
152 /** This method modifies the clip, to cancel the given
155 As the clip is relative to the render state
156 transformation, offsetting or scaling the render state
157 must modify the clip, to keep it at the same position
158 relative to the primitive at hand
160 @param o_rRenderState
161 Render state to change the clip in
164 Input state. Is used to retrieve the original clip from
167 The clip is offsetted by the negative of this value.
170 The clip is inversely scaled by this value (if given)
173 The clip is inversely rotated by this value (if given)
175 @return true, if the clip has changed, false if not
177 bool modifyClip( ::com::sun::star::rendering::RenderState
& o_rRenderState
,
178 const struct ::cppcanvas::internal::OutDevState
& rOutdevState
,
179 const CanvasSharedPtr
& rCanvas
,
180 const ::basegfx::B2DPoint
& rOffset
,
181 const ::basegfx::B2DVector
* pScaling
,
182 const double* pRotation
);
184 /** This method modifies the clip, to cancel the given
187 As the clip is relative to the render state
188 transformation, transforming the render state further must
189 modify the clip, to keep it at the same position relative
190 to the primitive at hand
192 @param o_rRenderState
193 Render state to change the clip in
196 Input state. Is used to retrieve the original clip from
199 The clip is transformed by the inverse of this value.
201 @return true, if the clip has changed, false if not
203 bool modifyClip( ::com::sun::star::rendering::RenderState
& o_rRenderState
,
204 const struct ::cppcanvas::internal::OutDevState
& rOutdevState
,
205 const CanvasSharedPtr
& rCanvas
,
206 const ::basegfx::B2DHomMatrix
& rTransform
);
210 TextLineInfo( const double& rLineHeight
,
211 const double& rOverlineHeight
,
212 const double& rOverlineOffset
,
213 const double& rUnderlineOffset
,
214 const double& rStrikeoutOffset
,
215 sal_Int8 nOverlineStyle
,
216 sal_Int8 nUnderlineStyle
,
217 sal_Int8 nStrikeoutStyle
) :
218 mnLineHeight( rLineHeight
),
219 mnOverlineHeight( rOverlineHeight
),
220 mnOverlineOffset( rOverlineOffset
),
221 mnUnderlineOffset( rUnderlineOffset
),
222 mnStrikeoutOffset( rStrikeoutOffset
),
223 mnOverlineStyle( nOverlineStyle
),
224 mnUnderlineStyle( nUnderlineStyle
),
225 mnStrikeoutStyle( nStrikeoutStyle
)
230 double mnOverlineHeight
;
231 double mnOverlineOffset
;
232 double mnUnderlineOffset
;
233 double mnStrikeoutOffset
;
234 sal_Int8 mnOverlineStyle
;
235 sal_Int8 mnUnderlineStyle
;
236 sal_Int8 mnStrikeoutStyle
;
239 /** Transform given bounds to device coordinate system.
241 ::basegfx::B2DRange
calcDevicePixelBounds( const ::basegfx::B2DRange
& rBounds
,
242 const ::com::sun::star::rendering::ViewState
& viewState
,
243 const ::com::sun::star::rendering::RenderState
& renderState
);
245 /** Generate text underline/strikeout info struct from OutDev
248 TextLineInfo
createTextLineInfo( const ::VirtualDevice
& rVDev
,
249 const ::cppcanvas::internal::OutDevState
& rState
);
251 /** Create a poly-polygon representing the given combination
252 of overline, strikeout and underline.
255 Offset in X direction, where the underline starts
258 Width of the line of text to overline/strikeout/underline
261 Common info needed for overline/strikeout/underline generation
263 ::basegfx::B2DPolyPolygon
createTextLinesPolyPolygon( const double& rStartOffset
,
264 const double& rLineWidth
,
265 const TextLineInfo
& rTextLineInfo
);
267 ::basegfx::B2DPolyPolygon
createTextLinesPolyPolygon( const ::basegfx::B2DPoint rStartPos
,
268 const double& rLineWidth
,
269 const TextLineInfo
& rTextLineInfo
);
273 #endif /* _CPPCANVAS_RENDERER_MTFTOOLS_HXX */