1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _BGFX_TOOLS_TOOLS_HXX 29 #define _BGFX_TOOLS_TOOLS_HXX 30 31 #include <sal/types.h> 32 33 namespace basegfx 34 { 35 class B2DPoint; 36 class B2DRange; 37 38 namespace tools 39 { 40 /** Liang-Barsky 2D line clipping algorithm 41 42 This function clips a line given by two points against the 43 given rectangle. The resulting line is returned in the 44 given points. 45 46 @param io_rStart 47 Start point of the line. On return, contains the clipped 48 start point. 49 50 @param io_rEnd 51 End point of the line. On return, contains the clipped 52 end point. 53 54 @param rClipRect 55 The rectangle to clip against 56 57 @return true, when at least part of the line is visible 58 after the clip, false otherwise 59 */ 60 bool liangBarskyClip2D( ::basegfx::B2DPoint& io_rStart, 61 ::basegfx::B2DPoint& io_rEnd, 62 const ::basegfx::B2DRange& rClipRect ); 63 64 /** Expand given parallelogram, such that it extends beyond 65 bound rect in a given direction. 66 67 This method is useful when e.g. generating one-dimensional 68 gradients, such as linear or axial gradients: those 69 gradients vary only in one direction, the other has 70 constant color. Most of the time, those gradients extends 71 infinitely in the direction with the constant color, but 72 practically, one always has a limiting bound rect into 73 which the gradient is painted. The method at hand now 74 extends a given parallelogram (e.g. the transformed 75 bounding box of a gradient) virtually into infinity to the 76 top and to the bottom (i.e. normal to the line io_rLeftTop 77 io_rRightTop), such that the given rectangle is guaranteed 78 to be covered in that direction. 79 80 @attention There might be some peculiarities with this 81 method, that might limit its usage to the described 82 gradients. One of them is the fact that when determining 83 how far the parallelogram has to be extended to the top or 84 the bottom, the upper and lower border are assumed to be 85 infinite lines. 86 87 @param io_rLeftTop 88 Left, top edge of the parallelogramm. Note that this need 89 not be the left, top edge geometrically, it's just used 90 when determining the extension direction. Thus, it's 91 perfectly legal to affine-transform a rectangle, and given 92 the transformed point here. On method return, this 93 parameter will contain the adapted output. 94 95 @param io_rLeftBottom 96 Left, bottom edge of the parallelogramm. Note that this need 97 not be the left, bottom edge geometrically, it's just used 98 when determining the extension direction. Thus, it's 99 perfectly legal to affine-transform a rectangle, and given 100 the transformed point here. On method return, this 101 parameter will contain the adapted output. 102 103 @param io_rRightTop 104 Right, top edge of the parallelogramm. Note that this need 105 not be the right, top edge geometrically, it's just used 106 when determining the extension direction. Thus, it's 107 perfectly legal to affine-transform a rectangle, and given 108 the transformed point here. On method return, this 109 parameter will contain the adapted output. 110 111 @param io_rRightBottom 112 Right, bottom edge of the parallelogramm. Note that this need 113 not be the right, bottom edge geometrically, it's just used 114 when determining the extension direction. Thus, it's 115 perfectly legal to affine-transform a rectangle, and given 116 the transformed point here. On method return, this 117 parameter will contain the adapted output. 118 119 @param rFitTarget 120 The rectangle to fit the parallelogram into. 121 */ 122 void infiniteLineFromParallelogram( ::basegfx::B2DPoint& io_rLeftTop, 123 ::basegfx::B2DPoint& io_rLeftBottom, 124 ::basegfx::B2DPoint& io_rRightTop, 125 ::basegfx::B2DPoint& io_rRightBottom, 126 const ::basegfx::B2DRange& rFitTarget ); 127 128 } 129 } 130 131 #endif /* _BGFX_TOOLS_TOOLS_HXX */ 132