Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / doctok / WW8PropertySetImpl.cxx
blobe72f69a7a10950c3969cc89e7d43b9f4a5f44e21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WW8DocumentImpl.hxx"
21 #include "WW8ResourceModelImpl.hxx"
22 #include <doctok/resourceids.hxx>
23 #include <resourcemodel/QNameToString.hxx>
25 namespace writerfilter {
26 namespace doctok
30 bool operator != (const WW8PropertySetIterator & rA,
31 const WW8PropertySetIterator & rB)
33 return ! (rA.equal(rB));
36 WW8Property::~WW8Property()
40 WW8PropertySet::~WW8PropertySet()
44 WW8PropertySetIterator::~WW8PropertySetIterator()
48 WW8PropertyImpl::WW8PropertyImpl(const WW8StructBase & rBase,
49 sal_uInt32 nOffset,
50 sal_uInt32 nCount)
51 : WW8StructBase(rBase, nOffset, nCount)
55 WW8PropertyImpl::~WW8PropertyImpl()
59 sal_uInt32 WW8PropertyImpl::getParam() const
61 sal_uInt32 nResult = 0;
63 switch (get_spra())
65 case 0:
66 case 1:
67 nResult = getU8(2);
69 break;
71 case 2:
72 case 4:
73 case 5:
74 nResult = getU16(2);
76 break;
78 case 3:
79 nResult = getU32(2);
81 break;
83 case 7:
84 nResult = getU16(2) + (getU8(4) << 16);
86 break;
88 default:
89 break;
92 return nResult;
95 WW8Stream::Sequence WW8PropertyImpl::getParams() const
97 return WW8Stream::Sequence(mSequence, 2, getCount() - 2);
100 sal_uInt32 WW8PropertyImpl::getByteLength() const
102 sal_uInt32 nParamSize = 0;
104 switch (get_spra())
106 case 0:
107 case 1:
108 nParamSize = 1;
110 break;
112 case 2:
113 case 4:
114 case 5:
115 nParamSize = 2;
117 break;
119 case 3:
120 nParamSize = 4;
122 break;
124 case 7:
125 nParamSize = 3;
127 break;
128 default:
129 switch (getId())
131 case 0xd608:
132 nParamSize = getU16(2) + 1;
133 break;
134 default:
135 nParamSize = getU8(2) + 1;
136 break;
139 break;
142 return nParamSize + 2;
145 void WW8PropertyImpl::dump(OutputWithDepth<string> & o) const
147 o.addItem(toString());
150 string WW8PropertyImpl::toString() const
152 string aResult;
154 aResult += "<sprmcommon";
156 char sBuffer[256];
157 snprintf(sBuffer, sizeof(sBuffer), " id=\"%" SAL_PRIuUINT32 "\"", getId());
158 aResult += sBuffer;
159 aResult += " name=\"";
160 aResult += (*SprmIdToString::Instance())(getId());
161 aResult += "\"";
162 snprintf(sBuffer, sizeof(sBuffer), " sgc=\"%x\"", get_sgc());
163 aResult += sBuffer;
164 snprintf(sBuffer, sizeof(sBuffer), " spra=\"%x\"", get_spra());
165 aResult += sBuffer;
166 snprintf(sBuffer, sizeof(sBuffer), " size=\"%" SAL_PRIxUINT32 "\"", getByteLength());
167 aResult += sBuffer;
168 snprintf(sBuffer, sizeof(sBuffer), " param=\"%" SAL_PRIxUINT32 "\"", getParam());
169 aResult += sBuffer;
170 aResult += ">\n";
172 aResult += mSequence.toString();
174 aResult += "</sprmcommon>";
176 return aResult;
179 WW8PropertySetImpl::WW8PropertySetImpl(WW8Stream & rStream,
180 sal_uInt32 nOffset,
181 sal_uInt32 nCount,
182 bool bPap)
183 : WW8StructBase(rStream, nOffset, nCount), mbPap(bPap)
187 WW8PropertySetImpl::WW8PropertySetImpl(const WW8StructBase & rBase,
188 sal_uInt32 nOffset,
189 sal_uInt32 nCount,
190 bool bPap)
191 : WW8StructBase(rBase, nOffset, nCount), mbPap(bPap)
195 WW8PropertySetImpl::~WW8PropertySetImpl()
199 bool WW8PropertySetImpl::isPap() const
201 return mbPap;
204 sal_uInt32 WW8PropertySetImpl::get_istd() const
206 sal_uInt32 nResult = 0;
208 if (mbPap)
209 nResult = getU16(0);
211 return nResult;
214 WW8PropertySetIterator::Pointer_t WW8PropertySetImpl::begin()
216 return WW8PropertySetIterator::Pointer_t
217 (new WW8PropertySetIteratorImpl(this, mbPap ? 2 : 0));
220 WW8PropertySetIterator::Pointer_t WW8PropertySetImpl::end()
222 return WW8PropertySetIterator::Pointer_t
223 (new WW8PropertySetIteratorImpl(this, getCount()));
226 WW8PropertySetIteratorImpl::~WW8PropertySetIteratorImpl()
230 WW8Property::Pointer_t
231 WW8PropertySetImpl::getAttribute(sal_uInt32 nOffset) const
233 WW8PropertyImpl aTmpAttr(*this, nOffset, 3);
235 sal_uInt32 nLength = aTmpAttr.getByteLength();
237 if (nOffset + nLength > getCount())
238 nLength = getCount() - nOffset;
240 return WW8Property::Pointer_t
241 (new WW8PropertyImpl(*this, nOffset, nLength));
244 void WW8PropertySetImpl::dump(OutputWithDepth<string> & o) const
246 WW8StructBase::dump(o);
248 WW8PropertySetIterator::Pointer_t pIt =
249 const_cast<WW8PropertySetImpl *>(this)->begin();
250 WW8PropertySetIterator::Pointer_t pItEnd =
251 const_cast<WW8PropertySetImpl *>(this)->end();
253 while((*pIt) != (*pItEnd))
255 WW8Property::Pointer_t pAttr = pIt->get();
257 pAttr->dump(o);
258 ++(*pIt);
262 void WW8PropertySetImpl::dots(ostream & o)
264 WW8PropertySetIterator::Pointer_t pIt = begin();
265 WW8PropertySetIterator::Pointer_t pItEnd = end();
267 while((*pIt) != (*pItEnd))
269 WW8Property::Pointer_t pAttr = pIt->get();
271 o << "." << endl;
273 ++(*pIt);
277 string WW8PropertySetImpl::getType() const
279 return "WW8PropertySetImpl";
282 void WW8PropertySetImpl::resolveLocal(Sprm & sprm, Properties & rHandler)
284 switch (sprm.getId())
286 case 0x6a03:
288 Value::Pointer_t pValue = sprm.getValue();
289 getDocument()->setPicLocation(pValue->getInt());
290 getDocument()->setPicIsData(false);
292 break;
293 case 0x806:
295 getDocument()->setPicIsData(true);
297 break;
298 case 0x6646:
300 WW8Stream::Pointer_t pStream = getDocument()->getDataStream();
302 if (pStream.get() != NULL)
304 Value::Pointer_t pValue = sprm.getValue();
305 sal_uInt32 nOffset = pValue->getInt();
306 WW8StructBase aStruct(*pStream, nOffset, 2);
307 sal_uInt16 nCount = aStruct.getU16(0);
310 WW8PropertySetImpl * pPropSet =
311 new WW8PropertySetImpl(*pStream, nOffset + 2, nCount);
313 pPropSet->resolve(rHandler);
317 break;
318 default:
319 break;
323 void WW8PropertySetImpl::resolve(Properties & rHandler)
325 if (getCount() >= (isPap() ? 5U : 3U))
327 WW8PropertySetIterator::Pointer_t pIt = begin();
328 WW8PropertySetIterator::Pointer_t pItEnd = end();
330 if (isPap())
332 WW8Value::Pointer_t pValue = createValue(getU16(0));
333 rHandler.attribute(NS_rtf::LN_ISTD, *pValue);
336 while((*pIt) != (*pItEnd))
338 WW8Sprm aSprm(pIt->get());
340 rHandler.sprm(aSprm);
342 resolveLocal(aSprm, rHandler);
344 ++(*pIt);
349 WW8PropertySetIterator & WW8PropertySetIteratorImpl::operator++ ()
351 WW8Property::Pointer_t pTmpAttr = mpAttrSet->getAttribute(mnOffset);
353 mnOffset += dynamic_cast<WW8PropertyImpl *>(pTmpAttr.get())->
354 getByteLength();
356 if (mnOffset > mpAttrSet->getCount() ||
357 mpAttrSet->getCount() - mnOffset < 3)
358 mnOffset = mpAttrSet->getCount();
360 return *this;
363 WW8Property::Pointer_t WW8PropertySetIteratorImpl::get() const
365 return mpAttrSet->getAttribute(mnOffset);
368 bool WW8PropertySetIteratorImpl::equal
369 (const WW8PropertySetIterator & rIt) const
371 const WW8PropertySetIteratorImpl & rMyIt =
372 dynamic_cast<const WW8PropertySetIteratorImpl &>(rIt);
374 return mpAttrSet == rMyIt.mpAttrSet && mnOffset == rMyIt.mnOffset;
377 string WW8PropertySetIteratorImpl::toString() const
379 string sResult = "";
381 char sBuffer[256];
383 snprintf(sBuffer, sizeof(sBuffer), "(%" SAL_PRIuUINT32 ")", mnOffset);
384 sResult += sBuffer;
386 return sResult;
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */