LCOV - code coverage report
Current view: top level - svtools/source/misc - unitconv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 285 11.2 %
Date: 2012-08-25 Functions: 2 41 4.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 187 4.8 %

           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 2008 by Sun Microsystems, Inc.
       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                 :            : #include <svtools/unitconv.hxx>
      30                 :            : 
      31                 :            : // -----------------------------------------------------------------------
      32                 :            : 
      33                 :        129 : void SetFieldUnit( MetricField& rField, FieldUnit eUnit, sal_Bool bAll )
      34                 :            : {
      35                 :        129 :     sal_Int64 nFirst    = rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) );
      36                 :        129 :     sal_Int64 nLast = rField.Denormalize( rField.GetLast( FUNIT_TWIP ) );
      37                 :        129 :     sal_Int64 nMin = rField.Denormalize( rField.GetMin( FUNIT_TWIP ) );
      38                 :        129 :     sal_Int64 nMax = rField.Denormalize( rField.GetMax( FUNIT_TWIP ) );
      39                 :            : 
      40         [ +  - ]:        129 :     if ( !bAll )
      41                 :            :     {
      42      [ -  -  + ]:        129 :         switch ( eUnit )
      43                 :            :         {
      44                 :            :             case FUNIT_M:
      45                 :            :             case FUNIT_KM:
      46                 :          0 :                 eUnit = FUNIT_CM;
      47                 :          0 :                 break;
      48                 :            : 
      49                 :            :             case FUNIT_FOOT:
      50                 :            :             case FUNIT_MILE:
      51                 :          0 :                 eUnit = FUNIT_INCH;
      52                 :        129 :                 break;
      53                 :            :             default: ;//prevent warning
      54                 :            :         }
      55                 :            :     }
      56                 :        129 :     rField.SetUnit( eUnit );
      57      [ -  +  - ]:        129 :     switch( eUnit )
      58                 :            :     {
      59                 :            :         // _CHAR and _LINE sets the step of "char" and "line" unit, they are same as FUNIT_MM
      60                 :            :         case FUNIT_CHAR:
      61                 :            :         case FUNIT_LINE:
      62                 :            :         case FUNIT_MM:
      63                 :          0 :             rField.SetSpinSize( 50 );
      64                 :          0 :             break;
      65                 :            : 
      66                 :            :         case FUNIT_INCH:
      67                 :        129 :             rField.SetSpinSize( 2 );
      68                 :        129 :             break;
      69                 :            : 
      70                 :            :         default:
      71                 :          0 :             rField.SetSpinSize( 10 );
      72                 :            :     }
      73                 :            : 
      74         [ -  + ]:        129 :     if ( FUNIT_POINT == eUnit )
      75                 :            :     {
      76         [ #  # ]:          0 :         if( rField.GetDecimalDigits() > 1 )
      77                 :          0 :             rField.SetDecimalDigits( 1 );
      78                 :            :     }
      79                 :            :     else
      80                 :        129 :         rField.SetDecimalDigits( 2 );
      81                 :            : 
      82         [ +  - ]:        129 :     if ( !bAll )
      83                 :            :     {
      84                 :        129 :         rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
      85                 :        129 :         rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
      86                 :        129 :         rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
      87                 :        129 :         rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
      88                 :            :     }
      89                 :        129 : }
      90                 :            : 
      91                 :            : // -----------------------------------------------------------------------
      92                 :            : 
      93                 :          0 : void SetFieldUnit( MetricBox& rBox, FieldUnit eUnit, sal_Bool bAll )
      94                 :            : {
      95                 :          0 :     sal_Int64 nMin = rBox.Denormalize( rBox.GetMin( FUNIT_TWIP ) );
      96                 :          0 :     sal_Int64 nMax = rBox.Denormalize( rBox.GetMax( FUNIT_TWIP ) );
      97                 :            : 
      98         [ #  # ]:          0 :     if ( !bAll )
      99                 :            :     {
     100      [ #  #  # ]:          0 :         switch ( eUnit )
     101                 :            :         {
     102                 :            :             case FUNIT_M:
     103                 :            :             case FUNIT_KM:
     104                 :          0 :                 eUnit = FUNIT_CM;
     105                 :          0 :                 break;
     106                 :            : 
     107                 :            :             case FUNIT_FOOT:
     108                 :            :             case FUNIT_MILE:
     109                 :          0 :                 eUnit = FUNIT_INCH;
     110                 :          0 :                 break;
     111                 :            :             default: ;//prevent warning
     112                 :            :         }
     113                 :            :     }
     114                 :          0 :     rBox.SetUnit( eUnit );
     115                 :            : 
     116 [ #  # ][ #  # ]:          0 :     if ( FUNIT_POINT == eUnit && rBox.GetDecimalDigits() > 1 )
                 [ #  # ]
     117                 :          0 :         rBox.SetDecimalDigits( 1 );
     118                 :            :     else
     119                 :          0 :         rBox.SetDecimalDigits( 2 );
     120                 :            : 
     121         [ #  # ]:          0 :     if ( !bAll )
     122                 :            :     {
     123                 :          0 :         rBox.SetMin( rBox.Normalize( nMin ), FUNIT_TWIP );
     124                 :          0 :         rBox.SetMax( rBox.Normalize( nMax ), FUNIT_TWIP );
     125                 :            :     }
     126                 :          0 : }
     127                 :            : 
     128                 :            : // -----------------------------------------------------------------------
     129                 :          0 : void SetMetricValue( MetricField& rField, long nCoreValue, SfxMapUnit eUnit )
     130                 :            : {
     131                 :          0 :     sal_Int64 nVal = OutputDevice::LogicToLogic( nCoreValue, (MapUnit)eUnit, MAP_100TH_MM );
     132                 :          0 :     nVal = rField.Normalize( nVal );
     133                 :          0 :     rField.SetValue( nVal, FUNIT_100TH_MM );
     134                 :            : 
     135                 :          0 : }
     136                 :            : 
     137                 :            : // -----------------------------------------------------------------------
     138                 :            : 
     139                 :        150 : long GetCoreValue( const MetricField& rField, SfxMapUnit eUnit )
     140                 :            : {
     141                 :        150 :     sal_Int64 nVal = rField.GetValue( FUNIT_100TH_MM );
     142                 :            :     // avoid rounding issues
     143                 :        150 :     const sal_Int64 nSizeMask = 0xffffffffff000000LL;
     144                 :        150 :     bool bRoundBefore = true;
     145         [ +  - ]:        150 :     if( nVal >= 0 )
     146                 :            :     {
     147         [ +  - ]:        150 :         if( (nVal & nSizeMask) == 0 )
     148                 :        150 :             bRoundBefore = false;
     149                 :            :     }
     150                 :            :     else
     151                 :            :     {
     152         [ #  # ]:          0 :         if( ((-nVal) & nSizeMask ) == 0 )
     153                 :          0 :             bRoundBefore = false;
     154                 :            :     }
     155         [ -  + ]:        150 :     if( bRoundBefore )
     156                 :          0 :         nVal = rField.Denormalize( nVal );
     157                 :        150 :     sal_Int64 nUnitVal = OutputDevice::LogicToLogic( static_cast<long>(nVal), MAP_100TH_MM, (MapUnit)eUnit );
     158         [ +  - ]:        150 :     if( ! bRoundBefore )
     159                 :        150 :         nUnitVal = rField.Denormalize( nUnitVal );
     160                 :        150 :     return static_cast<long>(nUnitVal);
     161                 :            : }
     162                 :            : 
     163                 :            : // -----------------------------------------------------------------------
     164                 :            : 
     165                 :          0 : long CalcToUnit( float nIn, SfxMapUnit eUnit )
     166                 :            : {
     167                 :            :     // nIn ist in Points
     168                 :            : 
     169                 :            :     DBG_ASSERT( eUnit == SFX_MAPUNIT_TWIP       ||
     170                 :            :                 eUnit == SFX_MAPUNIT_100TH_MM   ||
     171                 :            :                 eUnit == SFX_MAPUNIT_10TH_MM    ||
     172                 :            :                 eUnit == SFX_MAPUNIT_MM         ||
     173                 :            :                 eUnit == SFX_MAPUNIT_CM, "this unit is not implemented" );
     174                 :            : 
     175                 :          0 :     float nTmp = nIn;
     176                 :            : 
     177         [ #  # ]:          0 :     if ( SFX_MAPUNIT_TWIP != eUnit )
     178                 :          0 :         nTmp = nIn * 10 / 567;
     179                 :            : 
     180   [ #  #  #  #  :          0 :     switch ( eUnit )
                      # ]
     181                 :            :     {
     182                 :          0 :         case SFX_MAPUNIT_100TH_MM:  nTmp *= 100; break;
     183                 :          0 :         case SFX_MAPUNIT_10TH_MM:   nTmp *= 10;  break;
     184                 :          0 :         case SFX_MAPUNIT_MM:                     break;
     185                 :          0 :         case SFX_MAPUNIT_CM:        nTmp /= 10;  break;
     186                 :            :         default: ;//prevent warning
     187                 :            :     }
     188                 :            : 
     189                 :          0 :     nTmp *= 20;
     190                 :          0 :     long nRet = (long)nTmp;
     191                 :          0 :     return nRet;
     192                 :            : //! return (long)(nTmp * 20);
     193                 :            : }
     194                 :            : 
     195                 :            : // -----------------------------------------------------------------------
     196                 :            : 
     197                 :          0 : long ItemToControl( long nIn, SfxMapUnit eItem, SfxFieldUnit eCtrl )
     198                 :            : {
     199                 :          0 :     long nOut = 0;
     200                 :            : 
     201   [ #  #  #  #  :          0 :     switch ( eItem )
                   #  # ]
     202                 :            :     {
     203                 :            :         case SFX_MAPUNIT_100TH_MM:
     204                 :            :         case SFX_MAPUNIT_10TH_MM:
     205                 :            :         case SFX_MAPUNIT_MM:
     206                 :            :         {
     207         [ #  # ]:          0 :             if ( eItem == SFX_MAPUNIT_10TH_MM )
     208                 :          0 :                 nIn /= 10;
     209         [ #  # ]:          0 :             else if ( eItem == SFX_MAPUNIT_100TH_MM )
     210                 :          0 :                 nIn /= 100;
     211                 :          0 :             nOut = TransformMetric( nIn, FUNIT_MM, (FieldUnit)eCtrl );
     212                 :            :         }
     213                 :          0 :         break;
     214                 :            : 
     215                 :            :         case SFX_MAPUNIT_CM:
     216                 :            :         {
     217                 :          0 :             nOut = TransformMetric( nIn, FUNIT_CM, (FieldUnit)eCtrl );
     218                 :            :         }
     219                 :          0 :         break;
     220                 :            : 
     221                 :            :         case SFX_MAPUNIT_1000TH_INCH:
     222                 :            :         case SFX_MAPUNIT_100TH_INCH:
     223                 :            :         case SFX_MAPUNIT_10TH_INCH:
     224                 :            :         case SFX_MAPUNIT_INCH:
     225                 :            :         {
     226         [ #  # ]:          0 :             if ( eItem == SFX_MAPUNIT_10TH_INCH )
     227                 :          0 :                 nIn /= 10;
     228         [ #  # ]:          0 :             else if ( eItem == SFX_MAPUNIT_100TH_INCH )
     229                 :          0 :                 nIn /= 100;
     230         [ #  # ]:          0 :             else if ( eItem == SFX_MAPUNIT_1000TH_INCH )
     231                 :          0 :                 nIn /= 1000;
     232                 :          0 :             nOut = TransformMetric( nIn, FUNIT_INCH, (FieldUnit)eCtrl );
     233                 :            :         }
     234                 :          0 :         break;
     235                 :            : 
     236                 :            :         case SFX_MAPUNIT_POINT:
     237                 :            :         {
     238                 :          0 :             nOut = TransformMetric( nIn, FUNIT_POINT, (FieldUnit)eCtrl );
     239                 :            :         }
     240                 :          0 :         break;
     241                 :            : 
     242                 :            :         case SFX_MAPUNIT_TWIP:
     243                 :            :         {
     244                 :          0 :             nOut = TransformMetric( nIn, FUNIT_TWIP, (FieldUnit)eCtrl );
     245                 :            :         }
     246                 :          0 :         break;
     247                 :            :         default: ;//prevent warning
     248                 :            :     }
     249                 :          0 :     return nOut;
     250                 :            : }
     251                 :            : 
     252                 :            : // -----------------------------------------------------------------------
     253                 :            : 
     254                 :          0 : long ControlToItem( long nIn, SfxFieldUnit eCtrl, SfxMapUnit eItem )
     255                 :            : {
     256                 :          0 :     return ItemToControl( nIn, eItem, eCtrl );
     257                 :            : }
     258                 :            : 
     259                 :            : // -----------------------------------------------------------------------
     260                 :            : 
     261                 :          0 : FieldUnit MapToFieldUnit( const SfxMapUnit eUnit )
     262                 :            : {
     263   [ #  #  #  #  :          0 :     switch ( eUnit )
                   #  # ]
     264                 :            :     {
     265                 :            :         case SFX_MAPUNIT_100TH_MM:
     266                 :            :         case SFX_MAPUNIT_10TH_MM:
     267                 :            :         case SFX_MAPUNIT_MM:
     268                 :          0 :             return FUNIT_MM;
     269                 :            : 
     270                 :            :         case SFX_MAPUNIT_CM:
     271                 :          0 :             return FUNIT_CM;
     272                 :            : 
     273                 :            :         case SFX_MAPUNIT_1000TH_INCH:
     274                 :            :         case SFX_MAPUNIT_100TH_INCH:
     275                 :            :         case SFX_MAPUNIT_10TH_INCH:
     276                 :            :         case SFX_MAPUNIT_INCH:
     277                 :          0 :             return FUNIT_INCH;
     278                 :            : 
     279                 :            :         case SFX_MAPUNIT_POINT:
     280                 :          0 :             return FUNIT_POINT;
     281                 :            : 
     282                 :            :         case SFX_MAPUNIT_TWIP:
     283                 :          0 :             return FUNIT_TWIP;
     284                 :            :         default: ;//prevent warning
     285                 :            :     }
     286                 :          0 :     return FUNIT_NONE;
     287                 :            : }
     288                 :            : 
     289                 :            : // -----------------------------------------------------------------------
     290                 :            : 
     291                 :          0 : long CalcToPoint( long nIn, SfxMapUnit eUnit, sal_uInt16 nFaktor )
     292                 :            : {
     293                 :            :     DBG_ASSERT( eUnit == SFX_MAPUNIT_TWIP       ||
     294                 :            :                 eUnit == SFX_MAPUNIT_100TH_MM   ||
     295                 :            :                 eUnit == SFX_MAPUNIT_10TH_MM    ||
     296                 :            :                 eUnit == SFX_MAPUNIT_MM         ||
     297                 :            :                 eUnit == SFX_MAPUNIT_CM, "this unit is not implemented" );
     298                 :            : 
     299                 :          0 :     long nRet = 0;
     300                 :            : 
     301         [ #  # ]:          0 :     if ( SFX_MAPUNIT_TWIP == eUnit )
     302                 :          0 :         nRet = nIn;
     303                 :            :     else
     304                 :          0 :         nRet = nIn * 567;
     305                 :            : 
     306   [ #  #  #  #  :          0 :     switch ( eUnit )
                      # ]
     307                 :            :     {
     308                 :          0 :         case SFX_MAPUNIT_100TH_MM:  nRet /= 100; break;
     309                 :          0 :         case SFX_MAPUNIT_10TH_MM:   nRet /= 10;  break;
     310                 :          0 :         case SFX_MAPUNIT_MM:                     break;
     311                 :          0 :         case SFX_MAPUNIT_CM:        nRet *= 10;  break;
     312                 :            :         default: ;//prevent warning
     313                 :            :     }
     314                 :            : 
     315                 :            :     // ggf. aufrunden
     316         [ #  # ]:          0 :     if ( SFX_MAPUNIT_TWIP != eUnit )
     317                 :            :     {
     318                 :          0 :         long nMod = 10;
     319                 :          0 :         long nTmp = nRet % nMod;
     320                 :            : 
     321         [ #  # ]:          0 :         if ( nTmp >= 4 )
     322                 :          0 :             nRet += 10 - nTmp;
     323                 :          0 :         nRet /= 10;
     324                 :            :     }
     325                 :          0 :     return nRet * nFaktor / 20;
     326                 :            : }
     327                 :            : 
     328                 :            : // -----------------------------------------------------------------------
     329                 :            : 
     330                 :          0 : long CMToTwips( long nIn )
     331                 :            : {
     332                 :          0 :     long nRet = 0;
     333                 :            : 
     334 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
     335                 :          0 :         nRet = nIn * 567;
     336                 :          0 :     return nRet;
     337                 :            : }
     338                 :            : 
     339                 :            : // -----------------------------------------------------------------------
     340                 :            : 
     341                 :          0 : long MMToTwips( long nIn )
     342                 :            : {
     343                 :          0 :     long nRet = 0;
     344                 :            : 
     345 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
     346                 :          0 :         nRet = nIn * 567 / 10;
     347                 :          0 :     return nRet;
     348                 :            : }
     349                 :            : 
     350                 :            : // -----------------------------------------------------------------------
     351                 :            : 
     352                 :          0 : long InchToTwips( long nIn )
     353                 :            : {
     354                 :          0 :     long nRet = 0;
     355                 :            : 
     356 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 1440 ) && nIn >= ( LONG_MIN / 1440 ) )
     357                 :          0 :         nRet = nIn * 1440;
     358                 :          0 :     return nRet;
     359                 :            : }
     360                 :            : 
     361                 :            : // -----------------------------------------------------------------------
     362                 :            : 
     363                 :          0 : long PointToTwips( long nIn )
     364                 :            : {
     365                 :          0 :     long nRet = 0;
     366                 :            : 
     367 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 20 ) && nIn >= ( LONG_MIN / 20 ) )
     368                 :          0 :         nRet = nIn * 20;
     369                 :          0 :     return nRet;
     370                 :            : }
     371                 :            : 
     372                 :            : // -----------------------------------------------------------------------
     373                 :            : 
     374                 :          0 : long PicaToTwips( long nIn )
     375                 :            : {
     376                 :          0 :     long nRet = 0;
     377                 :            : 
     378 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 240 ) && nIn >= ( LONG_MIN / 240 ) )
     379                 :          0 :         nRet = nIn * 240;
     380                 :          0 :     return nRet;
     381                 :            : }
     382                 :            : 
     383                 :            : // -----------------------------------------------------------------------
     384                 :            : 
     385                 :          0 : long TwipsToCM( long nIn )
     386                 :            : {
     387                 :          0 :     long nRet = nIn / 567;
     388                 :          0 :     return nRet;
     389                 :            : }
     390                 :            : 
     391                 :            : // -----------------------------------------------------------------------
     392                 :            : 
     393                 :          0 : long InchToCM( long nIn )
     394                 :            : {
     395                 :          0 :     long nRet = 0;
     396                 :            : 
     397 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 254 ) && nIn >= ( LONG_MIN / 254 ) )
     398                 :          0 :         nRet = nIn * 254 / 100;
     399                 :          0 :     return nRet;
     400                 :            : }
     401                 :            : 
     402                 :            : // -----------------------------------------------------------------------
     403                 :            : 
     404                 :          0 : long MMToCM( long nIn )
     405                 :            : {
     406                 :          0 :     long nRet = nIn / 10;
     407                 :          0 :     return nRet;
     408                 :            : }
     409                 :            : 
     410                 :            : // -----------------------------------------------------------------------
     411                 :            : 
     412                 :          0 : long PointToCM( long nIn )
     413                 :            : {
     414                 :          0 :     long nRet = 0;
     415                 :            : 
     416 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 20 ) && nIn >= ( LONG_MIN / 20 ) )
     417                 :          0 :         nRet = nIn * 20 / 567;
     418                 :          0 :     return nRet;
     419                 :            : }
     420                 :            : 
     421                 :            : // -----------------------------------------------------------------------
     422                 :            : 
     423                 :          0 : long PicaToCM( long nIn)
     424                 :            : {
     425                 :          0 :     long nRet = 0;
     426                 :            : 
     427 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 12 / 20 ) && nIn >= ( LONG_MIN / 12 / 20 ) )
     428                 :          0 :         nRet = nIn * 12 * 20 / 567;
     429                 :          0 :     return nRet;
     430                 :            : }
     431                 :            : 
     432                 :            : // -----------------------------------------------------------------------
     433                 :            : 
     434                 :          0 : long TwipsToMM( long nIn )
     435                 :            : {
     436                 :          0 :     long nRet = 0;
     437                 :            : 
     438 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
     439                 :          0 :         nRet = nIn * 10 / 566;
     440                 :          0 :     return nRet;
     441                 :            : }
     442                 :            : 
     443                 :            : // -----------------------------------------------------------------------
     444                 :            : 
     445                 :          0 : long CMToMM( long nIn )
     446                 :            : {
     447                 :          0 :     long nRet = 0;
     448                 :            : 
     449 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
     450                 :          0 :         nRet = nIn * 10;
     451                 :          0 :     return nRet;
     452                 :            : }
     453                 :            : 
     454                 :            : // -----------------------------------------------------------------------
     455                 :            : 
     456                 :          0 : long InchToMM( long nIn )
     457                 :            : {
     458                 :          0 :     long nRet = 0;
     459                 :            : 
     460 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 254 ) && nIn >= ( LONG_MIN / 254 ) )
     461                 :          0 :         nRet = nIn * 254 / 10;
     462                 :          0 :     return nRet;
     463                 :            : }
     464                 :            : 
     465                 :            : // -----------------------------------------------------------------------
     466                 :            : 
     467                 :          0 : long PointToMM( long nIn )
     468                 :            : {
     469                 :          0 :     long nRet = 0;
     470                 :            : 
     471 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 200 ) && nIn >= ( LONG_MIN / 200 ) )
     472                 :          0 :         nRet = nIn * 200 / 567;
     473                 :          0 :     return nRet;
     474                 :            : }
     475                 :            : 
     476                 :            : // -----------------------------------------------------------------------
     477                 :            : 
     478                 :          0 : long PicaToMM( long nIn )
     479                 :            : {
     480                 :          0 :     long nRet = 0;
     481                 :            : 
     482 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 12 / 200 ) && nIn >= ( LONG_MIN / 12 / 200 ) )
     483                 :          0 :         nRet = nIn * 12 * 200 / 567;
     484                 :          0 :     return nRet;
     485                 :            : }
     486                 :            : 
     487                 :            : // -----------------------------------------------------------------------
     488                 :            : 
     489                 :          0 : long TwipsToInch( long nIn )
     490                 :            : {
     491                 :          0 :     long nRet = nIn / 1440;
     492                 :          0 :     return nRet;
     493                 :            : }
     494                 :            : 
     495                 :            : // -----------------------------------------------------------------------
     496                 :            : 
     497                 :          0 : long CMToInch( long nIn )
     498                 :            : {
     499                 :          0 :     long nRet = 0;
     500                 :            : 
     501 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 100 ) && nIn >= ( LONG_MIN / 100 ) )
     502                 :          0 :         nRet = nIn * 100 / 254;
     503                 :          0 :     return nRet;
     504                 :            : }
     505                 :            : 
     506                 :            : // -----------------------------------------------------------------------
     507                 :            : 
     508                 :          0 : long MMToInch( long nIn )
     509                 :            : {
     510                 :          0 :     long nRet = 0;
     511                 :            : 
     512 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 10 ) && nIn >= ( LONG_MIN / 10 ) )
     513                 :          0 :         nRet = nIn * 10 / 254;
     514                 :          0 :     return nRet;
     515                 :            : }
     516                 :            : 
     517                 :            : // -----------------------------------------------------------------------
     518                 :            : 
     519                 :          0 : long PointToInch( long nIn )
     520                 :            : {
     521                 :          0 :     long nRet = nIn / 72;
     522                 :          0 :     return nRet;
     523                 :            : }
     524                 :            : 
     525                 :            : // -----------------------------------------------------------------------
     526                 :            : 
     527                 :          0 : long PicaToInch( long nIn )
     528                 :            : {
     529                 :          0 :     long nRet = nIn / 6;
     530                 :          0 :     return nRet;
     531                 :            : }
     532                 :            : 
     533                 :            : // -----------------------------------------------------------------------
     534                 :            : 
     535                 :          0 : long TwipsToPoint( long nIn )
     536                 :            : {
     537                 :          0 :     long nRet = nIn / 20;
     538                 :          0 :     return nRet;
     539                 :            : }
     540                 :            : 
     541                 :            : // -----------------------------------------------------------------------
     542                 :            : 
     543                 :          0 : long InchToPoint( long nIn )
     544                 :            : {
     545                 :          0 :     long nRet = 0;
     546                 :            : 
     547 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 72 ) && nIn >= ( LONG_MIN / 72 ) )
     548                 :          0 :         nRet = nIn * 72;
     549                 :          0 :     return nRet;
     550                 :            : }
     551                 :            : 
     552                 :            : // -----------------------------------------------------------------------
     553                 :            : 
     554                 :          0 : long CMToPoint( long nIn )
     555                 :            : {
     556                 :          0 :     long nRet = 0;
     557                 :            : 
     558 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
     559                 :          0 :         nRet = nIn * 567 / 20;
     560                 :          0 :     return nRet;
     561                 :            : }
     562                 :            : 
     563                 :            : // -----------------------------------------------------------------------
     564                 :            : 
     565                 :          0 : long MMToPoint( long nIn )
     566                 :            : {
     567                 :          0 :     long nRet = 0;
     568                 :            : 
     569 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
     570                 :          0 :         nRet = nIn * 567 / 200;
     571                 :          0 :     return nRet;
     572                 :            : }
     573                 :            : 
     574                 :            : // -----------------------------------------------------------------------
     575                 :            : 
     576                 :          0 : long PicaToPoint( long nIn )
     577                 :            : {
     578                 :          0 :     long nRet = nIn / 12;
     579                 :          0 :     return nRet;
     580                 :            : }
     581                 :            : 
     582                 :            : // -----------------------------------------------------------------------
     583                 :            : 
     584                 :          0 : long TwipsToPica( long nIn )
     585                 :            : {
     586                 :          0 :     long nRet = nIn / 240;
     587                 :          0 :     return nRet;
     588                 :            : }
     589                 :            : 
     590                 :            : // -----------------------------------------------------------------------
     591                 :            : 
     592                 :          0 : long InchToPica( long nIn )
     593                 :            : {
     594                 :          0 :     long nRet = 0;
     595                 :            : 
     596 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 6 ) && nIn >= ( LONG_MIN / 6 ) )
     597                 :          0 :         nRet = nIn * 6;
     598                 :          0 :     return nRet;
     599                 :            : }
     600                 :            : 
     601                 :            : // -----------------------------------------------------------------------
     602                 :            : 
     603                 :          0 : long PointToPica( long nIn )
     604                 :            : {
     605                 :          0 :     long nRet = 0;
     606                 :            : 
     607 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 12 ) && nIn >= ( LONG_MIN / 12 ) )
     608                 :          0 :         nRet = nIn * 12;
     609                 :          0 :     return nRet;
     610                 :            : }
     611                 :            : 
     612                 :            : // -----------------------------------------------------------------------
     613                 :            : 
     614                 :          0 : long CMToPica( long nIn )
     615                 :            : {
     616                 :          0 :     long nRet = 0;
     617                 :            : 
     618 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
     619                 :          0 :         nRet = nIn * 567 / 20 / 12;
     620                 :          0 :     return nRet;
     621                 :            : }
     622                 :            : 
     623                 :            : // -----------------------------------------------------------------------
     624                 :            : 
     625                 :          0 : long MMToPica( long nIn )
     626                 :            : {
     627                 :          0 :     long nRet = 0;
     628                 :            : 
     629 [ #  # ][ #  # ]:          0 :     if ( nIn <= ( LONG_MAX / 567 ) && nIn >= ( LONG_MIN / 567 ) )
     630                 :          0 :         nRet = nIn * 567 / 200 / 12;
     631                 :          0 :     return nRet;
     632                 :            : }
     633                 :            : 
     634                 :            : // -----------------------------------------------------------------------
     635                 :            : 
     636                 :          0 : long Nothing( long nIn )
     637                 :            : {
     638                 :          0 :     long nRet = nIn;
     639                 :          0 :     return nRet;
     640                 :            : }
     641                 :            : 
     642                 :            : FUNC_CONVERT ConvertTable[6][6] =
     643                 :            : {
     644                 :            : //  CM,         MM          INCH         POINT        PICAS=32     TWIPS
     645                 :            :     { Nothing,  CMToMM,     CMToInch,    CMToPoint,   CMToPica,    CMToTwips },
     646                 :            :     { MMToCM,       Nothing,    MMToInch,    MMToPoint,   MMToPica,    MMToTwips },
     647                 :            :     { InchToCM, InchToMM,   Nothing,     InchToPoint, InchToPica,  InchToTwips },
     648                 :            :     { PointToCM,    PointToMM,  PointToInch, Nothing,     PointToPica, PointToTwips },
     649                 :            :     { PicaToCM, PicaToMM,   PicaToInch,  PicaToPoint, Nothing,     PicaToTwips },
     650                 :            :     { TwipsToCM,    TwipsToMM,  TwipsToInch, TwipsToPoint,TwipsToPica, Nothing }
     651                 :            : };
     652                 :            : 
     653                 :            : // -----------------------------------------------------------------------
     654                 :            : 
     655                 :          0 : long TransformMetric( long nVal, FieldUnit aOld, FieldUnit aNew )
     656                 :            : {
     657 [ #  # ][ #  # ]:          0 :     if ( aOld == FUNIT_NONE   || aNew == FUNIT_NONE ||
         [ #  # ][ #  # ]
     658                 :            :          aOld == FUNIT_CUSTOM || aNew == FUNIT_CUSTOM )
     659                 :            :     {
     660                 :          0 :         return nVal;
     661                 :            :     }
     662                 :            : 
     663                 :          0 :     sal_uInt16 nOld = 0;
     664                 :          0 :     sal_uInt16 nNew = 0;
     665                 :            : 
     666   [ #  #  #  #  :          0 :     switch ( aOld )
                #  #  # ]
     667                 :            :     {
     668                 :            :         case FUNIT_CM:
     669                 :          0 :             nOld = 0; break;
     670                 :            :         case FUNIT_MM:
     671                 :          0 :             nOld = 1; break;
     672                 :            :         case FUNIT_INCH:
     673                 :          0 :             nOld = 2; break;
     674                 :            :         case FUNIT_POINT:
     675                 :          0 :             nOld = 3; break;
     676                 :            :         case FUNIT_PICA:
     677                 :          0 :             nOld = 4; break;
     678                 :            :         case FUNIT_TWIP:
     679                 :          0 :             nOld = 5; break;
     680                 :            :         default: ;//prevent warning
     681                 :            :     }
     682                 :            : 
     683   [ #  #  #  #  :          0 :     switch ( aNew )
                #  #  # ]
     684                 :            :     {
     685                 :            :         case FUNIT_CM:
     686                 :          0 :             nNew = 0; break;
     687                 :            :         case FUNIT_MM:
     688                 :          0 :             nNew = 1; break;
     689                 :            :         case FUNIT_INCH:
     690                 :          0 :             nNew = 2; break;
     691                 :            :         case FUNIT_POINT:
     692                 :          0 :             nNew = 3; break;
     693                 :            :         case FUNIT_PICA:
     694                 :          0 :             nNew = 4; break;
     695                 :            :         case FUNIT_TWIP:
     696                 :          0 :             nNew = 5; break;
     697                 :            :         default: ;//prevent warning
     698                 :            :     }
     699                 :          0 :     return ConvertTable[nOld][nNew]( nVal );
     700                 :            : }
     701                 :            : 
     702                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10