LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpstory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 129 215 60.0 %
Date: 2015-06-13 12:38:46 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          48 : LwpStory::LwpStory(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      71             :     : LwpContent(objHdr, pStrm)
      72             :     , m_bPMModified(false)
      73             :     , m_pCurrentLayout(NULL)
      74             :     , m_pTabLayout(NULL)
      75             :     , m_bDropcap(false)
      76          48 :     , m_pHyperlinkMgr(new LwpHyperlinkMgr)
      77          96 :     , m_pXFContainer(NULL)
      78             : {
      79          48 : }
      80             : 
      81         144 : LwpStory::~LwpStory()
      82             : {
      83          48 :     delete m_pHyperlinkMgr;
      84          96 : }
      85             : 
      86          48 : void LwpStory::Read()
      87             : {
      88          48 :     LwpContent::Read();
      89          48 :     m_ParaList.Read(m_pObjStrm);
      90          48 :     m_FirstParaStyle.ReadIndexed(m_pObjStrm);
      91          48 :     m_pObjStrm->SkipExtra();
      92          48 : }
      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          20 : void LwpStory::XFConvert(XFContentContainer* pCont)
     103             : {
     104             :     //process frame which anchor frame
     105          20 :     XFConvertFrameInFrame(pCont);
     106             :     //process para list
     107          20 :     XFContentContainer* pParaCont = pCont;
     108          20 :     LwpPara* pPara = dynamic_cast<LwpPara*> ( GetFirstPara().obj().get() );
     109         186 :     while(pPara)
     110             :     {
     111         146 :         pPara->SetFoundry(m_pFoundry);
     112         146 :         pPara->XFConvert(pParaCont);
     113             : 
     114             :         //Get the xfcontainer for the next para
     115         146 :         pParaCont = pPara->GetXFContainer();
     116         146 :         pPara = dynamic_cast<LwpPara*> ( pPara->GetNext().obj().get() );
     117             :     }
     118             : 
     119             :     //process frame which anchor is to cell after converter all the para
     120          20 :     XFConvertFrameInCell(pCont);
     121          20 :     XFConvertFrameInHeaderFooter(pCont);
     122             : 
     123             :     //Release Lwp Objects
     124          20 :     LwpPara* pCur = dynamic_cast<LwpPara*> (GetFirstPara().obj().get());
     125             :     LwpPara* pNext;
     126         186 :     while(pCur)
     127             :     {
     128         146 :         pNext = dynamic_cast<LwpPara*> ( pCur->GetNext().obj().get() );
     129         146 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     130         146 :         LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
     131         146 :         pObjMgr->ReleaseObject(pCur->GetObjectID());
     132         146 :         pCur = pNext;
     133             :     }
     134          20 : }
     135             : 
     136          57 : void LwpStory::RegisterStyle()
     137             : {
     138          57 :     LwpPara* pPara = dynamic_cast<LwpPara*>( GetFirstPara().obj().get() );
     139         372 :     while(pPara)
     140             :     {
     141         259 :         pPara->SetFoundry(m_pFoundry);
     142         259 :         pPara->RegisterStyle();
     143         258 :         pPara = dynamic_cast<LwpPara*>(pPara->GetNext().obj().get());
     144             :     }
     145          56 : }
     146             : 
     147           3 : void LwpStory::Parse(IXFStream* pOutputStream)
     148             : {
     149           3 :     m_pXFContainer = new XFContentContainer;
     150           3 :     XFConvert(m_pXFContainer);
     151           3 :     m_pXFContainer->ToXml(pOutputStream);
     152           3 :     delete m_pXFContainer;
     153           3 :     m_pXFContainer = NULL;
     154             : 
     155             :     //It seems that, currently, we do not need to process the child story
     156             :     /*LwpObject* pChildStory = GetFirstStory()->obj();
     157             :     if(pChildStory)
     158             :     {
     159             :         pChildStory->SetFoundry(m_pFoundry);
     160             :         pChildStory->Parse(pOutputStream);
     161             :     }*/
     162             : 
     163             :     //Don't process the next story
     164             : /*  LwpObject* pNextStory = GetNextStory()->obj();
     165             :     if(pNextStory)
     166             :     {
     167             :         pNextStory->SetFoundry(m_pFoundry);
     168             :         pNextStory->Parse(pOutputStream);
     169             :     }*/
     170             : 
     171           3 : }
     172             : 
     173             : #include "lwppagelayout.hxx"
     174             : /**************************************************************************
     175             :  * @descr:   Set current page layout. If pPageLayout is a mirro page layout,
     176             :              use odd child page layout as current page layout.
     177             :  * @param:
     178             :  * @param:
     179             :  * @return:
     180             : **************************************************************************/
     181           4 : void LwpStory::SetCurrentLayout(LwpPageLayout *pPageLayout)
     182             : {
     183           4 :     LwpPageLayout* pLayout = pPageLayout->GetOddChildLayout();
     184           4 :     if(pLayout)
     185             :     {
     186           0 :         m_pCurrentLayout = pLayout;
     187           0 :         m_pTabLayout = pLayout;
     188             :     }
     189             :     else
     190             :     {
     191           4 :         m_pCurrentLayout = pPageLayout;
     192           4 :         m_pTabLayout = pPageLayout;
     193             :     }
     194           4 :     m_bPMModified = true;
     195           4 : }
     196             : 
     197           0 : void LwpStory::AddPageLayout(LwpPageLayout * pObject)
     198             : {
     199           0 :     m_LayoutList.push_back(pObject);
     200           0 : }
     201             : /**************************************************************************
     202             :  * @descr:   Get the next page layout relative to m_pCurrentLayout
     203             :  * @param:
     204             :  * @param:
     205             :  * @return:
     206             : **************************************************************************/
     207           0 : LwpPageLayout* LwpStory::GetNextPageLayout()
     208             : {
     209           0 :     std::vector<LwpPageLayout*>::iterator it;
     210           0 :     for( it = m_LayoutList.begin(); it != m_LayoutList.end(); ++it )
     211             :     {
     212           0 :         if(m_pCurrentLayout == *it)
     213             :         {
     214           0 :             if((it+1) !=m_LayoutList.end())
     215             :             {
     216           0 :                 return *(it+1);
     217             :             }
     218             :         }
     219             :     }
     220           0 :     return NULL;
     221             : }
     222             : /**************************************************************************
     223             :  * @descr:   Sort the pagelayout according to their position
     224             :  * @param:
     225             :  * @param:
     226             :  * @return:
     227             : **************************************************************************/
     228           4 : void LwpStory::SortPageLayout()
     229             : {
     230             :     //Get all the pagelayout and store in list
     231           4 :     std::vector<LwpPageLayout*>  aLayoutList;
     232           4 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     233          12 :     while(pLayout)
     234             :     {
     235           4 :         if(pLayout->IsPage())
     236             :         {
     237           4 :             LwpLayout::UseWhenType eSectionType = static_cast<LwpPageLayout*>(pLayout)->GetUseWhenType();
     238             :             //for mirror page, the child  is pagelayout
     239           4 :             LwpVirtualLayout* pParent = pLayout->GetParentLayout();
     240           4 :             if(eSectionType != LwpLayout::StartWithinColume && pParent && !pParent->IsPage())
     241             :             {
     242           4 :                 aLayoutList.push_back(static_cast<LwpPageLayout*>(pLayout));
     243             :             }
     244             :         }
     245           4 :         pLayout = GetLayout(pLayout);
     246             :     }
     247             :     // sort the pagelayout according to their position
     248           4 :     std::vector<LwpPageLayout*>::iterator aIt;
     249           4 :     if (!aLayoutList.empty())
     250             :     {
     251           4 :         for( aIt = aLayoutList.begin(); aIt != aLayoutList.end() -1; ++aIt)
     252             :         {
     253           0 :             for( std::vector<LwpPageLayout*>::iterator bIt = aIt +1; bIt != aLayoutList.end(); ++bIt )
     254             :             {
     255           0 :                 if(**aIt < **bIt)
     256             :                 {
     257           0 :                     continue;
     258             :                 }
     259             :                 else
     260             :                 {
     261           0 :                     LwpPageLayout* pTemp = *aIt;
     262           0 :                     *aIt = *bIt;
     263           0 :                     *bIt = pTemp;
     264             :                 }
     265             :             }
     266             :         }
     267             :     }
     268             : 
     269             :     //put all the sorted  layouts into list
     270           4 :     m_LayoutList.clear();
     271             : 
     272           8 :     for( aIt = aLayoutList.begin(); aIt != aLayoutList.end(); ++aIt)
     273             :     {
     274           4 :         m_LayoutList.push_back(*aIt);
     275           4 :     }
     276           4 : }
     277             : 
     278             : /**************************************************************************
     279             :  * @descr:  whether need create a new section and reset column in current page layout
     280             :  * @param:
     281             :  * @param:
     282             :  * @return:  sal_True if need create a new section
     283             : **************************************************************************/
     284           4 : bool LwpStory::IsNeedSection()
     285             : {
     286           4 :     bool bNewSection = false;
     287           4 :     if(m_pCurrentLayout)
     288             :     {
     289           4 :         if(m_pCurrentLayout->HasColumns())
     290             :         {
     291             :             //get the following pagelayout and its type
     292           0 :             bool bColumns = true;
     293           0 :             LwpPageLayout* pNextLayout = GetNextPageLayout();
     294           0 :             if(pNextLayout)
     295             :             {
     296             :                 //get layout type
     297           0 :                 LwpLayout::UseWhenType eWhenType = pNextLayout->GetUseWhenType();
     298           0 :                 switch(eWhenType)
     299             :                 {
     300             :                 case LwpLayout::StartWithinColume://not support now
     301             :                 case LwpLayout::StartWithinPage:
     302             :                 {
     303           0 :                     bColumns =false;
     304           0 :                     bNewSection = true;
     305           0 :                     break;
     306             :                 }
     307             :                 case LwpLayout::StartOnNextPage:
     308             :                 case LwpLayout::StartOnOddPage://not support now
     309             :                 case LwpLayout::StartOnEvenPage://not support now
     310             :                 {
     311           0 :                     bColumns =true;
     312           0 :                     bNewSection = false;
     313           0 :                     break;
     314             :                 }
     315             :                 default:
     316           0 :                     break;
     317             :                 }
     318             :             }
     319             : 
     320             :             //if bColumns is true, the page layout doesn't need columns, set the xfcolumns to NULL in page master
     321           0 :             if(!bColumns)
     322             :             {
     323           0 :                 m_pCurrentLayout->ResetXFColumns();
     324             :             }
     325             :         }
     326           4 :         SetPMModified(false);
     327             :     }
     328           4 :     return bNewSection;
     329             : }
     330             : /**************************************************************************
     331             :  * @descr:  process frame which anchor type is to cell
     332             :  * @param:
     333             :  * @param:
     334             :  * @return:
     335             : **************************************************************************/
     336          20 : void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
     337             : {
     338          20 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     339          60 :     while(pLayout)
     340             :     {
     341          20 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
     342          46 :         while(pFrameLayout)
     343             :         {
     344             : 
     345             :             //if(pFrameLayout->IsAnchorCell())
     346           6 :             if(pFrameLayout->IsAnchorCell() && pFrameLayout->HasContent())
     347             :             {
     348             :                 //get the first xfpara
     349             :                 rtl::Reference<XFContent> first(
     350           0 :                     pCont->FindFirstContent(enumXFContentPara));
     351           0 :                 XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(first.get());
     352           0 :                 if(pXFFirtPara)
     353           0 :                     pFrameLayout->XFConvert(pXFFirtPara);
     354             :             }
     355           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
     356             :         }
     357          20 :         pLayout = GetLayout(pLayout);
     358             :     }
     359          20 : }
     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().get());
     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().get());
     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          20 : void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
     394             : {
     395          20 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     396          60 :     while(pLayout)
     397             :     {
     398          20 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
     399          46 :         while(pFrameLayout)
     400             :         {
     401           6 :             if(pFrameLayout->IsAnchorFrame())
     402             :             {
     403           0 :                 pFrameLayout->XFConvert(pCont);
     404             :             }
     405           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
     406             :         }
     407          20 :         pLayout = GetLayout(pLayout);
     408             :     }
     409          20 : }
     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          20 : void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont)
     417             : {
     418          20 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     419          60 :     while(pLayout)
     420             :     {
     421          20 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
     422          46 :         while(pFrameLayout)
     423             :         {
     424           6 :             if(pFrameLayout->IsAnchorPage() && (pLayout->IsHeader() || pLayout->IsFooter()))
     425             :             {
     426             :                 //The frame must be included by <text:p>
     427             :                 rtl::Reference<XFContent> first(
     428           0 :                     pCont->FindFirstContent(enumXFContentPara));
     429           0 :                 XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(first.get());
     430           0 :                 if(pXFFirtPara)
     431           0 :                     pFrameLayout->XFConvert(pXFFirtPara);
     432             :             }
     433           6 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
     434             :         }
     435          20 :         pLayout = GetLayout(pLayout);
     436             :     }
     437          20 : }
     438             : 
     439           0 : void LwpStory::AddXFContent(XFContent* pContent)
     440             : {
     441           0 :     if(m_pXFContainer)
     442           0 :         m_pXFContainer->Add(pContent);
     443           0 : }
     444             : 
     445           0 : XFContentContainer* LwpStory::GetXFContent()
     446             : {
     447           0 :     if(m_pXFContainer)
     448           0 :         return m_pXFContainer;
     449             :     else
     450           0 :         return NULL;
     451             : }
     452             : 
     453           2 : LwpPara* LwpStory::GetLastParaOfPreviousStory()
     454             : {
     455           2 :     LwpVirtualLayout* pVLayout = this->GetLayout(NULL);
     456           2 :     if (pVLayout)
     457             :     {
     458           1 :         return pVLayout->GetLastParaOfPreviousStory();
     459             :     }
     460             : 
     461           1 :     return NULL;
     462             : }
     463             : /**************************************************************************
     464             :  * @descr:  get text from story
     465             :  * @param:
     466             :  * @param:
     467             :  * @return:
     468             : **************************************************************************/
     469           0 : OUString LwpStory::GetContentText(bool bAllText)
     470             : {
     471           0 :     if (bAllText)//convert all text fribs
     472             :     {
     473           0 :         OUString sText("");
     474             :         //process para list
     475           0 :         LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara().obj().get());
     476           0 :         while (pPara)
     477             :         {
     478           0 :             pPara->SetFoundry(m_pFoundry);
     479           0 :             sText += pPara->GetContentText(true);
     480           0 :             pPara = dynamic_cast<LwpPara*>(pPara->GetNext().obj().get());
     481             :         }
     482           0 :         return sText;
     483             :     }
     484             :     else //only the first text frib
     485             :     {
     486           0 :         rtl::Reference<LwpObject> pObj = GetFirstPara().obj();
     487           0 :         if(pObj.is())
     488             :         {
     489           0 :             LwpPara* pPara = dynamic_cast<LwpPara*>(pObj.get());
     490           0 :             if (!pPara || pPara->GetNext().obj() != NULL)
     491           0 :                 return OUString("");
     492           0 :             pPara->SetFoundry(m_pFoundry);
     493           0 :             return pPara->GetContentText();
     494             :         }
     495           0 :         return  OUString("");
     496             :     }
     497             : 
     498             : }
     499           0 : OUString LwpStory::RegisterFirstFribStyle()
     500             : {
     501           0 :     LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara().obj().get());
     502           0 :     if (!pPara)
     503           0 :         return OUString("");
     504           0 :     pPara->SetFoundry(m_pFoundry);
     505           0 :     LwpFribPtr& rFribs = pPara->GetFribs();
     506           0 :     LwpFrib* pFirstFrib = rFribs.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             : 
     520           6 : bool LwpStory::IsBullStyleUsedBefore(const OUString& rStyleName, const sal_uInt8& nPos)
     521             : {
     522           6 :     std::vector <NamePosPair>::reverse_iterator rIter;
     523           6 :     for (rIter = m_vBulletStyleNameList.rbegin(); rIter != m_vBulletStyleNameList.rend(); ++rIter)
     524             :     {
     525           3 :         OUString aName = (*rIter).first;
     526           3 :         sal_uInt8 nPosition = (*rIter).second;
     527           3 :         if (aName == rStyleName && nPosition == nPos)
     528             :         {
     529           3 :             return true;
     530             :         }
     531           0 :     }
     532           3 :     return false;
     533             : }
     534             : 
     535             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11