LibreOffice Module sc (master)  1
unitconverter.hxx
Go to the documentation of this file.
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 #pragma once
21 
22 #include <map>
23 #include <vector>
24 #include <o3tl/enumarray.hxx>
25 #include "workbookhelper.hxx"
26 
27 namespace com::sun::star {
28  namespace util { struct Date; struct DateTime; }
29 }
30 
31 namespace oox::xls {
32 
34 enum class Unit
35 {
36  Inch,
37  Point,
38  Twip,
39  Emu,
40  ScreenX,
41  ScreenY,
42  Digit,
43  Space,
44  LAST
45 };
46 
60 {
61 public:
62  explicit UnitConverter( const WorkbookHelper& rHelper );
63 
65  void finalizeImport();
67  void finalizeNullDate( const css::util::Date& rNullDate );
68 
70  double scaleValue( double fValue, Unit eFromUnit, Unit eToUnit ) const;
71 
73  sal_Int32 scaleToMm100( double fValue, Unit eUnit ) const;
75  double scaleFromMm100( sal_Int32 nMm100, Unit eUnit ) const;
76 
78  double calcSerialFromDateTime( const css::util::DateTime& rDateTime ) const;
80  css::util::DateTime calcDateTimeFromSerial( double fSerial ) const;
81 
83  sal_uInt8 calcBiffErrorCode( const OUString& rErrorCode ) const;
84 
86  OUString calcErrorString( sal_uInt8 nErrorCode ) const;
87 
89  double getCoefficient( Unit eUnit ) const;
90 
91 private:
93  void addErrorCode( sal_uInt8 nErrorCode, const OUString& rErrorCode );
94 
95 private:
97  std::map<OUString, sal_uInt8> maOoxErrCodes;
98  sal_Int32 mnNullDate;
99 };
100 
101 } // namespace oox::xls
102 
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
exports com.sun.star.lib. util
Helper class to provide access to global workbook data.
double scaleValue(double fValue, Unit eFromUnit, Unit eToUnit) const
Converts the passed value between the passed units.
Helper class that provides functions to convert values from and to different units.
Space character width of document default font.
sal_Int32 scaleToMm100(double fValue, Unit eUnit) const
Converts the passed value to 1/100 millimeters.
double calcSerialFromDateTime(const css::util::DateTime &rDateTime) const
Returns the serial value of the passed datetime, based on current nulldate.
css::util::DateTime calcDateTimeFromSerial(double fSerial) const
Returns the datetime of the passed serial value, based on current nulldate.
std::map< OUString, sal_uInt8 > maOoxErrCodes
Coefficients for unit conversion.
OUString calcErrorString(sal_uInt8 nErrorCode) const
Returns an error string from the passed BIFF error code.
void finalizeNullDate(const css::util::Date &rNullDate)
Updates internal nulldate for date/serial conversion.
Unit
Units supported by the UnitConverter class.
void addErrorCode(sal_uInt8 nErrorCode, const OUString &rErrorCode)
Adds an error code to the internal maps.
Twips (1/20 point).
Digit width of document default font.
void finalizeImport()
Final processing after import of all style settings.
unsigned char sal_uInt8
Horizontal screen pixels.
English Metric Unit (1/360,000 cm).
UnitConverter(const WorkbookHelper &rHelper)
double scaleFromMm100(sal_Int32 nMm100, Unit eUnit) const
Converts the passed value from 1/100 millimeters to the passed unit.
sal_uInt8 calcBiffErrorCode(const OUString &rErrorCode) const
Returns a BIFF error code from the passed error string.
o3tl::enumarray< Unit, double > maCoeffs
sal_Int32 mnNullDate
Maps error code strings to BIFF error constants.
double getCoefficient(Unit eUnit) const
Returns the conversion coefficient for the passed unit.
Vertical screen pixels.