LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/vcl - graphictools.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 2 100.0 %
Date: 2012-12-27 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10