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
27namespace com::sun::star {
28 namespace util { struct Date; struct DateTime; }
29}
30
31namespace oox::xls {
32
34enum class Unit
35{
36 Twip,
37 Emu,
38 ScreenX,
39 ScreenY,
40 Digit,
41 Space,
42 LAST
43};
44
58{
59public:
60 explicit UnitConverter( const WorkbookHelper& rHelper );
61
63 void finalizeImport();
65 void finalizeNullDate( const css::util::Date& rNullDate );
66
68 double scaleValue( double fValue, Unit eFromUnit, Unit eToUnit ) const;
69
71 double calcSerialFromDateTime( const css::util::DateTime& rDateTime ) const;
73 css::util::DateTime calcDateTimeFromSerial( double fSerial ) const;
74
76 sal_uInt8 calcBiffErrorCode( const OUString& rErrorCode ) const;
77
79 OUString calcErrorString( sal_uInt8 nErrorCode ) const;
80
81private:
83 void addErrorCode( sal_uInt8 nErrorCode, const OUString& rErrorCode );
84
86 double getCoefficient( Unit eUnit ) const;
87
88private:
90 std::map<OUString, sal_uInt8> maOoxErrCodes;
91 sal_Int32 mnNullDate;
92};
93
94} // namespace oox::xls
95
96/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class that provides functions to convert values from and to different units.
double calcSerialFromDateTime(const css::util::DateTime &rDateTime) const
Returns the serial value of the passed datetime, based on current nulldate.
void finalizeImport()
Final processing after import of all style settings.
void addErrorCode(sal_uInt8 nErrorCode, const OUString &rErrorCode)
Adds an error code to the internal maps.
sal_uInt8 calcBiffErrorCode(const OUString &rErrorCode) const
Returns a BIFF error code from the passed error string.
std::map< OUString, sal_uInt8 > maOoxErrCodes
Coefficients for unit conversion.
sal_Int32 mnNullDate
Maps error code strings to BIFF error constants.
o3tl::enumarray< Unit, double > maCoeffs
void finalizeNullDate(const css::util::Date &rNullDate)
Updates internal nulldate for date/serial conversion.
UnitConverter(const WorkbookHelper &rHelper)
double scaleValue(double fValue, Unit eFromUnit, Unit eToUnit) const
Converts the passed value between the passed units.
OUString calcErrorString(sal_uInt8 nErrorCode) const
Returns an error string from the passed BIFF error code.
css::util::DateTime calcDateTimeFromSerial(double fSerial) const
Returns the datetime of the passed serial value, based on current nulldate.
double getCoefficient(Unit eUnit) const
Returns the conversion coefficient for the passed unit.
Helper class to provide access to global workbook data.
Unit
Units supported by the UnitConverter class.
@ ScreenX
English Metric Unit (1/360,000 cm).
@ Emu
Twips (1/20 point).
@ Digit
Vertical screen pixels.
@ ScreenY
Horizontal screen pixels.
unsigned char sal_uInt8