STOFFPosition.hxx Source File documentation

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{
49public:
51 enum AnchorTo { Cell, Char, CharBaseLine, Frame, Paragraph, Page, Unknown };
52
53public:
55 STOFFPosition() : m_anchorTo(Unknown), m_propertyList() {}
57 virtual ~STOFFPosition();
59 void addTo(librevenge::RVNGPropertyList &propList) const
60 {
61 librevenge::RVNGPropertyList::Iter i(m_propertyList);
62 switch (m_anchorTo) {
63 case Cell:
64 propList.insert("text:anchor-type", "cell");
65 break;
66 case Char:
67 propList.insert("text:anchor-type", "char");
68 break;
69 case CharBaseLine:
70 propList.insert("text:anchor-type", "as-char");
71 break;
72 case Frame:
73 propList.insert("text:anchor-type", "frame");
74 break;
75 case Paragraph:
76 propList.insert("text:anchor-type", "paragraph");
77 break;
78 case Page:
79 propList.insert("text:anchor-type", "page");
80 break;
81 case Unknown:
82 default:
83 STOFF_DEBUG_MSG(("STOFFPosition::addTo: unknown anchor\n"));
84 break;
85 }
86 for (i.rewind(); i.next();) {
87 if (i.child()) {
88 STOFF_DEBUG_MSG(("STOFFPosition::addTo: find unexpected property child\n"));
89 propList.insert(i.key(), *i.child());
90 continue;
91 }
92 propList.insert(i.key(), i()->clone());
93 }
94 }
95
96 void setOrigin(STOFFVec2f const &origin, librevenge::RVNGUnit unit)
97 {
98 m_propertyList.insert("svg:x",double(origin[0]), unit);
99 m_propertyList.insert("svg:y",double(origin[1]), unit);
100 }
101
102 void setSize(STOFFVec2f const &size, librevenge::RVNGUnit unit)
103 {
104 if (size.x()>0)
105 m_propertyList.insert("svg:width",double(size.x()), unit);
106 else if (size.x()<0)
107 m_propertyList.insert("fo:min-width",double(-size.x()), unit);
108 if (size.y()>0)
109 m_propertyList.insert("svg:height",double(size.y()), unit);
110 else if (size.y()<0)
111 m_propertyList.insert("fo:min-height",double(-size.y()), unit);
112 }
113
114 void setAnchor(AnchorTo anchor)
115 {
116 m_anchorTo=anchor;
117 }
118
119 friend std::ostream &operator<<(std::ostream &o, STOFFPosition const &pos)
120 {
121 o << "prop=[" << pos.m_propertyList.getPropString().cstr() << "],";
122 return o;
123 }
124
125 bool operator==(STOFFPosition const &f) const
126 {
127 return m_anchorTo==f.m_anchorTo && m_propertyList.getPropString()==f.m_propertyList.getPropString();
128 }
129
130 bool operator!=(STOFFPosition const &f) const
131 {
132 return !operator==(f);
133 }
134
136 AnchorTo m_anchorTo;
138 librevenge::RVNGPropertyList m_propertyList;
139};
140
141#endif
142// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFPosition::operator==
bool operator==(STOFFPosition const &f) const
basic operator==
Definition STOFFPosition.hxx:125
STOFFPosition::STOFFPosition
STOFFPosition()
constructor
Definition STOFFPosition.hxx:55
STOFFPosition::operator!=
bool operator!=(STOFFPosition const &f) const
basic operator!=
Definition STOFFPosition.hxx:130
STOFFPosition::m_propertyList
librevenge::RVNGPropertyList m_propertyList
the property list
Definition STOFFPosition.hxx:138
STOFFPosition::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition STOFFPosition.hxx:59
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:119
STOFFPosition::setSize
void setSize(STOFFVec2f const &size, librevenge::RVNGUnit unit)
utility function to set a size
Definition STOFFPosition.hxx:102
STOFFPosition::~STOFFPosition
virtual ~STOFFPosition()
destructor
Definition STOFFPosition.cxx:36
STOFFPosition::m_anchorTo
AnchorTo m_anchorTo
anchor position
Definition STOFFPosition.hxx:136
STOFFPosition::setAnchor
void setAnchor(AnchorTo anchor)
set the anchor
Definition STOFFPosition.hxx:114
STOFFPosition::setOrigin
void setOrigin(STOFFVec2f const &origin, librevenge::RVNGUnit unit)
utility function to set a origin
Definition STOFFPosition.hxx:96
STOFFVec2::y
T y() const
second element
Definition libstaroffice_internal.hxx:587
STOFFVec2::x
T x() const
first element
Definition libstaroffice_internal.hxx:582
libstaroffice_internal.hxx
STOFFVec2f
STOFFVec2< float > STOFFVec2f
STOFFVec2 of float.
Definition libstaroffice_internal.hxx:752
STOFF_DEBUG_MSG
#define STOFF_DEBUG_MSG(M)
Definition libstaroffice_internal.hxx:127