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 <librevenge/librevenge.h>
#include "libmwaw_internal.hxx"
class MWAWPosition
{
public:
enum AnchorTo { Char, CharBaseLine, Frame, Paragraph, Page, Cell, Unknown };
enum Wrapping { WNone, WBackground, WDynamic, WForeground, WParallel, WRunThrough };
enum XPos { XRight, XLeft, XCenter, XFull };
enum YPos { YTop, YBottom, YCenter, YFull };
public:
explicit MWAWPosition(MWAWVec2f const &orig=MWAWVec2f(), MWAWVec2f const &sz=MWAWVec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_INCH)
: m_anchorTo(Unknown)
, m_anchorCellName("")
, 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)
{
}
MWAWPosition(MWAWPosition const &)=default;
MWAWPosition &operator=(MWAWPosition const &)=default;
MWAWPosition &operator=(MWAWPosition &&)=default;
~MWAWPosition();
friend std::ostream &operator<<(std::ostream &o, MWAWPosition const &pos)
{
MWAWVec2f dest(pos.m_orig+pos.m_size);
o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
switch (pos.m_unit) {
case librevenge::RVNG_INCH:
o << "(inch)";
break;
case librevenge::RVNG_POINT:
o << "(pt)";
break;
case librevenge::RVNG_TWIP:
o << "(tw)";
break;
case librevenge::RVNG_PERCENT:
case librevenge::RVNG_GENERIC:
case librevenge::RVNG_UNIT_ERROR:
#if !defined(__clang__)
default:
#endif
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;
}
MWAWVec2f const &origin() const
{
return m_orig;
}
MWAWVec2f const &size() const
{
return m_size;
}
MWAWVec2f const &naturalSize() const
{
return m_naturalSize;
}
MWAWVec2f const &leftTopClipping() const
{
return m_LTClip;
}
MWAWVec2f const &rightBottomClipping() const
{
return m_RBClip;
}
librevenge::RVNGUnit unit() const
{
return m_unit;
}
static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
{
float actSc = 1.0, newSc = 1.0;
switch (orig) {
case librevenge::RVNG_TWIP:
break;
case librevenge::RVNG_POINT:
actSc=20;
break;
case librevenge::RVNG_INCH:
actSc = 1440;
break;
case librevenge::RVNG_PERCENT:
case librevenge::RVNG_GENERIC:
case librevenge::RVNG_UNIT_ERROR:
#if !defined(__clang__)
default:
#endif
MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
}
switch (dest) {
case librevenge::RVNG_TWIP:
break;
case librevenge::RVNG_POINT:
newSc=20;
break;
case librevenge::RVNG_INCH:
newSc = 1440;
break;
case librevenge::RVNG_PERCENT:
case librevenge::RVNG_GENERIC:
case librevenge::RVNG_UNIT_ERROR:
#if !defined(__clang__)
default:
#endif
MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
}
return actSc/newSc;
}
float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
{
return getScaleFactor(fromUnit, m_unit);
}
void setPage(int pg) const
{
const_cast<MWAWPosition *>(this)->m_page = pg;
}
void setOrigin(MWAWVec2f const &orig)
{
m_orig = orig;
}
void setSize(MWAWVec2f const &sz)
{
m_size = sz;
}
void setNaturalSize(MWAWVec2f const &naturalSz)
{
m_naturalSize = naturalSz;
}
void setUnit(librevenge::RVNGUnit newUnit)
{
m_unit = newUnit;
}
void setPagePos(int pg, MWAWVec2f 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 setAnchorToCell(librevenge::RVNGString const &cellName)
{
m_anchorTo = Cell;
m_xPos = XLeft;
m_yPos = YTop;
m_anchorCellName=cellName;
}
void setClippingPosition(MWAWVec2f lTop, MWAWVec2f rBottom)
{
m_LTClip = lTop;
m_RBClip = rBottom;
}
int order() const
{
return m_order;
}
void setOrder(int ord) const
{
m_order = ord;
}
AnchorTo m_anchorTo;
librevenge::RVNGString m_anchorCellName;
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;
if (m_anchorCellName<f.m_anchorCellName) return -1;
if (m_anchorCellName>f.m_anchorCellName) return 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;
MWAWVec2f m_orig , m_size /* the size of the data*/, m_naturalSize ;
MWAWVec2f m_LTClip , m_RBClip /* the right bottom clip position */;
librevenge::RVNGUnit m_unit;
mutable int m_order;
};
#endif
// 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