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