LCOV - code coverage report
Current view: top level - vcl/source/gdi - mapmod.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 118 119 99.2 %
Date: 2014-11-03 Functions: 22 22 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 <tools/stream.hxx>
      21             : #include <tools/vcompat.hxx>
      22             : #include <tools/debug.hxx>
      23             : #include <vcl/mapmod.hxx>
      24             : 
      25       68451 : ImplMapMode::ImplMapMode() :
      26             :     maOrigin( 0, 0 ),
      27             :     maScaleX( 1, 1 ),
      28       68451 :     maScaleY( 1, 1 )
      29             : {
      30       68451 :     mnRefCount  = 1;
      31       68451 :     meUnit      = MAP_PIXEL;
      32       68451 :     mbSimple    = false;
      33       68451 : }
      34             : 
      35      111365 : ImplMapMode::ImplMapMode( const ImplMapMode& rImplMapMode ) :
      36             :     maOrigin( rImplMapMode.maOrigin ),
      37             :     maScaleX( rImplMapMode.maScaleX ),
      38      111365 :     maScaleY( rImplMapMode.maScaleY )
      39             : {
      40      111365 :     mnRefCount      = 1;
      41      111365 :     meUnit          = rImplMapMode.meUnit;
      42      111365 :     mbSimple        = false;
      43      111365 : }
      44             : 
      45       10500 : SvStream& ReadImplMapMode( SvStream& rIStm, ImplMapMode& rImplMapMode )
      46             : {
      47       10500 :     VersionCompat   aCompat( rIStm, STREAM_READ );
      48             :     sal_uInt16          nTmp16;
      49             : 
      50       10500 :     rIStm.ReadUInt16( nTmp16 ); rImplMapMode.meUnit = (MapUnit) nTmp16;
      51       10500 :     ReadPair( rIStm, rImplMapMode.maOrigin );
      52       10500 :     ReadFraction( rIStm, rImplMapMode.maScaleX );
      53       10500 :     ReadFraction( rIStm, rImplMapMode.maScaleY );
      54       10500 :     rIStm.ReadCharAsBool( rImplMapMode.mbSimple );
      55             : 
      56       10500 :     return rIStm;
      57             : }
      58             : 
      59       11382 : SvStream& WriteImplMapMode( SvStream& rOStm, const ImplMapMode& rImplMapMode )
      60             : {
      61       11382 :     VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
      62             : 
      63       11382 :     rOStm.WriteUInt16( rImplMapMode.meUnit );
      64       11382 :     WritePair( rOStm, rImplMapMode.maOrigin );
      65       11382 :     WriteFraction( rOStm, rImplMapMode.maScaleX );
      66       11382 :     WriteFraction( rOStm, rImplMapMode.maScaleY );
      67       11382 :     rOStm.WriteUChar( rImplMapMode.mbSimple );
      68             : 
      69       11382 :     return rOStm;
      70             : }
      71             : 
      72    12593013 : ImplMapMode* ImplMapMode::ImplGetStaticMapMode( MapUnit eUnit )
      73             : {
      74             :     static long aStaticImplMapModeAry[(MAP_LASTENUMDUMMY)*sizeof(ImplMapMode)/sizeof(long)];
      75             : 
      76             :     // #i19496 check for out-of-bounds
      77    12593013 :      if( eUnit >= MAP_LASTENUMDUMMY )
      78           0 :         return (ImplMapMode*)aStaticImplMapModeAry;
      79             : 
      80    12593013 :     ImplMapMode* pImplMapMode = ((ImplMapMode*)aStaticImplMapModeAry)+eUnit;
      81    12593013 :     if ( !pImplMapMode->mbSimple )
      82             :     {
      83        1117 :         Fraction aDefFraction( 1, 1 );
      84        1117 :         pImplMapMode->maScaleX  = aDefFraction;
      85        1117 :         pImplMapMode->maScaleY  = aDefFraction;
      86        1117 :         pImplMapMode->meUnit    = eUnit;
      87        1117 :         pImplMapMode->mbSimple  = true;
      88             :     }
      89             : 
      90    12593013 :     return pImplMapMode;
      91             : }
      92             : 
      93      285906 : inline void MapMode::ImplMakeUnique()
      94             : {
      95             :     // If there are other references, copy
      96      285906 :     if ( mpImplMapMode->mnRefCount != 1 )
      97             :     {
      98      111365 :         if ( mpImplMapMode->mnRefCount )
      99       45766 :             mpImplMapMode->mnRefCount--;
     100      111365 :         mpImplMapMode = new ImplMapMode( *mpImplMapMode );
     101             :     }
     102      285906 : }
     103             : 
     104     8894695 : MapMode::MapMode()
     105             : {
     106             : 
     107     8894695 :     mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
     108     8894695 : }
     109             : 
     110     5619997 : MapMode::MapMode( const MapMode& rMapMode )
     111             : {
     112             :     DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
     113             : 
     114             :     // Take over Shared Instance Data and increment refcount
     115     5619997 :     mpImplMapMode = rMapMode.mpImplMapMode;
     116             :     // RefCount == 0 for static objects
     117     5619997 :     if ( mpImplMapMode->mnRefCount )
     118      378275 :         mpImplMapMode->mnRefCount++;
     119     5619997 : }
     120             : 
     121      375160 : MapMode::MapMode( MapUnit eUnit )
     122             : {
     123             : 
     124      375160 :     mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( eUnit );
     125      375160 : }
     126             : 
     127       68451 : MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
     128             :                   const Fraction& rScaleX, const Fraction& rScaleY )
     129             : {
     130             : 
     131       68451 :     mpImplMapMode           = new ImplMapMode;
     132       68451 :     mpImplMapMode->meUnit   = eUnit;
     133       68451 :     mpImplMapMode->maOrigin = rLogicOrg;
     134       68451 :     mpImplMapMode->maScaleX = rScaleX;
     135       68451 :     mpImplMapMode->maScaleY = rScaleY;
     136       68451 : }
     137             : 
     138    14951443 : MapMode::~MapMode()
     139             : {
     140             : 
     141             :     // If it's not static ImpData and it's the last reference, delete it,
     142             :     // else decrement refcounter
     143    14951443 :     if ( mpImplMapMode->mnRefCount )
     144             :     {
     145      564775 :         if ( mpImplMapMode->mnRefCount == 1 )
     146      167864 :             delete mpImplMapMode;
     147             :         else
     148      396911 :             mpImplMapMode->mnRefCount--;
     149             :     }
     150    14951443 : }
     151             : 
     152       18616 : void MapMode::SetMapUnit( MapUnit eUnit )
     153             : {
     154             : 
     155       18616 :     ImplMakeUnique();
     156       18616 :     mpImplMapMode->meUnit = eUnit;
     157       18616 : }
     158             : 
     159      149902 : void MapMode::SetOrigin( const Point& rLogicOrg )
     160             : {
     161             : 
     162      149902 :     ImplMakeUnique();
     163      149902 :     mpImplMapMode->maOrigin = rLogicOrg;
     164      149902 : }
     165             : 
     166       53444 : void MapMode::SetScaleX( const Fraction& rScaleX )
     167             : {
     168             : 
     169       53444 :     ImplMakeUnique();
     170       53444 :     mpImplMapMode->maScaleX = rScaleX;
     171       53444 : }
     172             : 
     173       53444 : void MapMode::SetScaleY( const Fraction& rScaleY )
     174             : {
     175             : 
     176       53444 :     ImplMakeUnique();
     177       53444 :     mpImplMapMode->maScaleY = rScaleY;
     178       53444 : }
     179             : 
     180     5312582 : MapMode& MapMode::operator=( const MapMode& rMapMode )
     181             : {
     182             :     DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
     183             : 
     184             :     // First increment refcount so that we can reference ourselves
     185             :     // RefCount == 0 for static objects
     186     5312582 :     if ( rMapMode.mpImplMapMode->mnRefCount )
     187      147928 :         rMapMode.mpImplMapMode->mnRefCount++;
     188             : 
     189             :     // If it's not static ImpData and it's the last reference, delete it,
     190             :     // else decrement refcounter
     191     5312582 :     if ( mpImplMapMode->mnRefCount )
     192             :     {
     193       95382 :         if ( mpImplMapMode->mnRefCount == 1 )
     194       11881 :             delete mpImplMapMode;
     195             :         else
     196       83501 :             mpImplMapMode->mnRefCount--;
     197             :     }
     198             : 
     199     5312582 :     mpImplMapMode = rMapMode.mpImplMapMode;
     200             : 
     201     5312582 :     return *this;
     202             : }
     203             : 
     204      814329 : bool MapMode::operator==( const MapMode& rMapMode ) const
     205             : {
     206             : 
     207      814329 :     if ( mpImplMapMode == rMapMode.mpImplMapMode )
     208      284578 :         return true;
     209             : 
     210     1230049 :     if ( (mpImplMapMode->meUnit   == rMapMode.mpImplMapMode->meUnit)   &&
     211      319026 :          (mpImplMapMode->maOrigin == rMapMode.mpImplMapMode->maOrigin) &&
     212      820393 :          (mpImplMapMode->maScaleX == rMapMode.mpImplMapMode->maScaleX) &&
     213      142163 :          (mpImplMapMode->maScaleY == rMapMode.mpImplMapMode->maScaleY) )
     214      141923 :         return true;
     215             :     else
     216      387828 :         return false;
     217             : }
     218             : 
     219     3323158 : bool MapMode::IsDefault() const
     220             : {
     221             : 
     222     3323158 :     ImplMapMode* pDefMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
     223     3323158 :     if ( mpImplMapMode == pDefMapMode )
     224       16618 :         return true;
     225             : 
     226     6631876 :     if ( (mpImplMapMode->meUnit   == pDefMapMode->meUnit)   &&
     227       19218 :          (mpImplMapMode->maOrigin == pDefMapMode->maOrigin) &&
     228     3306998 :          (mpImplMapMode->maScaleX == pDefMapMode->maScaleX) &&
     229          36 :          (mpImplMapMode->maScaleY == pDefMapMode->maScaleY) )
     230          36 :         return true;
     231             :     else
     232     3306504 :         return false;
     233             : }
     234             : 
     235       10500 : SvStream& ReadMapMode( SvStream& rIStm, MapMode& rMapMode )
     236             : {
     237       10500 :     rMapMode.ImplMakeUnique();
     238       10500 :     return ReadImplMapMode( rIStm, *rMapMode.mpImplMapMode );
     239             : }
     240             : 
     241       11382 : SvStream& WriteMapMode( SvStream& rOStm, const MapMode& rMapMode )
     242             : {
     243       11382 :     return WriteImplMapMode( rOStm, *rMapMode.mpImplMapMode );
     244        1233 : }
     245             : 
     246             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10