Main Page
Namespaces
Classes
Files
File List
File Members
MWAWPosition.hxx
Go to the documentation of this file.
1
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3
/* libmwaw
4
* Version: MPL 2.0 / LGPLv2+
5
*
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 2.0 (the "License"); you may not use this file except in compliance with
8
* the License or as specified alternatively below. You may obtain a copy of
9
* the License at http://www.mozilla.org/MPL/
10
*
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
14
* License.
15
*
16
* Major Contributor(s):
17
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20
* Copyright (C) 2006, 2007 Andrew Ziem
21
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22
*
23
*
24
* All Rights Reserved.
25
*
26
* For minor contributions see the git repository.
27
*
28
* Alternatively, the contents of this file may be used under the terms of
29
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30
* in which case the provisions of the LGPLv2+ are applicable
31
* instead of those above.
32
*/
33
34
#ifndef MWAW_POSITION_H
35
#define MWAW_POSITION_H
36
37
#include <ostream>
38
39
#include <libwpd/libwpd.h>
40
41
#include "
libmwaw_internal.hxx
"
42
47
class
MWAWPosition
48
{
49
public
:
51
enum
AnchorTo
{
Char
,
CharBaseLine
,
Frame
,
Paragraph
,
Page
,
Unknown
};
53
enum
Wrapping
{
WNone
,
WBackground
,
WDynamic
,
WRunThrough
};
55
enum
XPos
{
XRight
,
XLeft
,
XCenter
,
XFull
};
57
enum
YPos
{
YTop
,
YBottom
,
YCenter
,
YFull
};
58
59
public
:
61
MWAWPosition
(
Vec2f
const
&orig=
Vec2f
(),
Vec2f
const
&sz=
Vec2f
(), WPXUnit theUnit=WPX_INCH):
62
m_anchorTo
(
Unknown
),
m_xPos
(
XLeft
),
m_yPos
(
YTop
),
m_wrapping
(
WNone
),
63
m_page
(0),
m_orig
(orig),
m_size
(sz),
m_naturalSize
(),
m_LTClip
(),
m_RBClip
(),
m_unit
(theUnit),
m_order
(0) {}
64
65
virtual
~MWAWPosition
() {}
67
friend
std::ostream &
operator<<
(std::ostream &o,
MWAWPosition
const
&pos) {
68
Vec2f
dest(pos.
m_orig
+pos.
m_size
);
69
o <<
"Pos=("
<< pos.
m_orig
<<
")x("
<< dest <<
")"
;
70
switch
(pos.
m_unit
) {
71
case
WPX_INCH:
72
o <<
"(inch)"
;
73
break
;
74
case
WPX_POINT:
75
o <<
"(pt)"
;
76
break
;
77
case
WPX_TWIP:
78
o <<
"(tw)"
;
79
break
;
80
case
WPX_PERCENT:
81
case
WPX_GENERIC:
82
default
:
83
break
;
84
}
85
if
(pos.
page
()>0) o <<
", page="
<< pos.
page
();
86
return
o;
87
}
89
bool
operator==
(
MWAWPosition
const
&f)
const
{
90
return
cmp
(f) == 0;
91
}
93
bool
operator!=
(
MWAWPosition
const
&f)
const
{
94
return
cmp
(f) != 0;
95
}
97
bool
operator<
(
MWAWPosition
const
&f)
const
{
98
return
cmp
(f) < 0;
99
}
100
102
int
page
()
const
{
103
return
m_page
;
104
}
106
Vec2f
const
&
origin
()
const
{
107
return
m_orig
;
108
}
110
Vec2f
const
&
size
()
const
{
111
return
m_size
;
112
}
114
Vec2f
const
&
naturalSize
()
const
{
115
return
m_naturalSize
;
116
}
118
Vec2f
const
&
leftTopClipping
()
const
{
119
return
m_LTClip
;
120
}
122
Vec2f
const
&
rightBottomClipping
()
const
{
123
return
m_RBClip
;
124
}
126
WPXUnit
unit
()
const
{
127
return
m_unit
;
128
}
129
static
float
getScaleFactor
(WPXUnit orig, WPXUnit dest) {
130
float
actSc = 1.0, newSc = 1.0;
131
switch
(orig) {
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
case
WPX_PERCENT:
141
case
WPX_GENERIC:
142
default
:
143
MWAW_DEBUG_MSG
((
"MWAWPosition::getScaleFactor %d unit must not appear\n"
,
int
(orig)));
144
}
145
switch
(dest) {
146
case
WPX_TWIP:
147
break
;
148
case
WPX_POINT:
149
newSc=20;
150
break
;
151
case
WPX_INCH:
152
newSc = 1440;
153
break
;
154
case
WPX_PERCENT:
155
case
WPX_GENERIC:
156
default
:
157
MWAW_DEBUG_MSG
((
"MWAWPosition::getScaleFactor %d unit must not appear\n"
,
int
(dest)));
158
}
159
return
actSc/newSc;
160
}
162
float
getInvUnitScale
(WPXUnit fromUnit)
const
{
163
return
getScaleFactor
(fromUnit,
m_unit
);
164
}
165
167
void
setPage
(
int
pg)
const
{
168
const_cast<
MWAWPosition
*
>
(
this
)->
m_page
= pg;
169
}
171
void
setOrigin
(
Vec2f
const
&orig) {
172
m_orig
= orig;
173
}
175
void
setSize
(
Vec2f
const
&sz) {
176
m_size
= sz;
177
}
179
void
setNaturalSize
(
Vec2f
const
&naturalSz) {
180
m_naturalSize
= naturalSz;
181
}
183
void
setUnit
(WPXUnit newUnit) {
184
m_unit
= newUnit;
185
}
187
void
setPagePos
(
int
pg,
Vec2f
const
&newOrig)
const
{
188
const_cast<
MWAWPosition
*
>
(
this
)->
m_page
= pg;
189
const_cast<
MWAWPosition
*
>
(
this
)->
m_orig
= newOrig;
190
}
191
193
void
setRelativePosition
(
AnchorTo
anchor,
XPos
X =
XLeft
,
YPos
Y=
YTop
) {
194
m_anchorTo
= anchor;
195
m_xPos
= X;
196
m_yPos
= Y;
197
}
198
200
void
setClippingPosition
(
Vec2f
lTop,
Vec2f
rBottom) {
201
m_LTClip
= lTop;
202
m_RBClip
= rBottom;
203
}
204
206
int
order
()
const
{
207
return
m_order
;
208
}
210
void
setOrder
(
int
ord)
const
{
211
m_order
= ord;
212
}
213
215
AnchorTo
m_anchorTo
;
217
XPos
m_xPos
;
219
YPos
m_yPos
;
221
Wrapping
m_wrapping
;
222
223
protected
:
225
int
cmp
(
MWAWPosition
const
&f)
const
{
226
int
diff = int(
m_anchorTo
) - int(f.
m_anchorTo
);
227
if
(diff)
return
diff < 0 ? -1 : 1;
228
diff = int(
m_xPos
) - int(f.
m_xPos
);
229
if
(diff)
return
diff < 0 ? -1 : 1;
230
diff = int(
m_yPos
) - int(f.
m_yPos
);
231
if
(diff)
return
diff < 0 ? -1 : 1;
232
diff =
page
() - f.
page
();
233
if
(diff)
return
diff < 0 ? -1 : 1;
234
diff = int(
m_unit
) - int(f.
m_unit
);
235
if
(diff)
return
diff < 0 ? -1 : 1;
236
diff =
m_orig
.
cmpY
(f.
m_orig
);
237
if
(diff)
return
diff;
238
diff =
m_size
.
cmpY
(f.
m_size
);
239
if
(diff)
return
diff;
240
diff =
m_naturalSize
.
cmpY
(f.
m_naturalSize
);
241
if
(diff)
return
diff;
242
diff =
m_LTClip
.
cmpY
(f.
m_LTClip
);
243
if
(diff)
return
diff;
244
diff =
m_RBClip
.
cmpY
(f.
m_RBClip
);
245
if
(diff)
return
diff;
246
247
return
0;
248
}
249
251
int
m_page
;
252
Vec2f
m_orig
,
m_size
/* the size of the data*/
,
m_naturalSize
;
253
Vec2f
m_LTClip
,
m_RBClip
/* the right bottom clip position */
;
255
WPXUnit
m_unit
;
257
mutable
int
m_order
;
258
};
259
260
#endif
261
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Generated on Wed Jul 10 2013 18:15:30 for libmwaw by
doxygen
1.8.4