LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpstory.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 131 217 60.4 %
Date: 2014-04-11 Functions: 16 22 72.7 %
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             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      12             :  *  GNU Lesser General Public License Version 2.1
      13             :  *  =============================================
      14             :  *  Copyright 2000 by Sun Microsystems, Inc.
      15             :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16             :  *
      17             :  *  This library is free software; you can redistribute it and/or
      18             :  *  modify it under the terms of the GNU Lesser General Public
      19             :  *  License version 2.1, as published by the Free Software Foundation.
      20             :  *
      21             :  *  This library is distributed in the hope that it will be useful,
      22             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  *  Lesser General Public License for more details.
      25             :  *
      26             :  *  You should have received a copy of the GNU Lesser General Public
      27             :  *  License along with this library; if not, write to the Free Software
      28             :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29             :  *  MA  02111-1307  USA
      30             :  *
      31             :  *
      32             :  *  Sun Industry Standards Source License Version 1.1
      33             :  *  =================================================
      34             :  *  The contents of this file are subject to the Sun Industry Standards
      35             :  *  Source License Version 1.1 (the "License"); You may not use this file
      36             :  *  except in compliance with the License. You may obtain a copy of the
      37             :  *  License at http://www.openoffice.org/license.html.
      38             :  *
      39             :  *  Software provided under this License is provided on an "AS IS" basis,
      40             :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41             :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42             :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43             :  *  See the License for the specific provisions governing your rights and
      44             :  *  obligations concerning the Software.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : /*************************************************************************
      57             :  * @file
      58             :  *  LwpStory:
      59             :         1. Word Pro object for paragraph list;
      60             :         2. the content of layout object
      61             :  ************************************************************************/
      62             : /*************************************************************************
      63             :  * Change History
      64             :  Jan 2005           Created
      65             :  ************************************************************************/
      66             : #include "lwpglobalmgr.hxx"
      67             : #include "lwpstory.hxx"
      68             : #include "xfilter/xfstylemanager.hxx"
      69             : 
      70          51 : LwpStory::LwpStory(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      71             :     : LwpContent(objHdr, pStrm)
      72             :     , m_bPMModified(sal_False)
      73             :     , m_pCurrentLayout(NULL)
      74             :     , m_pTabLayout(NULL)
      75             :     , m_bDropcap(sal_False)
      76          51 :     , m_pHyperlinkMgr(new LwpHyperlinkMgr)
      77         102 :     , m_pXFContainer(NULL)
      78             : {
      79          51 : }
      80             : 
      81         153 : LwpStory::~LwpStory()
      82             : {
      83          51 :     delete m_pHyperlinkMgr;
      84         102 : }
      85             : 
      86          51 : void LwpStory::Read()
      87             : {
      88          51 :     LwpContent::Read();
      89          51 :     m_ParaList.Read(m_pObjStrm);
      90          51 :     m_FirstParaStyle.ReadIndexed(m_pObjStrm);
      91          51 :     m_pObjStrm->SkipExtra();
      92          51 : }
      93             : 
      94             : #include "lwppara.hxx"
      95             : #include "lwpobjfactory.hxx"
      96             : /**************************************************************************
      97             :  * @descr:   Convert all the contents in current story
      98             :  * @param:
      99             :  * @param:
     100             :  * @return:
     101             : **************************************************************************/
     102          23 : void LwpStory::XFConvert(XFContentContainer* pCont)
     103             : {
     104             :     //process frame which anchor frame
     105          23 :     XFConvertFrameInFrame(pCont);
     106             :     //process para list
     107          23 :     XFContentContainer* pParaCont = pCont;
     108          23 :     LwpPara* pPara = dynamic_cast<LwpPara*> ( GetFirstPara()->obj() );
     109         195 :     while(pPara)
     110             :     {
     111         149 :         pPara->SetFoundry(m_pFoundry);
     112         149 :         pPara->XFConvert(pParaCont);
     113             : 
     114             :         //Get the xfcontainer for the next para
     115         149 :         pParaCont = pPara->GetXFContainer();
     116         149 :         pPara = dynamic_cast<LwpPara*> ( pPara->GetNext()->obj() );
     117             :     }
     118             : 
     119             :     //process frame which anchor is to cell after converter all the para
     120          23 :     XFConvertFrameInCell(pCont);
     121          23 :     XFConvertFrameInHeaderFooter(pCont);
     122             : 
     123             :     //Release Lwp Objects
     124          23 :     LwpPara* pCur = dynamic_cast<LwpPara*> (GetFirstPara()->obj());
     125             :     LwpPara* pNext;
     126         195 :     while(pCur)
     127             :     {
     128         149 :         pCur->Release();
     129         149 :         pNext = dynamic_cast<LwpPara*> ( pCur->GetNext()->obj() );
     130         149 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     131         149 :         LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
     132         149 :         pObjMgr->ReleaseObject(*pCur->GetObjectID());
     133         149 :         pCur = pNext;
     134             :     }
     135          23 : }
     136             : 
     137          60 : void LwpStory::RegisterStyle()
     138             : {
     139          60 :     LwpPara* pPara = dynamic_cast<LwpPara*>( GetFirstPara()->obj() );
     140         381 :     while(pPara)
     141             :     {
     142         262 :         pPara->SetFoundry(m_pFoundry);
     143         262 :         pPara->RegisterStyle();
     144         261 :         pPara = dynamic_cast<LwpPara*>(pPara->GetNext()->obj());
     145             :     }
     146          59 : }
     147             : 
     148           3 : void LwpStory::Parse(IXFStream* pOutputStream)
     149             : {
     150           3 :     m_pXFContainer = new XFContentContainer;
     151           3 :     XFConvert(m_pXFContainer);
     152           3 :     m_pXFContainer->ToXml(pOutputStream);
     153           3 :     delete m_pXFContainer;
     154           3 :     m_pXFContainer = NULL;
     155             : 
     156             :     //It seems that, currently, we do not need to process the child story
     157             :     /*LwpObject* pChildStory = GetFirstStory()->obj();
     158             :     if(pChildStory)
     159             :     {
     160             :         pChildStory->SetFoundry(m_pFoundry);
     161             :         pChildStory->Parse(pOutputStream);
     162             :     }*/
     163             : 
     164             :     //Don't process the next story
     165             : /*  LwpObject* pNextStory = GetNextStory()->obj();
     166             :     if(pNextStory)
     167             :     {
     168             :         pNextStory->SetFoundry(m_pFoundry);
     169             :         pNextStory->Parse(pOutputStream);
     170             :     }*/
     171             : 
     172           3 : }
     173             : 
     174             : #include "lwppagelayout.hxx"
     175             : /**************************************************************************
     176             :  * @descr:   Set current page layout. If pPageLayout is a mirro page layout,
     177             :              use odd child page layout as current page layout.
     178             :  * @param:
     179             :  * @param:
     180             :  * @return:
     181             : **************************************************************************/
     182           4 : void LwpStory::SetCurrentLayout(LwpPageLayout *pPageLayout)
     183             : {
     184           4 :     LwpPageLayout* pLayout = pPageLayout->GetOddChildLayout();
     185           4 :     if(pLayout)
     186             :     {
     187           0 :         m_pCurrentLayout = pLayout;
     188           0 :         m_pTabLayout = pLayout;
     189             :     }
     190             :     else
     191             :     {
     192           4 :         m_pCurrentLayout = pPageLayout;
     193           4 :         m_pTabLayout = pPageLayout;
     194             :     }
     195           4 :     m_bPMModified = sal_True;
     196           4 : }
     197             : 
     198           0 : void LwpStory::AddPageLayout(LwpPageLayout * pObject)
     199             : {
     200           0 :     m_LayoutList.push_back(pObject);
     201           0 : }
     202             : /**************************************************************************
     203             :  * @descr:   Get the next page layout relative to m_pCurrentLayout
     204             :  * @param:
     205             :  * @param:
     206             :  * @return:
     207             : **************************************************************************/
     208           0 : LwpPageLayout* LwpStory::GetNextPageLayout()
     209             : {
     210           0 :     std::vector<LwpPageLayout*>::iterator it;
     211           0 :     for( it = m_LayoutList.begin(); it != m_LayoutList.end(); ++it )
     212             :     {
     213           0 :         if(m_pCurrentLayout == *it)
     214             :         {
     215           0 :             if((it+1) !=m_LayoutList.end())
     216             :             {
     217           0 :                 return *(it+1);
     218             :             }
     219             :         }
     220             :     }
     221           0 :     return NULL;
     222             : }
     223             : /**************************************************************************
     224             :  * @descr:   Sort the pagelayout according to their position
     225             :  * @param:
     226             :  * @param:
     227             :  * @return:
     228             : **************************************************************************/
     229           4 : void LwpStory::SortPageLayout()
     230             : {
     231             :     //Get all the pagelayout and store in list
     232           4 :     std::vector<LwpPageLayout*>  aLayoutList;
     233           4 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     234          12 :     while(pLayout)
     235             :     {
     236           4 :         if(pLayout->IsPage())
     237             :         {
     238           4 :             LwpLayout::UseWhenType eSectionType = static_cast<LwpPageLayout*>(pLayout)->GetUseWhenType();
     239             :             //for mirror page, the child  is pagelayout
     240           4 :             LwpVirtualLayout* pParent = pLayout->GetParentLayout();
     241           4 :             if(eSectionType != LwpLayout::StartWithinColume && pParent && !pParent->IsPage())
     242             :             {
     243           4 :                 aLayoutList.push_back(static_cast<LwpPageLayout*>(pLayout));
     244             :             }
     245             :         }
     246           4 :         pLayout = GetLayout(pLayout);
     247             :     }
     248             :     // sort the pagelayout according to their position
     249           4 :     std::vector<LwpPageLayout*>::iterator aIt;
     250           4 :     if (!aLayoutList.empty())
     251             :     {
     252           4 :         for( aIt = aLayoutList.begin(); aIt != aLayoutList.end() -1; ++aIt)
     253             :         {
     254           0 :             for( std::vector<LwpPageLayout*>::iterator bIt = aIt +1; bIt != aLayoutList.end(); ++bIt )
     255             :             {
     256           0 :                 if(**aIt < **bIt)
     257             :                 {
     258           0 :                     continue;
     259             :                 }
     260             :                 else
     261             :                 {
     262           0 :                     LwpPageLayout* pTemp = *aIt;
     263           0 :                     *aIt = *bIt;
     264           0 :                     *bIt = pTemp;
     265             :                 }
     266             :             }
     267             :         }
     268             :     }
     269             : 
     270             :     //put all the sorted  layouts into list
     271           4 :     m_LayoutList.clear();
     272             : 
     273           8 :     for( aIt = aLayoutList.begin(); aIt != aLayoutList.end(); ++aIt)
     274             :     {
     275           4 :         m_LayoutList.push_back(*aIt);
     276           4 :     }
     277           4 : }
     278             : 
     279             : /**************************************************************************
     280             :  * @descr:  whether need create a new section and reset column in current page layout
     281             :  * @param:
     282             :  * @param:
     283             :  * @return:  sal_True if need create a new section
     284             : **************************************************************************/
     285           4 : sal_Bool LwpStory::IsNeedSection()
     286             : {
     287           4 :     sal_Bool bColumns = sal_False;
     288           4 :     sal_Bool bNewSection = sal_False;
     289           4 :     if(m_pCurrentLayout)
     290             :     {
     291           4 :         if(m_pCurrentLayout->HasColumns())
     292             :         {
     293             :             //get the following pagelayout and its type
     294           0 :             bColumns = sal_True;
     295           0 :             LwpPageLayout* pNextLayout = GetNextPageLayout();
     296           0 :             if(pNextLayout)
     297             :             {
     298             :                 //get layout type
     299           0 :                 LwpLayout::UseWhenType eWhenType = pNextLayout->GetUseWhenType();
     300           0 :                 switch(eWhenType)
     301             :                 {
     302             :                 case LwpLayout::StartWithinColume://not support now
     303             :                 case LwpLayout::StartWithinPage:
     304             :                 {
     305           0 :                     bColumns =sal_False;
     306           0 :                     bNewSection = sal_True;
     307           0 :                     break;
     308             :                 }
     309             :                 case LwpLayout::StartOnNextPage:
     310             :                 case LwpLayout::StartOnOddPage://not support now
     311             :                 case LwpLayout::StartOnEvenPage://not support now
     312             :                 {
     313           0 :                     bColumns =sal_True;
     314           0 :                     bNewSection = sal_False;
     315           0 :                     break;
     316             :                 }
     317             :                 default:
     318           0 :                     break;
     319             :                 }
     320             :             }
     321             : 
     322             :             //if bColumns is ture, the page layout doesn't need columns, set the xfcolumns to NULL in page master
     323           0 :             if(!bColumns)
     324             :             {
     325           0 :                 m_pCurrentLayout->ResetXFColumns();
     326             :             }
     327             :         }
     328           4 :         SetPMModified(sal_False);
     329             :     }
     330           4 :     return bNewSection;
     331             : }
     332             : /**************************************************************************
     333             :  * @descr:  process frame which anchor type is to cell
     334             :  * @param:
     335             :  * @param:
     336             :  * @return:
     337             : **************************************************************************/
     338          23 : void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
     339             : {
     340          23 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     341          69 :     while(pLayout)
     342             :     {
     343          23 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     344          52 :         while(pFrameLayout)
     345             :         {
     346             : 
     347             :             //if(pFrameLayout->IsAnchorCell())
     348           6 :             if(pFrameLayout->IsAnchorCell() && pFrameLayout->HasContent())
     349             :             {
     350             :                 //get the first xfpara
     351           0 :                 XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(pCont->FindFirstContent(enumXFContentPara));
     352           0 :                 if(pXFFirtPara)
     353           0 :                     pFrameLayout->XFConvert(pXFFirtPara);
     354             :             }
     355           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     356             :         }
     357          23 :         pLayout = GetLayout(pLayout);
     358             :     }
     359          23 : }
     360             : 
     361             : /**************************************************************************
     362             :  * @descr:  process frame which anchor type is to page
     363             :  * @param:
     364             :  * @param:
     365             :  * @return:
     366             : **************************************************************************/
     367           3 : void LwpStory::XFConvertFrameInPage(XFContentContainer* pCont)
     368             : {
     369           3 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     370           9 :     while(pLayout)
     371             :     {
     372           3 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     373          12 :         while(pFrameLayout)
     374             :         {
     375          12 :             if((pFrameLayout->IsAnchorPage()
     376           6 :                 &&(pFrameLayout->IsFrame()
     377           6 :                       ||pFrameLayout->IsSuperTable()
     378           6 :                       ||pFrameLayout->IsGroupHead())))
     379             :             {
     380           0 :                 pFrameLayout->XFConvert(pCont);
     381             :             }
     382           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     383             :         }
     384           3 :         pLayout = GetLayout(pLayout);
     385             :     }
     386           3 : }
     387             : /**************************************************************************
     388             :  * @descr:  process frame which anchor type is to frame
     389             :  * @param:
     390             :  * @param:
     391             :  * @return:
     392             : **************************************************************************/
     393          23 : void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
     394             : {
     395          23 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     396          69 :     while(pLayout)
     397             :     {
     398          23 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     399          52 :         while(pFrameLayout)
     400             :         {
     401           6 :             if(pFrameLayout->IsAnchorFrame())
     402             :             {
     403           0 :                 pFrameLayout->XFConvert(pCont);
     404             :             }
     405           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     406             :         }
     407          23 :         pLayout = GetLayout(pLayout);
     408             :     }
     409          23 : }
     410             : /**************************************************************************
     411             :  * @descr:  process frame which anchor type is to page and the frame is contained by header or footer
     412             :  * @param:
     413             :  * @param:
     414             :  * @return:
     415             : **************************************************************************/
     416          23 : void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont)
     417             : {
     418          23 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     419          69 :     while(pLayout)
     420             :     {
     421          23 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     422          52 :         while(pFrameLayout)
     423             :         {
     424           6 :             if(pFrameLayout->IsAnchorPage() && (pLayout->IsHeader() || pLayout->IsFooter()))
     425             :             {
     426             :                 //The frame must be included by <text:p>
     427           0 :                 XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(pCont->FindFirstContent(enumXFContentPara));
     428           0 :                 if(pXFFirtPara)
     429           0 :                     pFrameLayout->XFConvert(pXFFirtPara);
     430             :             }
     431           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     432             :         }
     433          23 :         pLayout = GetLayout(pLayout);
     434             :     }
     435          23 : }
     436             : 
     437           0 : void LwpStory::AddXFContent(XFContent* pContent)
     438             : {
     439           0 :     if(m_pXFContainer)
     440           0 :         m_pXFContainer->Add(pContent);
     441           0 : }
     442             : 
     443           0 : XFContentContainer* LwpStory::GetXFContent()
     444             : {
     445           0 :     if(m_pXFContainer)
     446           0 :         return m_pXFContainer;
     447             :     else
     448           0 :         return NULL;
     449             : }
     450             : 
     451           2 : LwpPara* LwpStory::GetLastParaOfPreviousStory()
     452             : {
     453           2 :     LwpVirtualLayout* pVLayout = this->GetLayout(NULL);
     454           2 :     if (pVLayout)
     455             :     {
     456           1 :         return pVLayout->GetLastParaOfPreviousStory();
     457             :     }
     458             : 
     459           1 :     return NULL;
     460             : }
     461             : /**************************************************************************
     462             :  * @descr:  get text from story
     463             :  * @param:
     464             :  * @param:
     465             :  * @return:
     466             : **************************************************************************/
     467           0 : OUString LwpStory::GetContentText(sal_Bool bAllText)
     468             : {
     469           0 :     if (bAllText)//convert all text fribs
     470             :     {
     471           0 :         OUString sText("");
     472             :         //process para list
     473           0 :         LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara()->obj());
     474           0 :         while (pPara)
     475             :         {
     476           0 :             pPara->SetFoundry(m_pFoundry);
     477           0 :             sText += pPara->GetContentText(sal_True);
     478           0 :             pPara = dynamic_cast<LwpPara*>(pPara->GetNext()->obj());
     479             :         }
     480           0 :         return sText;
     481             :     }
     482             :     else //only the first text frib
     483             :     {
     484           0 :         LwpObject* pObj = GetFirstPara()->obj();
     485           0 :         if(pObj)
     486             :         {
     487           0 :             LwpPara* pPara = dynamic_cast<LwpPara*>(pObj);
     488           0 :             if (!pPara || pPara->GetNext()->obj() != NULL)
     489           0 :                 return OUString("");
     490           0 :             pPara->SetFoundry(m_pFoundry);
     491           0 :             return pPara->GetContentText();
     492             :         }
     493           0 :         return  OUString("");
     494             :     }
     495             : 
     496             : }
     497           0 : OUString LwpStory::RegisterFirstFribStyle()
     498             : {
     499           0 :     LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara()->obj());
     500           0 :     if (!pPara)
     501           0 :         return OUString("");
     502           0 :     pPara->SetFoundry(m_pFoundry);
     503           0 :     LwpFribPtr* pFribs = pPara->GetFribs();
     504           0 :     if (pFribs)
     505             :     {
     506           0 :         LwpFrib* pFirstFrib = pFribs->GetFribs();
     507           0 :         pFirstFrib->RegisterStyle(m_pFoundry);
     508           0 :         XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     509           0 :         XFTextStyle* pBaseStyle = pXFStyleManager->FindTextStyle(pFirstFrib->GetStyleName());
     510           0 :         if (pBaseStyle == NULL)
     511           0 :             return OUString("");
     512           0 :         XFTextStyle* pStyle = new XFTextStyle;
     513           0 :         *pStyle = *pBaseStyle;
     514           0 :         OUString sName = "Ruby" + pFirstFrib->GetStyleName();
     515           0 :         pStyle->SetStyleName(sName);
     516           0 :         pXFStyleManager->AddStyle(pStyle);
     517           0 :         return sName;
     518             :     }
     519           0 :     return OUString("");
     520             : }
     521             : 
     522           6 : sal_Bool LwpStory::IsBullStyleUsedBefore(const OUString& rStyleName, const sal_uInt8& nPos)
     523             : {
     524           6 :     std::vector <NamePosPair>::reverse_iterator rIter;
     525           6 :     for (rIter = m_vBulletStyleNameList.rbegin(); rIter != m_vBulletStyleNameList.rend(); ++rIter)
     526             :     {
     527           3 :         OUString aName = (*rIter).first;
     528           3 :         sal_uInt8 nPosition = (*rIter).second;
     529           3 :         if (aName == rStyleName && nPosition == nPos)
     530             :         {
     531           3 :             return sal_True;
     532             :         }
     533           0 :     }
     534           3 :     return sal_False;
     535             : }
     536             : 
     537             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10