MWAWPosition.hxx Source File documentation

- 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 <librevenge/librevenge.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, WForeground, 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(), librevenge::RVNGUnit theUnit=librevenge::RVNG_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 {
69 Vec2f dest(pos.m_orig+pos.m_size);
70 o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
71 switch (pos.m_unit) {
72 case librevenge::RVNG_INCH:
73 o << "(inch)";
74 break;
75 case librevenge::RVNG_POINT:
76 o << "(pt)";
77 break;
78 case librevenge::RVNG_TWIP:
79 o << "(tw)";
80 break;
81 case librevenge::RVNG_PERCENT:
82 case librevenge::RVNG_GENERIC:
83 case librevenge::RVNG_UNIT_ERROR:
84 default:
85 break;
86 }
87 if (pos.page()>0) o << ", page=" << pos.page();
88 return o;
89 }
91 bool operator==(MWAWPosition const &f) const
92 {
93 return cmp(f) == 0;
94 }
96 bool operator!=(MWAWPosition const &f) const
97 {
98 return cmp(f) != 0;
99 }
101 bool operator<(MWAWPosition const &f) const
102 {
103 return cmp(f) < 0;
104 }
105
107 int page() const
108 {
109 return m_page;
110 }
112 Vec2f const &origin() const
113 {
114 return m_orig;
115 }
117 Vec2f const &size() const
118 {
119 return m_size;
120 }
122 Vec2f const &naturalSize() const
123 {
124 return m_naturalSize;
125 }
127 Vec2f const &leftTopClipping() const
128 {
129 return m_LTClip;
130 }
132 Vec2f const &rightBottomClipping() const
133 {
134 return m_RBClip;
135 }
137 librevenge::RVNGUnit unit() const
138 {
139 return m_unit;
140 }
141 static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
142 {
143 float actSc = 1.0, newSc = 1.0;
144 switch (orig) {
145 case librevenge::RVNG_TWIP:
146 break;
147 case librevenge::RVNG_POINT:
148 actSc=20;
149 break;
150 case librevenge::RVNG_INCH:
151 actSc = 1440;
152 break;
153 case librevenge::RVNG_PERCENT:
154 case librevenge::RVNG_GENERIC:
155 case librevenge::RVNG_UNIT_ERROR:
156 default:
157 MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
158 }
159 switch (dest) {
160 case librevenge::RVNG_TWIP:
161 break;
162 case librevenge::RVNG_POINT:
163 newSc=20;
164 break;
165 case librevenge::RVNG_INCH:
166 newSc = 1440;
167 break;
168 case librevenge::RVNG_PERCENT:
169 case librevenge::RVNG_GENERIC:
170 case librevenge::RVNG_UNIT_ERROR:
171 default:
172 MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
173 }
174 return actSc/newSc;
175 }
177 float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
178 {
179 return getScaleFactor(fromUnit, m_unit);
180 }
181
183 void setPage(int pg) const
184 {
185 const_cast<MWAWPosition *>(this)->m_page = pg;
186 }
188 void setOrigin(Vec2f const &orig)
189 {
190 m_orig = orig;
191 }
193 void setSize(Vec2f const &sz)
194 {
195 m_size = sz;
196 }
198 void setNaturalSize(Vec2f const &naturalSz)
199 {
200 m_naturalSize = naturalSz;
201 }
203 void setUnit(librevenge::RVNGUnit newUnit)
204 {
205 m_unit = newUnit;
206 }
208 void setPagePos(int pg, Vec2f const &newOrig) const
209 {
210 const_cast<MWAWPosition *>(this)->m_page = pg;
211 const_cast<MWAWPosition *>(this)->m_orig = newOrig;
212 }
213
215 void setRelativePosition(AnchorTo anchor, XPos X = XLeft, YPos Y=YTop)
216 {
217 m_anchorTo = anchor;
218 m_xPos = X;
219 m_yPos = Y;
220 }
221
223 void setClippingPosition(Vec2f lTop, Vec2f rBottom)
224 {
225 m_LTClip = lTop;
226 m_RBClip = rBottom;
227 }
228
230 int order() const
231 {
232 return m_order;
233 }
235 void setOrder(int ord) const
236 {
237 m_order = ord;
238 }
239
241 AnchorTo m_anchorTo;
243 XPos m_xPos;
245 YPos m_yPos;
247 Wrapping m_wrapping;
248
249 protected:
251 int cmp(MWAWPosition const &f) const
252 {
253 int diff = int(m_anchorTo) - int(f.m_anchorTo);
254 if (diff) return diff < 0 ? -1 : 1;
255 diff = int(m_xPos) - int(f.m_xPos);
256 if (diff) return diff < 0 ? -1 : 1;
257 diff = int(m_yPos) - int(f.m_yPos);
258 if (diff) return diff < 0 ? -1 : 1;
259 diff = page() - f.page();
260 if (diff) return diff < 0 ? -1 : 1;
261 diff = int(m_unit) - int(f.m_unit);
262 if (diff) return diff < 0 ? -1 : 1;
263 diff = m_orig.cmpY(f.m_orig);
264 if (diff) return diff;
265 diff = m_size.cmpY(f.m_size);
266 if (diff) return diff;
267 diff = m_naturalSize.cmpY(f.m_naturalSize);
268 if (diff) return diff;
269 diff = m_LTClip.cmpY(f.m_LTClip);
270 if (diff) return diff;
271 diff = m_RBClip.cmpY(f.m_RBClip);
272 if (diff) return diff;
273
274 return 0;
275 }
276
278 int m_page;
279 Vec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
280 Vec2f m_LTClip , m_RBClip /* the right bottom clip position */;
282 librevenge::RVNGUnit m_unit;
284 mutable int m_order;
285 };
286
287 #endif
288 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPosition::Page
Definition: MWAWPosition.hxx:51
MWAWPosition::setPagePos
void setPagePos(int pg, Vec2f const &newOrig) const
sets/resets the page and the origin
Definition: MWAWPosition.hxx:208
MWAWPosition::m_unit
librevenge::RVNGUnit m_unit
the unit used in orig, in m_size and in m_LTClip , .... Default: in inches
Definition: MWAWPosition.hxx:282
MWAWPosition::XFull
Definition: MWAWPosition.hxx:55
MWAWPosition::WForeground
Definition: MWAWPosition.hxx:53
MWAWPosition::m_size
Vec2f m_size
Definition: MWAWPosition.hxx:279
MWAWPosition::leftTopClipping
Vec2f const & leftTopClipping() const
returns the left top clipping
Definition: MWAWPosition.hxx:127
MWAWPosition::setPage
void setPage(int pg) const
sets the page
Definition: MWAWPosition.hxx:183
MWAWPosition::m_order
int m_order
background/foward order
Definition: MWAWPosition.hxx:284
MWAWPosition::Char
Definition: MWAWPosition.hxx:51
MWAWPosition::WDynamic
Definition: MWAWPosition.hxx:53
MWAWPosition::XRight
Definition: MWAWPosition.hxx:55
libmwaw_internal.hxx
MWAWPosition::YPos
YPos
an enum used to define the relative Y position
Definition: MWAWPosition.hxx:57
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libmwaw_internal.hxx:711
MWAWPosition::m_orig
Vec2f m_orig
the origin position in a page
Definition: MWAWPosition.hxx:279
MWAWPosition::XCenter
Definition: MWAWPosition.hxx:55
MWAWPosition::XPos
XPos
an enum used to define the relative X position
Definition: MWAWPosition.hxx:55
MWAWPosition::m_LTClip
Vec2f m_LTClip
the left top clip position
Definition: MWAWPosition.hxx:280
MWAWPosition::operator<
bool operator<(MWAWPosition const &f) const
basic operator<
Definition: MWAWPosition.hxx:101
MWAWPosition::operator!=
bool operator!=(MWAWPosition const &f) const
basic operator!=
Definition: MWAWPosition.hxx:96
MWAWPosition::getScaleFactor
static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
Definition: MWAWPosition.hxx:141
MWAWPosition::m_anchorTo
AnchorTo m_anchorTo
anchor position
Definition: MWAWPosition.hxx:241
MWAWPosition::origin
Vec2f const & origin() const
return the frame origin
Definition: MWAWPosition.hxx:112
MWAWPosition::setClippingPosition
void setClippingPosition(Vec2f lTop, Vec2f rBottom)
sets the clipping position
Definition: MWAWPosition.hxx:223
MWAWPosition::YTop
Definition: MWAWPosition.hxx:57
MWAWPosition::YBottom
Definition: MWAWPosition.hxx:57
MWAWPosition::naturalSize
Vec2f const & naturalSize() const
returns the natural size (if known)
Definition: MWAWPosition.hxx:122
MWAWPosition::operator<<
friend std::ostream & operator<<(std::ostream &o, MWAWPosition const &pos)
operator<<
Definition: MWAWPosition.hxx:67
MWAWPosition::Unknown
Definition: MWAWPosition.hxx:51
MWAWPosition::XLeft
Definition: MWAWPosition.hxx:55
MWAWPosition::setOrder
void setOrder(int ord) const
set background/foward order
Definition: MWAWPosition.hxx:235
MWAWPosition::setSize
void setSize(Vec2f const &sz)
sets the frame size
Definition: MWAWPosition.hxx:193
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:117
MWAWPosition::WRunThrough
Definition: MWAWPosition.hxx:53
MWAWPosition::operator==
bool operator==(MWAWPosition const &f) const
basic operator==
Definition: MWAWPosition.hxx:91
MWAWPosition::AnchorTo
AnchorTo
a list of enum used to defined the anchor
Definition: MWAWPosition.hxx:51
MWAWPosition::YCenter
Definition: MWAWPosition.hxx:57
MWAWPosition::rightBottomClipping
Vec2f const & rightBottomClipping() const
returns the right bottom clipping
Definition: MWAWPosition.hxx:132
MWAWPosition::m_yPos
YPos m_yPos
Y relative position.
Definition: MWAWPosition.hxx:245
MWAWPosition::setRelativePosition
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: MWAWPosition.hxx:215
Vec2::cmpY
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:655
MWAWPosition::m_xPos
XPos m_xPos
X relative position.
Definition: MWAWPosition.hxx:243
MWAWPosition::setNaturalSize
void setNaturalSize(Vec2f const &naturalSz)
sets the natural size (if known)
Definition: MWAWPosition.hxx:198
MWAWPosition::setOrigin
void setOrigin(Vec2f const &orig)
sets the frame origin
Definition: MWAWPosition.hxx:188
MWAWPosition::Paragraph
Definition: MWAWPosition.hxx:51
MWAWPosition::~MWAWPosition
virtual ~MWAWPosition()
Definition: MWAWPosition.hxx:65
MWAWPosition::MWAWPosition
MWAWPosition(Vec2f const &orig=Vec2f(), Vec2f const &sz=Vec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_INCH)
constructor
Definition: MWAWPosition.hxx:61
MWAWPosition::cmp
int cmp(MWAWPosition const &f) const
basic function to compare two positions
Definition: MWAWPosition.hxx:251
MWAWPosition::WNone
Definition: MWAWPosition.hxx:53
MWAWPosition::Wrapping
Wrapping
an enum used to define the wrapping: none, ...
Definition: MWAWPosition.hxx:53
MWAWPosition::unit
librevenge::RVNGUnit unit() const
returns the unit
Definition: MWAWPosition.hxx:137
MWAWPosition::WBackground
Definition: MWAWPosition.hxx:53
MWAWPosition
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: MWAWPosition.hxx:47
MWAWPosition::setUnit
void setUnit(librevenge::RVNGUnit newUnit)
sets the dimension unit
Definition: MWAWPosition.hxx:203
MWAWPosition::page
int page() const
returns the frame page
Definition: MWAWPosition.hxx:107
MWAWPosition::m_naturalSize
Vec2f m_naturalSize
the natural size of the data (if known)
Definition: MWAWPosition.hxx:279
Vec2< float >
MWAWPosition::Frame
Definition: MWAWPosition.hxx:51
MWAWPosition::CharBaseLine
Definition: MWAWPosition.hxx:51
MWAWPosition::m_wrapping
Wrapping m_wrapping
Wrapping.
Definition: MWAWPosition.hxx:247
MWAWPosition::m_page
int m_page
the page
Definition: MWAWPosition.hxx:278
MWAWPosition::YFull
Definition: MWAWPosition.hxx:57
MWAWPosition::m_RBClip
Vec2f m_RBClip
Definition: MWAWPosition.hxx:280
MWAWPosition::order
int order() const
returns background/foward order
Definition: MWAWPosition.hxx:230
MWAWPosition::size
Vec2f const & size() const
returns the frame size
Definition: MWAWPosition.hxx:117
MWAWPosition::getInvUnitScale
float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
returns a float which can be used to scale some data in object unit
Definition: MWAWPosition.hxx:177