LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/vcl - graphictools.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 2 100.0 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _VCL_GRAPHICTOOLS_HXX_
      30                 :            : #define _VCL_GRAPHICTOOLS_HXX_
      31                 :            : 
      32                 :            : #include <vcl/dllapi.h>
      33                 :            : #include <sal/types.h>
      34                 :            : #include <rtl/string.hxx>
      35                 :            : #include <tools/color.hxx>
      36                 :            : #include <tools/poly.hxx>
      37                 :            : #include <tools/stream.hxx>
      38                 :            : #include <vcl/graph.hxx>
      39                 :            : 
      40                 :            : #include <memory>
      41                 :            : #include <vector>
      42                 :            : 
      43                 :            : /** Encapsulates geometry and associated attributes of a graphical 'pen stroke'
      44                 :            : 
      45                 :            :     @attention Widespread use is deprecated. See declarations above
      46                 :            :     for the way to go. Especially the copied enums from svx/xenum.hxx
      47                 :            :     are troublesome.
      48                 :            : 
      49                 :            :     Use this class to store geometry and attributes of a graphical
      50                 :            :     'pen stroke', such as pen width, dashing etc. The geometry is the
      51                 :            :     so-called 'path' along which the stroke is traced, with the given
      52                 :            :     pen width. The cap type determines how the open ends of the path
      53                 :            :     should be drawn. If the geometry consists of more than one
      54                 :            :     segment, the join type determines in which way the segments are
      55                 :            :     joined.
      56                 :            :  */
      57 [ +  - ][ +  - ]:       4735 : class VCL_DLLPUBLIC SvtGraphicStroke
      58                 :            : {
      59                 :            : public:
      60                 :            :     /// Style for open stroke ends
      61                 :            :     enum CapType
      62                 :            :     {
      63                 :            :         /// No additional cap
      64                 :            :         capButt=0,
      65                 :            :         /// Half-round cap at the line end, the center lying at the end point
      66                 :            :         capRound,
      67                 :            :         /// Half-square cap at the line end, the center lying at the end point
      68                 :            :         capSquare
      69                 :            :     };
      70                 :            :     /// Style for joins of individual stroke segments
      71                 :            :     enum JoinType
      72                 :            :     {
      73                 :            :         /// Extend segment edges, until they cross
      74                 :            :         joinMiter=0,
      75                 :            :         /// Connect segments by a filled round arc
      76                 :            :         joinRound,
      77                 :            :         /// Connect segments by a direct straight line
      78                 :            :         joinBevel,
      79                 :            :         /// Perform no join, leads to visible gaps between thick line segments
      80                 :            :         joinNone
      81                 :            :     };
      82                 :            :     enum
      83                 :            :     {
      84                 :            :         /// Width of stroke start/end arrow to exactly fit the joining stroke
      85                 :            :         normalizedArrowWidth=65536
      86                 :            :     };
      87                 :            :     typedef ::std::vector< double > DashArray;
      88                 :            : 
      89                 :            :     SvtGraphicStroke();
      90                 :            :     /** All in one constructor
      91                 :            : 
      92                 :            :         See accessor method descriptions for argument description
      93                 :            :      */
      94                 :            :     SvtGraphicStroke( const Polygon&        rPath,
      95                 :            :                       const PolyPolygon&    rStartArrow,
      96                 :            :                       const PolyPolygon&    rEndArrow,
      97                 :            :                       double                fTransparency,
      98                 :            :                       double                fStrokeWidth,
      99                 :            :                       CapType               aCap,
     100                 :            :                       JoinType              aJoin,
     101                 :            :                       double                fMiterLimit,
     102                 :            :                       const DashArray&      rDashArray  );      // TODO: Dash array offset (position where to start, see PS)
     103                 :            : 
     104                 :            :     // accessors
     105                 :            :     /// Query path to stroke
     106                 :            :     void            getPath             ( Polygon& ) const;
     107                 :            :     /** Get the polygon that is put at the start of the line
     108                 :            : 
     109                 :            :         The polygon is in a special normalized position: the center of
     110                 :            :         the stroked path will meet the given polygon at (0,0) from
     111                 :            :         negative y values. Thus, an arrow would have its baseline on
     112                 :            :         the x axis, going upwards to positive y values. Furthermore,
     113                 :            :         the polygon is also scaled in a special way: the width of the
     114                 :            :         joining stroke is defined to be
     115                 :            :         SvtGraphicStroke::normalizedArrowWidth (0x10000), i.e. ranging
     116                 :            :         from x=-0x8000 to x=0x8000. So, if the arrow does have this
     117                 :            :         width, it has to fit every stroke with every stroke width
     118                 :            :         exactly.
     119                 :            :      */
     120                 :            :     void            getStartArrow       ( PolyPolygon& ) const;
     121                 :            :     /** Get the polygon that is put at the end of the line
     122                 :            : 
     123                 :            :         The polygon is in a special normalized position, and already
     124                 :            :         scaled to the desired size: the center of the stroked path
     125                 :            :         will meet the given polygon at (0,0) from negative y
     126                 :            :         values. Thus, an arrow would have its baseline on the x axis,
     127                 :            :         going upwards to positive y values. Furthermore, the polygon
     128                 :            :         is also scaled in a special way: the width of the joining
     129                 :            :         stroke is defined to be SvtGraphicStroke::normalizedArrowWidth
     130                 :            :         (0x10000), i.e. ranging from x=-0x8000 to x=0x8000. So, if the
     131                 :            :         arrow does have this width, it has to fit every stroke with
     132                 :            :         every stroke width exactly.
     133                 :            :      */
     134                 :            :     void            getEndArrow         ( PolyPolygon& ) const;
     135                 :            :     /** Get stroke transparency
     136                 :            : 
     137                 :            :         @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
     138                 :            :      */
     139                 :            :     double          getTransparency     () const;
     140                 :            :     /// Get width of the stroke
     141                 :            :     double          getStrokeWidth      () const;
     142                 :            :     /// Get the style in which open stroke ends are drawn
     143                 :            :     CapType         getCapType          () const;
     144                 :            :     /// Get the style in which the stroke segments are joined
     145                 :            :     JoinType        getJoinType         () const;
     146                 :            :     /// Get the maximum length of mitered joins
     147                 :            :     double          getMiterLimit       () const;
     148                 :            :     /// Get an array of "on" and "off" lengths for stroke dashing
     149                 :            :     void            getDashArray        ( DashArray& ) const;
     150                 :            :     /// Query a textual representation of the object's content
     151                 :            :     ::rtl::OString  toString            () const;
     152                 :            : 
     153                 :            :     // mutators
     154                 :            :     /// Set path to stroke
     155                 :            :     void    setPath             ( const Polygon& );
     156                 :            : 
     157                 :            : private:
     158                 :            :     // friends
     159                 :            :     VCL_DLLPUBLIC friend SvStream& operator<<( SvStream& rOStm, const SvtGraphicStroke& rClass );
     160                 :            :     VCL_DLLPUBLIC friend SvStream& operator>>( SvStream& rIStm, SvtGraphicStroke& rClass );
     161                 :            : 
     162                 :            :     Polygon         maPath;
     163                 :            :     PolyPolygon     maStartArrow;
     164                 :            :     PolyPolygon     maEndArrow;
     165                 :            :     double          mfTransparency;
     166                 :            :     double          mfStrokeWidth;
     167                 :            :     CapType         maCapType;
     168                 :            :     JoinType        maJoinType;
     169                 :            :     double          mfMiterLimit;
     170                 :            :     DashArray       maDashArray;
     171                 :            : };
     172                 :            : 
     173                 :            : /** Encapsulates geometry and associated attributes of a filled area
     174                 :            : 
     175                 :            :     @attention Widespread use is deprecated. See declarations above
     176                 :            :     for the way to go. Especially the copied enums from svx/xenum.hxx
     177                 :            :     is troublesome.
     178                 :            : 
     179                 :            :     Use this class to store geometry and attributes of a filled area,
     180                 :            :     such as fill color, transparency, texture or hatch.  The geometry
     181                 :            :     is the so-called 'path', whose inner area will get filled
     182                 :            :     according to the attributes set. If the path is intersecting, or
     183                 :            :     one part of the path is lying fully within another part, then the
     184                 :            :     fill rule determines which parts are filled and which are not.
     185                 :            :  */
     186         [ +  - ]:       1195 : class VCL_DLLPUBLIC SvtGraphicFill
     187                 :            : {
     188                 :            : public:
     189                 :            :     /// Type of fill algorithm used
     190                 :            :     enum FillRule
     191                 :            :     {
     192                 :            :         /** Non-zero winding rule
     193                 :            : 
     194                 :            :             Fill shape scanline-wise. Starting at the left, determine
     195                 :            :             the winding number as follows: every segment crossed that
     196                 :            :             runs counter-clockwise adds one to the winding number,
     197                 :            :             every segment crossed that runs clockwise subtracts
     198                 :            :             one. The part of the scanline where the winding number is
     199                 :            :             non-zero gets filled.
     200                 :            :          */
     201                 :            :         fillNonZero=0,
     202                 :            :         /** Even-odd fill rule
     203                 :            : 
     204                 :            :             Fill shape scanline-wise. Starting at the left, count the
     205                 :            :             number of segments crossed. If this number is odd, the
     206                 :            :             part of the scanline is filled, otherwise not.
     207                 :            :          */
     208                 :            :         fillEvenOdd
     209                 :            :     };
     210                 :            :     /// Type of filling used
     211                 :            :     enum FillType
     212                 :            :     {
     213                 :            :         /// Fill with a specified solid color
     214                 :            :         fillSolid=0,
     215                 :            :         /// Fill with the specified gradient
     216                 :            :         fillGradient,
     217                 :            :         /// Fill with the specified hatch
     218                 :            :         fillHatch,
     219                 :            :         /// Fill with the specified texture (a Graphic object)
     220                 :            :         fillTexture
     221                 :            :     };
     222                 :            :     /// Type of hatching used
     223                 :            :     enum HatchType
     224                 :            :     {
     225                 :            :         /// horizontal parallel lines, one unit apart
     226                 :            :         hatchSingle=0,
     227                 :            :         /// horizontal and verticall orthogonally crossing lines, one unit apart
     228                 :            :         hatchDouble,
     229                 :            :         /// three crossing lines, like HatchType::hatchDouble, but
     230                 :            :         /// with an additional diagonal line, rising to the upper
     231                 :            :         /// right corner. The first diagonal line goes through the
     232                 :            :         /// upper left corner, the other are each spaced a unit apart.
     233                 :            :         hatchTriple
     234                 :            :     };
     235                 :            :     /// Type of gradient used
     236                 :            :     enum GradientType {gradientLinear=0, gradientRadial, gradientRectangular};
     237                 :            :     /// Special values for gradient step count
     238                 :            :     enum { gradientStepsInfinite=0 };
     239                 :            :     /** Homogeneous 2D transformation matrix
     240                 :            : 
     241                 :            :         This is a 2x3 matrix representing an affine transformation on
     242                 :            :         the R^2, in the usual C/C++ row major form. It is structured as follows:
     243                 :            :         <pre>
     244                 :            :         a b t_x
     245                 :            :         c d t_y
     246                 :            :         0 0 1
     247                 :            :         </pre>
     248                 :            :         where the lowest line is not stored in the matrix, since it is
     249                 :            :         constant. Variables t_x and t_y contain translational
     250                 :            :         components, a to d rotation, scale and shear (for details,
     251                 :            :         look up your favorite linear algebra/computer graphics book).
     252                 :            :      */
     253                 :            :     struct VCL_DLLPUBLIC Transform
     254                 :            :     {
     255                 :            :         enum { MatrixSize=6 };
     256                 :            :         Transform();
     257                 :            :         double matrix[MatrixSize];
     258                 :            :     };
     259                 :            : 
     260                 :            :     SvtGraphicFill();
     261                 :            :     /** All in one constructor
     262                 :            : 
     263                 :            :         See accessor method descriptions for argument description
     264                 :            :      */
     265                 :            :     SvtGraphicFill( const PolyPolygon&  rPath,
     266                 :            :                     Color               aFillColor,
     267                 :            :                     double              fTransparency,
     268                 :            :                     FillRule            aFillRule,
     269                 :            :                     FillType            aFillType,              // TODO: Multitexturing
     270                 :            :                     const Transform&    aFillTransform,
     271                 :            :                     bool                bTiling,
     272                 :            :                     HatchType           aHatchType,             // TODO: vector of directions and start points
     273                 :            :                     Color               aHatchColor,
     274                 :            :                     GradientType        aGradientType,          // TODO: Transparent gradients (orthogonal to normal ones)
     275                 :            :                     Color               aGradient1stColor,      // TODO: vector of colors and offsets
     276                 :            :                     Color               aGradient2ndColor,
     277                 :            :                     sal_Int32           aGradientStepCount,     // numbers of steps to render the gradient. gradientStepsInfinite means infinitely many.
     278                 :            :                     const Graphic&      aFillGraphic );
     279                 :            : 
     280                 :            :     // accessors
     281                 :            :     /// Query path to fill
     282                 :            :     void            getPath             ( PolyPolygon& ) const;
     283                 :            :     /// Get color used for solid fills
     284                 :            :     Color           getFillColor        () const;
     285                 :            :     /** Get stroke transparency
     286                 :            : 
     287                 :            :         @return the transparency, ranging from 0.0 (opaque) to 1.0 (fully translucent)
     288                 :            :      */
     289                 :            :     double          getTransparency     () const;
     290                 :            :     /// Get fill rule used
     291                 :            :     FillRule        getFillRule         () const;
     292                 :            :     /** Get fill type used
     293                 :            : 
     294                 :            :         Currently, only one of the fill types can be used
     295                 :            :         simultaneously. If you specify e.g. FillRule::fillGradient,
     296                 :            :         hatching, texture and solid fill color are ignored.
     297                 :            :      */
     298                 :            :     FillType        getFillType         () const;
     299                 :            :     /** Get transformation applied to hatch, gradient or texture during fill
     300                 :            : 
     301                 :            :         A fill operation generally starts at the top left position of
     302                 :            :         the object's bounding box. At that position (if tiling is on,
     303                 :            :         also all successive positions), the specified fill graphic is
     304                 :            :         rendered, after applying the fill transformation to it. For
     305                 :            :         example, if the fill transformation contains a translation,
     306                 :            :         the fill graphic is rendered at the object's bounding box's
     307                 :            :         top left corner plus the translation components.
     308                 :            : 
     309                 :            :      */
     310                 :            :     void            getTransform        ( Transform& ) const;
     311                 :            :     /// deprecated
     312                 :            :     bool            IsTiling            () const;
     313                 :            :     /** Query state of texture tiling
     314                 :            : 
     315                 :            :         @return true, if texture is tiled, false, if output only once.
     316                 :            :      */
     317                 :            :     bool            isTiling            () const;
     318                 :            :     /// Get type of gradient used
     319                 :            :     GradientType    getGradientType     () const;
     320                 :            : 
     321                 :            :     /** Get the texture graphic used
     322                 :            : 
     323                 :            :         The Graphic object returned is used to fill the geometry, if
     324                 :            :         the FillType is fillTexture. The Graphic object is always
     325                 :            :         assumed to be of size 1x1, the transformation is used to scale
     326                 :            :         it to the appropriate size.
     327                 :            :      */
     328                 :            :     void            getGraphic          ( Graphic& ) const;
     329                 :            : 
     330                 :            :     // mutators
     331                 :            :     /// Set path to fill
     332                 :            :     void    setPath             ( const PolyPolygon& rPath );
     333                 :            : 
     334                 :            : private:
     335                 :            :     // friends
     336                 :            :     VCL_DLLPUBLIC friend SvStream& operator<<( SvStream& rOStm, const SvtGraphicFill& rClass );
     337                 :            :     VCL_DLLPUBLIC friend SvStream& operator>>( SvStream& rIStm, SvtGraphicFill& rClass );
     338                 :            : 
     339                 :            :     PolyPolygon     maPath;
     340                 :            :     Color           maFillColor;
     341                 :            :     double          mfTransparency;
     342                 :            :     FillRule        maFillRule;
     343                 :            :     FillType        maFillType;
     344                 :            :     Transform       maFillTransform;
     345                 :            :     bool            mbTiling;
     346                 :            :     HatchType       maHatchType;
     347                 :            :     Color           maHatchColor;
     348                 :            :     GradientType    maGradientType;
     349                 :            :     Color           maGradient1stColor;
     350                 :            :     Color           maGradient2ndColor;
     351                 :            :     sal_Int32       maGradientStepCount;
     352                 :            :     Graphic         maFillGraphic;
     353                 :            : };
     354                 :            : 
     355                 :            : #endif /* _VCL_GRAPHICTOOLS_HXX_ */
     356                 :            : 
     357                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10