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 <libwpd/libwpd.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(), WPXUnit unt=WPX_INCH):
55  m_page(0), m_orig(orig), m_size(sz), m_naturalSize(), m_unit(unt), m_order(0) {}
56 
57  virtual ~WPSPosition() {}
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 WPX_INCH:
66  o << "(inch)";
67  break;
68  case WPX_POINT:
69  o << "(pt)";
70  break;
71  case WPX_TWIP:
72  o << "(tw)";
73  break;
74  case WPX_PERCENT:
75  case WPX_GENERIC:
76  default:
77  break;
78  }
79  if (pos.page()>0) o << ", page=" << pos.page();
80  return o;
81  }
83  bool operator==(WPSPosition const &f) const
84  {
85  return cmp(f) == 0;
86  }
88  bool operator!=(WPSPosition const &f) const
89  {
90  return cmp(f) != 0;
91  }
93  bool operator<(WPSPosition const &f) const
94  {
95  return cmp(f) < 0;
96  }
97 
99  int page() const
100  {
101  return m_page;
102  }
104  Vec2f const &origin() const
105  {
106  return m_orig;
107  }
109  Vec2f const &size() const
110  {
111  return m_size;
112  }
114  Vec2f const &naturalSize() const
115  {
116  return m_naturalSize;
117  }
119  WPXUnit unit() const
120  {
121  return m_unit;
122  }
124  static float getScaleFactor(WPXUnit orig, WPXUnit dest)
125  {
126  float actSc = 1.0, newSc = 1.0;
127  switch(orig)
128  {
129  case WPX_TWIP:
130  break;
131  case WPX_POINT:
132  actSc=20;
133  break;
134  case WPX_INCH:
135  actSc = 1440;
136  break;
137  case WPX_PERCENT:
138  case WPX_GENERIC:
139  default:
140  WPS_DEBUG_MSG(("WPSPosition::getScaleFactor %d unit must not appear\n", int(orig)));
141  }
142  switch(dest)
143  {
144  case WPX_TWIP:
145  break;
146  case WPX_POINT:
147  newSc=20;
148  break;
149  case WPX_INCH:
150  newSc = 1440;
151  break;
152  case WPX_PERCENT:
153  case WPX_GENERIC:
154  default:
155  WPS_DEBUG_MSG(("WPSPosition::getScaleFactor %d unit must not appear\n", int(dest)));
156  }
157  return actSc/newSc;
158  }
160  float getInvUnitScale(WPXUnit unt) const
161  {
162  return getScaleFactor(unt, m_unit);
163  }
164 
166  void setPage(int pg) const
167  {
168  const_cast<WPSPosition *>(this)->m_page = pg;
169  }
171  void setOrigin(Vec2f const &orig)
172  {
173  m_orig = orig;
174  }
176  void setSize(Vec2f const &sz)
177  {
178  m_size = sz;
179  }
181  void setNaturalSize(Vec2f const &natSize)
182  {
183  m_naturalSize = natSize;
184  }
186  void setUnit(WPXUnit unt)
187  {
188  m_unit = unt;
189  }
191  void setPagePos(int pg, Vec2f const &newOrig) const
192  {
193  const_cast<WPSPosition *>(this)->m_page = pg;
194  const_cast<WPSPosition *>(this)->m_orig = newOrig;
195  }
196 
199  {
200  m_anchorTo = anchor;
201  m_xPos = X;
202  m_yPos = Y;
203  }
204 
206  int order() const
207  {
208  return m_order;
209  }
211  void setOrder(int ord) const
212  {
213  m_order = ord;
214  }
215 
224 
225 protected:
227  int cmp(WPSPosition const &f) const
228  {
229  int diff = int(m_anchorTo) - int(f.m_anchorTo);
230  if (diff) return diff < 0 ? -1 : 1;
231  diff = int(m_xPos) - int(f.m_xPos);
232  if (diff) return diff < 0 ? -1 : 1;
233  diff = int(m_yPos) - int(f.m_yPos);
234  if (diff) return diff < 0 ? -1 : 1;
235  diff = page() - f.page();
236  if (diff) return diff < 0 ? -1 : 1;
237  diff = int(m_unit) - int(f.m_unit);
238  if (diff) return diff < 0 ? -1 : 1;
239  diff = m_orig.cmpY(f.m_orig);
240  if (diff) return diff;
241  diff = m_size.cmpY(f.m_size);
242  if (diff) return diff;
243  diff = m_naturalSize.cmpY(f.m_naturalSize);
244  if (diff) return diff;
245 
246  return 0;
247  }
248 
250  int m_page;
251  Vec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
253  WPXUnit m_unit;
255  mutable int m_order;
256 };
257 
258 #endif
259 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Vec2f m_naturalSize
the natural size of the data (if known)
Definition: WPSPosition.h:251
void setPage(int pg) const
sets the page
Definition: WPSPosition.h:166
YPos
an enum used to define the relative Y position
Definition: WPSPosition.h:49
bool operator==(WPSPosition const &f) const
basic operator==
Definition: WPSPosition.h:83
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:496
virtual ~WPSPosition()
Definition: WPSPosition.h:57
Definition: WPSPosition.h:47
int page() const
returns the frame page
Definition: WPSPosition.h:99
int cmp(WPSPosition const &f) const
basic function to compare two positions
Definition: WPSPosition.h:227
bool operator!=(WPSPosition const &f) const
basic operator!=
Definition: WPSPosition.h:88
float getInvUnitScale(WPXUnit unt) const
returns a float which can be used to scale some data in object unit
Definition: WPSPosition.h:160
Definition: WPSPosition.h:49
Definition: WPSPosition.h:43
WPSPosition(Vec2f const &orig=Vec2f(), Vec2f const &sz=Vec2f(), WPXUnit unt=WPX_INCH)
constructor
Definition: WPSPosition.h:53
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: WPSPosition.h:198
void setSize(Vec2f const &sz)
sets the frame size
Definition: WPSPosition.h:176
int m_order
background/foward order
Definition: WPSPosition.h:255
Definition: WPSPosition.h:45
WPXUnit m_unit
the unit used in orig and in m_size. Default: in inches
Definition: WPSPosition.h:253
friend std::ostream & operator<<(std::ostream &o, WPSPosition const &pos)
operator&lt;&lt;
Definition: WPSPosition.h:59
Definition: WPSPosition.h:45
Definition: WPSPosition.h:49
void setNaturalSize(Vec2f const &natSize)
sets the natural size (if known)
Definition: WPSPosition.h:181
Wrapping
an enum used to define the wrapping
Definition: WPSPosition.h:45
Vec2f const & naturalSize() const
returns the natural size (if known)
Definition: WPSPosition.h:114
Definition: WPSPosition.h:47
AnchorTo m_anchorTo
anchor position
Definition: WPSPosition.h:217
Definition: WPSPosition.h:45
Wrapping m_wrapping
Wrapping.
Definition: WPSPosition.h:223
Definition: WPSPosition.h:47
Definition: WPSPosition.h:49
Vec2f m_orig
the origin position in a page
Definition: WPSPosition.h:251
void setPagePos(int pg, Vec2f const &newOrig) const
sets/resets the page and the origin
Definition: WPSPosition.h:191
Vec2f m_size
Definition: WPSPosition.h:251
YPos m_yPos
Y relative position.
Definition: WPSPosition.h:221
Definition: WPSPosition.h:43
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libwps_internal.h:438
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:80
static float getScaleFactor(WPXUnit orig, WPXUnit dest)
returns a float which can be used to convert between to unit
Definition: WPSPosition.h:124
XPos
an enum used to define the relative X position
Definition: WPSPosition.h:47
bool operator<(WPSPosition const &f) const
basic operator&lt;
Definition: WPSPosition.h:93
void setOrigin(Vec2f const &orig)
sets the frame origin
Definition: WPSPosition.h:171
Definition: WPSPosition.h:43
Definition: WPSPosition.h:49
Vec2f const & origin() const
return the frame origin
Definition: WPSPosition.h:104
XPos m_xPos
X relative position.
Definition: WPSPosition.h:219
WPXUnit unit() const
returns the unit
Definition: WPSPosition.h:119
int order() const
returns background/foward order
Definition: WPSPosition.h:206
Definition: WPSPosition.h:47
void setUnit(WPXUnit unt)
sets the dimension unit
Definition: WPSPosition.h:186
Vec2f const & size() const
returns the frame size
Definition: WPSPosition.h:109
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: WPSPosition.h:39
void setOrder(int ord) const
set background/foward order
Definition: WPSPosition.h:211
int m_page
the page
Definition: WPSPosition.h:250
Definition: WPSPosition.h:43
AnchorTo
a list of enum used to defined the anchor
Definition: WPSPosition.h:43

Generated on Wed Jun 11 2014 02:26:01 for libwps by doxygen 1.8.5