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):
55  m_page(0), m_orig(orig), m_size(sz), m_naturalSize(), m_unit(unt), m_order(0) {}
59  friend std::ostream &operator<<(std::ostream &o, WPSPosition const &pos)
60  {
61  Vec2f dest(pos.m_orig+pos.m_size);
62  o << "Pos=" << pos.m_orig << "x" << dest;
63  switch (pos.m_unit)
64  {
65  case librevenge::RVNG_INCH:
66  o << "(inch)";
67  break;
68  case librevenge::RVNG_POINT:
69  o << "(pt)";
70  break;
71  case librevenge::RVNG_TWIP:
72  o << "(tw)";
73  break;
74  case librevenge::RVNG_PERCENT:
75  case librevenge::RVNG_GENERIC:
76  case librevenge::RVNG_UNIT_ERROR:
77  default:
78  break;
79  }
80  if (pos.page()>0) o << ", page=" << pos.page();
81  return o;
82  }
84  bool operator==(WPSPosition const &f) const
85  {
86  return cmp(f) == 0;
87  }
89  bool operator!=(WPSPosition const &f) const
90  {
91  return cmp(f) != 0;
92  }
94  bool operator<(WPSPosition const &f) const
95  {
96  return cmp(f) < 0;
97  }
98 
100  int page() const
101  {
102  return m_page;
103  }
105  Vec2f const &origin() const
106  {
107  return m_orig;
108  }
110  Vec2f const &size() const
111  {
112  return m_size;
113  }
115  Vec2f const &naturalSize() const
116  {
117  return m_naturalSize;
118  }
120  librevenge::RVNGUnit unit() const
121  {
122  return m_unit;
123  }
125  static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
126  {
127  float actSc = 1.0, newSc = 1.0;
128  switch (orig)
129  {
130  case librevenge::RVNG_TWIP:
131  break;
132  case librevenge::RVNG_POINT:
133  actSc=20;
134  break;
135  case librevenge::RVNG_INCH:
136  actSc = 1440;
137  break;
138  case librevenge::RVNG_PERCENT:
139  case librevenge::RVNG_GENERIC:
140  case librevenge::RVNG_UNIT_ERROR:
141  default:
142  WPS_DEBUG_MSG(("WPSPosition::getScaleFactor %d unit must not appear\n", int(orig)));
143  }
144  switch (dest)
145  {
146  case librevenge::RVNG_TWIP:
147  break;
148  case librevenge::RVNG_POINT:
149  newSc=20;
150  break;
151  case librevenge::RVNG_INCH:
152  newSc = 1440;
153  break;
154  case librevenge::RVNG_PERCENT:
155  case librevenge::RVNG_GENERIC:
156  case librevenge::RVNG_UNIT_ERROR:
157  default:
158  WPS_DEBUG_MSG(("WPSPosition::getScaleFactor %d unit must not appear\n", int(dest)));
159  }
160  return actSc/newSc;
161  }
163  float getInvUnitScale(librevenge::RVNGUnit unt) const
164  {
165  return getScaleFactor(unt, m_unit);
166  }
167 
169  void setPage(int pg) const
170  {
171  const_cast<WPSPosition *>(this)->m_page = pg;
172  }
174  void setOrigin(Vec2f const &orig)
175  {
176  m_orig = orig;
177  }
179  void setSize(Vec2f const &sz)
180  {
181  m_size = sz;
182  }
184  void setNaturalSize(Vec2f const &natSize)
185  {
186  m_naturalSize = natSize;
187  }
189  void setUnit(librevenge::RVNGUnit unt)
190  {
191  m_unit = unt;
192  }
194  void setPagePos(int pg, Vec2f const &newOrig) const
195  {
196  const_cast<WPSPosition *>(this)->m_page = pg;
197  const_cast<WPSPosition *>(this)->m_orig = newOrig;
198  }
199 
202  {
203  m_anchorTo = anchor;
204  m_xPos = X;
205  m_yPos = Y;
206  }
207 
209  int order() const
210  {
211  return m_order;
212  }
214  void setOrder(int ord) const
215  {
216  m_order = ord;
217  }
218 
227 
228 protected:
230  int cmp(WPSPosition const &f) const
231  {
232  int diff = int(m_anchorTo) - int(f.m_anchorTo);
233  if (diff) return diff < 0 ? -1 : 1;
234  diff = int(m_xPos) - int(f.m_xPos);
235  if (diff) return diff < 0 ? -1 : 1;
236  diff = int(m_yPos) - int(f.m_yPos);
237  if (diff) return diff < 0 ? -1 : 1;
238  diff = page() - f.page();
239  if (diff) return diff < 0 ? -1 : 1;
240  diff = int(m_unit) - int(f.m_unit);
241  if (diff) return diff < 0 ? -1 : 1;
242  diff = m_orig.cmpY(f.m_orig);
243  if (diff) return diff;
244  diff = m_size.cmpY(f.m_size);
245  if (diff) return diff;
246  diff = m_naturalSize.cmpY(f.m_naturalSize);
247  if (diff) return diff;
248 
249  return 0;
250  }
251 
253  int m_page;
254  Vec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
256  librevenge::RVNGUnit m_unit;
258  mutable int m_order;
259 };
260 
261 #endif
262 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Vec2f m_naturalSize
the natural size of the data (if known)
Definition: WPSPosition.h:254
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libwps_internal.h:673
YPos
an enum used to define the relative Y position
Definition: WPSPosition.h:49
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:721
bool operator==(WPSPosition const &f) const
basic operator==
Definition: WPSPosition.h:84
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:201
void setSize(Vec2f const &sz)
sets the frame size
Definition: WPSPosition.h:179
int m_order
background/foward order
Definition: WPSPosition.h:258
Definition: WPSPosition.h:45
friend std::ostream & operator<<(std::ostream &o, WPSPosition const &pos)
operator<<
Definition: WPSPosition.h:59
void setPage(int pg) const
sets the page
Definition: WPSPosition.h:169
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:256
int page() const
returns the frame page
Definition: WPSPosition.h:100
void setNaturalSize(Vec2f const &natSize)
sets the natural size (if known)
Definition: WPSPosition.h:184
Wrapping
an enum used to define the wrapping
Definition: WPSPosition.h:45
Definition: WPSPosition.h:47
AnchorTo m_anchorTo
anchor position
Definition: WPSPosition.h:220
Definition: WPSPosition.h:45
Wrapping m_wrapping
Wrapping.
Definition: WPSPosition.h:226
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:194
Definition: WPSPosition.h:49
Vec2f const & naturalSize() const
returns the natural size (if known)
Definition: WPSPosition.h:115
Vec2f m_orig
the origin position in a page
Definition: WPSPosition.h:254
Vec2f m_size
Definition: WPSPosition.h:254
float getInvUnitScale(librevenge::RVNGUnit unt) const
returns a float which can be used to scale some data in object unit
Definition: WPSPosition.h:163
Vec2f const & origin() const
return the frame origin
Definition: WPSPosition.h:105
bool operator<(WPSPosition const &f) const
basic operator<
Definition: WPSPosition.h:94
int order() const
returns background/foward order
Definition: WPSPosition.h:209
YPos m_yPos
Y relative position.
Definition: WPSPosition.h:224
Definition: WPSPosition.h:43
void setUnit(librevenge::RVNGUnit unt)
sets the dimension unit
Definition: WPSPosition.h:189
void setOrder(int ord) const
set background/foward order
Definition: WPSPosition.h:214
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:132
bool operator!=(WPSPosition const &f) const
basic operator!=
Definition: WPSPosition.h:89
Vec2f const & size() const
returns the frame size
Definition: WPSPosition.h:110
XPos
an enum used to define the relative X position
Definition: WPSPosition.h:47
~WPSPosition()
destructor
Definition: WPSPosition.h:57
void setOrigin(Vec2f const &orig)
sets the frame origin
Definition: WPSPosition.h:174
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:120
XPos m_xPos
X relative position.
Definition: WPSPosition.h:222
Definition: WPSPosition.h:47
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:125
int cmp(WPSPosition const &f) const
basic function to compare two positions
Definition: WPSPosition.h:230
int m_page
the page
Definition: WPSPosition.h:253
Definition: WPSPosition.h:43
AnchorTo
a list of enum used to defined the anchor
Definition: WPSPosition.h:43

Generated on Fri Jun 16 2017 12:32:59 for libwps by doxygen 1.8.13