File: MsooXmlUnits.h

package info (click to toggle)
calligra 1%3A2.9.11%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 189,332 kB
  • sloc: cpp: 919,806; xml: 27,759; ansic: 10,472; python: 8,190; perl: 2,724; yacc: 2,557; sh: 1,675; lex: 1,431; java: 1,304; sql: 903; ruby: 734; makefile: 48
file content (135 lines) | stat: -rw-r--r-- 5,102 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * This file is part of Office 2007 Filters for Calligra
 * Copyright (C) 2002 Laurent Montel <lmontel@mandrakesoft.com>
 * Copyright (c) 2003 Lukas Tinkl <lukas@kde.org>
 * Copyright (C) 2003 David Faure <faure@kde.org>
 * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Suresh Chande suresh.chande@nokia.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef MSOOXML_UNITS_H
#define MSOOXML_UNITS_H

#include <QString>

// conversion from twips (http://en.wikipedia.org/wiki/Twip)
#define TWIP_TO_DM(tw) ((tw)*0.000176389)
#define TWIP_TO_CM(tw) ((tw)*0.001763889)
#define TWIP_TO_MM(tw) ((tw)*0.017638889)
#define TWIP_TO_POINT(tw) ((tw)*0.05)
#define TWIP_TO_INCH(tw) ((tw)*0.000694444)
#define TWIP_TO_PI(tw) ((tw)*0.004166667)
#define TWIP_TO_CC(tw) ((tw)*0.00389404975957)
#define TWIP_TO_PX(tw) ((tw)*0.066798611)

// conversion to twips
#define DM_TO_TWIP(dm) ((dm)*5669.28776738)
#define CM_TO_TWIP(cm) ((cm)*566.929098146)
#define MM_TO_TWIP(mm) ((mm)*56.6929130287)
#define POINT_TO_TWIP(pt) ((pt)*20.0)
#define INCH_TO_TWIP(in) ((in)*1440.0)
#define PI_TO_TWIP(pi) ((pi)*240.0)
#define CC_TO_TWIP(cc) ((cc)*256.80206)
#define PX_TO_TWIP(px) ((px)*14.970371)

// EMU conversion (ECMA-376, 20.1.2.1: EMU Unit of Measurement)
//! Converts emu value (integer or double) to cm
#define EMU_TO_CM(emu) ((emu)/360000.0)

//! Converts emu value (integer or double) to inches
#define EMU_TO_INCH(emu) ((emu)/914400.0)

//! Converts emu value (integer or double) to points
#define EMU_TO_POINT(emu) ((emu)/12700.0)

namespace MSOOXML
{

namespace Utils {

//! Performs EMU conversion and returns string.
inline QString cmString(qreal cm)
{
    QString res;
    return res.sprintf("%3.3fcm", cm);
}

//! Converts EMU Unit of Measurement to cm.
/*! Converts value expressed in EMU (ECMA-376, 20.1.2.1: EMU Unit of Measurement)
    to ODF-compliant "0.000cm" unit.
    "0" and "" is converted to "0cm".
    @return empty string on error. */
//! CASE #P505
KOMSOOXML_EXPORT QString EMU_to_ODF(const QString& emuValue);

//! Converts TWIP Unit of Measurement to cm.
/*! Converts value expressed in TWIPs  to ODF-compliant "0.000cm" unit.
    "0" and "" is converted to "0cm".
    @return empty string on error. */
KOMSOOXML_EXPORT QString TWIP_to_ODF(const QString& twipValue);

//! ECMA-376, 17.18.23 ST_EighthPointMeasure (Measurement in Eighths of a Point), p. 1540
/*! Converts eighths of a point (equivalent to 1/576th of an inch) to point
    to ODF-compliant "0.000pt" unit.
    @return empty string on failure. */
KOMSOOXML_EXPORT QString ST_EighthPointMeasure_to_ODF(const QString& value);

//! ECMA-376, 22.9.2.14 ST_TwipsMeasure (Measurement in Twentieths of a Point), p. 4339
/*! Converts:
    * Case 1: a positive number in twips (twentieths of a point, equivalent to 1/1440th of an inch), or
    * Case 2: a positive decimal number immediately followed by a unit identifier.
    The conversion's target is ODF-compliant "0.000xx" unit, where xx is "mm", "cm", "pt", etc.
    For case 1 it is always "pt".
    @return empty string on error. */
KOMSOOXML_EXPORT QString ST_TwipsMeasure_to_pt(const QString& value);

//! Like ST_TwipsMeasure_to_pt() but for case 1 always converts to "cm".
KOMSOOXML_EXPORT QString ST_TwipsMeasure_to_cm(const QString& value);

//! ECMA-376, 22.9.2.12 ST_PositiveUniversalMeasure (Positive Universal Measurement), p. 4340
/*! Converts number+unit of measurement into ODF-compliant number+unit.
    @a value should match the following regular expression pattern: [0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi).
    Values with units mm, cm, in, pt, pi are just copied.
    Values with "pc" (another name for Pica) are replaced with "pi".
    @return empty string on error. */
KOMSOOXML_EXPORT QString ST_PositiveUniversalMeasure_to_ODF(const QString& value);

//! Like ST_PositiveUniversalMeasure_to_ODF(const QString&) but always converts to cm.
KOMSOOXML_EXPORT QString ST_PositiveUniversalMeasure_to_cm(const QString& value);

} // Utils
} // MSOOXML

//! Performs EMU conversion and returns string.
inline QString EMU_TO_CM_STRING(int emu)
{
    return MSOOXML::Utils::cmString(EMU_TO_CM(qreal(emu)));
}

//! Performs EMU conversion and returns string.
inline QString EMU_TO_INCH_STRING(int emu)
{
    return MSOOXML::Utils::cmString(EMU_TO_INCH(qreal(emu)));
}

// px conversion
#define PT_TO_PX(pt) ((pt)*1.33597222222)
#define PX_TO_CM(px) ((px)*0.0264)

#endif /* MSOOXML_UNITS_H */