Blame src/lib/MWAWPosition.hxx

rpm-build 6f7582
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
rpm-build 6f7582
rpm-build 6f7582
/* libmwaw
rpm-build 6f7582
* Version: MPL 2.0 / LGPLv2+
rpm-build 6f7582
*
rpm-build 6f7582
* The contents of this file are subject to the Mozilla Public License Version
rpm-build 6f7582
* 2.0 (the "License"); you may not use this file except in compliance with
rpm-build 6f7582
* the License or as specified alternatively below. You may obtain a copy of
rpm-build 6f7582
* the License at http://www.mozilla.org/MPL/
rpm-build 6f7582
*
rpm-build 6f7582
* Software distributed under the License is distributed on an "AS IS" basis,
rpm-build 6f7582
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
rpm-build 6f7582
* for the specific language governing rights and limitations under the
rpm-build 6f7582
* License.
rpm-build 6f7582
*
rpm-build 6f7582
* Major Contributor(s):
rpm-build 6f7582
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
rpm-build 6f7582
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
rpm-build 6f7582
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
rpm-build 6f7582
* Copyright (C) 2006, 2007 Andrew Ziem
rpm-build 6f7582
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
rpm-build 6f7582
*
rpm-build 6f7582
*
rpm-build 6f7582
* All Rights Reserved.
rpm-build 6f7582
*
rpm-build 6f7582
* For minor contributions see the git repository.
rpm-build 6f7582
*
rpm-build 6f7582
* Alternatively, the contents of this file may be used under the terms of
rpm-build 6f7582
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
rpm-build 6f7582
* in which case the provisions of the LGPLv2+ are applicable
rpm-build 6f7582
* instead of those above.
rpm-build 6f7582
*/
rpm-build 6f7582
rpm-build 6f7582
#ifndef MWAW_POSITION_H
rpm-build 6f7582
#define MWAW_POSITION_H
rpm-build 6f7582
rpm-build 6f7582
#include <ostream>
rpm-build 6f7582
rpm-build 6f7582
#include <librevenge/librevenge.h>
rpm-build 6f7582
rpm-build 6f7582
#include "libmwaw_internal.hxx"
rpm-build 6f7582
rpm-build 6f7582
/** Class to define the position of an object (textbox, picture, ..) in the document
rpm-build 6f7582
 *
rpm-build 6f7582
 * Stores the page, object position, object size, anchor, wrapping, ...
rpm-build 6f7582
 */
rpm-build 6f7582
class MWAWPosition
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! a list of enum used to defined the anchor
rpm-build 6f7582
  enum AnchorTo { Char, CharBaseLine, Frame, Paragraph, Page, Cell, Unknown };
rpm-build 6f7582
  //! an enum used to define the wrapping: none, ...
rpm-build 6f7582
  enum Wrapping { WNone, WBackground, WDynamic, WForeground, WParallel, WRunThrough };
rpm-build 6f7582
  //! an enum used to define the relative X position
rpm-build 6f7582
  enum XPos { XRight, XLeft, XCenter, XFull };
rpm-build 6f7582
  //! an enum used to define the relative Y position
rpm-build 6f7582
  enum YPos { YTop, YBottom, YCenter, YFull };
rpm-build 6f7582
rpm-build 6f7582
public:
rpm-build 6f7582
  //! constructor
rpm-build 6f7582
  explicit MWAWPosition(MWAWVec2f const &orig=MWAWVec2f(), MWAWVec2f const &sz=MWAWVec2f(), librevenge::RVNGUnit theUnit=librevenge::RVNG_INCH)
rpm-build 6f7582
    : m_anchorTo(Unknown)
rpm-build 6f7582
    , m_anchorCellName("")
rpm-build 6f7582
    , m_xPos(XLeft)
rpm-build 6f7582
    , m_yPos(YTop)
rpm-build 6f7582
    , m_wrapping(WNone)
rpm-build 6f7582
    , m_page(0)
rpm-build 6f7582
    , m_orig(orig)
rpm-build 6f7582
    , m_size(sz)
rpm-build 6f7582
    , m_naturalSize()
rpm-build 6f7582
    , m_LTClip()
rpm-build 6f7582
    , m_RBClip()
rpm-build 6f7582
    , m_unit(theUnit)
rpm-build 6f7582
    , m_order(0)
rpm-build 6f7582
  {
rpm-build 6f7582
  }
rpm-build 6f7582
  //! destructor
rpm-build 6f7582
  ~MWAWPosition();
rpm-build 6f7582
  //! operator<<
rpm-build 6f7582
  friend  std::ostream &operator<<(std::ostream &o, MWAWPosition const &pos)
rpm-build 6f7582
  {
rpm-build 6f7582
    MWAWVec2f dest(pos.m_orig+pos.m_size);
rpm-build 6f7582
    o << "Pos=(" << pos.m_orig << ")x(" << dest << ")";
rpm-build 6f7582
    switch (pos.m_unit) {
rpm-build 6f7582
    case librevenge::RVNG_INCH:
rpm-build 6f7582
      o << "(inch)";
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_POINT:
rpm-build 6f7582
      o << "(pt)";
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_TWIP:
rpm-build 6f7582
      o << "(tw)";
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_PERCENT:
rpm-build 6f7582
    case librevenge::RVNG_GENERIC:
rpm-build 6f7582
    case librevenge::RVNG_UNIT_ERROR:
rpm-build 6f7582
#if !defined(__clang__)
rpm-build 6f7582
    default:
rpm-build 6f7582
#endif
rpm-build 6f7582
      break;
rpm-build 6f7582
    }
rpm-build 6f7582
    if (pos.page()>0) o << ", page=" << pos.page();
rpm-build 6f7582
    return o;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! basic operator==
rpm-build 6f7582
  bool operator==(MWAWPosition const &f) const
rpm-build 6f7582
  {
rpm-build 6f7582
    return cmp(f) == 0;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! basic operator!=
rpm-build 6f7582
  bool operator!=(MWAWPosition const &f) const
rpm-build 6f7582
  {
rpm-build 6f7582
    return cmp(f) != 0;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! basic operator<
rpm-build 6f7582
  bool operator<(MWAWPosition const &f) const
rpm-build 6f7582
  {
rpm-build 6f7582
    return cmp(f) < 0;
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
  //! returns the frame page
rpm-build 6f7582
  int page() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_page;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! return the frame origin
rpm-build 6f7582
  MWAWVec2f const &origin() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_orig;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the frame size
rpm-build 6f7582
  MWAWVec2f const &size() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_size;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the natural size (if known)
rpm-build 6f7582
  MWAWVec2f const &naturalSize() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_naturalSize;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the left top clipping
rpm-build 6f7582
  MWAWVec2f const &leftTopClipping() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_LTClip;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the right bottom clipping
rpm-build 6f7582
  MWAWVec2f const &rightBottomClipping() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_RBClip;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the unit
rpm-build 6f7582
  librevenge::RVNGUnit unit() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_unit;
rpm-build 6f7582
  }
rpm-build 6f7582
  static float getScaleFactor(librevenge::RVNGUnit orig, librevenge::RVNGUnit dest)
rpm-build 6f7582
  {
rpm-build 6f7582
    float actSc = 1.0, newSc = 1.0;
rpm-build 6f7582
    switch (orig) {
rpm-build 6f7582
    case librevenge::RVNG_TWIP:
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_POINT:
rpm-build 6f7582
      actSc=20;
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_INCH:
rpm-build 6f7582
      actSc = 1440;
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_PERCENT:
rpm-build 6f7582
    case librevenge::RVNG_GENERIC:
rpm-build 6f7582
    case librevenge::RVNG_UNIT_ERROR:
rpm-build 6f7582
#if !defined(__clang__)
rpm-build 6f7582
    default:
rpm-build 6f7582
#endif
rpm-build 6f7582
      MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(orig)));
rpm-build 6f7582
    }
rpm-build 6f7582
    switch (dest) {
rpm-build 6f7582
    case librevenge::RVNG_TWIP:
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_POINT:
rpm-build 6f7582
      newSc=20;
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_INCH:
rpm-build 6f7582
      newSc = 1440;
rpm-build 6f7582
      break;
rpm-build 6f7582
    case librevenge::RVNG_PERCENT:
rpm-build 6f7582
    case librevenge::RVNG_GENERIC:
rpm-build 6f7582
    case librevenge::RVNG_UNIT_ERROR:
rpm-build 6f7582
#if !defined(__clang__)
rpm-build 6f7582
    default:
rpm-build 6f7582
#endif
rpm-build 6f7582
      MWAW_DEBUG_MSG(("MWAWPosition::getScaleFactor %d unit must not appear\n", int(dest)));
rpm-build 6f7582
    }
rpm-build 6f7582
    return actSc/newSc;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns a float which can be used to scale some data in object unit
rpm-build 6f7582
  float getInvUnitScale(librevenge::RVNGUnit fromUnit) const
rpm-build 6f7582
  {
rpm-build 6f7582
    return getScaleFactor(fromUnit, m_unit);
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
  //! sets the page
rpm-build 6f7582
  void setPage(int pg) const
rpm-build 6f7582
  {
rpm-build 6f7582
    const_cast<MWAWPosition *>(this)->m_page = pg;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the frame origin
rpm-build 6f7582
  void setOrigin(MWAWVec2f const &orig)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_orig = orig;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the frame size
rpm-build 6f7582
  void setSize(MWAWVec2f const &sz)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_size = sz;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the natural size (if known)
rpm-build 6f7582
  void setNaturalSize(MWAWVec2f const &naturalSz)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_naturalSize = naturalSz;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the dimension unit
rpm-build 6f7582
  void setUnit(librevenge::RVNGUnit newUnit)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_unit = newUnit;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets/resets the page and the origin
rpm-build 6f7582
  void setPagePos(int pg, MWAWVec2f const &newOrig) const
rpm-build 6f7582
  {
rpm-build 6f7582
    const_cast<MWAWPosition *>(this)->m_page = pg;
rpm-build 6f7582
    const_cast<MWAWPosition *>(this)->m_orig = newOrig;
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
  //! sets the relative position
rpm-build 6f7582
  void setRelativePosition(AnchorTo anchor, XPos X = XLeft, YPos Y=YTop)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_anchorTo = anchor;
rpm-build 6f7582
    m_xPos = X;
rpm-build 6f7582
    m_yPos = Y;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the anchor to a cell position
rpm-build 6f7582
  void setAnchorToCell(librevenge::RVNGString const &cellName)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_anchorTo = Cell;
rpm-build 6f7582
    m_xPos = XLeft;
rpm-build 6f7582
    m_yPos = YTop;
rpm-build 6f7582
    m_anchorCellName=cellName;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the clipping position
rpm-build 6f7582
  void setClippingPosition(MWAWVec2f lTop, MWAWVec2f rBottom)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_LTClip = lTop;
rpm-build 6f7582
    m_RBClip = rBottom;
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
  //! returns background/foward order
rpm-build 6f7582
  int order() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_order;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! set background/foward order
rpm-build 6f7582
  void setOrder(int ord) const
rpm-build 6f7582
  {
rpm-build 6f7582
    m_order = ord;
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
  //! anchor position
rpm-build 6f7582
  AnchorTo m_anchorTo;
rpm-build 6f7582
  //! the anchor cell name
rpm-build 6f7582
  librevenge::RVNGString m_anchorCellName;
rpm-build 6f7582
  //! X relative position
rpm-build 6f7582
  XPos m_xPos;
rpm-build 6f7582
  //! Y relative position
rpm-build 6f7582
  YPos m_yPos;
rpm-build 6f7582
  //! Wrapping
rpm-build 6f7582
  Wrapping m_wrapping;
rpm-build 6f7582
rpm-build 6f7582
protected:
rpm-build 6f7582
  //! basic function to compare two positions
rpm-build 6f7582
  int cmp(MWAWPosition const &f) const
rpm-build 6f7582
  {
rpm-build 6f7582
    int diff = int(m_anchorTo) - int(f.m_anchorTo);
rpm-build 6f7582
    if (diff) return diff < 0 ? -1 : 1;
rpm-build 6f7582
    if (m_anchorCellName
rpm-build 6f7582
    if (m_anchorCellName>f.m_anchorCellName) return 1;
rpm-build 6f7582
    diff = int(m_xPos) - int(f.m_xPos);
rpm-build 6f7582
    if (diff) return diff < 0 ? -1 : 1;
rpm-build 6f7582
    diff = int(m_yPos) - int(f.m_yPos);
rpm-build 6f7582
    if (diff) return diff < 0 ? -1 : 1;
rpm-build 6f7582
    diff = page() - f.page();
rpm-build 6f7582
    if (diff) return diff < 0 ? -1 : 1;
rpm-build 6f7582
    diff = int(m_unit) - int(f.m_unit);
rpm-build 6f7582
    if (diff) return diff < 0 ? -1 : 1;
rpm-build 6f7582
    diff = m_orig.cmpY(f.m_orig);
rpm-build 6f7582
    if (diff) return diff;
rpm-build 6f7582
    diff = m_size.cmpY(f.m_size);
rpm-build 6f7582
    if (diff) return diff;
rpm-build 6f7582
    diff = m_naturalSize.cmpY(f.m_naturalSize);
rpm-build 6f7582
    if (diff) return diff;
rpm-build 6f7582
    diff = m_LTClip.cmpY(f.m_LTClip);
rpm-build 6f7582
    if (diff) return diff;
rpm-build 6f7582
    diff = m_RBClip.cmpY(f.m_RBClip);
rpm-build 6f7582
    if (diff) return diff;
rpm-build 6f7582
rpm-build 6f7582
    return 0;
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
  //! the page
rpm-build 6f7582
  int m_page;
rpm-build 6f7582
  MWAWVec2f m_orig /** the origin position in a page */, m_size /* the size of the data*/, m_naturalSize /** the natural size of the data (if known) */;
rpm-build 6f7582
  MWAWVec2f m_LTClip /** the left top clip position */, m_RBClip /* the right bottom clip position */;
rpm-build 6f7582
  //! the unit used in \a orig, in \a m_size and in \a m_LTClip , .... Default: in inches
rpm-build 6f7582
  librevenge::RVNGUnit m_unit;
rpm-build 6f7582
  //! background/foward order
rpm-build 6f7582
  mutable int m_order;
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
#endif
rpm-build 6f7582
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: