LibreOffice Module writerfilter (master) 1
rtfvalue.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
11#include "rtfdocumentimpl.hxx"
12#include <com/sun/star/embed/XEmbeddedObject.hpp>
13
14using namespace com::sun::star;
15
17{
18RTFValue::RTFValue(int nValue, OUString sValue, const RTFSprms* pAttributes, const RTFSprms* pSprms,
19 uno::Reference<drawing::XShape> xShape, uno::Reference<io::XInputStream> xStream,
20 uno::Reference<embed::XEmbeddedObject> xObject, bool bForceString,
21 const RTFShape* pShape, const RTFPicture* pPicture)
22 : m_nValue(nValue)
23 , m_sValue(std::move(sValue))
24 , m_xShape(std::move(xShape))
25 , m_xStream(std::move(xStream))
26 , m_xObject(std::move(xObject))
27 , m_bForceString(bForceString)
28{
29 if (pAttributes)
30 m_pAttributes = new RTFSprms(*pAttributes);
31 if (pSprms)
32 m_pSprms = new RTFSprms(*pSprms);
33 if (pShape)
34 m_pShape = new RTFShape(*pShape);
35 if (pPicture)
36 m_pPicture = new RTFPicture(*pPicture);
37}
38
39RTFValue::RTFValue() {}
40
41RTFValue::RTFValue(int nValue)
42 : m_nValue(nValue)
43{
44}
45
46RTFValue::RTFValue(OUString sValue, bool bForce)
47 : m_sValue(std::move(sValue))
48 , m_bForceString(bForce)
49{
50}
51
52RTFValue::RTFValue(const RTFSprms& rAttributes)
53 : m_pAttributes(new RTFSprms(rAttributes))
54{
55}
56
57RTFValue::RTFValue(const RTFSprms& rAttributes, const RTFSprms& rSprms)
58 : m_pAttributes(new RTFSprms(rAttributes))
59 , m_pSprms(new RTFSprms(rSprms))
60{
61}
62
64 : m_xShape(std::move(xShape))
65{
66}
67
69 : m_xStream(std::move(xStream))
70{
71}
72
73RTFValue::RTFValue(uno::Reference<embed::XEmbeddedObject> xObject)
74 : m_xObject(std::move(xObject))
75{
76}
77
79 : m_pShape(new RTFShape(aShape))
80{
81}
82
84 : m_pPicture(new RTFPicture(rPicture))
85{
86}
87
88RTFValue::~RTFValue() = default;
89
90int RTFValue::getInt() const { return m_nValue; }
91
92OUString RTFValue::getString() const
93{
94 if (!m_sValue.isEmpty() || m_bForceString)
95 return m_sValue;
96
97 return OUString::number(m_nValue);
98}
99
100void RTFValue::setString(const OUString& sValue) { m_sValue = sValue; }
101
103{
104 uno::Any ret;
105 if (!m_sValue.isEmpty() || m_bForceString)
106 ret <<= m_sValue;
107 else if (m_xShape.is())
108 ret <<= m_xShape;
109 else if (m_xStream.is())
110 ret <<= m_xStream;
111 else if (m_xObject.is())
112 ret <<= m_xObject;
113 else
114 ret <<= static_cast<sal_Int32>(m_nValue);
115 return ret;
116}
117
119{
120 if (!m_pShape)
121 m_pShape = new RTFShape();
122 return *m_pShape;
123}
124
126{
127 if (!m_pPicture)
129 return *m_pPicture;
130}
131
133{
135}
136
138{
140}
141
142#ifdef DBG_UTIL
143std::string RTFValue::toString() const
144{
145 if (!m_sValue.isEmpty() || m_bForceString)
146 return std::string(OUStringToOString(m_sValue, RTL_TEXTENCODING_UTF8));
147
148 return std::string(OString::number(m_nValue));
149}
150#endif
151
153{
154 return new RTFValue(m_nValue, m_sValue, m_pAttributes.get(), m_pSprms.get(), m_xShape,
156}
157
158RTFValue* RTFValue::CloneWithSprms(RTFSprms const& rAttributes, RTFSprms const& rSprms) const
159{
160 return new RTFValue(m_nValue, m_sValue, &rAttributes, &rSprms, m_xShape, m_xStream, m_xObject,
161 m_bForceString, m_pShape.get(), m_pPicture.get());
162}
163
164bool RTFValue::equals(const RTFValue& rOther) const
165{
166 if (m_nValue != rOther.m_nValue)
167 return false;
168 if (m_sValue != rOther.m_sValue)
169 return false;
170
171 if (m_pAttributes && rOther.m_pAttributes)
172 {
173 if (m_pAttributes->size() != rOther.m_pAttributes->size())
174 return false;
175 if (!m_pAttributes->equals(rOther))
176 return false;
177 }
178 else if (m_pAttributes && m_pAttributes->size())
179 {
180 return false;
181 }
182 else if (rOther.m_pAttributes && rOther.m_pAttributes->size())
183 {
184 return false;
185 }
186
187 if (m_pSprms && rOther.m_pSprms)
188 {
189 if (m_pSprms->size() != rOther.m_pSprms->size())
190 return false;
191 if (!m_pSprms->equals(rOther))
192 return false;
193 }
194 else if (m_pSprms && m_pSprms->size())
195 {
196 return false;
197 }
198 else if (rOther.m_pSprms && rOther.m_pSprms->size())
199 {
200 return false;
201 }
202
203 return true;
204}
205
207{
208 if (!m_pAttributes)
209 m_pAttributes = new RTFSprms();
210 return *m_pAttributes;
211}
212
214{
215 if (!m_pSprms)
216 m_pSprms = new RTFSprms();
217 return *m_pSprms;
218}
219
220} // namespace writerfilter::rtftok
221
222/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XInputStream > xStream
tools::SvRef< Reference< T > > Pointer_t
Pointer to reference.
Stores the properties of a picture.
Sends RTFSprm instances to DomainMapper.
Stores the properties of a shape.
A list of RTFSprm with a copy constructor that performs a deep copy.
Definition: rtfsprm.hxx:39
Value of an RTF keyword.
Definition: rtfvalue.hxx:33
writerfilter::Reference< BinaryObj >::Pointer_t getBinary() override
Returns binary object of this value.
Definition: rtfvalue.cxx:137
RTFValue * CloneWithSprms(RTFSprms const &rAttributes, RTFSprms const &rSprms) const
Definition: rtfvalue.cxx:158
css::uno::Reference< css::drawing::XShape > m_xShape
Definition: rtfvalue.hxx:76
tools::SvRef< RTFShape > m_pShape
Definition: rtfvalue.hxx:80
tools::SvRef< RTFSprms > m_pAttributes
Definition: rtfvalue.hxx:74
tools::SvRef< RTFPicture > m_pPicture
Definition: rtfvalue.hxx:81
RTFSprms & getAttributes() const
Definition: rtfvalue.cxx:206
css::uno::Any getAny() const override
Returns representation of the value as uno::Any.
Definition: rtfvalue.cxx:102
RTFShape & getShape() const
Definition: rtfvalue.cxx:118
void setString(const OUString &sValue)
Definition: rtfvalue.cxx:100
std::string toString() const override
Returns string representation of this value.
Definition: rtfvalue.cxx:143
css::uno::Reference< css::embed::XEmbeddedObject > m_xObject
Definition: rtfvalue.hxx:78
RTFSprms & getSprms() const
Definition: rtfvalue.cxx:213
RTFValue * Clone() const
Definition: rtfvalue.cxx:152
tools::SvRef< RTFSprms > m_pSprms
Definition: rtfvalue.hxx:75
RTFPicture & getPicture() const
Definition: rtfvalue.cxx:125
int getInt() const override
Returns integer representation of the value.
Definition: rtfvalue.cxx:90
css::uno::Reference< css::io::XInputStream > m_xStream
Definition: rtfvalue.hxx:77
OUString getString() const override
Returns string representation of the value.
Definition: rtfvalue.cxx:92
bool equals(const RTFValue &rOther) const
Definition: rtfvalue.cxx:164
writerfilter::Reference< Properties >::Pointer_t getProperties() override
Returns properties of this value.
Definition: rtfvalue.cxx:132
sal_Int16 nValue
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Reference< XStream > m_xStream