MWAWPosition.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef MWAW_POSITION_H
#define MWAW_POSITION_H
#include <ostream>
#include <libwpd/libwpd.h>
#include "libmwaw_internal.hxx"
class MWAWPosition
{
public:
enum AnchorTo { Char, CharBaseLine, Frame, Paragraph, Page, Unknown };
enum Wrapping { WNone, WBackground, WDynamic, WRunThrough };
enum XPos { XRight, XLeft, XCenter, XFull };
enum YPos { YTop, YBottom, YCenter, YFull };
public:
MWAWPosition(Vec2f const &orig=Vec2f(), Vec2f const &sz=Vec2f(), WPXUnit theUnit=WPX_INCH):
m_anchorTo(Unknown), m_xPos(XLeft), m_yPos(YTop), m_wrapping(WNone),
m_page(0), m_orig(orig), m_size(sz), m_naturalSize(), m_LTClip(), m_RBClip(), m_unit(theUnit), m_order(0) {}
virtual ~MWAWPosition() {}
friend std::ostream &operator<<(std::ostream &o, MWAWPosition const &pos) {
Vec2f dest(pos.m_orig+pos.m_size);
o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
switch(pos.m_unit) {
case WPX_INCH:
o << "(inch)";
break;
case WPX_POINT:
o << "(pt)";
break;
case WPX_TWIP:
o << "(tw)";
break;
case WPX_PERCENT:
case WPX_GENERIC:
default:
break;
}
if (pos.page()>0) o << ", page=" << pos.page();
return o;
}
bool operator==(MWAWPosition const &f) const {
return cmp(f) == 0;
}
bool operator!=(MWAWPosition const &f) const {
return cmp(f) != 0;
}
bool operator<(MWAWPosition const &f) const {
return cmp(f) < 0;
}
int page() const {
return m_page;
}
Vec2f const &origin() const {
return m_orig;
}
Vec2f const &size() const {
return m_size;
}
Vec2f const &naturalSize() const {
return m_naturalSize;
}
Vec2f const &leftTopClipping() const {
return m_LTClip;
}
Vec2f const &rightBottomClipping() const {
return m_RBClip;
}
WPXUnit unit() const {
return m_unit;
}
static float getScaleFactor(WPXUnit orig, WPXUnit dest) {
float actSc = 1.0, newSc = 1.0;
switch(orig) {
case WPX_TWIP:
break;
case WPX_POINT:
actSc=20;
break;
case WPX_INCH:
actSc = 1440;
break;
case WPX_PERCENT:
case WPX_GENERIC:
default:
MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
}
switch(dest) {
case WPX_TWIP:
break;
case WPX_POINT:
newSc=20;
break;
case WPX_INCH:
newSc = 1440;
break;
case WPX_PERCENT:
case WPX_GENERIC:
default:
MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
}
return actSc/newSc;
}
float getInvUnitScale(WPXUnit fromUnit) const {
return getScaleFactor(fromUnit, m_unit);
}
void setPage(int pg) const {
const_cast<MWAWPosition *>(this)->m_page = pg;
}
void setOrigin(Vec2f const &orig) {
m_orig = orig;
}
void setSize(Vec2f const &sz) {
m_size = sz;
}
void setNaturalSize(Vec2f const &naturalSz) {
m_naturalSize = naturalSz;
}
void setUnit(WPXUnit newUnit) {
m_unit = newUnit;
}
void setPagePos(int pg, Vec2f const &newOrig) const {
const_cast<MWAWPosition *>(this)->m_page = pg;
const_cast<MWAWPosition *>(this)->m_orig = newOrig;
}
void setRelativePosition(AnchorTo anchor, XPos X = XLeft, YPos Y=YTop) {
m_anchorTo = anchor;
m_xPos = X;
m_yPos = Y;
}
void setClippingPosition(Vec2f lTop, Vec2f rBottom) {
m_LTClip = lTop;
m_RBClip = rBottom;
}
int order() const {
return m_order;
}
void setOrder(int ord) const {
m_order = ord;
}
AnchorTo m_anchorTo;
XPos m_xPos;
YPos m_yPos;
Wrapping m_wrapping;
protected:
int cmp(MWAWPosition const &f) const {
int diff = int(m_anchorTo) - int(f.m_anchorTo);
if (diff) return diff < 0 ? -1 : 1;
diff = int(m_xPos) - int(f.m_xPos);
if (diff) return diff < 0 ? -1 : 1;
diff = int(m_yPos) - int(f.m_yPos);
if (diff) return diff < 0 ? -1 : 1;
diff = page() - f.page();
if (diff) return diff < 0 ? -1 : 1;
diff = int(m_unit) - int(f.m_unit);
if (diff) return diff < 0 ? -1 : 1;
diff = m_orig.cmpY(f.m_orig);
if (diff) return diff;
diff = m_size.cmpY(f.m_size);
if (diff) return diff;
diff = m_naturalSize.cmpY(f.m_naturalSize);
if (diff) return diff;
diff = m_LTClip.cmpY(f.m_LTClip);
if (diff) return diff;
diff = m_RBClip.cmpY(f.m_RBClip);
if (diff) return diff;
return 0;
}
int m_page;
Vec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
Vec2f m_LTClip , m_RBClip /* the right bottom clip position */;
WPXUnit m_unit;
mutable int m_order;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPosition::Page
Definition: MWAWPosition.hxx:51
MWAWPosition::setPagePos
void setPagePos(int pg, Vec2f const &newOrig) const
sets/resets the page and the origin
Definition: MWAWPosition.hxx:187
MWAWPosition::getInvUnitScale
float getInvUnitScale(WPXUnit fromUnit) const
returns a float which can be used to scale some data in object unit
Definition: MWAWPosition.hxx:162
MWAWPosition::XFull
Definition: MWAWPosition.hxx:55
MWAWPosition::MWAWPosition
MWAWPosition(Vec2f const &orig=Vec2f(), Vec2f const &sz=Vec2f(), WPXUnit theUnit=WPX_INCH)
constructor
Definition: MWAWPosition.hxx:61
MWAWPosition::m_size
Vec2f m_size
Definition: MWAWPosition.hxx:252
MWAWPosition::leftTopClipping
Vec2f const & leftTopClipping() const
returns the left top clipping
Definition: MWAWPosition.hxx:118
MWAWPosition::m_unit
WPXUnit m_unit
the unit used in orig, in m_size and in m_LTClip , .... Default: in inches
Definition: MWAWPosition.hxx:255
MWAWPosition::setPage
void setPage(int pg) const
sets the page
Definition: MWAWPosition.hxx:167
MWAWPosition::m_order
int m_order
background/foward order
Definition: MWAWPosition.hxx:257
MWAWPosition::Char
Definition: MWAWPosition.hxx:51
MWAWPosition::WDynamic
Definition: MWAWPosition.hxx:53
MWAWPosition::XRight
Definition: MWAWPosition.hxx:55
libmwaw_internal.hxx
MWAWPosition::YPos
YPos
an enum used to define the relative Y position
Definition: MWAWPosition.hxx:57
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libmwaw_internal.hxx:582
MWAWPosition::m_orig
Vec2f m_orig
the origin position in a page
Definition: MWAWPosition.hxx:252
MWAWPosition::XCenter
Definition: MWAWPosition.hxx:55
MWAWPosition::XPos
XPos
an enum used to define the relative X position
Definition: MWAWPosition.hxx:55
MWAWPosition::m_LTClip
Vec2f m_LTClip
the left top clip position
Definition: MWAWPosition.hxx:253
MWAWPosition::operator<
bool operator<(MWAWPosition const &f) const
basic operator<
Definition: MWAWPosition.hxx:97
MWAWPosition::operator!=
bool operator!=(MWAWPosition const &f) const
basic operator!=
Definition: MWAWPosition.hxx:93
MWAWPosition::m_anchorTo
AnchorTo m_anchorTo
anchor position
Definition: MWAWPosition.hxx:215
MWAWPosition::origin
Vec2f const & origin() const
return the frame origin
Definition: MWAWPosition.hxx:106
MWAWPosition::setClippingPosition
void setClippingPosition(Vec2f lTop, Vec2f rBottom)
sets the clipping position
Definition: MWAWPosition.hxx:200
MWAWPosition::YTop
Definition: MWAWPosition.hxx:57
MWAWPosition::YBottom
Definition: MWAWPosition.hxx:57
MWAWPosition::naturalSize
Vec2f const & naturalSize() const
returns the natural size (if known)
Definition: MWAWPosition.hxx:114
MWAWPosition::operator<<
friend std::ostream & operator<<(std::ostream &o, MWAWPosition const &pos)
operator<<
Definition: MWAWPosition.hxx:67
MWAWPosition::Unknown
Definition: MWAWPosition.hxx:51
MWAWPosition::XLeft
Definition: MWAWPosition.hxx:55
MWAWPosition::unit
WPXUnit unit() const
returns the unit
Definition: MWAWPosition.hxx:126
MWAWPosition::setOrder
void setOrder(int ord) const
set background/foward order
Definition: MWAWPosition.hxx:210
MWAWPosition::setSize
void setSize(Vec2f const &sz)
sets the frame size
Definition: MWAWPosition.hxx:175
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:111
MWAWPosition::WRunThrough
Definition: MWAWPosition.hxx:53
MWAWPosition::operator==
bool operator==(MWAWPosition const &f) const
basic operator==
Definition: MWAWPosition.hxx:89
MWAWPosition::AnchorTo
AnchorTo
a list of enum used to defined the anchor
Definition: MWAWPosition.hxx:51
MWAWPosition::YCenter
Definition: MWAWPosition.hxx:57
MWAWPosition::rightBottomClipping
Vec2f const & rightBottomClipping() const
returns the right bottom clipping
Definition: MWAWPosition.hxx:122
MWAWPosition::m_yPos
YPos m_yPos
Y relative position.
Definition: MWAWPosition.hxx:219
MWAWPosition::setRelativePosition
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: MWAWPosition.hxx:193
Vec2::cmpY
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:528
MWAWPosition::getScaleFactor
static float getScaleFactor(WPXUnit orig, WPXUnit dest)
Definition: MWAWPosition.hxx:129
MWAWPosition::m_xPos
XPos m_xPos
X relative position.
Definition: MWAWPosition.hxx:217
MWAWPosition::setNaturalSize
void setNaturalSize(Vec2f const &naturalSz)
sets the natural size (if known)
Definition: MWAWPosition.hxx:179
MWAWPosition::setOrigin
void setOrigin(Vec2f const &orig)
sets the frame origin
Definition: MWAWPosition.hxx:171
MWAWPosition::Paragraph
Definition: MWAWPosition.hxx:51
MWAWPosition::~MWAWPosition
virtual ~MWAWPosition()
Definition: MWAWPosition.hxx:65
MWAWPosition::cmp
int cmp(MWAWPosition const &f) const
basic function to compare two positions
Definition: MWAWPosition.hxx:225
MWAWPosition::WNone
Definition: MWAWPosition.hxx:53
MWAWPosition::Wrapping
Wrapping
an enum used to define the wrapping
Definition: MWAWPosition.hxx:53
MWAWPosition::WBackground
Definition: MWAWPosition.hxx:53
MWAWPosition
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: MWAWPosition.hxx:47
MWAWPosition::page
int page() const
returns the frame page
Definition: MWAWPosition.hxx:102
MWAWPosition::m_naturalSize
Vec2f m_naturalSize
the natural size of the data (if known)
Definition: MWAWPosition.hxx:252
Vec2< float >
MWAWPosition::Frame
Definition: MWAWPosition.hxx:51
MWAWPosition::CharBaseLine
Definition: MWAWPosition.hxx:51
MWAWPosition::m_wrapping
Wrapping m_wrapping
Wrapping.
Definition: MWAWPosition.hxx:221
MWAWPosition::m_page
int m_page
the page
Definition: MWAWPosition.hxx:251
MWAWPosition::YFull
Definition: MWAWPosition.hxx:57
MWAWPosition::m_RBClip
Vec2f m_RBClip
Definition: MWAWPosition.hxx:253
MWAWPosition::order
int order() const
returns background/foward order
Definition: MWAWPosition.hxx:206
MWAWPosition::size
Vec2f const & size() const
returns the frame size
Definition: MWAWPosition.hxx:110
MWAWPosition::setUnit
void setUnit(WPXUnit newUnit)
sets the dimension unit
Definition: MWAWPosition.hxx:183