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
* Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
4
* Copyright (C) 2006, 2007 Andrew Ziem
5
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
6
* Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
7
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
8
*
9
*
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Library General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
14
*
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Library General Public License for more details.
19
*
20
* You should have received a copy of the GNU Library General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23
*
24
* For further information visit http://libwps.sourceforge.net
25
*/
26
27
/* "This product is not manufactured, approved, or supported by
28
* Corel Corporation or Corel Corporation Limited."
29
*/
30
31
#ifndef WPS_POSITION_H
32
#define WPS_POSITION_H
33
34
#include <ostream>
35
36
#include <libwpd/WPXProperty.h>
37
38
#include "
libwps_internal.h
"
39
44
class
WPSPosition
45
{
46
public
:
48
enum
AnchorTo
{
Char
,
CharBaseLine
,
Paragraph
,
Page
};
50
enum
Wrapping
{
WNone
,
WDynamic
,
WRunThrough
};
// Add something for background ?
52
enum
XPos
{
XRight
,
XLeft
,
XCenter
,
XFull
};
54
enum
YPos
{
YTop
,
YBottom
,
YCenter
,
YFull
};
55
56
public
:
58
WPSPosition
(
Vec2f
const
&orig=
Vec2f
(),
Vec2f
const
&sz=
Vec2f
(), WPXUnit unt=WPX_INCH):
59
m_anchorTo
(
Char
),
m_xPos
(
XLeft
),
m_yPos
(
YTop
),
m_wrapping
(
WNone
),
60
m_page
(0),
m_orig
(orig),
m_size
(sz),
m_naturalSize
(),
m_unit
(unt),
m_order
(0) {}
61
62
virtual
~WPSPosition
() {}
64
friend
std::ostream &
operator<<
(std::ostream &o,
WPSPosition
const
&pos)
65
{
66
Vec2f
dest(pos.
m_orig
+pos.
m_size
);
67
o <<
"Pos="
<< pos.
m_orig
<<
"x"
<< dest;
68
switch
(pos.
m_unit
)
69
{
70
case
WPX_INCH:
71
o <<
"(inch)"
;
72
break
;
73
case
WPX_POINT:
74
o <<
"(pt)"
;
75
break
;
76
case
WPX_TWIP:
77
o <<
"(tw)"
;
78
break
;
79
default
:
80
break
;
81
}
82
if
(pos.
page
()>0) o <<
", page="
<< pos.
page
();
83
return
o;
84
}
86
bool
operator==
(
WPSPosition
const
&f)
const
87
{
88
return
cmp
(f) == 0;
89
}
91
bool
operator!=
(
WPSPosition
const
&f)
const
92
{
93
return
cmp
(f) != 0;
94
}
96
bool
operator<
(
WPSPosition
const
&f)
const
97
{
98
return
cmp
(f) < 0;
99
}
100
102
int
page
()
const
103
{
104
return
m_page
;
105
}
107
Vec2f
const
&
origin
()
const
108
{
109
return
m_orig
;
110
}
112
Vec2f
const
&
size
()
const
113
{
114
return
m_size
;
115
}
117
Vec2f
const
&
naturalSize
()
const
118
{
119
return
m_naturalSize
;
120
}
122
WPXUnit
unit
()
const
123
{
124
return
m_unit
;
125
}
127
static
float
getScaleFactor
(WPXUnit orig, WPXUnit dest)
128
{
129
float
actSc = 1.0, newSc = 1.0;
130
switch
(orig)
131
{
132
case
WPX_TWIP:
133
break
;
134
case
WPX_POINT:
135
actSc=20;
136
break
;
137
case
WPX_INCH:
138
actSc = 1440;
139
break
;
140
default
:
141
WPS_DEBUG_MSG
((
"WPSPosition::getScaleFactor %d unit must not appear\n"
,
int
(orig)));
142
}
143
switch
(dest)
144
{
145
case
WPX_TWIP:
146
break
;
147
case
WPX_POINT:
148
newSc=20;
149
break
;
150
case
WPX_INCH:
151
newSc = 1440;
152
break
;
153
default
:
154
WPS_DEBUG_MSG
((
"WPSPosition::getScaleFactor %d unit must not appear\n"
,
int
(dest)));
155
}
156
return
actSc/newSc;
157
}
159
float
getInvUnitScale
(WPXUnit unt)
const
160
{
161
return
getScaleFactor
(unt,
m_unit
);
162
}
163
165
void
setPage
(
int
pg)
const
166
{
167
const_cast<
WPSPosition
*
>
(
this
)->
m_page
= pg;
168
}
170
void
setOrigin
(
Vec2f
const
&orig)
171
{
172
m_orig
= orig;
173
}
175
void
setSize
(
Vec2f
const
&sz)
176
{
177
m_size
= sz;
178
}
180
void
setNaturalSize
(
Vec2f
const
&natSize)
181
{
182
m_naturalSize
= natSize;
183
}
185
void
setUnit
(WPXUnit unt)
186
{
187
m_unit
= unt;
188
}
190
void
setPagePos
(
int
pg,
Vec2f
const
&newOrig)
const
191
{
192
const_cast<
WPSPosition
*
>
(
this
)->
m_page
= pg;
193
const_cast<
WPSPosition
*
>
(
this
)->
m_orig
= newOrig;
194
}
195
197
void
setRelativePosition
(
AnchorTo
anchor,
XPos
X =
XLeft
,
YPos
Y=
YTop
)
198
{
199
m_anchorTo
= anchor;
200
m_xPos
= X;
201
m_yPos
= Y;
202
}
203
205
int
order
()
const
206
{
207
return
m_order
;
208
}
210
void
setOrder
(
int
ord)
const
211
{
212
m_order
= ord;
213
}
214
216
AnchorTo
m_anchorTo
;
218
XPos
m_xPos
;
220
YPos
m_yPos
;
222
Wrapping
m_wrapping
;
223
224
protected
:
226
int
cmp
(
WPSPosition
const
&f)
const
227
{
228
int
diff = int(
m_anchorTo
) - int(f.
m_anchorTo
);
229
if
(diff)
return
diff < 0 ? -1 : 1;
230
diff = int(
m_xPos
) - int(f.
m_xPos
);
231
if
(diff)
return
diff < 0 ? -1 : 1;
232
diff = int(
m_yPos
) - int(f.
m_yPos
);
233
if
(diff)
return
diff < 0 ? -1 : 1;
234
diff =
page
() - f.
page
();
235
if
(diff)
return
diff < 0 ? -1 : 1;
236
diff = int(
m_unit
) - int(f.
m_unit
);
237
if
(diff)
return
diff < 0 ? -1 : 1;
238
diff =
m_orig
.
cmpY
(f.
m_orig
);
239
if
(diff)
return
diff;
240
diff =
m_size
.
cmpY
(f.
m_size
);
241
if
(diff)
return
diff;
242
diff =
m_naturalSize
.
cmpY
(f.
m_naturalSize
);
243
if
(diff)
return
diff;
244
245
return
0;
246
}
247
249
int
m_page
;
250
Vec2f
m_orig
,
m_size
/* the size of the data*/
,
m_naturalSize
;
252
WPXUnit
m_unit
;
254
mutable
int
m_order
;
255
};
256
257
#endif
258
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Generated on Wed Aug 8 2012 16:07:57 for libwps by
doxygen
1.8.1.2