LCOV - code coverage report
Current view: top level - vcl/source/gdi - mapmod.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 127 128 99.2 %
Date: 2015-06-13 12:38:46 Functions: 26 26 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             : #include <vcl/mapmod.hxx>
      21             : 
      22             : #include <tools/gen.hxx>
      23             : #include <tools/fract.hxx>
      24             : #include <tools/stream.hxx>
      25             : #include <tools/vcompat.hxx>
      26             : #include <tools/debug.hxx>
      27             : 
      28             : 
      29             : // - ImplMapMode -
      30             : 
      31      117759 : struct MapMode::ImplMapMode
      32             : {
      33             :     sal_uLong       mnRefCount;
      34             :     MapUnit         meUnit;
      35             :     Point           maOrigin;
      36             :     // NOTE: these Fraction must NOT have more than 32 bits precision
      37             :     // because ReadFraction / WriteFraction do only 32 bits, so more than
      38             :     // that cannot be stored in MetaFiles!
      39             :     // => call ReduceInaccurate whenever setting these
      40             :     Fraction        maScaleX;
      41             :     Fraction        maScaleY;
      42             :     bool            mbSimple;
      43             : 
      44             :     friend SvStream& ReadImplMapMode(SvStream& rIStm, ImplMapMode& rMapMode);
      45             :     friend SvStream& WriteImplMapMode(SvStream& rOStm, const ImplMapMode& rMapMode);
      46             : 
      47             :     static ImplMapMode* ImplGetStaticMapMode( MapUnit eUnit );
      48             : 
      49             :     ImplMapMode();
      50             :     ImplMapMode(const ImplMapMode& rImpMapMode);
      51             : };
      52             : 
      53       44853 : MapMode::ImplMapMode::ImplMapMode() :
      54             :     maOrigin( 0, 0 ),
      55             :     maScaleX( 1, 1 ),
      56       44853 :     maScaleY( 1, 1 )
      57             : {
      58       44853 :     mnRefCount  = 1;
      59       44853 :     meUnit      = MAP_PIXEL;
      60       44853 :     mbSimple    = false;
      61       44853 : }
      62             : 
      63       74436 : MapMode::ImplMapMode::ImplMapMode( const ImplMapMode& rImplMapMode ) :
      64             :     maOrigin( rImplMapMode.maOrigin ),
      65             :     maScaleX( rImplMapMode.maScaleX ),
      66       74436 :     maScaleY( rImplMapMode.maScaleY )
      67             : {
      68       74436 :     mnRefCount      = 1;
      69       74436 :     meUnit          = rImplMapMode.meUnit;
      70       74436 :     mbSimple        = false;
      71       74436 : }
      72             : 
      73        5497 : SvStream& ReadImplMapMode(SvStream& rIStm, MapMode::ImplMapMode& rImplMapMode)
      74             : {
      75        5497 :     VersionCompat   aCompat( rIStm, StreamMode::READ );
      76             :     sal_uInt16          nTmp16;
      77             : 
      78        5497 :     rIStm.ReadUInt16( nTmp16 ); rImplMapMode.meUnit = (MapUnit) nTmp16;
      79        5497 :     ReadPair( rIStm, rImplMapMode.maOrigin );
      80        5497 :     ReadFraction( rIStm, rImplMapMode.maScaleX );
      81        5497 :     ReadFraction( rIStm, rImplMapMode.maScaleY );
      82        5497 :     rIStm.ReadCharAsBool( rImplMapMode.mbSimple );
      83             : 
      84        5497 :     return rIStm;
      85             : }
      86             : 
      87        6111 : SvStream& WriteImplMapMode(SvStream& rOStm, const MapMode::ImplMapMode& rImplMapMode)
      88             : {
      89        6111 :     VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
      90             : 
      91        6111 :     rOStm.WriteUInt16( rImplMapMode.meUnit );
      92        6111 :     WritePair( rOStm, rImplMapMode.maOrigin );
      93        6111 :     WriteFraction( rOStm, rImplMapMode.maScaleX );
      94        6111 :     WriteFraction( rOStm, rImplMapMode.maScaleY );
      95        6111 :     rOStm.WriteBool( rImplMapMode.mbSimple );
      96             : 
      97        6111 :     return rOStm;
      98             : }
      99             : 
     100             : MapMode::ImplMapMode *
     101     7483720 : MapMode::ImplMapMode::ImplGetStaticMapMode(MapUnit eUnit)
     102             : {
     103             :     static long aStaticImplMapModeAry[(MAP_LASTENUMDUMMY)*sizeof(ImplMapMode)/sizeof(long)];
     104             : 
     105             :     // #i19496 check for out-of-bounds
     106     7483720 :      if( eUnit >= MAP_LASTENUMDUMMY )
     107           0 :         return reinterpret_cast<ImplMapMode*>(aStaticImplMapModeAry);
     108             : 
     109     7483720 :     ImplMapMode* pImplMapMode = reinterpret_cast<ImplMapMode*>(aStaticImplMapModeAry)+eUnit;
     110     7483720 :     if ( !pImplMapMode->mbSimple )
     111             :     {
     112         751 :         Fraction aDefFraction( 1, 1 );
     113         751 :         pImplMapMode->maScaleX  = aDefFraction;
     114         751 :         pImplMapMode->maScaleY  = aDefFraction;
     115         751 :         pImplMapMode->meUnit    = eUnit;
     116         751 :         pImplMapMode->mbSimple  = true;
     117             :     }
     118             : 
     119     7483720 :     return pImplMapMode;
     120             : }
     121             : 
     122      204608 : inline void MapMode::ImplMakeUnique()
     123             : {
     124             :     // If there are other references, copy
     125      204608 :     if ( mpImplMapMode->mnRefCount != 1 )
     126             :     {
     127       74436 :         if ( mpImplMapMode->mnRefCount )
     128       33532 :             mpImplMapMode->mnRefCount--;
     129       74436 :         mpImplMapMode = new ImplMapMode( *mpImplMapMode );
     130             :     }
     131      204608 : }
     132             : 
     133     5220007 : MapMode::MapMode()
     134             : {
     135             : 
     136     5220007 :     mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
     137     5220007 : }
     138             : 
     139     3699920 : MapMode::MapMode( const MapMode& rMapMode )
     140             : {
     141             :     DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
     142             : 
     143             :     // Take over Shared Instance Data and increment refcount
     144     3699920 :     mpImplMapMode = rMapMode.mpImplMapMode;
     145             :     // RefCount == 0 for static objects
     146     3699920 :     if ( mpImplMapMode->mnRefCount )
     147      463986 :         mpImplMapMode->mnRefCount++;
     148     3699920 : }
     149             : 
     150      435725 : MapMode::MapMode( MapUnit eUnit )
     151             : {
     152             : 
     153      435725 :     mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( eUnit );
     154      435725 : }
     155             : 
     156       44853 : MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
     157             :                   const Fraction& rScaleX, const Fraction& rScaleY )
     158             : {
     159             : 
     160       44853 :     mpImplMapMode           = new ImplMapMode;
     161       44853 :     mpImplMapMode->meUnit   = eUnit;
     162       44853 :     mpImplMapMode->maOrigin = rLogicOrg;
     163       44853 :     mpImplMapMode->maScaleX = rScaleX;
     164       44853 :     mpImplMapMode->maScaleY = rScaleY;
     165       44853 :     mpImplMapMode->maScaleX.ReduceInaccurate(32);
     166       44853 :     mpImplMapMode->maScaleY.ReduceInaccurate(32);
     167       44853 : }
     168             : 
     169     9338538 : MapMode::~MapMode()
     170             : {
     171             : 
     172             :     // If it's not static ImpData and it's the last reference, delete it,
     173             :     // else decrement refcounter
     174     9338538 :     if ( mpImplMapMode->mnRefCount )
     175             :     {
     176      580702 :         if ( mpImplMapMode->mnRefCount == 1 )
     177      107160 :             delete mpImplMapMode;
     178             :         else
     179      473542 :             mpImplMapMode->mnRefCount--;
     180             :     }
     181     9338538 : }
     182             : 
     183       11212 : void MapMode::SetMapUnit( MapUnit eUnit )
     184             : {
     185             : 
     186       11212 :     ImplMakeUnique();
     187       11212 :     mpImplMapMode->meUnit = eUnit;
     188       11212 : }
     189             : 
     190      112507 : void MapMode::SetOrigin( const Point& rLogicOrg )
     191             : {
     192             : 
     193      112507 :     ImplMakeUnique();
     194      112507 :     mpImplMapMode->maOrigin = rLogicOrg;
     195      112507 : }
     196             : 
     197       37696 : void MapMode::SetScaleX( const Fraction& rScaleX )
     198             : {
     199             : 
     200       37696 :     ImplMakeUnique();
     201       37696 :     mpImplMapMode->maScaleX = rScaleX;
     202       37696 :     mpImplMapMode->maScaleX.ReduceInaccurate(32);
     203       37696 : }
     204             : 
     205       37696 : void MapMode::SetScaleY( const Fraction& rScaleY )
     206             : {
     207             : 
     208       37696 :     ImplMakeUnique();
     209       37696 :     mpImplMapMode->maScaleY = rScaleY;
     210       37696 :     mpImplMapMode->maScaleY.ReduceInaccurate(32);
     211       37696 : }
     212             : 
     213     3299688 : MapMode& MapMode::operator=( const MapMode& rMapMode )
     214             : {
     215             :     DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
     216             : 
     217             :     // First increment refcount so that we can reference ourselves
     218             :     // RefCount == 0 for static objects
     219     3299688 :     if ( rMapMode.mpImplMapMode->mnRefCount )
     220      113093 :         rMapMode.mpImplMapMode->mnRefCount++;
     221             : 
     222             :     // If it's not static ImpData and it's the last reference, delete it,
     223             :     // else decrement refcounter
     224     3299688 :     if ( mpImplMapMode->mnRefCount )
     225             :     {
     226       80570 :         if ( mpImplMapMode->mnRefCount == 1 )
     227       10599 :             delete mpImplMapMode;
     228             :         else
     229       69971 :             mpImplMapMode->mnRefCount--;
     230             :     }
     231             : 
     232     3299688 :     mpImplMapMode = rMapMode.mpImplMapMode;
     233             : 
     234     3299688 :     return *this;
     235             : }
     236             : 
     237      675450 : bool MapMode::operator==( const MapMode& rMapMode ) const
     238             : {
     239             : 
     240      675450 :     if ( mpImplMapMode == rMapMode.mpImplMapMode )
     241      225798 :         return true;
     242             : 
     243     1013146 :     if ( (mpImplMapMode->meUnit   == rMapMode.mpImplMapMode->meUnit)   &&
     244      209625 :          (mpImplMapMode->maOrigin == rMapMode.mpImplMapMode->maOrigin) &&
     245      637736 :          (mpImplMapMode->maScaleX == rMapMode.mpImplMapMode->maScaleX) &&
     246       92301 :          (mpImplMapMode->maScaleY == rMapMode.mpImplMapMode->maScaleY) )
     247       92175 :         return true;
     248             :     else
     249      357477 :         return false;
     250             : }
     251             : 
     252     1827988 : bool MapMode::IsDefault() const
     253             : {
     254             : 
     255     1827988 :     ImplMapMode* pDefMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
     256     1827988 :     if ( mpImplMapMode == pDefMapMode )
     257       23765 :         return true;
     258             : 
     259     3634826 :     if ( (mpImplMapMode->meUnit   == pDefMapMode->meUnit)   &&
     260       26694 :          (mpImplMapMode->maOrigin == pDefMapMode->maOrigin) &&
     261     1804571 :          (mpImplMapMode->maScaleX == pDefMapMode->maScaleX) &&
     262          34 :          (mpImplMapMode->maScaleY == pDefMapMode->maScaleY) )
     263          34 :         return true;
     264             :     else
     265     1804189 :         return false;
     266             : }
     267             : 
     268        5497 : SvStream& ReadMapMode( SvStream& rIStm, MapMode& rMapMode )
     269             : {
     270        5497 :     rMapMode.ImplMakeUnique();
     271        5497 :     return ReadImplMapMode( rIStm, *rMapMode.mpImplMapMode );
     272             : }
     273             : 
     274        6111 : SvStream& WriteMapMode( SvStream& rOStm, const MapMode& rMapMode )
     275             : {
     276        6111 :     return WriteImplMapMode( rOStm, *rMapMode.mpImplMapMode );
     277             : }
     278             : 
     279             : 
     280     4725106 : MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
     281             : 
     282     1875953 : const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
     283             : 
     284     3034589 : const Fraction& MapMode::GetScaleX() const { return mpImplMapMode->maScaleX; }
     285             : 
     286     3026988 : const Fraction& MapMode::GetScaleY() const { return mpImplMapMode->maScaleY; }
     287             : 
     288      201931 : bool MapMode::IsSimple() const { return mpImplMapMode->mbSimple; }
     289             : 
     290             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11