Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / unitconverter.hxx
blobf418eaaf0449aef3d3452334a58041ecd6c56e81
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 #pragma once
22 #include <map>
23 #include <vector>
24 #include <o3tl/enumarray.hxx>
25 #include "workbookhelper.hxx"
27 namespace com::sun::star {
28 namespace util { struct Date; struct DateTime; }
31 namespace oox::xls {
33 /** Units supported by the UnitConverter class. */
34 enum class Unit
36 Twip, /// Twips (1/20 point).
37 Emu, /// English Metric Unit (1/360,000 cm).
38 ScreenX, /// Horizontal screen pixels.
39 ScreenY, /// Vertical screen pixels.
40 Digit, /// Digit width of document default font.
41 Space, /// Space character width of document default font.
42 LAST
45 /** Helper class that provides functions to convert values from and to
46 different units.
48 Provides functions to calculate the width of certain characters of the
49 default font of the imported/exported document. The default font is always
50 the first font in the styles font list, and is always referenced by the
51 default cell style ("Normal" style in Excel) which is used by all empty
52 unformatted cells in the document. To be able to calculate the character
53 width correctly, the default font must be known, which is the case after
54 the finalizeImport() or finalizeExport() functions have been called. Caller
55 must make sure to not call the character width conversion functions before.
57 class UnitConverter : public WorkbookHelper
59 public:
60 explicit UnitConverter( const WorkbookHelper& rHelper );
62 /** Final processing after import of all style settings. */
63 void finalizeImport();
64 /** Updates internal nulldate for date/serial conversion. */
65 void finalizeNullDate( const css::util::Date& rNullDate );
67 /** Converts the passed value between the passed units. */
68 double scaleValue( double fValue, Unit eFromUnit, Unit eToUnit ) const;
70 /** Returns the serial value of the passed datetime, based on current nulldate. */
71 double calcSerialFromDateTime( const css::util::DateTime& rDateTime ) const;
72 /** Returns the datetime of the passed serial value, based on current nulldate. */
73 css::util::DateTime calcDateTimeFromSerial( double fSerial ) const;
75 /** Returns a BIFF error code from the passed error string. */
76 sal_uInt8 calcBiffErrorCode( const OUString& rErrorCode ) const;
78 /** Returns an error string from the passed BIFF error code. */
79 OUString calcErrorString( sal_uInt8 nErrorCode ) const;
81 private:
82 /** Adds an error code to the internal maps. */
83 void addErrorCode( sal_uInt8 nErrorCode, const OUString& rErrorCode );
85 /** Returns the conversion coefficient for the passed unit. */
86 double getCoefficient( Unit eUnit ) const;
88 private:
89 o3tl::enumarray<Unit, double> maCoeffs; /// Coefficients for unit conversion.
90 std::map<OUString, sal_uInt8> maOoxErrCodes; /// Maps error code strings to BIFF error constants.
91 sal_Int32 mnNullDate; /// Nulldate of this workbook (number of days since 0000-01-01).
94 } // namespace oox::xls
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */