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

Generated by: LCOV version 1.11