-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlength.cpp
146 lines (124 loc) · 2.04 KB
/
length.cpp
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
136
137
138
139
140
141
142
143
144
145
#include "length.h"
#include <math.h>
namespace Docx {
//
const int EMUS_PER_INCH = 914400;
const int EMUS_PER_CM = 360000;
const int EMUS_PER_MM = 36000;
const int EMUS_PER_PX = 12700;
const int EMUS_PER_TWIP = 635;
const int UNITS_PER_POINT = 100;
Length::Length()
{
}
Length::Length(int emu) : m_value(emu)
{
m_isEmpty = false;
}
float Length::cm() const
{
return (float)m_value/(float)EMUS_PER_CM;
}
int Length::emu() const
{
return m_value;
}
float Length::inches() const
{
return (float)m_value/(float)EMUS_PER_INCH;
}
float Length::mm() const
{
return (float)m_value/(float)EMUS_PER_MM;
}
int Length::px() const
{
return (int)(round((float)m_value/(float)EMUS_PER_PX) + 0.1);
}
int Length::twips() const
{
return (int)(round((float)m_value/(float)EMUS_PER_TWIP));
}
bool Length::isEmpty() const
{
return m_isEmpty;
}
/*!
* \brief Inches长度
*
* eg width = Inches(0.5)
* \param inches
* \return
*/
Length Inches::emus(float inches)
{
int emu = int(inches * EMUS_PER_INCH);
return Length(emu);
}
/*!
* \brief centimetres 长度
*
* eg height = Cm(12)
* \param inches
* \return
*/
Length Cm::emus(float cm)
{
int emu = int(cm * EMUS_PER_CM);
return Length(emu);
}
/*!
* \brief English Metric Units
*
* eg width = Emu(457200)
* \param emu
* \return
*/
Length Emu::emus(float emu)
{
return Length(emu);
}
/*!
* \brief millimeters 长度
* \param cm
* \return
*/
Length Mm::emus(float mm)
{
int emu = int(mm * EMUS_PER_MM);
return Length(emu);
}
/*!
* \brief setting font sizes in points
* \param pts
* \return
*/
Length Pt::emus(float pts)
{
int units = int(pts * UNITS_PER_POINT);
return Length(units);
}
/*!
* \brief pixels
* \param px
* \return
*/
Length Px::emus(float px)
{
int emu = int(px * EMUS_PER_PX);
return Length(emu);
}
/*!
* \brief Twips
*
* eg width = Twips(42)
* A twip is a twentieth of a point, 635 EMU
* \param px
* \return
*/
Length Twips::emus(float twips)
{
int emu = int(twips * EMUS_PER_TWIP);
return Length(emu);
}
}