MWAWPosition.hxx Source File documentation

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, Cell, Unknown };
53 enum Wrapping { WNone, WBackground, WDynamic, WForeground, WParallel, WRunThrough };
55 enum XPos { XRight, XLeft, XCenter, XFull };
57 enum YPos { YTop, YBottom, YCenter, YFull };
58
59 public:
61 explicit MWAWPosition(MWAWVec2f const &orig=MWAWVec2f(), MWAWVec2f const &sz=MWAWVec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_INCH)
62 : m_anchorTo(Unknown)
63 , m_anchorCellName("")
64 , m_xPos(XLeft)
65 , m_yPos(YTop)
66 , m_wrapping(WNone)
67 , m_page(0)
68 , m_orig(orig)
69 , m_size(sz)
70 , m_naturalSize()
71 , m_LTClip()
72 , m_RBClip()
73 , m_unit(theUnit)
74 , m_order(0)
75 {
76 }
77 MWAWPosition(MWAWPosition const &)=default;
78 MWAWPosition &operator=(MWAWPosition const &)=default;
80 ~MWAWPosition();
82 friend std::ostream &operator<<(std::ostream &o, MWAWPosition const &pos)
83 {
84 MWAWVec2f dest(pos.m_orig+pos.m_size);
85 o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
86 switch (pos.m_unit) {
87 case librevenge::RVNG_INCH:
88 o << "(inch)";
89 break;
90 case librevenge::RVNG_POINT:
91 o << "(pt)";
92 break;
93 case librevenge::RVNG_TWIP:
94 o << "(tw)";
95 break;
96 case librevenge::RVNG_PERCENT:
97 case librevenge::RVNG_GENERIC:
98 case librevenge::RVNG_UNIT_ERROR:
99 #if !defined(__clang__)
100 default:
101 #endif
102 break;
103 }
104 if (pos.page()>0) o << ", page=" << pos.page();
105 return o;
106 }
108 bool operator==(MWAWPosition const &f) const
109 {
110 return cmp(f) == 0;
111 }
113 bool operator!=(MWAWPosition const &f) const
114 {
115 return cmp(f) != 0;
116 }
118 bool operator<(MWAWPosition const &f) const
119 {
120 return cmp(f) < 0;
121 }
122
124 int page() const
125 {
126 return m_page;
127 }
129 MWAWVec2f const &origin() const
130 {
131 return m_orig;
132 }
134 MWAWVec2f const &size() const
135 {
136 return m_size;
137 }
139 MWAWVec2f const &naturalSize() const
140 {
141 return m_naturalSize;
142 }
144 MWAWVec2f const &leftTopClipping() const
145 {
146 return m_LTClip;
147 }
149 MWAWVec2f const &rightBottomClipping() const
150 {
151 return m_RBClip;
152 }
154 librevenge::RVNGUnit unit() const
155 {
156 return m_unit;
157 }
158 static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
159 {
160 float actSc = 1.0, newSc = 1.0;
161 switch (orig) {
162 case librevenge::RVNG_TWIP:
163 break;
164 case librevenge::RVNG_POINT:
165 actSc=20;
166 break;
167 case librevenge::RVNG_INCH:
168 actSc = 1440;
169 break;
170 case librevenge::RVNG_PERCENT:
171 case librevenge::RVNG_GENERIC:
172 case librevenge::RVNG_UNIT_ERROR:
173 #if !defined(__clang__)
174 default:
175 #endif
176 MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
177 }
178 switch (dest) {
179 case librevenge::RVNG_TWIP:
180 break;
181 case librevenge::RVNG_POINT:
182 newSc=20;
183 break;
184 case librevenge::RVNG_INCH:
185 newSc = 1440;
186 break;
187 case librevenge::RVNG_PERCENT:
188 case librevenge::RVNG_GENERIC:
189 case librevenge::RVNG_UNIT_ERROR:
190 #if !defined(__clang__)
191 default:
192 #endif
193 MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
194 }
195 return actSc/newSc;
196 }
198 float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
199 {
200 return getScaleFactor(fromUnit, m_unit);
201 }
202
204 void setPage(int pg) const
205 {
206 const_cast<MWAWPosition *>(this)->m_page = pg;
207 }
209 void setOrigin(MWAWVec2f const &orig)
210 {
211 m_orig = orig;
212 }
214 void setSize(MWAWVec2f const &sz)
215 {
216 m_size = sz;
217 }
219 void setNaturalSize(MWAWVec2f const &naturalSz)
220 {
221 m_naturalSize = naturalSz;
222 }
224 void setUnit(librevenge::RVNGUnit newUnit)
225 {
226 m_unit = newUnit;
227 }
229 void setPagePos(int pg, MWAWVec2f const &newOrig) const
230 {
231 const_cast<MWAWPosition *>(this)->m_page = pg;
232 const_cast<MWAWPosition *>(this)->m_orig = newOrig;
233 }
234
236 void setRelativePosition(AnchorTo anchor, XPos X = XLeft, YPos Y=YTop)
237 {
238 m_anchorTo = anchor;
239 m_xPos = X;
240 m_yPos = Y;
241 }
243 void setAnchorToCell(librevenge::RVNGString const &cellName)
244 {
245 m_anchorTo = Cell;
246 m_xPos = XLeft;
247 m_yPos = YTop;
248 m_anchorCellName=cellName;
249 }
251 void setClippingPosition(MWAWVec2f lTop, MWAWVec2f rBottom)
252 {
253 m_LTClip = lTop;
254 m_RBClip = rBottom;
255 }
256
258 int order() const
259 {
260 return m_order;
261 }
263 void setOrder(int ord) const
264 {
265 m_order = ord;
266 }
267
269 AnchorTo m_anchorTo;
271 librevenge::RVNGString m_anchorCellName;
273 XPos m_xPos;
275 YPos m_yPos;
277 Wrapping m_wrapping;
278
279 protected:
281 int cmp(MWAWPosition const &f) const
282 {
283 int diff = int(m_anchorTo) - int(f.m_anchorTo);
284 if (diff) return diff < 0 ? -1 : 1;
285 if (m_anchorCellName<f.m_anchorCellName) return -1;
286 if (m_anchorCellName>f.m_anchorCellName) return 1;
287 diff = int(m_xPos) - int(f.m_xPos);
288 if (diff) return diff < 0 ? -1 : 1;
289 diff = int(m_yPos) - int(f.m_yPos);
290 if (diff) return diff < 0 ? -1 : 1;
291 diff = page() - f.page();
292 if (diff) return diff < 0 ? -1 : 1;
293 diff = int(m_unit) - int(f.m_unit);
294 if (diff) return diff < 0 ? -1 : 1;
295 diff = m_orig.cmpY(f.m_orig);
296 if (diff) return diff;
297 diff = m_size.cmpY(f.m_size);
298 if (diff) return diff;
299 diff = m_naturalSize.cmpY(f.m_naturalSize);
300 if (diff) return diff;
301 diff = m_LTClip.cmpY(f.m_LTClip);
302 if (diff) return diff;
303 diff = m_RBClip.cmpY(f.m_RBClip);
304 if (diff) return diff;
305
306 return 0;
307 }
308
310 int m_page;
311 MWAWVec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
312 MWAWVec2f m_LTClip , m_RBClip /* the right bottom clip position */;
314 librevenge::RVNGUnit m_unit;
316 mutable int m_order;
317 };
318
319 #endif
320 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPosition::Page
Definition: MWAWPosition.hxx:51
MWAWPosition::m_orig
MWAWVec2f m_orig
the origin position in a page
Definition: MWAWPosition.hxx:311
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:314
MWAWPosition::XFull
Definition: MWAWPosition.hxx:55
MWAWPosition::WForeground
Definition: MWAWPosition.hxx:53
MWAWPosition::setOrigin
void setOrigin(MWAWVec2f const &orig)
sets the frame origin
Definition: MWAWPosition.hxx:209
MWAWPosition::cmp
int cmp(MWAWPosition const &f) const
basic function to compare two positions
Definition: MWAWPosition.hxx:281
MWAWPosition::m_order
int m_order
background/foward order
Definition: MWAWPosition.hxx:316
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
MWAWPosition::operator!=
bool operator!=(MWAWPosition const &f) const
basic operator!=
Definition: MWAWPosition.hxx:113
MWAWPosition::m_naturalSize
MWAWVec2f m_naturalSize
the natural size of the data (if known)
Definition: MWAWPosition.hxx:311
MWAWPosition::setNaturalSize
void setNaturalSize(MWAWVec2f const &naturalSz)
sets the natural size (if known)
Definition: MWAWPosition.hxx:219
MWAWPosition::XCenter
Definition: MWAWPosition.hxx:55
MWAWPosition::XPos
XPos
an enum used to define the relative X position
Definition: MWAWPosition.hxx:55
MWAWPosition::m_anchorCellName
librevenge::RVNGString m_anchorCellName
the anchor cell name
Definition: MWAWPosition.hxx:271
MWAWPosition::rightBottomClipping
MWAWVec2f const & rightBottomClipping() const
returns the right bottom clipping
Definition: MWAWPosition.hxx:149
MWAWPosition::leftTopClipping
MWAWVec2f const & leftTopClipping() const
returns the left top clipping
Definition: MWAWPosition.hxx:144
MWAWPosition::getScaleFactor
static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
Definition: MWAWPosition.hxx:158
MWAWPosition::m_anchorTo
AnchorTo m_anchorTo
anchor position
Definition: MWAWPosition.hxx:269
MWAWPosition::operator==
bool operator==(MWAWPosition const &f) const
basic operator==
Definition: MWAWPosition.hxx:108
MWAWPosition::order
int order() const
returns background/foward order
Definition: MWAWPosition.hxx:258
MWAWPosition::YTop
Definition: MWAWPosition.hxx:57
MWAWPosition::YBottom
Definition: MWAWPosition.hxx:57
MWAWPosition::operator<<
friend std::ostream & operator<<(std::ostream &o, MWAWPosition const &pos)
operator<<
Definition: MWAWPosition.hxx:82
MWAWPosition::unit
librevenge::RVNGUnit unit() const
returns the unit
Definition: MWAWPosition.hxx:154
MWAWPosition::Unknown
Definition: MWAWPosition.hxx:51
MWAWPosition::XLeft
Definition: MWAWPosition.hxx:55
MWAWPosition::WParallel
Definition: MWAWPosition.hxx:53
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
MWAWPosition::WRunThrough
Definition: MWAWPosition.hxx:53
MWAWPosition::AnchorTo
AnchorTo
a list of enum used to defined the anchor
Definition: MWAWPosition.hxx:51
MWAWPosition::YCenter
Definition: MWAWPosition.hxx:57
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:840
MWAWPosition::m_RBClip
MWAWVec2f m_RBClip
Definition: MWAWPosition.hxx:312
MWAWPosition::m_yPos
YPos m_yPos
Y relative position.
Definition: MWAWPosition.hxx:275
MWAWPosition::~MWAWPosition
~MWAWPosition()
destructor
Definition: MWAWPosition.cxx:36
MWAWPosition::naturalSize
MWAWVec2f const & naturalSize() const
returns the natural size (if known)
Definition: MWAWPosition.hxx:139
MWAWPosition::setRelativePosition
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: MWAWPosition.hxx:236
MWAWPosition::m_size
MWAWVec2f m_size
Definition: MWAWPosition.hxx:311
MWAWPosition::setSize
void setSize(MWAWVec2f const &sz)
sets the frame size
Definition: MWAWPosition.hxx:214
MWAWPosition::size
MWAWVec2f const & size() const
returns the frame size
Definition: MWAWPosition.hxx:134
MWAWPosition::m_xPos
XPos m_xPos
X relative position.
Definition: MWAWPosition.hxx:273
MWAWPosition::Cell
Definition: MWAWPosition.hxx:51
MWAWPosition::Paragraph
Definition: MWAWPosition.hxx:51
MWAWPosition::m_LTClip
MWAWVec2f m_LTClip
the left top clip position
Definition: MWAWPosition.hxx:312
MWAWPosition::setAnchorToCell
void setAnchorToCell(librevenge::RVNGString const &cellName)
sets the anchor to a cell position
Definition: MWAWPosition.hxx:243
MWAWPosition::MWAWPosition
MWAWPosition(MWAWVec2f const &orig=MWAWVec2f(), MWAWVec2f const &sz=MWAWVec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_INCH)
constructor
Definition: MWAWPosition.hxx:61
MWAWPosition::WNone
Definition: MWAWPosition.hxx:53
MWAWPosition::setPagePos
void setPagePos(int pg, MWAWVec2f const &newOrig) const
sets/resets the page and the origin
Definition: MWAWPosition.hxx:229
MWAWPosition::Wrapping
Wrapping
an enum used to define the wrapping: none, ...
Definition: MWAWPosition.hxx:53
MWAWPosition::operator<
bool operator<(MWAWPosition const &f) const
basic operator<
Definition: MWAWPosition.hxx:118
MWAWVec2::cmpY
int cmpY(MWAWVec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:784
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:224
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:198
MWAWPosition::operator=
MWAWPosition & operator=(MWAWPosition const &)=default
MWAWPosition::setClippingPosition
void setClippingPosition(MWAWVec2f lTop, MWAWVec2f rBottom)
sets the clipping position
Definition: MWAWPosition.hxx:251
MWAWPosition::Frame
Definition: MWAWPosition.hxx:51
MWAWPosition::CharBaseLine
Definition: MWAWPosition.hxx:51
MWAWPosition::origin
MWAWVec2f const & origin() const
return the frame origin
Definition: MWAWPosition.hxx:129
MWAWPosition::m_wrapping
Wrapping m_wrapping
Wrapping.
Definition: MWAWPosition.hxx:277
MWAWPosition::setOrder
void setOrder(int ord) const
set background/foward order
Definition: MWAWPosition.hxx:263
MWAWPosition::m_page
int m_page
the page
Definition: MWAWPosition.hxx:310
MWAWPosition::setPage
void setPage(int pg) const
sets the page
Definition: MWAWPosition.hxx:204
MWAWPosition::YFull
Definition: MWAWPosition.hxx:57
MWAWPosition::page
int page() const
returns the frame page
Definition: MWAWPosition.hxx:124
MWAWVec2< float >