LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/doctok - WW8PropertySetImpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 171 0.6 %
Date: 2012-12-27 Functions: 2 37 5.4 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "WW8DocumentImpl.hxx"
      21             : #include "WW8ResourceModelImpl.hxx"
      22             : #include <doctok/resourceids.hxx>
      23             : #include <resourcemodel/QNameToString.hxx>
      24             : 
      25             : namespace writerfilter {
      26             : namespace doctok
      27             : {
      28             : 
      29             : 
      30           0 : bool operator != (const WW8PropertySetIterator & rA,
      31             :                   const WW8PropertySetIterator & rB)
      32             : {
      33           0 :     return ! (rA.equal(rB));
      34             : }
      35             : 
      36           0 : WW8Property::~WW8Property()
      37             : {
      38           0 : }
      39             : 
      40           0 : WW8PropertySet::~WW8PropertySet()
      41             : {
      42           0 : }
      43             : 
      44           0 : WW8PropertySetIterator::~WW8PropertySetIterator()
      45             : {
      46           0 : }
      47             : 
      48           0 : WW8PropertyImpl::WW8PropertyImpl(const WW8StructBase & rBase,
      49             :                                  sal_uInt32 nOffset,
      50             :                                  sal_uInt32 nCount)
      51           0 : : WW8StructBase(rBase, nOffset, nCount)
      52             : {
      53           0 : }
      54             : 
      55           0 : WW8PropertyImpl::~WW8PropertyImpl()
      56             : {
      57           0 : }
      58             : 
      59           0 : sal_uInt32 WW8PropertyImpl::getParam() const
      60             : {
      61           0 :     sal_uInt32 nResult = 0;
      62             : 
      63           0 :     switch (get_spra())
      64             :     {
      65             :     case 0:
      66             :     case 1:
      67           0 :         nResult = getU8(2);
      68             : 
      69           0 :         break;
      70             : 
      71             :     case 2:
      72             :     case 4:
      73             :     case 5:
      74           0 :         nResult = getU16(2);
      75             : 
      76           0 :         break;
      77             : 
      78             :     case 3:
      79           0 :         nResult = getU32(2);
      80             : 
      81           0 :         break;
      82             : 
      83             :     case 7:
      84           0 :         nResult = getU16(2) + (getU8(4) << 16);
      85             : 
      86           0 :         break;
      87             : 
      88             :     default:
      89           0 :         break;
      90             :     }
      91             : 
      92           0 :     return nResult;
      93             : }
      94             : 
      95           0 : WW8Stream::Sequence WW8PropertyImpl::getParams() const
      96             : {
      97           0 :     return WW8Stream::Sequence(mSequence, 2, getCount() - 2);
      98             : }
      99             : 
     100           0 : sal_uInt32 WW8PropertyImpl::getByteLength() const
     101             : {
     102           0 :     sal_uInt32 nParamSize = 0;
     103             : 
     104           0 :     switch (get_spra())
     105             :     {
     106             :     case 0:
     107             :     case 1:
     108           0 :         nParamSize = 1;
     109             : 
     110           0 :         break;
     111             : 
     112             :     case 2:
     113             :     case 4:
     114             :     case 5:
     115           0 :         nParamSize = 2;
     116             : 
     117           0 :         break;
     118             : 
     119             :     case 3:
     120           0 :         nParamSize = 4;
     121             : 
     122           0 :         break;
     123             : 
     124             :     case 7:
     125           0 :         nParamSize = 3;
     126             : 
     127           0 :         break;
     128             :     default:
     129           0 :         switch (getId())
     130             :         {
     131             :         case 0xd608:
     132           0 :                 nParamSize = getU16(2) + 1;
     133           0 :                 break;
     134             :         default:
     135           0 :                 nParamSize = getU8(2) + 1;
     136           0 :                 break;
     137             :         }
     138             : 
     139           0 :         break;
     140             :     }
     141             : 
     142           0 :     return nParamSize + 2;
     143             : }
     144             : 
     145           0 : void WW8PropertyImpl::dump(OutputWithDepth<string> & o) const
     146             : {
     147           0 :     o.addItem(toString());
     148           0 : }
     149             : 
     150           0 : string WW8PropertyImpl::toString() const
     151             : {
     152           0 :     string aResult;
     153             : 
     154           0 :     aResult += "<sprmcommon";
     155             : 
     156             :     char sBuffer[256];
     157           0 :     snprintf(sBuffer, sizeof(sBuffer), " id=\"%" SAL_PRIuUINT32 "\"", getId());
     158           0 :     aResult += sBuffer;
     159           0 :     aResult += " name=\"";
     160           0 :     aResult += (*SprmIdToString::Instance())(getId());
     161           0 :     aResult += "\"";
     162           0 :     snprintf(sBuffer, sizeof(sBuffer), " sgc=\"%x\"", get_sgc());
     163           0 :     aResult += sBuffer;
     164           0 :     snprintf(sBuffer, sizeof(sBuffer), " spra=\"%x\"", get_spra());
     165           0 :     aResult += sBuffer;
     166           0 :     snprintf(sBuffer, sizeof(sBuffer), " size=\"%" SAL_PRIxUINT32 "\"", getByteLength());
     167           0 :     aResult += sBuffer;
     168           0 :     snprintf(sBuffer, sizeof(sBuffer), " param=\"%" SAL_PRIxUINT32 "\"", getParam());
     169           0 :     aResult += sBuffer;
     170           0 :     aResult += ">\n";
     171             : 
     172           0 :     aResult += mSequence.toString();
     173             : 
     174           0 :     aResult += "</sprmcommon>";
     175             : 
     176           0 :     return aResult;
     177             : }
     178             : 
     179           0 : WW8PropertySetImpl::WW8PropertySetImpl(WW8Stream & rStream,
     180             :                                        sal_uInt32 nOffset,
     181             :                                        sal_uInt32 nCount,
     182             :                                        bool bPap)
     183           0 : : WW8StructBase(rStream, nOffset, nCount), mbPap(bPap)
     184             : {
     185           0 : }
     186             : 
     187           0 : WW8PropertySetImpl::WW8PropertySetImpl(const WW8StructBase & rBase,
     188             :                                        sal_uInt32 nOffset,
     189             :                                        sal_uInt32 nCount,
     190             :                                        bool bPap)
     191           0 : : WW8StructBase(rBase, nOffset, nCount), mbPap(bPap)
     192             : {
     193           0 : }
     194             : 
     195           0 : WW8PropertySetImpl::~WW8PropertySetImpl()
     196             : {
     197           0 : }
     198             : 
     199           0 : bool WW8PropertySetImpl::isPap() const
     200             : {
     201           0 :     return mbPap;
     202             : }
     203             : 
     204           0 : sal_uInt32 WW8PropertySetImpl::get_istd() const
     205             : {
     206           0 :     sal_uInt32 nResult = 0;
     207             : 
     208           0 :     if (mbPap)
     209           0 :         nResult = getU16(0);
     210             : 
     211           0 :     return nResult;
     212             : }
     213             : 
     214           0 : WW8PropertySetIterator::Pointer_t WW8PropertySetImpl::begin()
     215             : {
     216             :     return WW8PropertySetIterator::Pointer_t
     217           0 :         (new WW8PropertySetIteratorImpl(this, mbPap ? 2 : 0));
     218             : }
     219             : 
     220           0 : WW8PropertySetIterator::Pointer_t WW8PropertySetImpl::end()
     221             : {
     222             :     return WW8PropertySetIterator::Pointer_t
     223           0 :         (new WW8PropertySetIteratorImpl(this, getCount()));
     224             : }
     225             : 
     226           0 : WW8PropertySetIteratorImpl::~WW8PropertySetIteratorImpl()
     227             : {
     228           0 : }
     229             : 
     230             : WW8Property::Pointer_t
     231           0 : WW8PropertySetImpl::getAttribute(sal_uInt32 nOffset) const
     232             : {
     233           0 :     WW8PropertyImpl aTmpAttr(*this, nOffset, 3);
     234             : 
     235           0 :     sal_uInt32 nLength = aTmpAttr.getByteLength();
     236             : 
     237           0 :     if (nOffset + nLength > getCount())
     238           0 :         nLength = getCount() - nOffset;
     239             : 
     240             :     return WW8Property::Pointer_t
     241           0 :         (new WW8PropertyImpl(*this, nOffset, nLength));
     242             : }
     243             : 
     244           0 : void WW8PropertySetImpl::dump(OutputWithDepth<string> & o) const
     245             : {
     246           0 :     WW8StructBase::dump(o);
     247             : 
     248             :     WW8PropertySetIterator::Pointer_t pIt =
     249           0 :         const_cast<WW8PropertySetImpl *>(this)->begin();
     250             :     WW8PropertySetIterator::Pointer_t pItEnd =
     251           0 :         const_cast<WW8PropertySetImpl *>(this)->end();
     252             : 
     253           0 :     while((*pIt) != (*pItEnd))
     254             :     {
     255           0 :         WW8Property::Pointer_t pAttr = pIt->get();
     256             : 
     257           0 :         pAttr->dump(o);
     258           0 :         ++(*pIt);
     259           0 :     }
     260           0 : }
     261             : 
     262           0 : void WW8PropertySetImpl::dots(ostream & o)
     263             : {
     264           0 :     WW8PropertySetIterator::Pointer_t pIt = begin();
     265           0 :     WW8PropertySetIterator::Pointer_t pItEnd = end();
     266             : 
     267           0 :     while((*pIt) != (*pItEnd))
     268             :     {
     269           0 :         WW8Property::Pointer_t pAttr = pIt->get();
     270             : 
     271           0 :         o << "." << endl;
     272             : 
     273           0 :         ++(*pIt);
     274           0 :     }
     275           0 : }
     276             : 
     277           0 : string WW8PropertySetImpl::getType() const
     278             : {
     279           0 :     return "WW8PropertySetImpl";
     280             : }
     281             : 
     282           0 : void WW8PropertySetImpl::resolveLocal(Sprm & sprm, Properties & rHandler)
     283             : {
     284           0 :     switch (sprm.getId())
     285             :     {
     286             :     case 0x6a03:
     287             :         {
     288           0 :             Value::Pointer_t pValue = sprm.getValue();
     289           0 :             getDocument()->setPicLocation(pValue->getInt());
     290           0 :             getDocument()->setPicIsData(false);
     291             :         }
     292           0 :         break;
     293             :     case 0x806:
     294             :         {
     295           0 :             getDocument()->setPicIsData(true);
     296             :         }
     297           0 :         break;
     298             :     case 0x6646:
     299             :         {
     300           0 :             WW8Stream::Pointer_t pStream = getDocument()->getDataStream();
     301             : 
     302           0 :             if (pStream.get() != NULL)
     303             :             {
     304           0 :                 Value::Pointer_t pValue = sprm.getValue();
     305           0 :                 sal_uInt32 nOffset = pValue->getInt();
     306           0 :                 WW8StructBase aStruct(*pStream, nOffset, 2);
     307           0 :                 sal_uInt16 nCount = aStruct.getU16(0);
     308             : 
     309             :                 {
     310             :                     WW8PropertySetImpl * pPropSet =
     311           0 :                     new WW8PropertySetImpl(*pStream, nOffset + 2, nCount);
     312             : 
     313           0 :                     pPropSet->resolve(rHandler);
     314           0 :                 }
     315           0 :             }
     316             :         }
     317           0 :         break;
     318             :     default:
     319           0 :         break;
     320             :     }
     321           0 : }
     322             : 
     323           0 : void WW8PropertySetImpl::resolve(Properties & rHandler)
     324             : {
     325           0 :     if (getCount() >= (isPap() ? 5U : 3U))
     326             :     {
     327           0 :         WW8PropertySetIterator::Pointer_t pIt = begin();
     328           0 :         WW8PropertySetIterator::Pointer_t pItEnd = end();
     329             : 
     330           0 :         if (isPap())
     331             :         {
     332           0 :             WW8Value::Pointer_t pValue = createValue(getU16(0));
     333           0 :             rHandler.attribute(NS_rtf::LN_ISTD, *pValue);
     334             :         }
     335             : 
     336           0 :         while((*pIt) != (*pItEnd))
     337             :         {
     338           0 :             WW8Sprm aSprm(pIt->get());
     339             : 
     340           0 :             rHandler.sprm(aSprm);
     341             : 
     342           0 :             resolveLocal(aSprm, rHandler);
     343             : 
     344           0 :             ++(*pIt);
     345           0 :         }
     346             :     }
     347           0 : }
     348             : 
     349           0 : WW8PropertySetIterator & WW8PropertySetIteratorImpl::operator++ ()
     350             : {
     351           0 :     WW8Property::Pointer_t pTmpAttr = mpAttrSet->getAttribute(mnOffset);
     352             : 
     353           0 :     mnOffset += dynamic_cast<WW8PropertyImpl *>(pTmpAttr.get())->
     354           0 :         getByteLength();
     355             : 
     356           0 :     if (mnOffset > mpAttrSet->getCount() ||
     357           0 :         mpAttrSet->getCount() - mnOffset < 3)
     358           0 :         mnOffset = mpAttrSet->getCount();
     359             : 
     360           0 :     return *this;
     361             : }
     362             : 
     363           0 : WW8Property::Pointer_t WW8PropertySetIteratorImpl::get() const
     364             : {
     365           0 :     return mpAttrSet->getAttribute(mnOffset);
     366             : }
     367             : 
     368           0 : bool WW8PropertySetIteratorImpl::equal
     369             : (const WW8PropertySetIterator & rIt) const
     370             : {
     371             :     const WW8PropertySetIteratorImpl & rMyIt =
     372           0 :         dynamic_cast<const WW8PropertySetIteratorImpl &>(rIt);
     373             : 
     374           0 :     return mpAttrSet == rMyIt.mpAttrSet && mnOffset == rMyIt.mnOffset;
     375             : }
     376             : 
     377           0 : string WW8PropertySetIteratorImpl::toString() const
     378             : {
     379           0 :     string sResult = "";
     380             : 
     381             :     char sBuffer[256];
     382             : 
     383           0 :     snprintf(sBuffer, sizeof(sBuffer), "(%" SAL_PRIuUINT32 ")", mnOffset);
     384           0 :     sResult += sBuffer;
     385             : 
     386           0 :     return sResult;
     387             : }
     388             : 
     389          15 : }}
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10