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
41#include "libstaroffice_internal.hxx"
42
47 class STOFFPosition
48{
49 public:
51 enum AnchorTo { Cell, Char, CharBaseLine, Frame, Paragraph, Page, Unknown };
52
53 public:
55 STOFFPosition()
56 : m_anchorTo(Unknown)
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
145 AnchorTo m_anchorTo;
147 STOFFVec2f m_origin;
149 STOFFVec2f m_size;
151 STOFFVec2f m_offset;
153 librevenge::RVNGPropertyList m_propertyList;
154};
155
156#endif
157// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFPosition
Class to define the position of an object (textbox, picture, ..) in the document.
Definition STOFFPosition.hxx:48
STOFFPosition::operator==
bool operator==(STOFFPosition const &f) const
basic operator==
Definition STOFFPosition.hxx:132
STOFFPosition::STOFFPosition
STOFFPosition()
constructor
Definition STOFFPosition.hxx:55
STOFFPosition::operator!=
bool operator!=(STOFFPosition const &f) const
basic operator!=
Definition STOFFPosition.hxx:139
STOFFPosition::setOrigin
void setOrigin(STOFFVec2f const &origin)
utility function to set a origin in point
Definition STOFFPosition.hxx:101
STOFFPosition::m_propertyList
librevenge::RVNGPropertyList m_propertyList
the property list
Definition STOFFPosition.hxx:153
STOFFPosition::setSize
void setSize(STOFFVec2f const &size)
utility function to set a size in point
Definition STOFFPosition.hxx:108
STOFFPosition::m_size
STOFFVec2f m_size
the size in point
Definition STOFFPosition.hxx:149
STOFFPosition::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition STOFFPosition.hxx:64
STOFFPosition::AnchorTo
AnchorTo
a list of enum used to defined the anchor
Definition STOFFPosition.hxx:51
STOFFPosition::Unknown
@ Unknown
Definition STOFFPosition.hxx:51
STOFFPosition::Frame
@ Frame
Definition STOFFPosition.hxx:51
STOFFPosition::CharBaseLine
@ CharBaseLine
Definition STOFFPosition.hxx:51
STOFFPosition::Cell
@ Cell
Definition STOFFPosition.hxx:51
STOFFPosition::Page
@ Page
Definition STOFFPosition.hxx:51
STOFFPosition::Char
@ Char
Definition STOFFPosition.hxx:51
STOFFPosition::Paragraph
@ Paragraph
Definition STOFFPosition.hxx:51
STOFFPosition::operator<<
friend std::ostream & operator<<(std::ostream &o, STOFFPosition const &pos)
operator<<
Definition STOFFPosition.hxx:126
STOFFPosition::~STOFFPosition
virtual ~STOFFPosition()
destructor
Definition STOFFPosition.cxx:36
STOFFPosition::m_anchorTo
AnchorTo m_anchorTo
anchor position
Definition STOFFPosition.hxx:145
STOFFPosition::m_offset
STOFFVec2f m_offset
internal: an offset used to retrieve the local position in a DrawingLayer
Definition STOFFPosition.hxx:151
STOFFPosition::setAnchor
void setAnchor(AnchorTo anchor)
set the anchor
Definition STOFFPosition.hxx:121
STOFFPosition::m_origin
STOFFVec2f m_origin
the origin in point
Definition STOFFPosition.hxx:147
STOFFVec2< float >
STOFFVec2::y
T y() const
second element
Definition libstaroffice_internal.hxx:602
STOFFVec2::x
T x() const
first element
Definition libstaroffice_internal.hxx:597
libstaroffice_internal.hxx
STOFF_DEBUG_MSG
#define STOFF_DEBUG_MSG(M)
Definition libstaroffice_internal.hxx:129