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 
48 {
49 public:
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)
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  }
78  ~MWAWPosition();
80  friend std::ostream &operator<<(std::ostream &o, MWAWPosition const &pos)
81  {
82  MWAWVec2f dest(pos.m_orig+pos.m_size);
83  o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
84  switch (pos.m_unit) {
85  case librevenge::RVNG_INCH:
86  o << "(inch)";
87  break;
88  case librevenge::RVNG_POINT:
89  o << "(pt)";
90  break;
91  case librevenge::RVNG_TWIP:
92  o << "(tw)";
93  break;
94  case librevenge::RVNG_PERCENT:
95  case librevenge::RVNG_GENERIC:
96  case librevenge::RVNG_UNIT_ERROR:
97 #if !defined(__clang__)
98  default:
99 #endif
100  break;
101  }
102  if (pos.page()>0) o << ", page=" << pos.page();
103  return o;
104  }
106  bool operator==(MWAWPosition const &f) const
107  {
108  return cmp(f) == 0;
109  }
111  bool operator!=(MWAWPosition const &f) const
112  {
113  return cmp(f) != 0;
114  }
116  bool operator<(MWAWPosition const &f) const
117  {
118  return cmp(f) < 0;
119  }
120 
122  int page() const
123  {
124  return m_page;
125  }
127  MWAWVec2f const &origin() const
128  {
129  return m_orig;
130  }
132  MWAWVec2f const &size() const
133  {
134  return m_size;
135  }
137  MWAWVec2f const &naturalSize() const
138  {
139  return m_naturalSize;
140  }
142  MWAWVec2f const &leftTopClipping() const
143  {
144  return m_LTClip;
145  }
148  {
149  return m_RBClip;
150  }
152  librevenge::RVNGUnit unit() const
153  {
154  return m_unit;
155  }
156  static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
157  {
158  float actSc = 1.0, newSc = 1.0;
159  switch (orig) {
160  case librevenge::RVNG_TWIP:
161  break;
162  case librevenge::RVNG_POINT:
163  actSc=20;
164  break;
165  case librevenge::RVNG_INCH:
166  actSc = 1440;
167  break;
168  case librevenge::RVNG_PERCENT:
169  case librevenge::RVNG_GENERIC:
170  case librevenge::RVNG_UNIT_ERROR:
171 #if !defined(__clang__)
172  default:
173 #endif
174  MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
175  }
176  switch (dest) {
177  case librevenge::RVNG_TWIP:
178  break;
179  case librevenge::RVNG_POINT:
180  newSc=20;
181  break;
182  case librevenge::RVNG_INCH:
183  newSc = 1440;
184  break;
185  case librevenge::RVNG_PERCENT:
186  case librevenge::RVNG_GENERIC:
187  case librevenge::RVNG_UNIT_ERROR:
188 #if !defined(__clang__)
189  default:
190 #endif
191  MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
192  }
193  return actSc/newSc;
194  }
196  float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
197  {
198  return getScaleFactor(fromUnit, m_unit);
199  }
200 
202  void setPage(int pg) const
203  {
204  const_cast<MWAWPosition *>(this)->m_page = pg;
205  }
207  void setOrigin(MWAWVec2f const &orig)
208  {
209  m_orig = orig;
210  }
212  void setSize(MWAWVec2f const &sz)
213  {
214  m_size = sz;
215  }
217  void setNaturalSize(MWAWVec2f const &naturalSz)
218  {
219  m_naturalSize = naturalSz;
220  }
222  void setUnit(librevenge::RVNGUnit newUnit)
223  {
224  m_unit = newUnit;
225  }
227  void setPagePos(int pg, MWAWVec2f const &newOrig) const
228  {
229  const_cast<MWAWPosition *>(this)->m_page = pg;
230  const_cast<MWAWPosition *>(this)->m_orig = newOrig;
231  }
232 
235  {
236  m_anchorTo = anchor;
237  m_xPos = X;
238  m_yPos = Y;
239  }
241  void setAnchorToCell(librevenge::RVNGString const &cellName)
242  {
243  m_anchorTo = Cell;
244  m_xPos = XLeft;
245  m_yPos = YTop;
246  m_anchorCellName=cellName;
247  }
250  {
251  m_LTClip = lTop;
252  m_RBClip = rBottom;
253  }
254 
256  int order() const
257  {
258  return m_order;
259  }
261  void setOrder(int ord) const
262  {
263  m_order = ord;
264  }
265 
269  librevenge::RVNGString m_anchorCellName;
276 
277 protected:
279  int cmp(MWAWPosition const &f) const
280  {
281  int diff = int(m_anchorTo) - int(f.m_anchorTo);
282  if (diff) return diff < 0 ? -1 : 1;
283  if (m_anchorCellName<f.m_anchorCellName) return -1;
284  if (m_anchorCellName>f.m_anchorCellName) return 1;
285  diff = int(m_xPos) - int(f.m_xPos);
286  if (diff) return diff < 0 ? -1 : 1;
287  diff = int(m_yPos) - int(f.m_yPos);
288  if (diff) return diff < 0 ? -1 : 1;
289  diff = page() - f.page();
290  if (diff) return diff < 0 ? -1 : 1;
291  diff = int(m_unit) - int(f.m_unit);
292  if (diff) return diff < 0 ? -1 : 1;
293  diff = m_orig.cmpY(f.m_orig);
294  if (diff) return diff;
295  diff = m_size.cmpY(f.m_size);
296  if (diff) return diff;
297  diff = m_naturalSize.cmpY(f.m_naturalSize);
298  if (diff) return diff;
299  diff = m_LTClip.cmpY(f.m_LTClip);
300  if (diff) return diff;
301  diff = m_RBClip.cmpY(f.m_RBClip);
302  if (diff) return diff;
303 
304  return 0;
305  }
306 
308  int m_page;
309  MWAWVec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
310  MWAWVec2f m_LTClip , m_RBClip /* the right bottom clip position */;
312  librevenge::RVNGUnit m_unit;
314  mutable int m_order;
315 };
316 
317 #endif
318 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Definition: MWAWPosition.hxx:51
MWAWVec2f m_orig
the origin position in a page
Definition: MWAWPosition.hxx:309
librevenge::RVNGUnit m_unit
the unit used in orig, in m_size and in m_LTClip , .... Default: in inches
Definition: MWAWPosition.hxx:312
Definition: MWAWPosition.hxx:55
Definition: MWAWPosition.hxx:53
void setOrigin(MWAWVec2f const &orig)
sets the frame origin
Definition: MWAWPosition.hxx:207
int cmp(MWAWPosition const &f) const
basic function to compare two positions
Definition: MWAWPosition.hxx:279
int m_order
background/foward order
Definition: MWAWPosition.hxx:314
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
bool operator!=(MWAWPosition const &f) const
basic operator!=
Definition: MWAWPosition.hxx:111
MWAWVec2f m_naturalSize
the natural size of the data (if known)
Definition: MWAWPosition.hxx:309
void setNaturalSize(MWAWVec2f const &naturalSz)
sets the natural size (if known)
Definition: MWAWPosition.hxx:217
Definition: MWAWPosition.hxx:55
XPos
an enum used to define the relative X position
Definition: MWAWPosition.hxx:55
librevenge::RVNGString m_anchorCellName
the anchor cell name
Definition: MWAWPosition.hxx:269
MWAWVec2f const & rightBottomClipping() const
returns the right bottom clipping
Definition: MWAWPosition.hxx:147
MWAWVec2f const & leftTopClipping() const
returns the left top clipping
Definition: MWAWPosition.hxx:142
static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
Definition: MWAWPosition.hxx:156
AnchorTo m_anchorTo
anchor position
Definition: MWAWPosition.hxx:267
bool operator==(MWAWPosition const &f) const
basic operator==
Definition: MWAWPosition.hxx:106
int order() const
returns background/foward order
Definition: MWAWPosition.hxx:256
Definition: MWAWPosition.hxx:57
Definition: MWAWPosition.hxx:57
friend std::ostream & operator<<(std::ostream &o, MWAWPosition const &pos)
operator<<
Definition: MWAWPosition.hxx:80
librevenge::RVNGUnit unit() const
returns the unit
Definition: MWAWPosition.hxx:152
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:55
Definition: MWAWPosition.hxx:53
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
Definition: MWAWPosition.hxx:53
AnchorTo
a list of enum used to defined the anchor
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:57
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:838
MWAWVec2f m_RBClip
Definition: MWAWPosition.hxx:310
YPos m_yPos
Y relative position.
Definition: MWAWPosition.hxx:273
~MWAWPosition()
destructor
Definition: MWAWPosition.cxx:36
MWAWVec2f const & naturalSize() const
returns the natural size (if known)
Definition: MWAWPosition.hxx:137
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: MWAWPosition.hxx:234
MWAWVec2f m_size
Definition: MWAWPosition.hxx:309
void setSize(MWAWVec2f const &sz)
sets the frame size
Definition: MWAWPosition.hxx:212
MWAWVec2f const & size() const
returns the frame size
Definition: MWAWPosition.hxx:132
XPos m_xPos
X relative position.
Definition: MWAWPosition.hxx:271
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:51
MWAWVec2f m_LTClip
the left top clip position
Definition: MWAWPosition.hxx:310
void setAnchorToCell(librevenge::RVNGString const &cellName)
sets the anchor to a cell position
Definition: MWAWPosition.hxx:241
MWAWPosition(MWAWVec2f const &orig=MWAWVec2f(), MWAWVec2f const &sz=MWAWVec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_INCH)
constructor
Definition: MWAWPosition.hxx:61
Definition: MWAWPosition.hxx:53
void setPagePos(int pg, MWAWVec2f const &newOrig) const
sets/resets the page and the origin
Definition: MWAWPosition.hxx:227
Wrapping
an enum used to define the wrapping: none, ...
Definition: MWAWPosition.hxx:53
bool operator<(MWAWPosition const &f) const
basic operator<
Definition: MWAWPosition.hxx:116
int cmpY(MWAWVec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:782
Definition: MWAWPosition.hxx:53
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: MWAWPosition.hxx:47
void setUnit(librevenge::RVNGUnit newUnit)
sets the dimension unit
Definition: MWAWPosition.hxx:222
float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
returns a float which can be used to scale some data in object unit
Definition: MWAWPosition.hxx:196
void setClippingPosition(MWAWVec2f lTop, MWAWVec2f rBottom)
sets the clipping position
Definition: MWAWPosition.hxx:249
Definition: MWAWPosition.hxx:51
Definition: MWAWPosition.hxx:51
MWAWVec2f const & origin() const
return the frame origin
Definition: MWAWPosition.hxx:127
Wrapping m_wrapping
Wrapping.
Definition: MWAWPosition.hxx:275
void setOrder(int ord) const
set background/foward order
Definition: MWAWPosition.hxx:261
int m_page
the page
Definition: MWAWPosition.hxx:308
void setPage(int pg) const
sets the page
Definition: MWAWPosition.hxx:202
Definition: MWAWPosition.hxx:57
int page() const
returns the frame page
Definition: MWAWPosition.hxx:122

Generated on Thu May 3 2018 08:33:27 for libmwaw by doxygen 1.8.14