Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / unitconverter.hxx
blobec22a34a19de5a7faecad9a2e544da7595b4031b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_UNITCONVERTER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_UNITCONVERTER_HXX
23 #include <map>
24 #include <vector>
25 #include <o3tl/enumarray.hxx>
26 #include "workbookhelper.hxx"
28 namespace com { namespace sun { namespace star {
29 namespace util { struct Date; struct DateTime; }
30 } } }
32 namespace oox {
33 namespace xls {
35 /** Units supported by the UnitConverter class. */
36 enum class Unit
38 Inch, /// Inches.
39 Point, /// Points.
40 Twip, /// Twips (1/20 point).
41 Emu, /// English Metric Unit (1/360,000 cm).
42 ScreenX, /// Horizontal screen pixels.
43 ScreenY, /// Vertical screen pixels.
44 Digit, /// Digit width of document default font.
45 Space, /// Space character width of document default font.
46 LAST
49 /** Helper class that provides functions to convert values from and to
50 different units.
52 Provides functions to calculate the width of certain characters of the
53 default font of the imported/exported document. The default font is always
54 the first font in the styles font list, and is always referenced by the
55 default cell style ("Normal" style in Excel) which is used by all empty
56 unformatted cells in the document. To be able to calculate the character
57 width correctly, the default font must be known, which is the case after
58 the finalizeImport() or finalizeExport() functions have been called. Caller
59 must make sure to not call the character width conversion functions before.
61 class UnitConverter : public WorkbookHelper
63 public:
64 explicit UnitConverter( const WorkbookHelper& rHelper );
66 /** Final processing after import of all style settings. */
67 void finalizeImport();
68 /** Updates internal nulldate for date/serial conversion. */
69 void finalizeNullDate( const css::util::Date& rNullDate );
71 /** Converts the passed value between the passed units. */
72 double scaleValue( double fValue, Unit eFromUnit, Unit eToUnit ) const;
74 /** Converts the passed value to 1/100 millimeters. */
75 sal_Int32 scaleToMm100( double fValue, Unit eUnit ) const;
76 /** Converts the passed value from 1/100 millimeters to the passed unit. */
77 double scaleFromMm100( sal_Int32 nMm100, Unit eUnit ) const;
79 /** Returns the serial value of the passed datetime, based on current nulldate. */
80 double calcSerialFromDateTime( const css::util::DateTime& rDateTime ) const;
81 /** Returns the datetime of the passed serial value, based on current nulldate. */
82 css::util::DateTime calcDateTimeFromSerial( double fSerial ) const;
84 /** Returns a BIFF error code from the passed error string. */
85 sal_uInt8 calcBiffErrorCode( const OUString& rErrorCode ) const;
87 /** Returns an error string from the passed BIFF error code. */
88 OUString calcErrorString( sal_uInt8 nErrorCode ) const;
90 /** Returns the conversion coefficient for the passed unit. */
91 double getCoefficient( Unit eUnit ) const;
93 private:
94 /** Adds an error code to the internal maps. */
95 void addErrorCode( sal_uInt8 nErrorCode, const OUString& rErrorCode );
97 private:
98 o3tl::enumarray<Unit, double> maCoeffs; /// Coefficients for unit conversion.
99 std::map<OUString, sal_uInt8> maOoxErrCodes; /// Maps error code strings to BIFF error constants.
100 sal_Int32 mnNullDate; /// Nulldate of this workbook (number of days since 0000-01-01).
103 } // namespace xls
104 } // namespace oox
106 #endif
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */