LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/doctok - Dff.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 227 0.4 %
Date: 2012-12-27 Functions: 2 46 4.3 %
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 <stdio.h>
      21             : #include "Dff.hxx"
      22             : #include <doctok/resourceids.hxx>
      23             : #include <resourcemodel/WW8ResourceModel.hxx>
      24             : #include "doctok/resources.hxx"
      25             : 
      26             : namespace writerfilter {
      27             : namespace doctok {
      28             : 
      29             : typedef boost::shared_ptr<WW8Value> WW8ValueSharedPointer_t;
      30             : 
      31           0 : DffRecord::DffRecord(WW8Stream & rStream, sal_uInt32 nOffset,
      32             :                      sal_uInt32 nCount)
      33           0 : : WW8StructBase(rStream, nOffset, nCount), bInitialized(false)
      34             : {
      35           0 : }
      36             : 
      37           0 : DffRecord::DffRecord(WW8StructBase * pParent, sal_uInt32 nOffset,
      38             :                      sal_uInt32 nCount)
      39           0 : : WW8StructBase(pParent, nOffset, nCount), bInitialized(false)
      40             : {
      41           0 : }
      42             : 
      43           0 : Records_t::iterator DffRecord::begin()
      44             : {
      45           0 :     if (! bInitialized)
      46           0 :         initChildren();
      47             : 
      48           0 :     return mRecords.begin();
      49             : }
      50             : 
      51           0 : Records_t::iterator DffRecord::end()
      52             : {
      53           0 :     if (! bInitialized)
      54           0 :         initChildren();
      55             : 
      56           0 :     return mRecords.end();
      57             : }
      58             : 
      59           0 : bool DffRecord::isContainer() const
      60             : {
      61           0 :     return getVersion() == 0xf;
      62             : }
      63             : 
      64           0 : sal_uInt32 DffRecord::calcSize() const
      65             : {
      66           0 :     sal_uInt32 nResult = 0;
      67             : 
      68           0 :     switch (getRecordType())
      69             :     {
      70             :     case 0xf000:
      71             :     case 0xf001:
      72             :     case 0xf002:
      73             :     case 0xf003:
      74             :     case 0xf004:
      75           0 :         nResult = getU32(0x4) + 8;
      76             : 
      77           0 :         break;
      78             :     case 0xf700:
      79           0 :         nResult = 8;
      80             : 
      81           0 :         break;
      82             :     default:
      83           0 :         nResult = getU32(0x4);
      84             : 
      85           0 :         if (! isContainer())
      86           0 :             nResult += 8;
      87           0 :         break;
      88             :     }
      89             : 
      90           0 :     return nResult;
      91             : }
      92             : 
      93           0 : sal_uInt32 DffRecord::getVersion() const
      94             : {
      95           0 :     return getU8(0x0) & 0xf;
      96             : }
      97             : 
      98           0 : sal_uInt32 DffRecord::getInstance() const
      99             : {
     100           0 :     return (getU16(0x0) & 0xfff0) >> 4;
     101             : }
     102             : 
     103           0 : sal_uInt32 DffRecord::getRecordType() const
     104             : {
     105           0 :     return getU16(0x2);
     106             : }
     107             : 
     108           0 : void DffRecord::initChildren()
     109             : {
     110           0 :     if (isContainer())
     111             :     {
     112           0 :         sal_uInt32 nOffset = 8;
     113           0 :         sal_uInt32 nCount = calcSize();
     114             : 
     115           0 :         while (nCount - nOffset >= 8)
     116             :         {
     117           0 :             sal_uInt32 nSize = 0;
     118             :             boost::shared_ptr<DffRecord> pRec
     119           0 :                 (createDffRecord(this, nOffset, &nSize));
     120             : 
     121           0 :             if (nSize == 0)
     122             :                 break;
     123             : 
     124           0 :             mRecords.push_back(pRec);
     125             : 
     126           0 :             nOffset += nSize;
     127           0 :         }
     128             :     }
     129             : 
     130           0 :     bInitialized = true;
     131           0 : }
     132             : 
     133           0 : Records_t DffRecord::findRecords(sal_uInt32 nType, bool bRecursive, bool bAny)
     134             : {
     135           0 :     Records_t aResult;
     136             : 
     137           0 :     findRecords(nType, aResult, bRecursive, bAny);
     138             : 
     139           0 :     return aResult;
     140             : }
     141             : 
     142           0 : void DffRecord::findRecords
     143             : (sal_uInt32 nType, Records_t & rRecords, bool bRecursive, bool bAny)
     144             : {
     145           0 :     Records_t::iterator aIt = begin();
     146             : 
     147           0 :     while (aIt != end())
     148             :     {
     149           0 :         Pointer_t pPointer = *aIt;
     150           0 :         if (bAny || pPointer->getRecordType() == nType)
     151           0 :             rRecords.push_back(pPointer);
     152             : 
     153           0 :         if (bRecursive)
     154             :             pPointer->findRecords(nType, rRecords, bRecursive,
     155           0 :                                       bAny);
     156             : 
     157           0 :         ++aIt;
     158           0 :     }
     159           0 : }
     160             : 
     161           0 : void DffRecord::resolveChildren(Properties & rHandler)
     162             : {
     163           0 :     Records_t::iterator aIt;
     164           0 :     for (aIt = begin(); aIt != end(); ++aIt)
     165             :     {
     166           0 :         rHandler.sprm(**aIt);
     167             :     }
     168           0 : }
     169             : 
     170           0 : void DffRecord::resolveLocal(Properties &)
     171             : {
     172           0 : }
     173             : 
     174           0 : void DffRecord::resolve(Properties & rHandler)
     175             : {
     176           0 :     WW8Value::Pointer_t pVal = createValue(getRecordType());
     177           0 :     rHandler.attribute(NS_rtf::LN_dfftype, *pVal);
     178             : 
     179           0 :     pVal = createValue(getInstance());
     180           0 :     rHandler.attribute(NS_rtf::LN_dffinstance, *pVal);
     181             : 
     182           0 :     pVal = createValue(getVersion());
     183           0 :     rHandler.attribute(NS_rtf::LN_dffversion, *pVal);
     184             : 
     185           0 :     pVal = createValue(getU32(0x0));
     186           0 :     rHandler.attribute(NS_rtf::LN_dffheader, *pVal);
     187             : 
     188           0 :     if (isContainer())
     189             :     {
     190           0 :         resolveChildren(rHandler);
     191             :     }
     192             : 
     193           0 :     resolveLocal(rHandler);
     194             : 
     195             :     WW8BinaryObjReference::Pointer_t pBinObjRef
     196           0 :         (new WW8BinaryObjReference(this, 0, getCount()));
     197           0 :     WW8Sprm aSprm(pBinObjRef);
     198             : 
     199           0 :     rHandler.sprm(aSprm);
     200           0 : }
     201             : 
     202           0 : sal_uInt32 DffRecord::getShapeType()
     203             : {
     204           0 :     sal_uInt32 nResult = 0;
     205             : 
     206           0 :     Records_t aRecords = findRecords(0xf00a);
     207             : 
     208           0 :     if (!aRecords.empty())
     209             :     {
     210           0 :         DffFSP * pDffFSP = dynamic_cast<DffFSP*>((*aRecords.begin()).get());
     211           0 :         nResult = pDffFSP->get_shptype();
     212             :     }
     213             : 
     214           0 :     return nResult;
     215             : }
     216             : 
     217           0 : sal_uInt32 DffRecord::getShapeId()
     218             : {
     219           0 :     sal_uInt32 nResult = 0;
     220             : 
     221           0 :     Records_t aRecords = findRecords(0xf00a);
     222             : 
     223           0 :     if (!aRecords.empty())
     224             :     {
     225           0 :         DffFSP * pDffFSP = dynamic_cast<DffFSP*>((*aRecords.begin()).get());
     226           0 :         nResult = pDffFSP->get_shpid();
     227             :     }
     228             : 
     229           0 :     return nResult;
     230             : }
     231             : 
     232             : class DffOPTHandler : public Properties
     233             : {
     234             :     map<int, WW8ValueSharedPointer_t> mMap;
     235             :     int nId;
     236             : 
     237             : public:
     238           0 :     DffOPTHandler() : nId(0) {}
     239           0 :     virtual ~DffOPTHandler() {}
     240             : 
     241           0 :     virtual void attribute(Id name, Value & val)
     242             :     {
     243           0 :         switch (name)
     244             :         {
     245             :         case NS_rtf::LN_shppid:
     246           0 :             nId = val.getInt();
     247           0 :             break;
     248             :         case NS_rtf::LN_shpvalue:
     249             :             {
     250           0 :                 WW8Value & rTmpVal = dynamic_cast<WW8Value &>(val);
     251             :                 WW8ValueSharedPointer_t
     252           0 :                     pVal(dynamic_cast<WW8Value *>(rTmpVal.clone()));
     253           0 :                 mMap[nId] = pVal;
     254             :             }
     255             :         }
     256           0 :     }
     257             : 
     258           0 :     virtual void sprm(Sprm & /*sprm_*/)
     259             :     {
     260           0 :     }
     261             : 
     262           0 :     WW8ValueSharedPointer_t & getValue(int nId_)
     263             :     {
     264           0 :         return mMap[nId_];
     265             :     }
     266             : 
     267             : };
     268             : 
     269           0 : sal_uInt32 DffRecord::getShapeBid()
     270             : {
     271           0 :     sal_uInt32 nResult = 0;
     272             : 
     273           0 :     if (getShapeType() == 75)
     274             :     {
     275           0 :         Records_t aRecords = findRecords(0xf00b);
     276             : 
     277           0 :         if (!aRecords.empty())
     278             :         {
     279           0 :             DffOPTHandler aHandler;
     280           0 :             DffOPT * pOpts = dynamic_cast<DffOPT*>((*aRecords.begin()).get());
     281             : 
     282           0 :             sal_uInt32 nCount = pOpts->get_property_count();
     283             : 
     284           0 :             for (sal_uInt32 n = 0; n < nCount; ++n)
     285             :             {
     286           0 :                 pOpts->get_property(n)->resolve(aHandler);
     287             :             }
     288             : 
     289           0 :             WW8ValueSharedPointer_t pVal = aHandler.getValue(260);
     290             : 
     291           0 :             if (pVal.get() != NULL)
     292           0 :                 nResult = pVal->getInt();
     293           0 :         }
     294             :     }
     295             : 
     296           0 :     return nResult;
     297             : }
     298             : 
     299           0 : string DffRecord::getType() const
     300             : {
     301           0 :     return "DffRecord";
     302             : }
     303             : 
     304           0 : Value::Pointer_t DffRecord::getValue()
     305             : {
     306           0 :     return Value::Pointer_t();
     307             : }
     308             : 
     309           0 : writerfilter::Reference<BinaryObj>::Pointer_t DffRecord::getBinary()
     310             : {
     311           0 :     return writerfilter::Reference<BinaryObj>::Pointer_t();
     312             : }
     313             : 
     314           0 : writerfilter::Reference<Stream>::Pointer_t DffRecord::getStream()
     315             : {
     316           0 :     return writerfilter::Reference<Stream>::Pointer_t();
     317             : }
     318             : 
     319           0 : writerfilter::Reference<Properties>::Pointer_t DffRecord::getProps()
     320             : {
     321           0 :     return writerfilter::Reference<Properties>::Pointer_t(this->clone());
     322             : }
     323             : 
     324           0 : string DffRecord::toString() const
     325             : {
     326             :     char sBuffer[1024];
     327             : 
     328             :     snprintf(sBuffer, sizeof(sBuffer),
     329             :              "<dffrecord type=\"%" SAL_PRIuUINT32 "\" instance=\"%" SAL_PRIuUINT32 "\" version=\"%" SAL_PRIuUINT32 "\">\n",
     330           0 :              getRecordType(), getInstance(), getVersion());
     331           0 :     string aResult = sBuffer;
     332             : 
     333             : 
     334           0 :     if (!isContainer())
     335           0 :         aResult += mSequence.toString();
     336             :     else
     337             :     {
     338           0 :         WW8StructBase::Sequence aSeq(mSequence, 0, 8);
     339           0 :         aResult += aSeq.toString();
     340             :     }
     341             : 
     342           0 :     aResult += "</dffrecord>";
     343             : 
     344           0 :     return aResult;
     345             : }
     346             : 
     347           0 : string DffRecord::getName() const
     348             : {
     349           0 :     return "";
     350             : }
     351             : 
     352           0 : Sprm::Kind DffRecord::getKind()
     353             : {
     354           0 :     return Sprm::UNKNOWN;
     355             : }
     356             : 
     357           0 : DffBlock::DffBlock(WW8Stream & rStream, sal_uInt32 nOffset,
     358             :                    sal_uInt32 nCount, sal_uInt32 nPadding)
     359             : : WW8StructBase(rStream, nOffset, nCount), bInitialized(false),
     360           0 :   mnPadding(nPadding)
     361             : {
     362           0 : }
     363             : 
     364           0 : DffBlock::DffBlock(WW8StructBase * pParent, sal_uInt32 nOffset,
     365             :                    sal_uInt32 nCount, sal_uInt32 nPadding)
     366             : : WW8StructBase(pParent, nOffset, nCount), bInitialized(false),
     367           0 :   mnPadding(nPadding)
     368             : {
     369           0 : }
     370             : 
     371           0 : DffBlock::DffBlock(const DffBlock & rSrc)
     372             : : WW8StructBase(rSrc), writerfilter::Reference<Properties>(rSrc),
     373           0 :   bInitialized(false), mnPadding(rSrc.mnPadding)
     374             : {
     375           0 : }
     376             : 
     377           0 : void DffBlock::initChildren()
     378             : {
     379           0 :     sal_uInt32 nOffset = 0;
     380           0 :     sal_uInt32 nCount = getCount();
     381             : 
     382           0 :     while (nOffset < nCount)
     383             :     {
     384           0 :         sal_uInt32 nSize = 0;
     385             :         DffRecord::Pointer_t pDffRecord
     386           0 :             (createDffRecord(this, nOffset, &nSize));
     387             : 
     388           0 :         if (nSize == 0)
     389             :             break;
     390             : 
     391           0 :         mRecords.push_back(pDffRecord);
     392             : 
     393           0 :         nOffset +=  nSize + mnPadding;
     394           0 :     }
     395             : 
     396           0 :     bInitialized = true;
     397           0 : }
     398             : 
     399           0 : Records_t DffBlock::findRecords(sal_uInt32 nType, bool bRecursive, bool bAny)
     400             : {
     401           0 :     Records_t aResult;
     402             : 
     403           0 :     findRecords(nType, aResult, bRecursive, bAny);
     404             : 
     405           0 :     return aResult;
     406             : }
     407             : 
     408           0 : void DffBlock::findRecords
     409             : (sal_uInt32 nType, Records_t & rRecords, bool bRecursive, bool bAny)
     410             : {
     411           0 :     Records_t::iterator aIt = begin();
     412             : 
     413           0 :     while (aIt != end())
     414             :     {
     415           0 :         DffRecord::Pointer_t pPointer(*aIt);
     416             : 
     417           0 :         if (bAny || pPointer->getRecordType() == nType)
     418           0 :             rRecords.push_back(pPointer);
     419             : 
     420           0 :         if (bRecursive)
     421             :             pPointer->findRecords(nType, rRecords, bRecursive,
     422           0 :                                   bAny);
     423             : 
     424           0 :         ++aIt;
     425           0 :     }
     426           0 : }
     427             : 
     428           0 : void DffBlock::resolve(Properties & rHandler)
     429             : {
     430           0 :     Records_t::iterator aIt;
     431             : 
     432           0 :     for (aIt = begin(); aIt != end(); ++aIt)
     433             :     {
     434           0 :         DffRecord * pDff = aIt->get();
     435           0 :         rHandler.sprm(*pDff);
     436             :     }
     437           0 : }
     438             : 
     439           0 : DffRecord::Pointer_t DffBlock::getShape(sal_uInt32 nSpid)
     440             : {
     441           0 :     DffRecord::Pointer_t pResult;
     442             : 
     443           0 :     Records_t aRecords = findRecords(0xf004);
     444           0 :     Records_t::iterator aIt;
     445           0 :     for (aIt = aRecords.begin(); aIt != aRecords.end(); ++aIt)
     446             :     {
     447           0 :         DffRecord::Pointer_t pPointer = *aIt;
     448             : 
     449           0 :         Records_t aFSPs = pPointer->findRecords(0xf00a);
     450           0 :         Records_t::iterator aItFSP = aFSPs.begin();
     451             : 
     452           0 :         if (aItFSP != aFSPs.end())
     453             :         {
     454           0 :             DffFSP * pFSP = dynamic_cast<DffFSP *>((*aItFSP).get());
     455             : 
     456           0 :             if (pFSP->get_shpid() == nSpid)
     457             :             {
     458           0 :                 pResult = pPointer;
     459             : 
     460             :                 break;
     461             :             }
     462             :         }
     463           0 :     }
     464             : 
     465           0 :     return pResult;
     466             : }
     467             : 
     468           0 : DffRecord::Pointer_t DffBlock::getBlip(sal_uInt32 nBlip)
     469             : {
     470           0 :     DffRecord::Pointer_t pResult;
     471             : 
     472           0 :     if (nBlip > 0)
     473             :     {
     474           0 :         nBlip--;
     475             : 
     476           0 :         Records_t aRecords = findRecords(0xf007);
     477             : 
     478           0 :         if (nBlip < aRecords.size())
     479             :         {
     480           0 :             pResult = aRecords[nBlip];
     481           0 :         }
     482             :     }
     483             : 
     484           0 :     return pResult;
     485             : }
     486             : 
     487           0 : Records_t::iterator DffBlock::begin()
     488             : {
     489           0 :     if (! bInitialized)
     490           0 :         initChildren();
     491             : 
     492           0 :     return mRecords.begin();
     493             : }
     494             : 
     495           0 : Records_t::iterator DffBlock::end()
     496             : {
     497           0 :     if (! bInitialized)
     498           0 :         initChildren();
     499             : 
     500           0 :     return mRecords.end();
     501             : }
     502             : 
     503           0 : string DffBlock::getType() const
     504             : {
     505           0 :     return "DffBlock";
     506             : }
     507             : 
     508          15 : }}
     509             : 
     510             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10