LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - ww8glsy.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 125 0.8 %
Date: 2014-11-03 Functions: 2 7 28.6 %
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 <tools/urlobj.hxx>
      21             : #include <svl/urihelper.hxx>
      22             : #include <rtl/tencinfo.h>
      23             : #include <swerror.h>
      24             : #include <ndtxt.hxx>
      25             : #include <pam.hxx>
      26             : #include <shellio.hxx>
      27             : #include <docsh.hxx>
      28             : #include <fmtanchr.hxx>
      29             : #include <frmfmt.hxx>
      30             : #include <doc.hxx>
      31             : #include <IDocumentStylePoolAccess.hxx>
      32             : #include <docary.hxx>
      33             : #include "ww8glsy.hxx"
      34             : #include "ww8par.hxx"
      35             : 
      36           0 : WW8Glossary::WW8Glossary(SvStorageStreamRef &refStrm, sal_uInt8 nVersion,
      37             :     SvStorage *pStg)
      38           0 :     : pGlossary(0), rStrm(refStrm), xStg(pStg), nStrings(0)
      39             : {
      40           0 :     refStrm->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
      41           0 :     WW8Fib aWwFib(*refStrm, nVersion);
      42             : 
      43           0 :     if (aWwFib.nFibBack >= 0x6A)   //Word97
      44             :     {
      45           0 :         xTableStream = pStg->OpenSotStream(OUString::createFromAscii(
      46           0 :             aWwFib.fWhichTblStm ? SL::a1Table : SL::a0Table), STREAM_STD_READ);
      47             : 
      48           0 :         if (xTableStream.Is() && SVSTREAM_OK == xTableStream->GetError())
      49             :         {
      50           0 :             xTableStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
      51             :             pGlossary =
      52           0 :                 new WW8GlossaryFib(*refStrm, nVersion, *xTableStream, aWwFib);
      53             :         }
      54             :     }
      55           0 : }
      56             : 
      57           0 : bool WW8Glossary::HasBareGraphicEnd(SwDoc *pDoc,SwNodeIndex &rIdx)
      58             : {
      59           0 :     bool bRet=false;
      60           0 :     for( sal_uInt16 nCnt = pDoc->GetSpzFrmFmts()->size(); nCnt; )
      61             :     {
      62           0 :         SwFrmFmt* pFrmFmt = (*pDoc->GetSpzFrmFmts())[ --nCnt ];
      63           0 :         if ( RES_FLYFRMFMT != pFrmFmt->Which() &&
      64           0 :             RES_DRAWFRMFMT != pFrmFmt->Which() )
      65           0 :                 continue;
      66           0 :         const SwFmtAnchor& rAnchor = pFrmFmt->GetAnchor();
      67           0 :         SwPosition const*const pAPos = rAnchor.GetCntntAnchor();
      68           0 :         if (pAPos &&
      69           0 :             ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
      70           0 :              (FLY_AT_CHAR == rAnchor.GetAnchorId())) &&
      71           0 :             rIdx == pAPos->nNode.GetIndex() )
      72             :             {
      73           0 :                 bRet=true;
      74           0 :                 break;
      75             :             }
      76             :     }
      77           0 :     return bRet;
      78             : }
      79             : 
      80           0 : bool WW8Glossary::MakeEntries(SwDoc *pD, SwTextBlocks &rBlocks,
      81             :     bool bSaveRelFile, const std::vector<OUString>& rStrings,
      82             :     const std::vector<ww::bytes>& rExtra)
      83             : {
      84             :     // this code will be called after reading all text into the
      85             :     // empty sections
      86           0 :     const OUString aOldURL( rBlocks.GetBaseURL() );
      87           0 :     bool bRet=false;
      88           0 :     if( bSaveRelFile )
      89             :     {
      90             :         rBlocks.SetBaseURL(
      91             :             URIHelper::SmartRel2Abs(
      92             :                 INetURLObject(), rBlocks.GetFileName(),
      93           0 :                 URIHelper::GetMaybeFileHdl()));
      94             :     }
      95             :     else
      96           0 :         rBlocks.SetBaseURL( OUString() );
      97             : 
      98           0 :     SwNodeIndex aDocEnd( pD->GetNodes().GetEndOfContent() );
      99           0 :     SwNodeIndex aStart( *aDocEnd.GetNode().StartOfSectionNode(), 1 );
     100             : 
     101             :     // search the first NormalStartNode
     102           0 :     while( !( aStart.GetNode().IsStartNode() && SwNormalStartNode ==
     103           0 :            aStart.GetNode().GetStartNode()->GetStartNodeType()) &&
     104           0 :             aStart < aDocEnd )
     105           0 :         ++aStart;
     106             : 
     107           0 :     if( aStart < aDocEnd )
     108             :     {
     109           0 :         SwTxtFmtColl* pColl = pD->getIDocumentStylePoolAccess().GetTxtCollFromPool
     110           0 :             (RES_POOLCOLL_STANDARD, false);
     111           0 :         sal_uInt16 nGlosEntry = 0;
     112           0 :         SwCntntNode* pCNd = 0;
     113           0 :         do {
     114           0 :             SwPaM aPam( aStart );
     115             :             {
     116           0 :                 SwNodeIndex& rIdx = aPam.GetPoint()->nNode;
     117           0 :                 ++rIdx;
     118           0 :                 if( 0 == ( pCNd = rIdx.GetNode().GetTxtNode() ) )
     119             :                 {
     120           0 :                     pCNd = pD->GetNodes().MakeTxtNode( rIdx, pColl );
     121           0 :                     rIdx = *pCNd;
     122             :                 }
     123             :             }
     124           0 :             aPam.GetPoint()->nContent.Assign( pCNd, 0 );
     125           0 :             aPam.SetMark();
     126             :             {
     127           0 :                 SwNodeIndex& rIdx = aPam.GetPoint()->nNode;
     128           0 :                 rIdx = aStart.GetNode().EndOfSectionIndex() - 1;
     129           0 :                 if(( 0 == ( pCNd = rIdx.GetNode().GetCntntNode() ) )
     130           0 :                         || HasBareGraphicEnd(pD,rIdx))
     131             :                 {
     132           0 :                     ++rIdx;
     133           0 :                     pCNd = pD->GetNodes().MakeTxtNode( rIdx, pColl );
     134           0 :                     rIdx = *pCNd;
     135             :                 }
     136             :             }
     137           0 :             aPam.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
     138             : 
     139             :             // now we have the right selection for one entry.  Copy this to
     140             :             // the definied TextBlock, but only if it is not an autocorrection
     141             :             // entry (== -1) otherwise the group indicates the group in the
     142             :             // sttbfglsystyle list that this entry belongs to. Unused at the
     143             :             // moment
     144           0 :             const ww::bytes &rData = rExtra[nGlosEntry];
     145           0 :             sal_uInt16 n = SVBT16ToShort( &(rData[2]) );
     146           0 :             if(n != 0xFFFF)
     147             :             {
     148           0 :                 rBlocks.ClearDoc();
     149           0 :                 const OUString &rLNm = rStrings[nGlosEntry];
     150             : 
     151           0 :                 OUString sShortcut = rLNm;
     152             : 
     153             :                 // Need to check make sure the shortcut is not already being used
     154           0 :                 sal_Int32 nStart = 0;
     155           0 :                 sal_uInt16 nCurPos = rBlocks.GetIndex( sShortcut );
     156           0 :                 sal_Int32 nLen = sShortcut.getLength();
     157           0 :                 while( (sal_uInt16)-1 != nCurPos )
     158             :                 {
     159           0 :                     sShortcut = sShortcut.copy( 0, nLen );
     160           0 :                     sShortcut += OUString::number(++nStart);    // add an Number to it
     161           0 :                     nCurPos = rBlocks.GetIndex( sShortcut );
     162             :                 }
     163             : 
     164           0 :                 if( rBlocks.BeginPutDoc( sShortcut, sShortcut ))    // Make the shortcut and the name the same
     165             : 
     166             :                 {
     167           0 :                     SwDoc* pGlDoc = rBlocks.GetDoc();
     168           0 :                     SwNodeIndex aIdx( pGlDoc->GetNodes().GetEndOfContent(),
     169           0 :                         -1 );
     170           0 :                     pCNd = aIdx.GetNode().GetCntntNode();
     171           0 :                     SwPosition aPos(aIdx, SwIndex(pCNd, (pCNd) ? pCNd->Len() : 0));
     172           0 :                     pD->getIDocumentContentOperations().CopyRange( aPam, aPos, false );
     173           0 :                     rBlocks.PutDoc();
     174           0 :                 }
     175             :             }
     176           0 :             aStart = aStart.GetNode().EndOfSectionIndex() + 1;
     177           0 :             ++nGlosEntry;
     178           0 :         } while( aStart.GetNode().IsStartNode() &&
     179           0 :                 SwNormalStartNode == aStart.GetNode().
     180           0 :                     GetStartNode()->GetStartNodeType());
     181           0 :         bRet=true;
     182             :     }
     183             : 
     184             : // this code will be called after reading all text into the empty sections
     185             : 
     186           0 :     rBlocks.SetBaseURL( aOldURL );
     187           0 :     return bRet;
     188             : }
     189             : 
     190           0 : bool WW8Glossary::Load( SwTextBlocks &rBlocks, bool bSaveRelFile )
     191             : {
     192           0 :     bool bRet=false;
     193           0 :     if (pGlossary && pGlossary->IsGlossaryFib() && rBlocks.StartPutMuchBlockEntries())
     194             :     {
     195             :         //read the names of the autotext entries
     196           0 :         std::vector<OUString> aStrings;
     197           0 :         std::vector<ww::bytes> aData;
     198             : 
     199             :         rtl_TextEncoding eStructCharSet =
     200           0 :             WW8Fib::GetFIBCharset(pGlossary->chseTables);
     201             : 
     202           0 :         WW8ReadSTTBF(true, *xTableStream, pGlossary->fcSttbfglsy,
     203           0 :             pGlossary->lcbSttbfglsy, 0, eStructCharSet, aStrings, &aData );
     204             : 
     205           0 :         rStrm->Seek(0);
     206             : 
     207           0 :         if ( 0 != (nStrings = static_cast< sal_uInt16 >(aStrings.size())))
     208             :         {
     209           0 :             SfxObjectShellLock xDocSh(new SwDocShell(SFX_CREATE_MODE_INTERNAL));
     210           0 :             if (xDocSh->DoInitNew(0))
     211             :             {
     212           0 :                 SwDoc *pD =  ((SwDocShell*)(&xDocSh))->GetDoc();
     213             :                 SwWW8ImplReader* pRdr = new SwWW8ImplReader(pGlossary->nVersion,
     214           0 :                     xStg, &rStrm, *pD, rBlocks.GetBaseURL(), true);
     215             : 
     216             :                 SwNodeIndex aIdx(
     217           0 :                     *pD->GetNodes().GetEndOfContent().StartOfSectionNode(), 1);
     218           0 :                 if( !aIdx.GetNode().IsTxtNode() )
     219             :                 {
     220             :                     OSL_ENSURE( false, "wo ist der TextNode?" );
     221           0 :                     pD->GetNodes().GoNext( &aIdx );
     222             :                 }
     223           0 :                 SwPaM aPamo( aIdx );
     224           0 :                 aPamo.GetPoint()->nContent.Assign(aIdx.GetNode().GetCntntNode(),
     225           0 :                     0);
     226           0 :                 pRdr->LoadDoc(aPamo,this);
     227             : 
     228           0 :                 bRet = MakeEntries(pD, rBlocks, bSaveRelFile, aStrings, aData);
     229             : 
     230           0 :                 delete pRdr;
     231             :             }
     232           0 :             xDocSh->DoClose();
     233           0 :             rBlocks.EndPutMuchBlockEntries();
     234           0 :         }
     235             :     }
     236           0 :     return bRet;
     237             : }
     238             : 
     239           0 : sal_uInt32 WW8GlossaryFib::FindGlossaryFibOffset(SvStream & /* rTableStrm */,
     240             :                                              SvStream & /* rStrm */,
     241             :                                              const WW8Fib &rFib)
     242             : {
     243           0 :     sal_uInt32 nGlossaryFibOffset = 0;
     244           0 :     if ( rFib.fDot ) // it's a template
     245             :     {
     246           0 :         if ( rFib.pnNext  )
     247           0 :             nGlossaryFibOffset = ( rFib.pnNext * 512 );
     248             :     }
     249           0 :     return nGlossaryFibOffset;
     250         102 : }
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10