LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/drawinglayer/primitive2d - baseprimitive2d.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 3 100.0 %
Date: 2012-08-25 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 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 INCLUDED_DRAWINGLAYER_PRIMITIVE2D_BASEPRIMITIVE2D_HXX
      30                 :            : #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_BASEPRIMITIVE2D_HXX
      31                 :            : 
      32                 :            : #include <drawinglayer/drawinglayerdllapi.h>
      33                 :            : 
      34                 :            : #include <cppuhelper/compbase1.hxx>
      35                 :            : #include <boost/utility.hpp>
      36                 :            : #include <com/sun/star/graphic/XPrimitive2D.hpp>
      37                 :            : #include <comphelper/broadcasthelper.hxx>
      38                 :            : #include <basegfx/range/b2drange.hxx>
      39                 :            : 
      40                 :            : //////////////////////////////////////////////////////////////////////////////
      41                 :            : /** defines for DeclPrimitrive2DIDBlock and ImplPrimitrive2DIDBlock
      42                 :            :     Added to be able to simply change identification stuff later, e.g. add
      43                 :            :     a identification string and/or ID to the interface and to the implementation
      44                 :            :     ATM used to delclare implement getPrimitive2DID()
      45                 :            : */
      46                 :            : 
      47                 :            : #define DeclPrimitrive2DIDBlock() \
      48                 :            :     virtual sal_uInt32 getPrimitive2DID() const;
      49                 :            : 
      50                 :            : #define ImplPrimitrive2DIDBlock(TheClass, TheID) \
      51                 :            :     sal_uInt32 TheClass::getPrimitive2DID() const { return TheID; }
      52                 :            : 
      53                 :            : //////////////////////////////////////////////////////////////////////////////
      54                 :            : // predefines
      55                 :            : 
      56                 :            : namespace drawinglayer { namespace geometry {
      57                 :            :     class ViewInformation2D;
      58                 :            : }}
      59                 :            : 
      60                 :            : namespace drawinglayer { namespace primitive2d {
      61                 :            :     /// typedefs for basePrimitive2DImplBase, Primitive2DSequence and Primitive2DReference
      62                 :            :     typedef cppu::WeakComponentImplHelper1< ::com::sun::star::graphic::XPrimitive2D > BasePrimitive2DImplBase;
      63                 :            :     typedef ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XPrimitive2D > Primitive2DReference;
      64                 :            :     typedef ::com::sun::star::uno::Sequence< Primitive2DReference > Primitive2DSequence;
      65                 :            : }}
      66                 :            : 
      67                 :            : //////////////////////////////////////////////////////////////////////////////
      68                 :            : // basePrimitive2D class
      69                 :            : 
      70                 :            : namespace drawinglayer
      71                 :            : {
      72                 :            :     namespace primitive2d
      73                 :            :     {
      74                 :            :         /** BasePrimitive2D class
      75                 :            : 
      76                 :            :             Baseclass for all C++ implementations of com::sun::star::graphic::XPrimitive2D
      77                 :            : 
      78                 :            :             This class is strongly virtual due to the lack of getPrimitiveID() implementation.
      79                 :            :             This is by purpose, this base class shall not be incarnated and be used directly as
      80                 :            :             a XPrimitive2D.
      81                 :            : 
      82                 :            :             Is is derived from boost::noncopyable to make clear that a primitive is a read-only
      83                 :            :             instance and copying or changing values is not intended. The idea is to hold all data
      84                 :            :             needed for visualisation of this primitive in unchangeable form.
      85                 :            : 
      86                 :            :             It is derived from comphelper::OBaseMutex to have a Mutex at hand; in a base
      87                 :            :             implementation this may not be needed, but e.g. when buffering at last decomposition
      88                 :            :             in a local member, multiple threads may try to decompose at the same time, so locking
      89                 :            :             is needed to avoid race conditions seen from the UNO object implementation.
      90                 :            : 
      91                 :            :             A method to get a simplified representation is provided by get2DDecomposition. The
      92                 :            :             default implementation returns an empty sequence. The idea is that processors
      93                 :            :             using this primitive and do not know it, may get the decomposition and process
      94                 :            :             these instead. An example is e.g. a fat line, who's decomposition may contain
      95                 :            :             the geometric representation of that line using filled polygon prmimitives. When
      96                 :            :             the renderer knows how to handle fat lines, he may proccess this primitive directly;
      97                 :            :             if not he can use the decomposition. With this functionality, renderers may operate by
      98                 :            :             knowing only a small set of primitives.
      99                 :            : 
     100                 :            :             When a primitive does not implement get2DDecomposition, it is called a 'Basic Primitive' and
     101                 :            :             belongs to the set of primitives which a processor should be able to handle. Practice
     102                 :            :             will define this minimal sets of primitives. When defined and the concept is prooved,
     103                 :            :             unique UNO APIs may be defined/implemented for these set to allow more intense work
     104                 :            :             with primitives using UNO.
     105                 :            : 
     106                 :            :             Current Basic 2D Primitives are:
     107                 :            : 
     108                 :            :             - BitmapPrimitive2D (bitmap data, evtl. with transparence)
     109                 :            :             - PointArrayPrimitive2D (single points)
     110                 :            :             - PolygonHairlinePrimitive2D (hairline curves/polygons)
     111                 :            :             - PolyPolygonColorPrimitive2D (colored polygons)
     112                 :            : 
     113                 :            :             UPDATE: MetafilePrimitive2D (VCL Metafile) is taken off this list since
     114                 :            :             it is implemented with the integration of CWS aw078 into DV300m69.
     115                 :            : 
     116                 :            :             All other implemented primitives have a defined decomposition and can thus be
     117                 :            :             decomposed down to this small set.
     118                 :            : 
     119                 :            :             A renderer implementing support for this minimal set of primitives can completely
     120                 :            :             render primitive-based visualisations. Of course, he also has to take states into account
     121                 :            :             which are representated by GroupPrimitive2D derivations, see groupprimitive2d.hxx
     122                 :            : 
     123                 :            :             To support getting the geometric BoundRect, getB2DRange is used. The default
     124                 :            :             implementation will use the get2DDecomposition result and merge a range from the
     125                 :            :             entries. Thus, an implementation is only necessary for the Basic Primitives, but
     126                 :            :             of course speedups are possible (and are used) by implementing the method at higher-level
     127                 :            :             primitives.
     128                 :            : 
     129                 :            :             For primitive identification, getPrimitiveID is used currently in this implementations
     130                 :            :             to allow a fast switch/case processing. This needs a unique identifier mechanism which
     131                 :            :             currently uses defines (see drawinglayer_primitivetypes2d.hxx). For UNO prmitive API
     132                 :            :             it will be needed to add a unique descriptor (Name?) later to the API.
     133                 :            : 
     134                 :            :             This base implementation provides mappings from the methods from XPrimitive2D
     135                 :            :             (getDecomposition/getRange) to the appropriate methods in the C++ implementations
     136                 :            :             (get2DDecomposition/getB2DRange). The PropertyValue ViewParameters is converted to
     137                 :            :             the appropriate C++ implementation class ViewInformation2D.
     138                 :            : 
     139                 :            :             This base class does not implement any buffering; e.g. buffering the decompositon
     140                 :            :             and/or the range. These may be buffered anytime since the definition is that the primitive
     141                 :            :             is read-only and thus unchangeable. This implies that the decomposition and/or getting
     142                 :            :             the range will lead to the same result as last time, under the precondition that
     143                 :            :             the parameter ViewInformation2D is the same as the last one. This is usually the case
     144                 :            :             for view-independent primitives which are defined by not using ViewInformation2D
     145                 :            :             in their get2DDecomposition/getB2DRange implementations.
     146                 :            :          */
     147                 :            :         class DRAWINGLAYER_DLLPUBLIC BasePrimitive2D
     148                 :            :         :   private boost::noncopyable,
     149                 :            :             protected comphelper::OBaseMutex,
     150                 :            :             public BasePrimitive2DImplBase
     151                 :            :         {
     152                 :            :         private:
     153                 :            :         protected:
     154                 :            :         public:
     155                 :            :             // constructor/destructor
     156                 :            :             BasePrimitive2D();
     157                 :            :             virtual ~BasePrimitive2D();
     158                 :            : 
     159                 :            :             /** the ==operator is mainly needed to allow testing newly-created primitives against their last
     160                 :            :                 incarnation which buffers/holds the made decompositions. The default implementation
     161                 :            :                 uses getPrimitive2DID()-calls to test if it's the same ID at last. Overloaded implementation are then
     162                 :            :                 based on this implementation
     163                 :            :              */
     164                 :            :             virtual bool operator==( const BasePrimitive2D& rPrimitive ) const;
     165                 :            :             bool operator!=( const BasePrimitive2D& rPrimitive ) const { return !operator==(rPrimitive); }
     166                 :            : 
     167                 :            :             /// The default implementation will use getDecomposition results to create the range
     168                 :            :             virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
     169                 :            : 
     170                 :            :             /** provide unique ID for fast identifying of known primitive implementations in renderers. These use
     171                 :            :                 the the defines from drawinglayer_primitivetypes2d.hxx to define unique IDs.
     172                 :            :                 This method is normally defined using DeclPrimitrive2DIDBlock()
     173                 :            :              */
     174                 :            :             virtual sal_uInt32 getPrimitive2DID() const = 0;
     175                 :            : 
     176                 :            :             /// The default implementation will return an empty sequence
     177                 :            :             virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
     178                 :            : 
     179                 :            :             //
     180                 :            :             // Methods from XPrimitive2D
     181                 :            :             //
     182                 :            : 
     183                 :            :             /** The getDecomposition implementation for UNO API will use getDecomposition from this implementation. It
     184                 :            :                 will construct a ViewInformation2D from the ViewParameters for that purpose
     185                 :            :              */
     186                 :            :             virtual Primitive2DSequence SAL_CALL getDecomposition( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rViewParameters ) throw ( ::com::sun::star::uno::RuntimeException );
     187                 :            : 
     188                 :            :             /** The getRange implementation for UNO API will use getRange from this implementation. It
     189                 :            :                 will construct a ViewInformation2D from the ViewParameters for that purpose
     190                 :            :              */
     191                 :            :             virtual ::com::sun::star::geometry::RealRectangle2D SAL_CALL getRange( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rViewParameters ) throw ( ::com::sun::star::uno::RuntimeException );
     192                 :            :         };
     193                 :            :     } // end of namespace primitive2d
     194                 :            : } // end of namespace drawinglayer
     195                 :            : 
     196                 :            : //////////////////////////////////////////////////////////////////////////////
     197                 :            : // BufferedDecompositionPrimitive2D class
     198                 :            : 
     199                 :            : namespace drawinglayer
     200                 :            : {
     201                 :            :     namespace primitive2d
     202                 :            :     {
     203                 :            :         /** BufferedDecompositionPrimitive2D class
     204                 :            : 
     205                 :            :             Baseclass for all C++ implementations of com::sun::star::graphic::XPrimitive2D
     206                 :            :             which want to buffer the decomoposition result
     207                 :            : 
     208                 :            :             Buffering the decomposition is the most-used buffering and is thus used my most
     209                 :            :             primitive implementations which support a decomposition as base class.
     210                 :            : 
     211                 :            :             The buffering is done by holding the last decomposition in the local parameter
     212                 :            :             maBuffered2DDecomposition. The default implementation of get2DDecomposition checks
     213                 :            :             if maBuffered2DDecomposition is empty. If yes, it uses create2DDecomposition
     214                 :            :             to create the content. In all cases, maBuffered2DDecomposition is returned.
     215                 :            : 
     216                 :            :             For view-dependent primitives derived from Primitive2DBufferDecomposition more needs
     217                 :            :             to be done when the decomposition depends on parts of the parameter ViewInformation2D.
     218                 :            :             This defines a standard method for processing these:
     219                 :            : 
     220                 :            :             Implement a view-dependent get2DDecomposition doing te following steps:
     221                 :            :             (a) Locally extract needed parameters from ViewInformation2D to new, local parameters
     222                 :            :                 (this may be a complete local copy of ViewInformation2D)
     223                 :            :             (b) If a buffered decomposition exists, ckeck if one of the new local parameters
     224                 :            :                 differs from the corresponding locally remembered (as member) ones. If yes,
     225                 :            :                 clear maBuffered2DDecomposition
     226                 :            :             (d) call baseclass::get2DDecomposition which will use create2DDecomposition
     227                 :            :                 to fill maBuffered2DDecomposition if it's empty
     228                 :            :             (e) copy the new local parameters to the corresponding locally remembered ones
     229                 :            :                 to identify if a new decomposition is needed at the next call
     230                 :            :             (f) return maBuffered2DDecomposition
     231                 :            :          */
     232 [ +  - ][ -  + ]:     244831 :         class DRAWINGLAYER_DLLPUBLIC BufferedDecompositionPrimitive2D
     233                 :            :         :   public BasePrimitive2D
     234                 :            :         {
     235                 :            :         private:
     236                 :            :             /// a sequence used for buffering the last create2DDecomposition() result
     237                 :            :             Primitive2DSequence                             maBuffered2DDecomposition;
     238                 :            : 
     239                 :            :         protected:
     240                 :            :             /** access methods to maBuffered2DDecomposition. The usage of this methods may allow
     241                 :            :                 later thread-safe stuff to be added if needed. Only to be used by getDecomposition()
     242                 :            :                 implementations for buffering the last decomposition.
     243                 :            :              */
     244                 :    1795172 :             const Primitive2DSequence& getBuffered2DDecomposition() const { return maBuffered2DDecomposition; }
     245                 :     125895 :             void setBuffered2DDecomposition(const Primitive2DSequence& rNew) { maBuffered2DDecomposition = rNew; }
     246                 :            : 
     247                 :            :             /** method which is to be used to implement the local decomposition of a 2D primitive. The default
     248                 :            :                 implementation will just return an empty decomposition
     249                 :            :              */
     250                 :            :             virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
     251                 :            : 
     252                 :            :         public:
     253                 :            :             // constructor/destructor
     254                 :            :             BufferedDecompositionPrimitive2D();
     255                 :            : 
     256                 :            :             /** The getDecomposition default implementation will on demand use create2DDecomposition() if
     257                 :            :                 maBuffered2DDecomposition is empty. It will set maBuffered2DDecomposition to this obtained decomposition
     258                 :            :                 to buffer it. If the decomposition is also ViewInformation2D-dependent, this method needs to be
     259                 :            :                 overloaded and the ViewInformation2D for the last decomposition need to be remembered, too, and
     260                 :            :                 be used in the next call to decide if the buffered decomposition may be reused or not.
     261                 :            :              */
     262                 :            :             virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
     263                 :            :         };
     264                 :            :     } // end of namespace primitive2d
     265                 :            : } // end of namespace drawinglayer
     266                 :            : 
     267                 :            : //////////////////////////////////////////////////////////////////////////////
     268                 :            : // tooling
     269                 :            : 
     270                 :            : namespace drawinglayer
     271                 :            : {
     272                 :            :     namespace primitive2d
     273                 :            :     {
     274                 :            :         /// get B2DRange from a given Primitive2DReference
     275                 :            :         basegfx::B2DRange DRAWINGLAYER_DLLPUBLIC getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation);
     276                 :            : 
     277                 :            :         /// get B2DRange from a given Primitive2DSequence
     278                 :            :         basegfx::B2DRange DRAWINGLAYER_DLLPUBLIC getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation);
     279                 :            : 
     280                 :            :         /** compare two Primitive2DReferences for equality, including trying to get implementations (BasePrimitive2D)
     281                 :            :             and using compare operator
     282                 :            :          */
     283                 :            :         bool DRAWINGLAYER_DLLPUBLIC arePrimitive2DReferencesEqual(const Primitive2DReference& rA, const Primitive2DReference& rB);
     284                 :            : 
     285                 :            :         /// compare two Primitive2DReferences for equality, uses arePrimitive2DReferencesEqual internally
     286                 :            :         bool DRAWINGLAYER_DLLPUBLIC arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB);
     287                 :            : 
     288                 :            :         /// concatenate sequence
     289                 :            :         void DRAWINGLAYER_DLLPUBLIC appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource);
     290                 :            : 
     291                 :            :         /// concatenate single Primitive2D
     292                 :            :         void DRAWINGLAYER_DLLPUBLIC appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource);
     293                 :            : 
     294                 :            :     } // end of namespace primitive2d
     295                 :            : } // end of namespace drawinglayer
     296                 :            : 
     297                 :            : //////////////////////////////////////////////////////////////////////////////
     298                 :            : 
     299                 :            : #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_BASEPRIMITIVE2D_HXX
     300                 :            : 
     301                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10