1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include "rtfreferenceproperties.hxx"
11 #include "rtfdocumentimpl.hxx"
12 #include <com/sun/star/embed/XEmbeddedObject.hpp>
14 using namespace com::sun::star
;
16 namespace writerfilter::rtftok
18 RTFValue::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
)
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
)
30 m_pAttributes
= new RTFSprms(*pAttributes
);
32 m_pSprms
= new RTFSprms(*pSprms
);
34 m_pShape
= new RTFShape(*pShape
);
36 m_pPicture
= new RTFPicture(*pPicture
);
39 RTFValue::RTFValue() {}
41 RTFValue::RTFValue(int nValue
)
46 RTFValue::RTFValue(OUString sValue
, bool bForce
)
47 : m_sValue(std::move(sValue
))
48 , m_bForceString(bForce
)
52 RTFValue::RTFValue(const RTFSprms
& rAttributes
)
53 : m_pAttributes(new RTFSprms(rAttributes
))
57 RTFValue::RTFValue(const RTFSprms
& rAttributes
, const RTFSprms
& rSprms
)
58 : m_pAttributes(new RTFSprms(rAttributes
))
59 , m_pSprms(new RTFSprms(rSprms
))
63 RTFValue::RTFValue(uno::Reference
<drawing::XShape
> xShape
)
64 : m_xShape(std::move(xShape
))
68 RTFValue::RTFValue(uno::Reference
<io::XInputStream
> xStream
)
69 : m_xStream(std::move(xStream
))
73 RTFValue::RTFValue(uno::Reference
<embed::XEmbeddedObject
> xObject
)
74 : m_xObject(std::move(xObject
))
78 RTFValue::RTFValue(const RTFShape
& aShape
)
79 : m_pShape(new RTFShape(aShape
))
83 RTFValue::RTFValue(const RTFPicture
& rPicture
)
84 : m_pPicture(new RTFPicture(rPicture
))
88 RTFValue::RTFValue(text::GraphicCrop
const& rCrop
)
93 RTFValue::~RTFValue() = default;
95 int RTFValue::getInt() const { return m_nValue
; }
97 OUString
RTFValue::getString() const
99 if (!m_sValue
.isEmpty() || m_bForceString
)
102 return OUString::number(m_nValue
);
105 void RTFValue::setString(const OUString
& sValue
) { m_sValue
= sValue
; }
107 uno::Any
RTFValue::getAny() const
110 if (!m_sValue
.isEmpty() || m_bForceString
)
112 else if (m_xShape
.is())
114 else if (m_xStream
.is())
116 else if (m_xObject
.is())
123 ret
<<= static_cast<sal_Int32
>(m_nValue
);
127 RTFShape
& RTFValue::getShape() const
130 m_pShape
= new RTFShape();
134 RTFPicture
& RTFValue::getPicture() const
137 m_pPicture
= new RTFPicture
;
141 writerfilter::Reference
<Properties
>::Pointer_t
RTFValue::getProperties()
143 return new RTFReferenceProperties(getAttributes(), getSprms());
146 writerfilter::Reference
<BinaryObj
>::Pointer_t
RTFValue::getBinary()
148 return writerfilter::Reference
<BinaryObj
>::Pointer_t();
152 std::string
RTFValue::toString() const
154 if (!m_sValue
.isEmpty() || m_bForceString
)
155 return std::string(OUStringToOString(m_sValue
, RTL_TEXTENCODING_UTF8
));
157 return std::string(OString::number(m_nValue
));
161 RTFValue
* RTFValue::Clone() const
163 return new RTFValue(m_nValue
, m_sValue
, m_pAttributes
.get(), m_pSprms
.get(), m_xShape
,
164 m_xStream
, m_xObject
, m_bForceString
, m_pShape
.get(), m_pPicture
.get());
167 RTFValue
* RTFValue::CloneWithSprms(RTFSprms
const& rAttributes
, RTFSprms
const& rSprms
) const
169 return new RTFValue(m_nValue
, m_sValue
, &rAttributes
, &rSprms
, m_xShape
, m_xStream
, m_xObject
,
170 m_bForceString
, m_pShape
.get(), m_pPicture
.get());
173 bool RTFValue::equals(const RTFValue
& rOther
) const
175 if (m_nValue
!= rOther
.m_nValue
)
177 if (m_sValue
!= rOther
.m_sValue
)
180 if (m_pAttributes
&& rOther
.m_pAttributes
)
182 if (m_pAttributes
->size() != rOther
.m_pAttributes
->size())
184 if (!m_pAttributes
->equals(*rOther
.m_pAttributes
))
187 else if (m_pAttributes
&& m_pAttributes
->size())
191 else if (rOther
.m_pAttributes
&& rOther
.m_pAttributes
->size())
196 if (m_pSprms
&& rOther
.m_pSprms
)
198 if (m_pSprms
->size() != rOther
.m_pSprms
->size())
200 if (!m_pSprms
->equals(*rOther
.m_pSprms
))
203 else if (m_pSprms
&& m_pSprms
->size())
207 else if (rOther
.m_pSprms
&& rOther
.m_pSprms
->size())
215 RTFSprms
& RTFValue::getAttributes() const
218 m_pAttributes
= new RTFSprms();
219 return *m_pAttributes
;
222 RTFSprms
& RTFValue::getSprms() const
225 m_pSprms
= new RTFSprms();
229 } // namespace writerfilter::rtftok
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */