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