Main Page
Namespaces
Classes
Files
File List
File Members
WPSPosition.h
Go to the documentation of this file.
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwps
3
* Version: MPL 2.0 / LGPLv2.1+
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
* Major Contributor(s):
10
* Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11
* Copyright (C) 2006, 2007 Andrew Ziem
12
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13
* Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15
*
16
* For minor contributions see the git repository.
17
*
18
* Alternatively, the contents of this file may be used under the terms
19
* of the GNU Lesser General Public License Version 2.1 or later
20
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21
* applicable instead of those above.
22
*
23
* For further information visit http://libwps.sourceforge.net
24
*/
25
26
#ifndef WPS_POSITION_H
27
#define WPS_POSITION_H
28
29
#include <ostream>
30
31
#include <libwpd/libwpd.h>
32
33
#include "
libwps_internal.h
"
34
39
class
WPSPosition
40
{
41
public
:
43
enum
AnchorTo
{
Char
,
CharBaseLine
,
Paragraph
,
Page
};
45
enum
Wrapping
{
WNone
,
WDynamic
,
WRunThrough
};
// Add something for background ?
47
enum
XPos
{
XRight
,
XLeft
,
XCenter
,
XFull
};
49
enum
YPos
{
YTop
,
YBottom
,
YCenter
,
YFull
};
50
51
public
:
53
WPSPosition
(
Vec2f
const
&orig=
Vec2f
(),
Vec2f
const
&sz=
Vec2f
(), WPXUnit unt=WPX_INCH):
54
m_anchorTo
(
Char
),
m_xPos
(
XLeft
),
m_yPos
(
YTop
),
m_wrapping
(
WNone
),
55
m_page
(0),
m_orig
(orig),
m_size
(sz),
m_naturalSize
(),
m_unit
(unt),
m_order
(0) {}
56
57
virtual
~WPSPosition
() {}
59
friend
std::ostream &
operator<<
(std::ostream &o,
WPSPosition
const
&pos)
60
{
61
Vec2f
dest(pos.
m_orig
+pos.
m_size
);
62
o <<
"Pos="
<< pos.
m_orig
<<
"x"
<< dest;
63
switch
(pos.
m_unit
)
64
{
65
case
WPX_INCH:
66
o <<
"(inch)"
;
67
break
;
68
case
WPX_POINT:
69
o <<
"(pt)"
;
70
break
;
71
case
WPX_TWIP:
72
o <<
"(tw)"
;
73
break
;
74
case
WPX_PERCENT:
75
case
WPX_GENERIC:
76
default
:
77
break
;
78
}
79
if
(pos.
page
()>0) o <<
", page="
<< pos.
page
();
80
return
o;
81
}
83
bool
operator==
(
WPSPosition
const
&f)
const
84
{
85
return
cmp
(f) == 0;
86
}
88
bool
operator!=
(
WPSPosition
const
&f)
const
89
{
90
return
cmp
(f) != 0;
91
}
93
bool
operator<
(
WPSPosition
const
&f)
const
94
{
95
return
cmp
(f) < 0;
96
}
97
99
int
page
()
const
100
{
101
return
m_page
;
102
}
104
Vec2f
const
&
origin
()
const
105
{
106
return
m_orig
;
107
}
109
Vec2f
const
&
size
()
const
110
{
111
return
m_size
;
112
}
114
Vec2f
const
&
naturalSize
()
const
115
{
116
return
m_naturalSize
;
117
}
119
WPXUnit
unit
()
const
120
{
121
return
m_unit
;
122
}
124
static
float
getScaleFactor
(WPXUnit orig, WPXUnit dest)
125
{
126
float
actSc = 1.0, newSc = 1.0;
127
switch
(orig)
128
{
129
case
WPX_TWIP:
130
break
;
131
case
WPX_POINT:
132
actSc=20;
133
break
;
134
case
WPX_INCH:
135
actSc = 1440;
136
break
;
137
case
WPX_PERCENT:
138
case
WPX_GENERIC:
139
default
:
140
WPS_DEBUG_MSG
((
"WPSPosition::getScaleFactor %d unit must not appear\n"
,
int
(orig)));
141
}
142
switch
(dest)
143
{
144
case
WPX_TWIP:
145
break
;
146
case
WPX_POINT:
147
newSc=20;
148
break
;
149
case
WPX_INCH:
150
newSc = 1440;
151
break
;
152
case
WPX_PERCENT:
153
case
WPX_GENERIC:
154
default
:
155
WPS_DEBUG_MSG
((
"WPSPosition::getScaleFactor %d unit must not appear\n"
,
int
(dest)));
156
}
157
return
actSc/newSc;
158
}
160
float
getInvUnitScale
(WPXUnit unt)
const
161
{
162
return
getScaleFactor
(unt,
m_unit
);
163
}
164
166
void
setPage
(
int
pg)
const
167
{
168
const_cast<
WPSPosition
*
>
(
this
)->
m_page
= pg;
169
}
171
void
setOrigin
(
Vec2f
const
&orig)
172
{
173
m_orig
= orig;
174
}
176
void
setSize
(
Vec2f
const
&sz)
177
{
178
m_size
= sz;
179
}
181
void
setNaturalSize
(
Vec2f
const
&natSize)
182
{
183
m_naturalSize
= natSize;
184
}
186
void
setUnit
(WPXUnit unt)
187
{
188
m_unit
= unt;
189
}
191
void
setPagePos
(
int
pg,
Vec2f
const
&newOrig)
const
192
{
193
const_cast<
WPSPosition
*
>
(
this
)->
m_page
= pg;
194
const_cast<
WPSPosition
*
>
(
this
)->
m_orig
= newOrig;
195
}
196
198
void
setRelativePosition
(
AnchorTo
anchor,
XPos
X =
XLeft
,
YPos
Y=
YTop
)
199
{
200
m_anchorTo
= anchor;
201
m_xPos
= X;
202
m_yPos
= Y;
203
}
204
206
int
order
()
const
207
{
208
return
m_order
;
209
}
211
void
setOrder
(
int
ord)
const
212
{
213
m_order
= ord;
214
}
215
217
AnchorTo
m_anchorTo
;
219
XPos
m_xPos
;
221
YPos
m_yPos
;
223
Wrapping
m_wrapping
;
224
225
protected
:
227
int
cmp
(
WPSPosition
const
&f)
const
228
{
229
int
diff = int(
m_anchorTo
) - int(f.
m_anchorTo
);
230
if
(diff)
return
diff < 0 ? -1 : 1;
231
diff = int(
m_xPos
) - int(f.
m_xPos
);
232
if
(diff)
return
diff < 0 ? -1 : 1;
233
diff = int(
m_yPos
) - int(f.
m_yPos
);
234
if
(diff)
return
diff < 0 ? -1 : 1;
235
diff =
page
() - f.
page
();
236
if
(diff)
return
diff < 0 ? -1 : 1;
237
diff = int(
m_unit
) - int(f.
m_unit
);
238
if
(diff)
return
diff < 0 ? -1 : 1;
239
diff =
m_orig
.
cmpY
(f.
m_orig
);
240
if
(diff)
return
diff;
241
diff =
m_size
.
cmpY
(f.
m_size
);
242
if
(diff)
return
diff;
243
diff =
m_naturalSize
.
cmpY
(f.
m_naturalSize
);
244
if
(diff)
return
diff;
245
246
return
0;
247
}
248
250
int
m_page
;
251
Vec2f
m_orig
,
m_size
/* the size of the data*/
,
m_naturalSize
;
253
WPXUnit
m_unit
;
255
mutable
int
m_order
;
256
};
257
258
#endif
259
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Generated on Mon Jun 3 2013 01:38:41 for libwps by
doxygen
1.8.3.1