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  MWAWPosition(MWAWVec2f const &orig=MWAWVec2f(), MWAWVec2f const &sz=MWAWVec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_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  {
69  MWAWVec2f dest(pos.m_orig+pos.m_size);
70  o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
71  switch (pos.m_unit) {
72  case librevenge::RVNG_INCH:
73  o << "(inch)";
74  break;
75  case librevenge::RVNG_POINT:
76  o << "(pt)";
77  break;
78  case librevenge::RVNG_TWIP:
79  o << "(tw)";
80  break;
81  case librevenge::RVNG_PERCENT:
82  case librevenge::RVNG_GENERIC:
83  case librevenge::RVNG_UNIT_ERROR:
84  default:
85  break;
86  }
87  if (pos.page()>0) o << ", page=" << pos.page();
88  return o;
89  }
91  bool operator==(MWAWPosition const &f) const
92  {
93  return cmp(f) == 0;
94  }
96  bool operator!=(MWAWPosition const &f) const
97  {
98  return cmp(f) != 0;
99  }
101  bool operator<(MWAWPosition const &f) const
102  {
103  return cmp(f) < 0;
104  }
105 
107  int page() const
108  {
109  return m_page;
110  }
112  MWAWVec2f const &origin() const
113  {
114  return m_orig;
115  }
117  MWAWVec2f const &size() const
118  {
119  return m_size;
120  }
122  MWAWVec2f const &naturalSize() const
123  {
124  return m_naturalSize;
125  }
127  MWAWVec2f const &leftTopClipping() const
128  {
129  return m_LTClip;
130  }
133  {
134  return m_RBClip;
135  }
137  librevenge::RVNGUnit unit() const
138  {
139  return m_unit;
140  }
141  static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
142  {
143  float actSc = 1.0, newSc = 1.0;
144  switch (orig) {
145  case librevenge::RVNG_TWIP:
146  break;
147  case librevenge::RVNG_POINT:
148  actSc=20;
149  break;
150  case librevenge::RVNG_INCH:
151  actSc = 1440;
152  break;
153  case librevenge::RVNG_PERCENT:
154  case librevenge::RVNG_GENERIC:
155  case librevenge::RVNG_UNIT_ERROR:
156  default:
157  MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
158  }
159  switch (dest) {
160  case librevenge::RVNG_TWIP:
161  break;
162  case librevenge::RVNG_POINT:
163  newSc=20;
164  break;
165  case librevenge::RVNG_INCH:
166  newSc = 1440;
167  break;
168  case librevenge::RVNG_PERCENT:
169  case librevenge::RVNG_GENERIC:
170  case librevenge::RVNG_UNIT_ERROR:
171  default:
172  MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
173  }
174  return actSc/newSc;
175  }
177  float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
178  {
179  return getScaleFactor(fromUnit, m_unit);
180  }
181 
183  void setPage(int pg) const
184  {
185  const_cast<MWAWPosition *>(this)->m_page = pg;
186  }
188  void setOrigin(MWAWVec2f const &orig)
189  {
190  m_orig = orig;
191  }
193  void setSize(MWAWVec2f const &sz)
194  {
195  m_size = sz;
196  }
198  void setNaturalSize(MWAWVec2f const &naturalSz)
199  {
200  m_naturalSize = naturalSz;
201  }
203  void setUnit(librevenge::RVNGUnit newUnit)
204  {
205  m_unit = newUnit;
206  }
208  void setPagePos(int pg, MWAWVec2f const &newOrig) const
209  {
210  const_cast<MWAWPosition *>(this)->m_page = pg;
211  const_cast<MWAWPosition *>(this)->m_orig = newOrig;
212  }
213 
216  {
217  m_anchorTo = anchor;
218  m_xPos = X;
219  m_yPos = Y;
220  }
222  void setAnchorToCell(librevenge::RVNGString const &cellName)
223  {
224  m_anchorTo = Cell;
225  m_xPos = XLeft;
226  m_yPos = YTop;
227  m_anchorCellName=cellName;
228  }
231  {
232  m_LTClip = lTop;
233  m_RBClip = rBottom;
234  }
235 
237  int order() const
238  {
239  return m_order;
240  }
242  void setOrder(int ord) const
243  {
244  m_order = ord;
245  }
246 
250  librevenge::RVNGString m_anchorCellName;
257 
258 protected:
260  int cmp(MWAWPosition const &f) const
261  {
262  int diff = int(m_anchorTo) - int(f.m_anchorTo);
263  if (diff) return diff < 0 ? -1 : 1;
264  diff = int(m_xPos) - int(f.m_xPos);
265  if (diff) return diff < 0 ? -1 : 1;
266  diff = int(m_yPos) - int(f.m_yPos);
267  if (diff) return diff < 0 ? -1 : 1;
268  diff = page() - f.page();
269  if (diff) return diff < 0 ? -1 : 1;
270  diff = int(m_unit) - int(f.m_unit);
271  if (diff) return diff < 0 ? -1 : 1;
272  diff = m_orig.cmpY(f.m_orig);
273  if (diff) return diff;
274  diff = m_size.cmpY(f.m_size);
275  if (diff) return diff;
276  diff = m_naturalSize.cmpY(f.m_naturalSize);
277  if (diff) return diff;
278  diff = m_LTClip.cmpY(f.m_LTClip);
279  if (diff) return diff;
280  diff = m_RBClip.cmpY(f.m_RBClip);
281  if (diff) return diff;
282 
283  return 0;
284  }
285 
287  int m_page;
288  MWAWVec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
289  MWAWVec2f m_LTClip , m_RBClip /* the right bottom clip position */;
291  librevenge::RVNGUnit m_unit;
293  mutable int m_order;
294 };
295 
296 #endif
297 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Mar 1 2016 23:42:50 for libmwaw by doxygen 1.8.4