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 <libwpd/libwpd.h>
40 
41 #include "libmwaw_internal.hxx"
42 
48 {
49 public:
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(), WPXUnit theUnit=WPX_INCH):
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  Vec2f dest(pos.m_orig+pos.m_size);
69  o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
70  switch(pos.m_unit) {
71  case WPX_INCH:
72  o << "(inch)";
73  break;
74  case WPX_POINT:
75  o << "(pt)";
76  break;
77  case WPX_TWIP:
78  o << "(tw)";
79  break;
80  case WPX_PERCENT:
81  case WPX_GENERIC:
82  default:
83  break;
84  }
85  if (pos.page()>0) o << ", page=" << pos.page();
86  return o;
87  }
89  bool operator==(MWAWPosition const &f) const {
90  return cmp(f) == 0;
91  }
93  bool operator!=(MWAWPosition const &f) const {
94  return cmp(f) != 0;
95  }
97  bool operator<(MWAWPosition const &f) const {
98  return cmp(f) < 0;
99  }
100 
102  int page() const {
103  return m_page;
104  }
106  Vec2f const &origin() const {
107  return m_orig;
108  }
110  Vec2f const &size() const {
111  return m_size;
112  }
114  Vec2f const &naturalSize() const {
115  return m_naturalSize;
116  }
118  Vec2f const &leftTopClipping() const {
119  return m_LTClip;
120  }
122  Vec2f const &rightBottomClipping() const {
123  return m_RBClip;
124  }
126  WPXUnit unit() const {
127  return m_unit;
128  }
129  static float getScaleFactor(WPXUnit orig, WPXUnit dest) {
130  float actSc = 1.0, newSc = 1.0;
131  switch(orig) {
132  case WPX_TWIP:
133  break;
134  case WPX_POINT:
135  actSc=20;
136  break;
137  case WPX_INCH:
138  actSc = 1440;
139  break;
140  case WPX_PERCENT:
141  case WPX_GENERIC:
142  default:
143  MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
144  }
145  switch(dest) {
146  case WPX_TWIP:
147  break;
148  case WPX_POINT:
149  newSc=20;
150  break;
151  case WPX_INCH:
152  newSc = 1440;
153  break;
154  case WPX_PERCENT:
155  case WPX_GENERIC:
156  default:
157  MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
158  }
159  return actSc/newSc;
160  }
162  float getInvUnitScale(WPXUnit fromUnit) const {
163  return getScaleFactor(fromUnit, m_unit);
164  }
165 
167  void setPage(int pg) const {
168  const_cast<MWAWPosition *>(this)->m_page = pg;
169  }
171  void setOrigin(Vec2f const &orig) {
172  m_orig = orig;
173  }
175  void setSize(Vec2f const &sz) {
176  m_size = sz;
177  }
179  void setNaturalSize(Vec2f const &naturalSz) {
180  m_naturalSize = naturalSz;
181  }
183  void setUnit(WPXUnit newUnit) {
184  m_unit = newUnit;
185  }
187  void setPagePos(int pg, Vec2f const &newOrig) const {
188  const_cast<MWAWPosition *>(this)->m_page = pg;
189  const_cast<MWAWPosition *>(this)->m_orig = newOrig;
190  }
191 
194  m_anchorTo = anchor;
195  m_xPos = X;
196  m_yPos = Y;
197  }
198 
200  void setClippingPosition(Vec2f lTop, Vec2f rBottom) {
201  m_LTClip = lTop;
202  m_RBClip = rBottom;
203  }
204 
206  int order() const {
207  return m_order;
208  }
210  void setOrder(int ord) const {
211  m_order = ord;
212  }
213 
222 
223 protected:
225  int cmp(MWAWPosition const &f) const {
226  int diff = int(m_anchorTo) - int(f.m_anchorTo);
227  if (diff) return diff < 0 ? -1 : 1;
228  diff = int(m_xPos) - int(f.m_xPos);
229  if (diff) return diff < 0 ? -1 : 1;
230  diff = int(m_yPos) - int(f.m_yPos);
231  if (diff) return diff < 0 ? -1 : 1;
232  diff = page() - f.page();
233  if (diff) return diff < 0 ? -1 : 1;
234  diff = int(m_unit) - int(f.m_unit);
235  if (diff) return diff < 0 ? -1 : 1;
236  diff = m_orig.cmpY(f.m_orig);
237  if (diff) return diff;
238  diff = m_size.cmpY(f.m_size);
239  if (diff) return diff;
240  diff = m_naturalSize.cmpY(f.m_naturalSize);
241  if (diff) return diff;
242  diff = m_LTClip.cmpY(f.m_LTClip);
243  if (diff) return diff;
244  diff = m_RBClip.cmpY(f.m_RBClip);
245  if (diff) return diff;
246 
247  return 0;
248  }
249 
251  int m_page;
252  Vec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
253  Vec2f m_LTClip , m_RBClip /* the right bottom clip position */;
255  WPXUnit m_unit;
257  mutable int m_order;
258 };
259 
260 #endif
261 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Definition: MWAWPosition.hxx:51
void setPagePos(int pg, Vec2f const &newOrig) const
sets/resets the page and the origin
Definition: MWAWPosition.hxx:187
float getInvUnitScale(WPXUnit fromUnit) const
returns a float which can be used to scale some data in object unit
Definition: MWAWPosition.hxx:162
Definition: MWAWPosition.hxx:55
MWAWPosition(Vec2f const &orig=Vec2f(), Vec2f const &sz=Vec2f(), WPXUnit theUnit=WPX_INCH)
constructor
Definition: MWAWPosition.hxx:61
Vec2f m_size
Definition: MWAWPosition.hxx:252
Vec2f const & leftTopClipping() const
returns the left top clipping
Definition: MWAWPosition.hxx:118
WPXUnit m_unit
the unit used in orig, in m_size and in m_LTClip , .... Default: in inches
Definition: MWAWPosition.hxx:255
void setPage(int pg) const
sets the page
Definition: MWAWPosition.hxx:167
int m_order
background/foward order
Definition: MWAWPosition.hxx:257
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:53
Definition: MWAWPosition.hxx:55
YPos
an enum used to define the relative Y position
Definition: MWAWPosition.hxx:57
Vec2< float > Vec2f
Vec2 of float.
Definition: libmwaw_internal.hxx:596
Vec2f m_orig
the origin position in a page
Definition: MWAWPosition.hxx:252
Definition: MWAWPosition.hxx:55
XPos
an enum used to define the relative X position
Definition: MWAWPosition.hxx:55
Vec2f m_LTClip
the left top clip position
Definition: MWAWPosition.hxx:253
bool operator<(MWAWPosition const &f) const
basic operator&lt;
Definition: MWAWPosition.hxx:97
bool operator!=(MWAWPosition const &f) const
basic operator!=
Definition: MWAWPosition.hxx:93
AnchorTo m_anchorTo
anchor position
Definition: MWAWPosition.hxx:215
Vec2f const & origin() const
return the frame origin
Definition: MWAWPosition.hxx:106
void setClippingPosition(Vec2f lTop, Vec2f rBottom)
sets the clipping position
Definition: MWAWPosition.hxx:200
Definition: MWAWPosition.hxx:57
Definition: MWAWPosition.hxx:57
Vec2f const & naturalSize() const
returns the natural size (if known)
Definition: MWAWPosition.hxx:114
friend std::ostream & operator<<(std::ostream &o, MWAWPosition const &pos)
operator&lt;&lt;
Definition: MWAWPosition.hxx:67
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:55
WPXUnit unit() const
returns the unit
Definition: MWAWPosition.hxx:126
void setOrder(int ord) const
set background/foward order
Definition: MWAWPosition.hxx:210
void setSize(Vec2f const &sz)
sets the frame size
Definition: MWAWPosition.hxx:175
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:116
Definition: MWAWPosition.hxx:53
bool operator==(MWAWPosition const &f) const
basic operator==
Definition: MWAWPosition.hxx:89
AnchorTo
a list of enum used to defined the anchor
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:57
Vec2f const & rightBottomClipping() const
returns the right bottom clipping
Definition: MWAWPosition.hxx:122
YPos m_yPos
Y relative position.
Definition: MWAWPosition.hxx:219
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: MWAWPosition.hxx:193
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:542
static float getScaleFactor(WPXUnit orig, WPXUnit dest)
Definition: MWAWPosition.hxx:129
XPos m_xPos
X relative position.
Definition: MWAWPosition.hxx:217
void setNaturalSize(Vec2f const &naturalSz)
sets the natural size (if known)
Definition: MWAWPosition.hxx:179
void setOrigin(Vec2f const &orig)
sets the frame origin
Definition: MWAWPosition.hxx:171
Definition: MWAWPosition.hxx:51
virtual ~MWAWPosition()
Definition: MWAWPosition.hxx:65
int cmp(MWAWPosition const &f) const
basic function to compare two positions
Definition: MWAWPosition.hxx:225
Definition: MWAWPosition.hxx:53
Wrapping
an enum used to define the wrapping
Definition: MWAWPosition.hxx:53
Definition: MWAWPosition.hxx:53
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: MWAWPosition.hxx:47
int page() const
returns the frame page
Definition: MWAWPosition.hxx:102
Vec2f m_naturalSize
the natural size of the data (if known)
Definition: MWAWPosition.hxx:252
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:51
Wrapping m_wrapping
Wrapping.
Definition: MWAWPosition.hxx:221
int m_page
the page
Definition: MWAWPosition.hxx:251
Definition: MWAWPosition.hxx:57
Vec2f m_RBClip
Definition: MWAWPosition.hxx:253
int order() const
returns background/foward order
Definition: MWAWPosition.hxx:206
Vec2f const & size() const
returns the frame size
Definition: MWAWPosition.hxx:110
void setUnit(WPXUnit newUnit)
sets the dimension unit
Definition: MWAWPosition.hxx:183

Generated on Tue Mar 10 2015 17:32:09 for libmwaw by doxygen 1.8.5