LCOV - code coverage report
Current view: top level - include/vcl - region.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 6 6 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 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 INCLUDED_VCL_REGION_HXX
      21             : #define INCLUDED_VCL_REGION_HXX
      22             : 
      23             : #include <tools/gen.hxx>
      24             : #include <vcl/dllapi.h>
      25             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      26             : #include <memory>
      27             : 
      28             : class ImplRegionBand;
      29             : class RegionBand;
      30             : class Polygon;
      31             : namespace tools { class PolyPolygon; }
      32             : namespace vcl { class Window; }
      33             : class OutputDevice;
      34             : class Bitmap;
      35             : 
      36             : typedef std::shared_ptr< RegionBand > RegionBandPtr;
      37             : typedef std::shared_ptr< tools::PolyPolygon > PolyPolygonPtr;
      38             : typedef std::shared_ptr< basegfx::B2DPolyPolygon > B2DPolyPolygonPtr;
      39             : typedef std::vector< Rectangle > RectangleVector;
      40             : 
      41             : namespace vcl {
      42             : 
      43             : class VCL_DLLPUBLIC Region
      44             : {
      45             : private:
      46             :     friend class ::OutputDevice;
      47             :     friend class ::vcl::Window;
      48             :     friend class ::Bitmap;
      49             : 
      50             :     // possible contents
      51             :     B2DPolyPolygonPtr           mpB2DPolyPolygon;
      52             :     PolyPolygonPtr              mpPolyPolygon;
      53             :     RegionBandPtr               mpRegionBand;
      54             : 
      55             :     /// bitfield
      56             :     bool                        mbIsNull : 1;
      57             : 
      58             :     // helpers
      59             :     SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const tools::PolyPolygon& rPolyPoly );
      60             :     SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly );
      61             : 
      62             :     SAL_DLLPRIVATE tools::PolyPolygon ImplCreatePolyPolygonFromRegionBand() const;
      63             :     SAL_DLLPRIVATE basegfx::B2DPolyPolygon ImplCreateB2DPolyPolygonFromRegionBand() const;
      64             : 
      65             : public:
      66             : 
      67             :     explicit Region(bool bIsNull = false); // default creates empty region, with true a null region is created
      68             :     explicit Region(const Rectangle& rRect);
      69             :     explicit Region(const Polygon& rPolygon);
      70             :     explicit Region(const tools::PolyPolygon& rPolyPoly);
      71             :     explicit Region(const basegfx::B2DPolyPolygon&);
      72             :     Region(const vcl::Region& rRegion);
      73             :     ~Region();
      74             : 
      75             :     // direct access to contents
      76     4620326 :     const basegfx::B2DPolyPolygon* getB2DPolyPolygon() const { return mpB2DPolyPolygon.get(); }
      77     4619612 :     const tools::PolyPolygon* getPolyPolygon() const { return mpPolyPolygon.get(); }
      78     8885154 :     const RegionBand* getRegionBand() const { return mpRegionBand.get(); }
      79             : 
      80             :     // access with converters, the asked data will be created from the most
      81             :     // valuable data, buffered and returned
      82             :     const tools::PolyPolygon GetAsPolyPolygon() const;
      83             :     const basegfx::B2DPolyPolygon GetAsB2DPolyPolygon() const;
      84             :     const RegionBand* GetAsRegionBand() const;
      85             : 
      86             :     // manipulators
      87             :     void Move( long nHorzMove, long nVertMove );
      88             :     void Scale( double fScaleX, double fScaleY );
      89             :     bool Union( const Rectangle& rRegion );
      90             :     bool Intersect( const Rectangle& rRegion );
      91             :     bool Exclude( const Rectangle& rRegion );
      92             :     bool XOr( const Rectangle& rRegion );
      93             :     bool Union( const vcl::Region& rRegion );
      94             :     bool Intersect( const vcl::Region& rRegion );
      95             :     bool Exclude( const vcl::Region& rRegion );
      96             :     bool XOr( const vcl::Region& rRegion );
      97             : 
      98             :     bool IsEmpty() const;
      99     4578211 :     bool IsNull() const { return mbIsNull;}
     100             : 
     101             :     void SetEmpty();
     102             :     void SetNull();
     103             : 
     104             :     bool IsRectangle() const;
     105             : 
     106             :     Rectangle GetBoundRect() const;
     107     2405147 :     bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); }
     108             :     void GetRegionRectangles(RectangleVector& rTarget) const;
     109             : 
     110             :     bool IsInside( const Point& rPoint ) const;
     111             :     bool IsInside( const Rectangle& rRect ) const;
     112             :     bool IsOver( const Rectangle& rRect ) const;
     113             : 
     114             :     vcl::Region& operator=( const vcl::Region& rRegion );
     115             :     vcl::Region& operator=( const Rectangle& rRect );
     116             : 
     117             :     bool operator==( const vcl::Region& rRegion ) const;
     118       26514 :     bool operator!=( const vcl::Region& rRegion ) const { return !(Region::operator==( rRegion )); }
     119             : 
     120             :     friend VCL_DLLPUBLIC SvStream& ReadRegion( SvStream& rIStm, vcl::Region& rRegion );
     121             :     friend VCL_DLLPUBLIC SvStream& WriteRegion( SvStream& rOStm, const vcl::Region& rRegion );
     122             : 
     123             :     /* workaround: faster conversion for PolyPolygons
     124             :      * if half of the Polygons contained in rPolyPoly are actually
     125             :      * rectangles, then the returned vcl::Region will be constructed by
     126             :      * XOr'ing the contained Polygons together; in the case of
     127             :      * only Rectangles this can be up to eight times faster than
     128             :      * Region( const tools::PolyPolygon& ).
     129             :      * Caution: this is only useful if the vcl::Region is known to be
     130             :      * changed to rectangles; e.g. if being set as clip region
     131             :      */
     132             :     static vcl::Region GetRegionFromPolyPolygon( const tools::PolyPolygon& rPolyPoly );
     133             : };
     134             : 
     135             : } /* namespace vcl */
     136             : 
     137             : template< typename charT, typename traits >
     138             : inline std::basic_ostream<charT, traits> & operator <<(
     139             :     std::basic_ostream<charT, traits> & stream, const vcl::Region& rRegion)
     140             : {
     141             :     if (rRegion.IsEmpty())
     142             :         return stream << "EMPTY";
     143             :     if (rRegion.getB2DPolyPolygon())
     144             :         return stream << "B2DPolyPolygon("
     145             :                       << *rRegion.getB2DPolyPolygon()
     146             :                       << ")";
     147             :     if (rRegion.getPolyPolygon())
     148             :         return stream << "unimplemented";
     149             :     if (rRegion.getRegionBand())
     150             :     {   // inlined because RegionBand is private to vcl
     151             :         stream << "RegionBand(";
     152             :         RectangleVector rects;
     153             :         rRegion.GetRegionRectangles(rects);
     154             :         if (rects.empty())
     155             :             stream << "EMPTY";
     156             :         for (size_t i = 0; i < rects.size(); ++i)
     157             :             stream << "[" << i << "] " << rects[i];
     158             :         stream << ")";
     159             :     }
     160             :     return stream;
     161             : }
     162             : 
     163             : #endif // INCLUDED_VCL_REGION_HXX
     164             : 
     165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11