LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpbulletstylemgr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 78 107 72.9 %
Date: 2014-11-03 Functions: 5 5 100.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             :  *
       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             :  *  For LWP filter architecture prototype
      59             :  ************************************************************************/
      60             : /*************************************************************************
      61             :  * Change History
      62             :  Jan 2005           Created
      63             :  ************************************************************************/
      64             : #include "lwpbulletstylemgr.hxx"
      65             : #include "lwpdoc.hxx"
      66             : #include "lwpstory.hxx"
      67             : #include "lwpdivinfo.hxx"
      68             : #include "lwppara.hxx"
      69             : #include "lwpsilverbullet.hxx"
      70             : #include "lwptools.hxx"
      71             : #include "lwpparaproperty.hxx"
      72             : #include "xfilter/xfliststyle.hxx"
      73             : #include "xfilter/xfstylemanager.hxx"
      74             : #include "xfilter/xflist.hxx"
      75             : #include "lwpglobalmgr.hxx"
      76             : 
      77          18 : LwpBulletStyleMgr::LwpBulletStyleMgr()
      78             :     : m_pFoundry(NULL)
      79             :     , m_pBulletList(NULL)
      80             :     , m_bContinue(true)
      81             :     , m_bIsBulletSkipped(false)
      82          18 :     , m_nCurrentPos(0xFF)
      83             : {
      84          18 : }
      85             : 
      86          54 : LwpBulletStyleMgr::~LwpBulletStyleMgr()
      87             : {
      88          18 :     if (m_pBulletList)
      89             :     {
      90           0 :         delete m_pBulletList;
      91             :     }
      92             : 
      93          18 :     m_vIDsPairList.clear();
      94          18 :     m_vStyleNameList.clear();
      95          36 : }
      96             : 
      97             : /**
      98             :  * @short   Register bullet style to style-list. The function only register the bullet and single customized numbering
      99             :  *      not inluding the numbering sequence.
     100             :  * @param   pPara pointer to the current paragraph which has a bullet/numbering.
     101             :  * @param   pBullOver pointer to the bulletoverride of current paragraph.
     102             :  * @param   pIndent pointer to the indentoverride of current paragraph.
     103             :  */
     104           4 : OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, LwpBulletOverride* pBullOver,
     105             :     LwpIndentOverride* pIndent)
     106             : {
     107           4 :     OUString aEmpty;
     108             : 
     109           4 :     if(!pPara || !pIndent || !pBullOver)
     110             :     {
     111           0 :         return aEmpty;
     112             :     }
     113             : 
     114           4 :     LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
     115           4 :     if (!pSilverBullet)
     116             :     {
     117             :         assert(false);
     118           0 :         return aEmpty;
     119             :     }
     120             : 
     121           4 :     LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
     122           4 :     if (!pBulletPara)
     123             :     {
     124             :         assert(false);
     125           0 :         return aEmpty;
     126             :     }
     127             : 
     128           4 :     LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
     129           4 :     LwpParaIndentProperty* pIndentProp = NULL;
     130           4 :     LwpObjectID aIndentID;
     131           4 :     if (pProp)
     132             :     {
     133           0 :         pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
     134           0 :         aIndentID = pIndentProp->GetIndentID();
     135             :     }
     136             : 
     137           4 :     LwpObjectID aBulletID = pBullOver->GetSilverBullet();
     138           8 :     boost::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
     139             : 
     140           4 :     sal_uInt16 nNameIndex = 0;
     141           4 :     std::vector <OverridePair>::iterator iter;
     142           4 :     for(iter = m_vIDsPairList.begin(); iter != m_vIDsPairList.end(); ++iter)
     143             :     {
     144           8 :         if (iter->first->GetSilverBullet() == aBulletID && iter->second == aIndentID
     145           8 :             && iter->first->IsRightAligned() == pBullOver->IsRightAligned())
     146             :         {
     147           2 :             return m_vStyleNameList[nNameIndex];
     148             :         }
     149             :         else
     150             :         {
     151           0 :             nNameIndex++;
     152             :         }
     153             :     }
     154             : 
     155           2 :     m_vIDsPairList.push_back(std::make_pair(pBulletOver, aIndentID));
     156           4 :     OUString aStyleName;
     157             : 
     158           2 :     LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs();
     159           2 :     bool bIsNumbering = (rBulletParaFribs.HasFrib(FRIB_TAG_PARANUMBER) != 0);
     160             : 
     161           2 :     enumXFAlignType eAlign = enumXFAlignStart;
     162           2 :     if (pBullOver->IsRightAligned())
     163             :     {
     164           0 :         eAlign = enumXFAlignEnd;
     165             :     }
     166             : 
     167           2 :     XFListStyle* pListStyle = new XFListStyle();
     168           2 :     XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     169             : 
     170           2 :     if (!bIsNumbering)
     171             :     {
     172           0 :         for (sal_uInt8 nC = 1; nC < 11; nC++)
     173             :         {
     174             :             pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
     175           0 :                 pSilverBullet->GetPrefix(), pSilverBullet->GetSuffix());
     176             : 
     177           0 :             if (pIndent->GetMRest() > 0.001)
     178             :             {
     179             :                 pListStyle->SetListPosition(nC, 0.0,
     180           0 :                     LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMRest())), 0.0, eAlign);
     181             :             }
     182             :             else
     183             :             {
     184             :                 pListStyle->SetListPosition(nC, 0.0,
     185           0 :                     0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMFirst())), eAlign);
     186             :             }
     187             :         }
     188             : 
     189           0 :         aStyleName = pXFStyleMgr->AddStyle(pListStyle)->GetStyleName();
     190             :     }
     191             :     else
     192             :     {
     193           2 :         ParaNumbering aParaNumbering;
     194           2 :         pBulletPara->GetParaNumber(1, &aParaNumbering);
     195           2 :         LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
     196           2 :         if (pParaNumber)
     197             :         {
     198          20 :             for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
     199             :             {
     200          18 :                 if (pParaNumber->GetStyleID() != NUMCHAR_other)
     201             :                 {
     202          18 :                     OUString aPrefix;
     203          36 :                     XFNumFmt aFmt;
     204          18 :                     if (aParaNumbering.pPrefix)
     205             :                     {
     206           0 :                         aPrefix += aParaNumbering.pPrefix->GetText();
     207             :                     }
     208             : 
     209          36 :                     OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
     210          18 :                     if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
     211             :                     {
     212           0 :                         aPrefix += "0";
     213             :                     }
     214          18 :                     aFmt.SetPrefix(aPrefix);
     215             : 
     216          18 :                     aFmt.SetFormat(aNumber);
     217             : 
     218          18 :                     if (aParaNumbering.pSuffix)
     219             :                     {
     220           0 :                         aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
     221             :                     }
     222             : 
     223             :                     //set numbering format into the style-list.
     224          36 :                     pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
     225             : 
     226             :                 }
     227             :                 else
     228             :                 {
     229           0 :                     OUString aPrefix, aSuffix;
     230           0 :                     if (aParaNumbering.pPrefix)
     231             :                     {
     232           0 :                         aPrefix = aParaNumbering.pPrefix->GetText();
     233             :                     }
     234           0 :                     if (aParaNumbering.pSuffix)
     235             :                     {
     236           0 :                         aSuffix = aParaNumbering.pSuffix->GetText();
     237             :                     }
     238             : 
     239           0 :                     pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber).toChar(),
     240           0 :                         "Times New Roman", aPrefix, aSuffix);
     241             :                 }
     242             : 
     243          18 :                 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
     244             :             }
     245           2 :             aStyleName = pXFStyleMgr->AddStyle(pListStyle)->GetStyleName();
     246             :         }
     247             :         else
     248           0 :             delete pListStyle;
     249             : 
     250             :     }
     251             : 
     252           2 :     m_vStyleNameList.push_back(aStyleName);
     253           6 :     return aStyleName;
     254             : 
     255             : }
     256             : 
     257             : #include "xfilter/xflistitem.hxx"
     258             : //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
     259             : //Return the inner XFItem created.
     260          10 : XFContentContainer* LwpBulletStyleMgr::AddBulletList(
     261             :         XFContentContainer* pCont, bool bIsOrdered,
     262             :         const OUString& rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
     263             : {
     264             :     assert(nLevel>0);
     265             : 
     266          10 :     m_bIsBulletSkipped = bIsBulletSkiped;
     267             : 
     268             :     //todo: need judge here.
     269          10 :     bool bContinue = m_bContinue;
     270             : 
     271             :     XFList* theList;
     272          10 :     XFList* prevList = NULL;
     273             :     XFListItem* theItem;
     274          10 :     XFListItem* InnerItem = NULL;
     275          36 :     for (sal_Int8 nC = nLevel-1; nC >= 0; nC--)
     276             :     {
     277          26 :         theList = new XFList();
     278          26 :         theItem = new XFListItem();
     279          26 :         theList->Add(theItem);
     280             : 
     281          26 :         if (bIsOrdered)
     282             :         {
     283          26 :             theList->SetOrdered(true);
     284             :         }
     285             :         else
     286             :         {
     287           0 :             bContinue = false;
     288           0 :             theList->SetOrdered(false);
     289             :         }
     290             : 
     291          26 :         if (nC == nLevel-1)
     292             :         {
     293          10 :             theList->SetContinueNumber(bContinue);
     294             :         }
     295             :         //Add the outer list to pCont
     296          26 :         if (nC == 0)
     297             :         {
     298          10 :             theList->SetStyleName(rStyleName);
     299          10 :             pCont->Add(theList);
     300             :         }
     301             : 
     302          26 :         if ((nC == nLevel-1) && bIsBulletSkiped)
     303             :         {
     304           0 :             theItem->SetIsHeader(true);
     305             : 
     306           0 :             theList->SetContinueNumber(true);
     307             :             // end of add
     308             :         }
     309             : 
     310          26 :         if(nC == nLevel-1)
     311             :         {
     312          10 :             InnerItem = theItem;
     313             :         }
     314             : 
     315          26 :         if(prevList)
     316             :         {
     317          16 :             theItem->Add(prevList);
     318             :         }
     319          26 :         prevList = theList;
     320             :     }
     321          10 :     return InnerItem;
     322             : }
     323             : 
     324             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10