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