STOFFPosition.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 /* libstaroffice
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 STOFF_POSITION_H
35 #define STOFF_POSITION_H
36 
37 #include <ostream>
38 
39 #include <librevenge/librevenge.h>
40 
42 
48 {
49 public:
52 
53 public:
57  , m_origin()
58  , m_size()
59  , m_offset(0,0)
60  , m_propertyList() {}
62  virtual ~STOFFPosition();
64  void addTo(librevenge::RVNGPropertyList &propList) const
65  {
66  librevenge::RVNGPropertyList::Iter i(m_propertyList);
67  switch (m_anchorTo) {
68  case Cell:
69  propList.insert("text:anchor-type", "cell");
70  break;
71  case Char:
72  propList.insert("text:anchor-type", "char");
73  break;
74  case CharBaseLine:
75  propList.insert("text:anchor-type", "as-char");
76  break;
77  case Frame:
78  propList.insert("text:anchor-type", "frame");
79  break;
80  case Paragraph:
81  propList.insert("text:anchor-type", "paragraph");
82  break;
83  case Page:
84  propList.insert("text:anchor-type", "page");
85  break;
86  case Unknown:
87  default:
88  STOFF_DEBUG_MSG(("STOFFPosition::addTo: unknown anchor\n"));
89  break;
90  }
91  for (i.rewind(); i.next();) {
92  if (i.child()) {
93  STOFF_DEBUG_MSG(("STOFFPosition::addTo: find unexpected property child\n"));
94  propList.insert(i.key(), *i.child());
95  continue;
96  }
97  propList.insert(i.key(), i()->clone());
98  }
99  }
101  void setOrigin(STOFFVec2f const &origin)
102  {
103  m_origin=origin;
104  m_propertyList.insert("svg:x",double(origin[0]), librevenge::RVNG_POINT);
105  m_propertyList.insert("svg:y",double(origin[1]), librevenge::RVNG_POINT);
106  }
108  void setSize(STOFFVec2f const &size)
109  {
110  m_size=size;
111  if (size.x()>0)
112  m_propertyList.insert("svg:width",double(size.x()), librevenge::RVNG_POINT);
113  else if (size.x()<0)
114  m_propertyList.insert("fo:min-width",double(-size.x()), librevenge::RVNG_POINT);
115  if (size.y()>0)
116  m_propertyList.insert("svg:height",double(size.y()), librevenge::RVNG_POINT);
117  else if (size.y()<0)
118  m_propertyList.insert("fo:min-height",double(-size.y()), librevenge::RVNG_POINT);
119  }
121  void setAnchor(AnchorTo anchor)
122  {
123  m_anchorTo=anchor;
124  }
126  friend std::ostream &operator<<(std::ostream &o, STOFFPosition const &pos)
127  {
128  o << "prop=[" << pos.m_propertyList.getPropString().cstr() << "],";
129  return o;
130  }
132  bool operator==(STOFFPosition const &f) const
133  {
134  return m_anchorTo==f.m_anchorTo && m_origin==f.m_origin && m_size==f.m_size &&
135  m_offset==f.m_offset &&
136  m_propertyList.getPropString()==f.m_propertyList.getPropString();
137  }
139  bool operator!=(STOFFPosition const &f) const
140  {
141  return !operator==(f);
142  }
143 
153  librevenge::RVNGPropertyList m_propertyList;
154 };
155 
156 #endif
157 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
T x() const
first element
Definition: libstaroffice_internal.hxx:593
Definition: STOFFPosition.hxx:51
friend std::ostream & operator<<(std::ostream &o, STOFFPosition const &pos)
operator<<
Definition: STOFFPosition.hxx:126
bool operator!=(STOFFPosition const &f) const
basic operator!=
Definition: STOFFPosition.hxx:139
AnchorTo m_anchorTo
anchor position
Definition: STOFFPosition.hxx:145
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: STOFFPosition.hxx:64
STOFFVec2f m_origin
the origin in point
Definition: STOFFPosition.hxx:147
#define STOFF_DEBUG_MSG(M)
Definition: libstaroffice_internal.hxx:129
Definition: STOFFPosition.hxx:51
Definition: STOFFPosition.hxx:51
STOFFVec2f m_size
the size in point
Definition: STOFFPosition.hxx:149
Definition: STOFFPosition.hxx:51
virtual ~STOFFPosition()
destructor
Definition: STOFFPosition.cxx:36
Definition: STOFFPosition.hxx:51
STOFFVec2f m_offset
internal: an offset used to retrieve the local position in a DrawingLayer
Definition: STOFFPosition.hxx:151
Definition: STOFFPosition.hxx:51
AnchorTo
a list of enum used to defined the anchor
Definition: STOFFPosition.hxx:51
void setAnchor(AnchorTo anchor)
set the anchor
Definition: STOFFPosition.hxx:121
void setSize(STOFFVec2f const &size)
utility function to set a size in point
Definition: STOFFPosition.hxx:108
T y() const
second element
Definition: libstaroffice_internal.hxx:598
void setOrigin(STOFFVec2f const &origin)
utility function to set a origin in point
Definition: STOFFPosition.hxx:101
librevenge::RVNGPropertyList m_propertyList
the property list
Definition: STOFFPosition.hxx:153
STOFFPosition()
constructor
Definition: STOFFPosition.hxx:55
bool operator==(STOFFPosition const &f) const
basic operator==
Definition: STOFFPosition.hxx:132
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: STOFFPosition.hxx:47
Definition: STOFFPosition.hxx:51

Generated on Sat May 29 2021 22:54:03 for libstaroffice by doxygen 1.8.14