LCOV - code coverage report
Current view: top level - sc/source/filter/inc - unitconverter.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1 100.0 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 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 OOX_XLS_UNITCONVERTER_HXX
      30                 :            : #define OOX_XLS_UNITCONVERTER_HXX
      31                 :            : 
      32                 :            : #include <map>
      33                 :            : #include <vector>
      34                 :            : #include "workbookhelper.hxx"
      35                 :            : 
      36                 :            : namespace com { namespace sun { namespace star {
      37                 :            :     namespace util { struct Date; struct DateTime; }
      38                 :            : } } }
      39                 :            : 
      40                 :            : namespace oox {
      41                 :            : namespace xls {
      42                 :            : 
      43                 :            : // ============================================================================
      44                 :            : 
      45                 :            : /** Units supported by the UnitConverter class. */
      46                 :            : enum Unit
      47                 :            : {
      48                 :            :     UNIT_INCH,          /// Inches.
      49                 :            :     UNIT_POINT,         /// Points.
      50                 :            :     UNIT_TWIP,          /// Twips (1/20 point).
      51                 :            :     UNIT_EMU,           /// English Metric Unit (1/360,000 cm).
      52                 :            :     UNIT_SCREENX,       /// Horizontal screen pixels.
      53                 :            :     UNIT_SCREENY,       /// Vertical screen pixels.
      54                 :            :     UNIT_REFDEVX,       /// Horizontal pixels in Calc reference device.
      55                 :            :     UNIT_REFDEVY,       /// Vertical pixels in Calc reference device.
      56                 :            :     UNIT_DIGIT,         /// Digit width of document default font.
      57                 :            :     UNIT_SPACE,         /// Space character width of document default font.
      58                 :            : 
      59                 :            :     UNIT_ENUM_SIZE
      60                 :            : };
      61                 :            : 
      62                 :            : /** Helper class that provides functions to convert values from and to
      63                 :            :     different units.
      64                 :            : 
      65                 :            :     Provides functions to calculate the width of certain characters of the
      66                 :            :     default font of the imported/exported document. The default font is always
      67                 :            :     the first font in the styles font list, and is always referenced by the
      68                 :            :     default cell style ("Normal" style in Excel) which is used by all empty
      69                 :            :     unformatted cells in the document. To be able to calculate the charcter
      70                 :            :     width correctly, the default font must be known, which is the case after
      71                 :            :     the finalizeImport() or finalizeExport() functions have been called. Caller
      72                 :            :     must make sure to not call the character width conversion functions before.
      73                 :            :  */
      74         [ -  + ]:         48 : class UnitConverter : public WorkbookHelper
      75                 :            : {
      76                 :            : public:
      77                 :            :     explicit            UnitConverter( const WorkbookHelper& rHelper );
      78                 :            : 
      79                 :            :     /** Final processing after import of all style settings. */
      80                 :            :     void                finalizeImport();
      81                 :            :     /** Updates internal nulldate for date/serial conversion. */
      82                 :            :     void                finalizeNullDate( const ::com::sun::star::util::Date& rNullDate );
      83                 :            : 
      84                 :            :     /** Converts the passed value between the passed units. */
      85                 :            :     double              scaleValue( double fValue, Unit eFromUnit, Unit eToUnit ) const;
      86                 :            : 
      87                 :            :     /** Converts the passed value to 1/100 millimeters. */
      88                 :            :     sal_Int32           scaleToMm100( double fValue, Unit eUnit ) const;
      89                 :            :     /** Converts the passed value from 1/100 millimeters to the passed unit. */
      90                 :            :     double              scaleFromMm100( sal_Int32 nMm100, Unit eUnit ) const;
      91                 :            : 
      92                 :            :     /** Returns the serial value of the passed datetime, based on current nulldate. */
      93                 :            :     double              calcSerialFromDateTime( const ::com::sun::star::util::DateTime& rDateTime ) const;
      94                 :            :     /** Returns the datetime of the passed serial value, based on current nulldate. */
      95                 :            :     ::com::sun::star::util::DateTime calcDateTimeFromSerial( double fSerial ) const;
      96                 :            : 
      97                 :            :     /** Returns a BIFF error code from the passed error string. */
      98                 :            :     sal_uInt8           calcBiffErrorCode( const ::rtl::OUString& rErrorCode ) const;
      99                 :            : 
     100                 :            : private:
     101                 :            :     /** Adds an error code to the internal maps. */
     102                 :            :     void                addErrorCode( sal_uInt8 nErrorCode, const ::rtl::OUString& rErrorCode );
     103                 :            :     /** Returns the conversion coefficient for the passed unit. */
     104                 :            :     double              getCoefficient( Unit eUnit ) const;
     105                 :            : 
     106                 :            : private:
     107                 :            :     typedef ::std::vector< double >                     DoubleVector;
     108                 :            :     typedef ::std::map< ::rtl::OUString, sal_uInt8 >    OoxErrorCodeMap;
     109                 :            :     typedef ::std::map< sal_uInt8, ::rtl::OUString >    BiffErrorCodeMap;
     110                 :            : 
     111                 :            :     DoubleVector        maCoeffs;           /// Coefficients for unit conversion.
     112                 :            :     OoxErrorCodeMap     maOoxErrCodes;      /// Maps error code strings to BIFF error constants.
     113                 :            :     sal_Int32           mnNullDate;         /// Nulldate of this workbook (number of days since 0000-01-01).
     114                 :            : };
     115                 :            : 
     116                 :            : // ============================================================================
     117                 :            : 
     118                 :            : } // namespace xls
     119                 :            : } // namespace oox
     120                 :            : 
     121                 :            : #endif
     122                 :            : 
     123                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10