LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpbulletstylemgr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 78 107 72.9 %
Date: 2015-06-13 12:38:46 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           9 : LwpBulletStyleMgr::LwpBulletStyleMgr()
      78             :     : m_pFoundry(NULL)
      79             :     , m_pBulletList(NULL)
      80             :     , m_bContinue(true)
      81             :     , m_bIsBulletSkipped(false)
      82           9 :     , m_nCurrentPos(0xFF)
      83             : {
      84           9 : }
      85             : 
      86          27 : LwpBulletStyleMgr::~LwpBulletStyleMgr()
      87             : {
      88           9 :     if (m_pBulletList)
      89             :     {
      90           0 :         delete m_pBulletList;
      91             :     }
      92             : 
      93           9 :     m_vIDsPairList.clear();
      94           9 :     m_vStyleNameList.clear();
      95          18 : }
      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           2 : OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, LwpBulletOverride* pBullOver,
     105             :     LwpIndentOverride* pIndent)
     106             : {
     107           2 :     OUString aEmpty;
     108             : 
     109           2 :     if(!pPara || !pIndent || !pBullOver)
     110             :     {
     111           0 :         return aEmpty;
     112             :     }
     113             : 
     114           2 :     LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
     115           2 :     if (!pSilverBullet)
     116             :     {
     117             :         assert(false);
     118           0 :         return aEmpty;
     119             :     }
     120             : 
     121           2 :     LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
     122           2 :     if (!pBulletPara)
     123             :     {
     124             :         assert(false);
     125           0 :         return aEmpty;
     126             :     }
     127             : 
     128           2 :     LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
     129           2 :     LwpParaIndentProperty* pIndentProp = NULL;
     130           2 :     LwpObjectID aIndentID;
     131           2 :     if (pProp)
     132             :     {
     133           0 :         pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
     134           0 :         aIndentID = pIndentProp->GetIndentID();
     135             :     }
     136             : 
     137           2 :     LwpObjectID aBulletID = pBullOver->GetSilverBullet();
     138           4 :     boost::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
     139             : 
     140           2 :     sal_uInt16 nNameIndex = 0;
     141           2 :     std::vector <OverridePair>::iterator iter;
     142           2 :     for(iter = m_vIDsPairList.begin(); iter != m_vIDsPairList.end(); ++iter)
     143             :     {
     144           4 :         if (iter->first->GetSilverBullet() == aBulletID && iter->second == aIndentID
     145           4 :             && iter->first->IsRightAligned() == pBullOver->IsRightAligned())
     146             :         {
     147           1 :             return m_vStyleNameList[nNameIndex];
     148             :         }
     149             :         else
     150             :         {
     151           0 :             nNameIndex++;
     152             :         }
     153             :     }
     154             : 
     155           1 :     m_vIDsPairList.push_back(std::make_pair(pBulletOver, aIndentID));
     156           2 :     OUString aStyleName;
     157             : 
     158           1 :     LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs();
     159           1 :     bool bIsNumbering = (rBulletParaFribs.HasFrib(FRIB_TAG_PARANUMBER) != 0);
     160             : 
     161           1 :     enumXFAlignType eAlign = enumXFAlignStart;
     162           1 :     if (pBullOver->IsRightAligned())
     163             :     {
     164           0 :         eAlign = enumXFAlignEnd;
     165             :     }
     166             : 
     167           1 :     XFListStyle* pListStyle = new XFListStyle();
     168           1 :     XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     169             : 
     170           1 :     if (!bIsNumbering)
     171             :     {
     172           0 :         for (sal_uInt8 nC = 1; nC < 11; nC++)
     173             :         {
     174             :             pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
     175           0 :                 LwpSilverBullet::GetPrefix(), LwpSilverBullet::GetSuffix());
     176             : 
     177           0 :             if (pIndent->GetMRest() > 0) /* note: used to be 0.001, no idea why */
     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)).m_pStyle->GetStyleName();
     190             :     }
     191             :     else
     192             :     {
     193           1 :         ParaNumbering aParaNumbering;
     194           1 :         pBulletPara->GetParaNumber(1, &aParaNumbering);
     195           1 :         LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
     196           1 :         if (pParaNumber)
     197             :         {
     198          10 :             for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
     199             :             {
     200           9 :                 if (pParaNumber->GetStyleID() != NUMCHAR_other)
     201             :                 {
     202           9 :                     OUString aPrefix;
     203          18 :                     XFNumFmt aFmt;
     204           9 :                     if (aParaNumbering.pPrefix)
     205             :                     {
     206           0 :                         aPrefix += aParaNumbering.pPrefix->GetText();
     207             :                     }
     208             : 
     209          18 :                     OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
     210           9 :                     if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
     211             :                     {
     212           0 :                         aPrefix += "0";
     213             :                     }
     214           9 :                     aFmt.SetPrefix(aPrefix);
     215             : 
     216           9 :                     aFmt.SetFormat(aNumber);
     217             : 
     218           9 :                     if (aParaNumbering.pSuffix)
     219             :                     {
     220           0 :                         aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
     221             :                     }
     222             : 
     223             :                     //set numbering format into the style-list.
     224          18 :                     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           9 :                 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
     244             :             }
     245           1 :             aStyleName = (pXFStyleMgr->AddStyle(pListStyle)).m_pStyle->GetStyleName();
     246             :         }
     247             :         else
     248           0 :             delete pListStyle;
     249             : 
     250             :     }
     251             : 
     252           1 :     m_vStyleNameList.push_back(aStyleName);
     253           3 :     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           5 : XFContentContainer* LwpBulletStyleMgr::AddBulletList(
     261             :         XFContentContainer* pCont, bool bIsOrdered,
     262             :         const OUString& rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
     263             : {
     264             :     assert(nLevel>0);
     265             : 
     266           5 :     m_bIsBulletSkipped = bIsBulletSkiped;
     267             : 
     268             :     //todo: need judge here.
     269           5 :     bool bContinue = m_bContinue;
     270             : 
     271             :     XFList* theList;
     272           5 :     XFList* prevList = NULL;
     273             :     XFListItem* theItem;
     274           5 :     XFListItem* InnerItem = NULL;
     275          18 :     for (sal_Int8 nC = nLevel-1; nC >= 0; nC--)
     276             :     {
     277          13 :         theList = new XFList();
     278          13 :         theItem = new XFListItem();
     279          13 :         theList->Add(theItem);
     280             : 
     281          13 :         if (bIsOrdered)
     282             :         {
     283          13 :             theList->SetOrdered(true);
     284             :         }
     285             :         else
     286             :         {
     287           0 :             bContinue = false;
     288           0 :             theList->SetOrdered(false);
     289             :         }
     290             : 
     291          13 :         if (nC == nLevel-1)
     292             :         {
     293           5 :             theList->SetContinueNumber(bContinue);
     294             :         }
     295             :         //Add the outer list to pCont
     296          13 :         if (nC == 0)
     297             :         {
     298           5 :             theList->SetStyleName(rStyleName);
     299           5 :             pCont->Add(theList);
     300             :         }
     301             : 
     302          13 :         if ((nC == nLevel-1) && bIsBulletSkiped)
     303             :         {
     304           0 :             theItem->SetIsHeader(true);
     305             : 
     306           0 :             theList->SetContinueNumber(true);
     307             :             // end of add
     308             :         }
     309             : 
     310          13 :         if(nC == nLevel-1)
     311             :         {
     312           5 :             InnerItem = theItem;
     313             :         }
     314             : 
     315          13 :         if(prevList)
     316             :         {
     317           8 :             theItem->Add(prevList);
     318             :         }
     319          13 :         prevList = theList;
     320             :     }
     321           5 :     return InnerItem;
     322             : }
     323             : 
     324             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11