1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <action.hxx>
23 #include <cppcanvas/canvas.hxx>
24 
25 
26 class VirtualDevice;
27 class Size;
28 
29 namespace basegfx
30 {
31     class B2DVector;
32     class B2DPoint;
33 }
34 namespace com::sun::star::rendering
35 {
36     struct RenderState;
37 }
38 
39 
40 namespace cppcanvas
41 {
42     namespace internal
43     {
44         struct OutDevState;
45     }
46 
47     namespace tools
48     {
49         /** Init render state from OutDevState
50 
51             This method initializes the given render state object,
52             sets up the transformation and the clip from the
53             OutDevState.
54          */
55         void initRenderState( css::rendering::RenderState&              renderState,
56                               const ::cppcanvas::internal::OutDevState& outdevState );
57 
58         /** Calc output offset relative to baseline
59 
60             The XCanvas API always renders text relative to its
61             baseline. This method calculates an offset in logical
62             coordinates, depending on the OutDevState's
63             textReferencePoint and the font currently set, to offset
64             the text from the baseline.
65 
66             @param outdevState
67             State to take textReferencePoint from
68 
69             @param rVDev
70             VDev to obtain font metrics from.
71          */
72         ::Size getBaselineOffset( const ::cppcanvas::internal::OutDevState& outdevState,
73                                   const VirtualDevice&                      rVDev );
74 
75         /** Construct a matrix that converts from logical to pixel
76             coordinate system.
77 
78             This method calculates a matrix that approximates the
79             VirtualDevice's LogicToPixel conversion (disregarding any
80             offset components, thus the 'linear' in the method name -
81             the returned matrix is guaranteed to be linear).
82 
83             @param o_rMatrix
84             This matrix will receive the calculated transform, and is
85             also returned from this method.
86 
87             @return the calculated transformation matrix.
88          */
89         ::basegfx::B2DHomMatrix& calcLogic2PixelLinearTransform( ::basegfx::B2DHomMatrix&   o_rMatrix,
90                                                                  const VirtualDevice&       rVDev );
91 
92         /** Construct a matrix that converts from logical to pixel
93             coordinate system.
94 
95             This method calculates a matrix that approximates the
96             VirtualDevice's LogicToPixel conversion.
97 
98             @param o_rMatrix
99             This matrix will receive the calculated transform, and is
100             also returned from this method.
101 
102             @return the calculated transformation matrix.
103          */
104         ::basegfx::B2DHomMatrix& calcLogic2PixelAffineTransform( ::basegfx::B2DHomMatrix&   o_rMatrix,
105                                                                  const VirtualDevice&       rVDev );
106 
107         /** This method modifies the clip, to cancel the given
108             transformation.
109 
110             As the clip is relative to the render state
111             transformation, offsetting or scaling the render state
112             must modify the clip, to keep it at the same position
113             relative to the primitive at hand
114 
115             @param o_rRenderState
116             Render state to change the clip in
117 
118             @param rOutdevState
119             Input state. Is used to retrieve the original clip from
120 
121             @param rOffset
122             The clip is offsetted by the negative of this value.
123 
124             @param pScaling
125             The clip is inversely scaled by this value (if given)
126 
127             @param pRotation
128             The clip is inversely rotated by this value (if given)
129 
130             @return true, if the clip has changed, false if not
131          */
132         bool modifyClip( css::rendering::RenderState&                       o_rRenderState,
133                          const struct ::cppcanvas::internal::OutDevState&   rOutdevState,
134                          const CanvasSharedPtr&                             rCanvas,
135                          const ::basegfx::B2DPoint&                         rOffset,
136                          const ::basegfx::B2DVector*                        pScaling,
137                          const double*                                      pRotation );
138 
139         struct TextLineInfo
140         {
TextLineInfocppcanvas::tools::TextLineInfo141             TextLineInfo( const double& rLineHeight,
142                           const double& rOverlineHeight,
143                           const double& rOverlineOffset,
144                           const double& rUnderlineOffset,
145                           const double& rStrikeoutOffset,
146                           sal_Int8      nOverlineStyle,
147                           sal_Int8      nUnderlineStyle,
148                           sal_Int8      nStrikeoutStyle ) :
149                 mnLineHeight( rLineHeight ),
150                 mnOverlineHeight( rOverlineHeight ),
151                 mnOverlineOffset( rOverlineOffset ),
152                 mnUnderlineOffset( rUnderlineOffset ),
153                 mnStrikeoutOffset( rStrikeoutOffset ),
154                 mnOverlineStyle( nOverlineStyle ),
155                 mnUnderlineStyle( nUnderlineStyle ),
156                 mnStrikeoutStyle( nStrikeoutStyle )
157             {
158             }
159 
160             double      mnLineHeight;
161             double      mnOverlineHeight;
162             double      mnOverlineOffset;
163             double      mnUnderlineOffset;
164             double      mnStrikeoutOffset;
165             sal_Int8    mnOverlineStyle;
166             sal_Int8    mnUnderlineStyle;
167             sal_Int8    mnStrikeoutStyle;
168         };
169 
170         /** Transform given bounds to device coordinate system.
171          */
172         ::basegfx::B2DRange calcDevicePixelBounds( const ::basegfx::B2DRange&          rBounds,
173                                                    const css::rendering::ViewState&    viewState,
174                                                    const css::rendering::RenderState&  renderState );
175 
176         /** Generate text underline/strikeout info struct from OutDev
177             state.
178          */
179         TextLineInfo createTextLineInfo( const ::VirtualDevice&                     rVDev,
180                                          const ::cppcanvas::internal::OutDevState&  rState );
181 
182         /** Create a poly-polygon representing the given combination
183             of overline, strikeout and underline.
184 
185             @param rStartOffset
186             Offset in X direction, where the underline starts
187 
188             @param rLineWidth
189             Width of the line of text to overline/strikeout/underline
190 
191             @param rTextLineInfo
192             Common info needed for overline/strikeout/underline generation
193          */
194         ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const double&         rStartOffset,
195                                                               const double&         rLineWidth,
196                                                               const TextLineInfo&   rTextLineInfo );
197 
198         ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const ::basegfx::B2DPoint& rStartPos,
199                                                               const double&              rLineWidth,
200                                                               const TextLineInfo&        rTextLineInfo );
201 
202         void createTextLinesPolyPolygon( const double&              rStartOffset,
203                                          const double&              rLineWidth,
204                                          const TextLineInfo&        rTextLineInfo,
205                                          ::basegfx::B2DPolyPolygon& rOverlinePolyPoly,
206                                          ::basegfx::B2DPolyPolygon& rUnderlinePolyPoly,
207                                          ::basegfx::B2DPolyPolygon& rStrikeoutPolyPoly );
208 
209     }
210 }
211 
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
213