STOFFPosition.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libstaroffice
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 #ifndef STOFF_POSITION_H
00035 #define STOFF_POSITION_H
00036 
00037 #include <ostream>
00038 
00039 #include <librevenge/librevenge.h>
00040 
00041 #include "libstaroffice_internal.hxx"
00042 
00047 class STOFFPosition
00048 {
00049 public:
00051   enum AnchorTo { Cell, Char, CharBaseLine, Frame, Paragraph, Page, Unknown };
00052 
00053 public:
00055   STOFFPosition() : m_anchorTo(Unknown), m_propertyList() {}
00057   virtual ~STOFFPosition();
00059   void addTo(librevenge::RVNGPropertyList &propList) const
00060   {
00061     librevenge::RVNGPropertyList::Iter i(m_propertyList);
00062     switch (m_anchorTo) {
00063     case Cell:
00064       propList.insert("text:anchor-type", "cell");
00065       break;
00066     case Char:
00067       propList.insert("text:anchor-type", "char");
00068       break;
00069     case CharBaseLine:
00070       propList.insert("text:anchor-type", "as-char");
00071       break;
00072     case Frame:
00073       propList.insert("text:anchor-type", "frame");
00074       break;
00075     case Paragraph:
00076       propList.insert("text:anchor-type", "paragraph");
00077       break;
00078     case Page:
00079       propList.insert("text:anchor-type", "page");
00080       break;
00081     case Unknown:
00082     default:
00083       STOFF_DEBUG_MSG(("STOFFPosition::addTo: unknown anchor\n"));
00084       break;
00085     }
00086     for (i.rewind(); i.next();) {
00087       if (i.child()) {
00088         STOFF_DEBUG_MSG(("STOFFPosition::addTo: find unexpected property child\n"));
00089         propList.insert(i.key(), *i.child());
00090         continue;
00091       }
00092       propList.insert(i.key(), i()->clone());
00093     }
00094   }
00096   void setOrigin(STOFFVec2f const &origin, librevenge::RVNGUnit unit)
00097   {
00098     m_propertyList.insert("svg:x",double(origin[0]), unit);
00099     m_propertyList.insert("svg:y",double(origin[1]), unit);
00100   }
00102   void setSize(STOFFVec2f const &size, librevenge::RVNGUnit unit)
00103   {
00104     if (size.x()>0)
00105       m_propertyList.insert("svg:width",double(size.x()), unit);
00106     else if (size.x()<0)
00107       m_propertyList.insert("fo:min-width",double(-size.x()), unit);
00108     if (size.y()>0)
00109       m_propertyList.insert("svg:height",double(size.y()), unit);
00110     else if (size.y()<0)
00111       m_propertyList.insert("fo:min-height",double(-size.y()), unit);
00112   }
00114   void setAnchor(AnchorTo anchor)
00115   {
00116     m_anchorTo=anchor;
00117   }
00119   friend  std::ostream &operator<<(std::ostream &o, STOFFPosition const &pos)
00120   {
00121     o << "prop=[" << pos.m_propertyList.getPropString().cstr() << "],";
00122     return o;
00123   }
00125   bool operator==(STOFFPosition const &f) const
00126   {
00127     return m_anchorTo==f.m_anchorTo && m_propertyList.getPropString()==f.m_propertyList.getPropString();
00128   }
00130   bool operator!=(STOFFPosition const &f) const
00131   {
00132     return !operator==(f);
00133   }
00134 
00136   AnchorTo m_anchorTo;
00138   librevenge::RVNGPropertyList m_propertyList;
00139 };
00140 
00141 #endif
00142 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: