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 <librevenge/librevenge.h>
32 
33 #include "libwps_internal.h"
34 
40 {
41 public:
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(), librevenge::RVNGUnit unt=librevenge::RVNG_INCH)
54  : m_anchorTo(Char)
56  , m_xPos(XLeft)
57  , m_yPos(YTop)
58  , m_wrapping(WNone)
59  , m_page(0)
60  , m_orig(orig)
61  , m_size(sz)
62  , m_naturalSize()
63  , m_unit(unt)
64  , m_order(0) {}
68  friend std::ostream &operator<<(std::ostream &o, WPSPosition const &pos)
69  {
70  Vec2f dest(pos.m_orig+pos.m_size);
71  o << "Pos=" << pos.m_orig << "x" << dest;
72  switch (pos.m_unit)
73  {
74  case librevenge::RVNG_INCH:
75  o << "(inch)";
76  break;
77  case librevenge::RVNG_POINT:
78  o << "(pt)";
79  break;
80  case librevenge::RVNG_TWIP:
81  o << "(tw)";
82  break;
83  case librevenge::RVNG_PERCENT:
84  case librevenge::RVNG_GENERIC:
85  case librevenge::RVNG_UNIT_ERROR:
86  default:
87  break;
88  }
89  if (pos.page()>0) o << ", page=" << pos.page();
90  return o;
91  }
93  bool operator==(WPSPosition const &f) const
94  {
95  return cmp(f) == 0;
96  }
98  bool operator!=(WPSPosition const &f) const
99  {
100  return cmp(f) != 0;
101  }
103  bool operator<(WPSPosition const &f) const
104  {
105  return cmp(f) < 0;
106  }
107 
109  int page() const
110  {
111  return m_page;
112  }
114  Vec2f const &origin() const
115  {
116  return m_orig;
117  }
119  Vec2f const &size() const
120  {
121  return m_size;
122  }
124  Vec2f const &naturalSize() const
125  {
126  return m_naturalSize;
127  }
129  librevenge::RVNGUnit unit() const
130  {
131  return m_unit;
132  }
134  static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
135  {
136  float actSc = 1.0, newSc = 1.0;
137  switch (orig)
138  {
139  case librevenge::RVNG_TWIP:
140  break;
141  case librevenge::RVNG_POINT:
142  actSc=20;
143  break;
144  case librevenge::RVNG_INCH:
145  actSc = 1440;
146  break;
147  case librevenge::RVNG_PERCENT:
148  case librevenge::RVNG_GENERIC:
149  case librevenge::RVNG_UNIT_ERROR:
150  default:
151  WPS_DEBUG_MSG(("WPSPosition::getScaleFactor %d unit must not appear\n", int(orig)));
152  }
153  switch (dest)
154  {
155  case librevenge::RVNG_TWIP:
156  break;
157  case librevenge::RVNG_POINT:
158  newSc=20;
159  break;
160  case librevenge::RVNG_INCH:
161  newSc = 1440;
162  break;
163  case librevenge::RVNG_PERCENT:
164  case librevenge::RVNG_GENERIC:
165  case librevenge::RVNG_UNIT_ERROR:
166  default:
167  WPS_DEBUG_MSG(("WPSPosition::getScaleFactor %d unit must not appear\n", int(dest)));
168  }
169  return actSc/newSc;
170  }
172  float getInvUnitScale(librevenge::RVNGUnit unt) const
173  {
174  return getScaleFactor(unt, m_unit);
175  }
176 
178  void setPage(int pg) const
179  {
180  const_cast<WPSPosition *>(this)->m_page = pg;
181  }
183  void setOrigin(Vec2f const &orig)
184  {
185  m_orig = orig;
186  }
188  void setSize(Vec2f const &sz)
189  {
190  m_size = sz;
191  }
193  void setNaturalSize(Vec2f const &natSize)
194  {
195  m_naturalSize = natSize;
196  }
198  void setUnit(librevenge::RVNGUnit unt)
199  {
200  m_unit = unt;
201  }
203  void setPagePos(int pg, Vec2f const &newOrig) const
204  {
205  const_cast<WPSPosition *>(this)->m_page = pg;
206  const_cast<WPSPosition *>(this)->m_orig = newOrig;
207  }
208 
211  {
212  m_anchorTo = anchor;
213  m_xPos = X;
214  m_yPos = Y;
215  }
216 
218  void setAnchorToCell(librevenge::RVNGString const &cellName)
219  {
220  m_anchorTo = Cell;
221  m_xPos = XLeft;
222  m_yPos = YTop;
223  m_anchorCellName=cellName;
224  }
226  int order() const
227  {
228  return m_order;
229  }
231  void setOrder(int ord) const
232  {
233  m_order = ord;
234  }
235 
239  librevenge::RVNGString m_anchorCellName;
246 
247 protected:
249  int cmp(WPSPosition const &f) const
250  {
251  int diff = int(m_anchorTo) - int(f.m_anchorTo);
252  if (diff) return diff < 0 ? -1 : 1;
253  if (m_anchorCellName<f.m_anchorCellName) return -1;
254  if (m_anchorCellName>f.m_anchorCellName) return 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 
270  return 0;
271  }
272 
274  int m_page;
275  Vec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
277  librevenge::RVNGUnit m_unit;
279  mutable int m_order;
280 };
281 
282 #endif
283 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Vec2f m_naturalSize
the natural size of the data (if known)
Definition: WPSPosition.h:275
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libwps_internal.h:656
librevenge::RVNGString m_anchorCellName
the anchor cell name
Definition: WPSPosition.h:239
YPos
an enum used to define the relative Y position
Definition: WPSPosition.h:49
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:704
bool operator==(WPSPosition const &f) const
basic operator==
Definition: WPSPosition.h:93
Definition: WPSPosition.h:47
Definition: WPSPosition.h:49
Definition: WPSPosition.h:43
Definition: WPSPosition.h:43
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: WPSPosition.h:210
void setSize(Vec2f const &sz)
sets the frame size
Definition: WPSPosition.h:188
int m_order
background/foward order
Definition: WPSPosition.h:279
Definition: WPSPosition.h:45
friend std::ostream & operator<<(std::ostream &o, WPSPosition const &pos)
operator<<
Definition: WPSPosition.h:68
void setAnchorToCell(librevenge::RVNGString const &cellName)
sets the anchor to a cell position
Definition: WPSPosition.h:218
void setPage(int pg) const
sets the page
Definition: WPSPosition.h:178
Definition: WPSPosition.h:45
Definition: WPSPosition.h:49
librevenge::RVNGUnit m_unit
the unit used in orig and in m_size. Default: in inches
Definition: WPSPosition.h:277
int page() const
returns the frame page
Definition: WPSPosition.h:109
void setNaturalSize(Vec2f const &natSize)
sets the natural size (if known)
Definition: WPSPosition.h:193
Wrapping
an enum used to define the wrapping
Definition: WPSPosition.h:45
Definition: WPSPosition.h:47
AnchorTo m_anchorTo
anchor position
Definition: WPSPosition.h:237
Definition: WPSPosition.h:45
Wrapping m_wrapping
Wrapping.
Definition: WPSPosition.h:245
Definition: WPSPosition.h:47
Definition: WPSPosition.h:43
void setPagePos(int pg, Vec2f const &newOrig) const
sets/resets the page and the origin
Definition: WPSPosition.h:203
Definition: WPSPosition.h:49
Vec2f const & naturalSize() const
returns the natural size (if known)
Definition: WPSPosition.h:124
Vec2f m_orig
the origin position in a page
Definition: WPSPosition.h:275
Vec2f m_size
Definition: WPSPosition.h:275
float getInvUnitScale(librevenge::RVNGUnit unt) const
returns a float which can be used to scale some data in object unit
Definition: WPSPosition.h:172
Vec2f const & origin() const
return the frame origin
Definition: WPSPosition.h:114
bool operator<(WPSPosition const &f) const
basic operator<
Definition: WPSPosition.h:103
int order() const
returns background/foward order
Definition: WPSPosition.h:226
YPos m_yPos
Y relative position.
Definition: WPSPosition.h:243
Definition: WPSPosition.h:43
void setUnit(librevenge::RVNGUnit unt)
sets the dimension unit
Definition: WPSPosition.h:198
void setOrder(int ord) const
set background/foward order
Definition: WPSPosition.h:231
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:134
bool operator!=(WPSPosition const &f) const
basic operator!=
Definition: WPSPosition.h:98
Vec2f const & size() const
returns the frame size
Definition: WPSPosition.h:119
XPos
an enum used to define the relative X position
Definition: WPSPosition.h:47
~WPSPosition()
destructor
Definition: WPSPosition.h:66
void setOrigin(Vec2f const &orig)
sets the frame origin
Definition: WPSPosition.h:183
WPSPosition(Vec2f const &orig=Vec2f(), Vec2f const &sz=Vec2f(), librevenge::RVNGUnit unt=librevenge::RVNG_INCH)
constructor
Definition: WPSPosition.h:53
Definition: WPSPosition.h:43
Definition: WPSPosition.h:49
librevenge::RVNGUnit unit() const
returns the unit
Definition: WPSPosition.h:129
XPos m_xPos
X relative position.
Definition: WPSPosition.h:241
Definition: WPSPosition.h:47
Definition: WPSPosition.h:43
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: WPSPosition.h:39
static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
returns a float which can be used to convert between to unit
Definition: WPSPosition.h:134
int cmp(WPSPosition const &f) const
basic function to compare two positions
Definition: WPSPosition.h:249
int m_page
the page
Definition: WPSPosition.h:274
Definition: WPSPosition.h:43
AnchorTo
a list of enum used to defined the anchor
Definition: WPSPosition.h:43

Generated on Fri May 27 2022 03:07:00 for libwps by doxygen 1.8.14