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/.
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
{
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
,
51 : WW8StructBase(rBase
, nOffset
, nCount
)
55 WW8PropertyImpl::~WW8PropertyImpl()
59 sal_uInt32
WW8PropertyImpl::getParam() const
61 sal_uInt32 nResult
= 0;
84 nResult
= getU16(2) + (getU8(4) << 16);
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;
132 nParamSize
= getU16(2) + 1;
135 nParamSize
= getU8(2) + 1;
142 return nParamSize
+ 2;
145 void WW8PropertyImpl::dump(OutputWithDepth
<string
> & o
) const
147 o
.addItem(toString());
150 string
WW8PropertyImpl::toString() const
154 aResult
+= "<sprmcommon";
157 snprintf(sBuffer
, sizeof(sBuffer
), " id=\"%" SAL_PRIuUINT32
"\"", getId());
159 aResult
+= " name=\"";
160 aResult
+= (*SprmIdToString::Instance())(getId());
162 snprintf(sBuffer
, sizeof(sBuffer
), " sgc=\"%x\"", get_sgc());
164 snprintf(sBuffer
, sizeof(sBuffer
), " spra=\"%x\"", get_spra());
166 snprintf(sBuffer
, sizeof(sBuffer
), " size=\"%" SAL_PRIxUINT32
"\"", getByteLength());
168 snprintf(sBuffer
, sizeof(sBuffer
), " param=\"%" SAL_PRIxUINT32
"\"", getParam());
172 aResult
+= mSequence
.toString();
174 aResult
+= "</sprmcommon>";
179 WW8PropertySetImpl::WW8PropertySetImpl(WW8Stream
& rStream
,
183 : WW8StructBase(rStream
, nOffset
, nCount
), mbPap(bPap
)
187 WW8PropertySetImpl::WW8PropertySetImpl(const WW8StructBase
& rBase
,
191 : WW8StructBase(rBase
, nOffset
, nCount
), mbPap(bPap
)
195 WW8PropertySetImpl::~WW8PropertySetImpl()
199 bool WW8PropertySetImpl::isPap() const
204 sal_uInt32
WW8PropertySetImpl::get_istd() const
206 sal_uInt32 nResult
= 0;
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();
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();
277 string
WW8PropertySetImpl::getType() const
279 return "WW8PropertySetImpl";
282 void WW8PropertySetImpl::resolveLocal(Sprm
& sprm
, Properties
& rHandler
)
284 switch (sprm
.getId())
288 Value::Pointer_t pValue
= sprm
.getValue();
289 getDocument()->setPicLocation(pValue
->getInt());
290 getDocument()->setPicIsData(false);
295 getDocument()->setPicIsData(true);
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
);
323 void WW8PropertySetImpl::resolve(Properties
& rHandler
)
325 if (getCount() >= (isPap() ? 5U : 3U))
327 WW8PropertySetIterator::Pointer_t pIt
= begin();
328 WW8PropertySetIterator::Pointer_t pItEnd
= end();
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
);
349 WW8PropertySetIterator
& WW8PropertySetIteratorImpl::operator++ ()
351 WW8Property::Pointer_t pTmpAttr
= mpAttrSet
->getAttribute(mnOffset
);
353 mnOffset
+= dynamic_cast<WW8PropertyImpl
*>(pTmpAttr
.get())->
356 if (mnOffset
> mpAttrSet
->getCount() ||
357 mpAttrSet
->getCount() - mnOffset
< 3)
358 mnOffset
= mpAttrSet
->getCount();
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
383 snprintf(sBuffer
, sizeof(sBuffer
), "(%" SAL_PRIuUINT32
")", mnOffset
);
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */