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

Generated by: LCOV version 1.10