/src/libreoffice/cppcanvas/source/mtfrenderer/mtftools.hxx
Line | Count | Source |
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 | | |
48 | | namespace cppcanvastools |
49 | | { |
50 | | /** Init render state from OutDevState |
51 | | |
52 | | This method initializes the given render state object, |
53 | | sets up the transformation and the clip from the |
54 | | OutDevState. |
55 | | */ |
56 | | void initRenderState( css::rendering::RenderState& renderState, |
57 | | const ::cppcanvas::internal::OutDevState& outdevState ); |
58 | | |
59 | | /** Calc output offset relative to baseline |
60 | | |
61 | | The XCanvas API always renders text relative to its |
62 | | baseline. This method calculates an offset in logical |
63 | | coordinates, depending on the OutDevState's |
64 | | textReferencePoint and the font currently set, to offset |
65 | | the text from the baseline. |
66 | | |
67 | | @param outdevState |
68 | | State to take textReferencePoint from |
69 | | |
70 | | @param rVDev |
71 | | VDev to obtain font metrics from. |
72 | | */ |
73 | | ::Size getBaselineOffset( const ::cppcanvas::internal::OutDevState& outdevState, |
74 | | const VirtualDevice& rVDev ); |
75 | | |
76 | | /** Construct a matrix that converts from logical to pixel |
77 | | coordinate system. |
78 | | |
79 | | This method calculates a matrix that approximates the |
80 | | VirtualDevice's LogicToPixel conversion (disregarding any |
81 | | offset components, thus the 'linear' in the method name - |
82 | | the returned matrix is guaranteed to be linear). |
83 | | |
84 | | @param o_rMatrix |
85 | | This matrix will receive the calculated transform, and is |
86 | | also returned from this method. |
87 | | |
88 | | @return the calculated transformation matrix. |
89 | | */ |
90 | | ::basegfx::B2DHomMatrix& calcLogic2PixelLinearTransform( ::basegfx::B2DHomMatrix& o_rMatrix, |
91 | | const VirtualDevice& rVDev ); |
92 | | |
93 | | /** Construct a matrix that converts from logical to pixel |
94 | | coordinate system. |
95 | | |
96 | | This method calculates a matrix that approximates the |
97 | | VirtualDevice's LogicToPixel conversion. |
98 | | |
99 | | @param o_rMatrix |
100 | | This matrix will receive the calculated transform, and is |
101 | | also returned from this method. |
102 | | |
103 | | @return the calculated transformation matrix. |
104 | | */ |
105 | | ::basegfx::B2DHomMatrix& calcLogic2PixelAffineTransform( ::basegfx::B2DHomMatrix& o_rMatrix, |
106 | | const VirtualDevice& rVDev ); |
107 | | |
108 | | /** This method modifies the clip, to cancel the given |
109 | | transformation. |
110 | | |
111 | | As the clip is relative to the render state |
112 | | transformation, offsetting or scaling the render state |
113 | | must modify the clip, to keep it at the same position |
114 | | relative to the primitive at hand |
115 | | |
116 | | @param o_rRenderState |
117 | | Render state to change the clip in |
118 | | |
119 | | @param rOutdevState |
120 | | Input state. Is used to retrieve the original clip from |
121 | | |
122 | | @param rOffset |
123 | | The clip is offsetted by the negative of this value. |
124 | | |
125 | | @param pScaling |
126 | | The clip is inversely scaled by this value (if given) |
127 | | |
128 | | @param pRotation |
129 | | The clip is inversely rotated by this value (if given) |
130 | | |
131 | | @return true, if the clip has changed, false if not |
132 | | */ |
133 | | bool modifyClip( css::rendering::RenderState& o_rRenderState, |
134 | | const struct ::cppcanvas::internal::OutDevState& rOutdevState, |
135 | | const ::cppcanvas::CanvasSharedPtr& rCanvas, |
136 | | const ::basegfx::B2DPoint& rOffset, |
137 | | const ::basegfx::B2DVector* pScaling, |
138 | | const double* pRotation ); |
139 | | |
140 | | struct TextLineInfo |
141 | | { |
142 | | TextLineInfo( const double& rLineHeight, |
143 | | const double& rOverlineHeight, |
144 | | const double& rOverlineOffset, |
145 | | const double& rUnderlineOffset, |
146 | | const double& rStrikeoutOffset, |
147 | | sal_Int8 nOverlineStyle, |
148 | | sal_Int8 nUnderlineStyle, |
149 | | sal_Int8 nStrikeoutStyle ) : |
150 | 0 | mnLineHeight( rLineHeight ), |
151 | 0 | mnOverlineHeight( rOverlineHeight ), |
152 | 0 | mnOverlineOffset( rOverlineOffset ), |
153 | 0 | mnUnderlineOffset( rUnderlineOffset ), |
154 | 0 | mnStrikeoutOffset( rStrikeoutOffset ), |
155 | 0 | mnOverlineStyle( nOverlineStyle ), |
156 | 0 | mnUnderlineStyle( nUnderlineStyle ), |
157 | 0 | mnStrikeoutStyle( nStrikeoutStyle ) |
158 | 0 | { |
159 | 0 | } |
160 | | |
161 | | double mnLineHeight; |
162 | | double mnOverlineHeight; |
163 | | double mnOverlineOffset; |
164 | | double mnUnderlineOffset; |
165 | | double mnStrikeoutOffset; |
166 | | sal_Int8 mnOverlineStyle; |
167 | | sal_Int8 mnUnderlineStyle; |
168 | | sal_Int8 mnStrikeoutStyle; |
169 | | }; |
170 | | |
171 | | /** Transform given bounds to device coordinate system. |
172 | | */ |
173 | | ::basegfx::B2DRange calcDevicePixelBounds( const ::basegfx::B2DRange& rBounds, |
174 | | const css::rendering::ViewState& viewState, |
175 | | const css::rendering::RenderState& renderState ); |
176 | | |
177 | | /** Generate text underline/strikeout info struct from OutDev |
178 | | state. |
179 | | */ |
180 | | TextLineInfo createTextLineInfo( const ::VirtualDevice& rVDev, |
181 | | const ::cppcanvas::internal::OutDevState& rState ); |
182 | | |
183 | | /** Create a poly-polygon representing the given combination |
184 | | of overline, strikeout and underline. |
185 | | |
186 | | @param rStartOffset |
187 | | Offset in X direction, where the underline starts |
188 | | |
189 | | @param rLineWidth |
190 | | Width of the line of text to overline/strikeout/underline |
191 | | |
192 | | @param rTextLineInfo |
193 | | Common info needed for overline/strikeout/underline generation |
194 | | */ |
195 | | ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const double& rStartOffset, |
196 | | const double& rLineWidth, |
197 | | const TextLineInfo& rTextLineInfo ); |
198 | | |
199 | | ::basegfx::B2DPolyPolygon createTextLinesPolyPolygon( const ::basegfx::B2DPoint& rStartPos, |
200 | | const double& rLineWidth, |
201 | | const TextLineInfo& rTextLineInfo ); |
202 | | |
203 | | void createTextLinesPolyPolygon( const double& rStartOffset, |
204 | | const double& rLineWidth, |
205 | | const TextLineInfo& rTextLineInfo, |
206 | | ::basegfx::B2DPolyPolygon& rOverlinePolyPoly, |
207 | | ::basegfx::B2DPolyPolygon& rUnderlinePolyPoly, |
208 | | ::basegfx::B2DPolyPolygon& rStrikeoutPolyPoly ); |
209 | | |
210 | | } |
211 | | |
212 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |