LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpsilverbullet.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 100 170 58.8 %
Date: 2014-11-03 Functions: 11 15 73.3 %
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 "lwpglobalmgr.hxx"
      65             : #include "lwpsilverbullet.hxx"
      66             : #include "lwpdoc.hxx"
      67             : #include "lwpdivinfo.hxx"
      68             : #include "lwpfoundry.hxx"
      69             : #include "lwpstory.hxx"
      70             : #include "lwppara.hxx"
      71             : #include "xfilter/xfliststyle.hxx"
      72             : #include "xfilter/xfstylemanager.hxx"
      73             : 
      74          26 : LwpSilverBullet::LwpSilverBullet(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
      75             :     : LwpDLNFVList(objHdr, pStrm)
      76             :     , m_nFlags(0)
      77             :     , m_nUseCount(0)
      78          26 :     , m_pAtomHolder(new LwpAtomHolder)
      79          52 :     , m_pBulletPara(NULL)
      80             : {
      81          26 : }
      82             : 
      83          78 : LwpSilverBullet::~LwpSilverBullet()
      84             : {
      85          26 :     if (m_pAtomHolder)
      86             :     {
      87          26 :         delete m_pAtomHolder;
      88             :     }
      89          52 : }
      90             : 
      91          26 : void LwpSilverBullet::Read()
      92             : {
      93          26 :     LwpDLNFVList::Read();
      94             : 
      95          26 :     m_nFlags = m_pObjStrm->QuickReaduInt16();
      96          26 :     m_aStory.ReadIndexed(m_pObjStrm);
      97             : 
      98          26 :     sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
      99             : 
     100         286 :     for (sal_uInt8 nC = 0; nC < nNumPos; nC++)
     101         260 :         m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
     102             : 
     103          26 :     m_nUseCount = m_pObjStrm->QuickReaduInt32();
     104             : 
     105          26 :     m_pAtomHolder->Read(m_pObjStrm);
     106          26 : }
     107             : 
     108             : /**
     109             :  * @short:   Register bullet or numbering style-list and store the returned
     110             :  *          name from XFStyleManager.
     111             :  * @descr:
     112             :  */
     113          26 : void LwpSilverBullet::RegisterStyle()
     114             : {
     115          26 :     XFListStyle* pListStyle = new XFListStyle();
     116          26 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     117             : 
     118          26 :     this->GetBulletPara();
     119             : 
     120          26 :     if (this->IsBulletOrdered() && this->HasName())
     121             :     {
     122             :         //todo: find the flag in the file
     123          24 :         bool bCumulative = false;
     124             : 
     125         240 :         for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
     126             :         {
     127         216 :             ParaNumbering aParaNumbering;
     128             :             //get numbering format according to the position.
     129         216 :             m_pBulletPara->GetParaNumber(nPos, &aParaNumbering);
     130         216 :             LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
     131         216 :             if (pParaNumber)
     132             :             {
     133         216 :                 if (pParaNumber->GetStyleID() != NUMCHAR_other)
     134             :                 {
     135         216 :                     m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
     136         216 :                     sal_uInt16 nDisplayLevel = this->GetDisplayLevel(nPos);
     137         216 :                     bCumulative = (nDisplayLevel > 1);
     138         216 :                     OUString aPrefix = this->GetAdditionalName(nPos);
     139             : 
     140         432 :                     XFNumFmt aFmt;
     141         216 :                     if (!bCumulative && aParaNumbering.pPrefix)
     142             :                     {
     143           8 :                         aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
     144             :                     }
     145             : 
     146         216 :                     aFmt.SetFormat(GetNumCharByStyleID(pParaNumber));
     147             : 
     148         216 :                     if (aParaNumbering.pSuffix)
     149             :                     {
     150          80 :                         aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
     151             :                     }
     152             : 
     153             :                     //set numbering format into the style-list.
     154         216 :                     pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
     155             : 
     156         216 :                     if (bCumulative && nPos > 1)
     157             :                     {
     158         128 :                         pListStyle->SetDisplayLevel(nPos, nDisplayLevel);
     159         216 :                     }
     160             : 
     161             :                 }
     162             :                 else
     163             :                 {
     164           0 :                     OUString aPrefix, aSuffix;
     165           0 :                     if (aParaNumbering.pPrefix)
     166             :                     {
     167           0 :                         aPrefix = aParaNumbering.pPrefix->GetText();
     168             :                     }
     169           0 :                     if (aParaNumbering.pSuffix)
     170             :                     {
     171           0 :                         aSuffix = aParaNumbering.pSuffix->GetText();
     172             :                     }
     173             : 
     174           0 :                     pListStyle->SetListBullet(nPos, GetNumCharByStyleID(pParaNumber).toChar(),
     175           0 :                         "Times New Roman", aPrefix, aSuffix);
     176             :                 }
     177             : 
     178         216 :                 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
     179         216 :                 aParaNumbering.clear();
     180             :             }
     181             :         }
     182             :     }
     183             : 
     184             :     //add style-list to style manager.
     185          26 :     m_strStyleName = pXFStyleManager->AddStyle(pListStyle)->GetStyleName();
     186          26 : }
     187             : 
     188             : /**
     189             :  * @short:   Get the font name of the bullet.
     190             :  * @descr:
     191             :  * @return:  Font name of the bullet.
     192             :  */
     193           0 : OUString LwpSilverBullet::GetBulletFontName()
     194             : {
     195           0 :     OUString aEmpty;
     196             : 
     197             :     //foundry has been set?
     198           0 :     if (!m_pFoundry)
     199             :     {
     200           0 :         return aEmpty;
     201             :     }
     202             : 
     203           0 :     LwpFontManager& rFontMgr = m_pFoundry->GetFontManger();
     204             : 
     205           0 :     sal_uInt32 nBulletFontID = m_pBulletPara->GetBulletFontID();
     206           0 :     sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
     207             : 
     208             :     //final fontid is valid?
     209           0 :     if (nFinalFont > 255 || nFinalFont == 0)
     210             :     {
     211           0 :         return aEmpty;
     212             :     }
     213             : 
     214             :     //get font name from font manager.
     215           0 :     OUString aFontName = rFontMgr.GetNameByID(nBulletFontID);
     216             : 
     217           0 :     return aFontName;
     218             : }
     219             : /**
     220             :  * @short:   Get bullet character of the bullet vo_para.
     221             :  * @descr:
     222             :  * @return:  An UChar32 bulle character.
     223             :  */
     224           0 : UChar32 LwpSilverBullet::GetBulletChar()
     225             : {
     226           0 :     OUString aBulletChar = m_pBulletPara->GetBulletChar();
     227             : 
     228           0 :     return aBulletChar.toChar();
     229             : }
     230             : 
     231             : /**
     232             :  * @short:   Get the LwpPara object through story id.
     233             :  */
     234          30 : LwpPara* LwpSilverBullet::GetBulletPara()
     235             : {
     236          30 :     if (!m_pBulletPara)
     237             :     {
     238          26 :         LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
     239          26 :         if (!pStory)
     240             :         {
     241           0 :             return NULL;
     242             :         }
     243             : 
     244          26 :         m_pBulletPara = dynamic_cast<LwpPara*>(pStory->GetFirstPara().obj(VO_PARA).get());
     245             :     }
     246             : 
     247          30 :     return m_pBulletPara;
     248             : }
     249             : 
     250             : /**
     251             :  * @short:   Get numbering character of the bullet vo_para.
     252             :  * @descr:
     253             :  * @param:   pParaNumber a pionter to the structure LwpFribParaNumber which
     254             :  *          includes numbering prefix, format and suffix.
     255             :  * @return:  An OUString object which store the numbering character.
     256             :  */
     257         234 : OUString LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber* pParaNumber)
     258             : {
     259         234 :     OUString aEmpty;
     260             : 
     261         234 :     if (!pParaNumber)
     262             :     {
     263             :         assert(false);
     264           0 :         return aEmpty;
     265             :     }
     266             : 
     267         468 :     OUString strNumChar("1");
     268         234 :     sal_uInt16 nStyleID = pParaNumber->GetStyleID();
     269         234 :     UChar32 uC = 0x0000;
     270             : 
     271         234 :     switch (nStyleID)
     272             :     {
     273             :     case NUMCHAR_1:
     274             :     case NUMCHAR_01:
     275             :     case NUMCHAR_Chinese4:
     276         186 :         strNumChar = "1";
     277         186 :         break;
     278             :     case NUMCHAR_A :
     279           8 :         strNumChar = "A";
     280           8 :         break;
     281             :     case NUMCHAR_a:
     282          16 :         strNumChar = "a";
     283          16 :         break;
     284             :     case NUMCHAR_I:
     285           8 :         strNumChar = "I";
     286           8 :         break;
     287             :     case NUMCHAR_i:
     288          16 :         strNumChar = "i";
     289          16 :         break;
     290             :     case NUMCHAR_other:
     291           0 :         uC = static_cast<UChar32>(pParaNumber->GetNumberChar());
     292           0 :         strNumChar = OUString(uC);
     293           0 :         break;
     294             :     case NUMCHAR_Chinese1:
     295             :         {
     296           0 :         sal_Unicode sBuf[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
     297           0 :         strNumChar = OUString(sBuf);
     298             :         }
     299           0 :         break;
     300             :     case NUMCHAR_Chinese2:
     301             :         {
     302           0 :         sal_Unicode sBuf[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
     303           0 :         strNumChar = OUString(sBuf);
     304             :         }
     305           0 :         break;
     306             :     case NUMCHAR_Chinese3:
     307             :         {
     308           0 :         sal_Unicode sBuf[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
     309           0 :         strNumChar = OUString(sBuf);
     310             :         }
     311           0 :         break;
     312             :     case NUMCHAR_none:
     313           0 :         strNumChar = aEmpty;
     314           0 :         break;
     315             :     default:
     316           0 :         break;
     317             :     }//mod end
     318         468 :     return strNumChar;
     319             : }
     320             : 
     321             : /**
     322             :  * @short:   To judge the silverbullet list is ordered or not.
     323             :  * @descr:
     324             :  * @return:  sal_True if list is ordered, sal_False if list is unordered.
     325             :  */
     326          48 : bool LwpSilverBullet::IsBulletOrdered()
     327             : {
     328          48 :     if (!m_pBulletPara)
     329           0 :         return false;
     330             : 
     331          48 :     LwpFribPtr& rFribs = m_pBulletPara->GetFribs();
     332             : 
     333          48 :     return (rFribs.HasFrib(FRIB_TAG_PARANUMBER) != NULL);
     334             : }
     335             : 
     336             : /**
     337             :  * @short:   Calculate the displaylevel according to the position and hidelevels.
     338             :  * @descr:
     339             :  * @param:   nPos position of the numbering.
     340             :  * @return:  displaylevel of the position passed in.
     341             :  */
     342         216 : sal_uInt16 LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos)
     343             : {
     344         216 :     if (nPos > 1)
     345             :     {
     346         192 :         sal_uInt16 nHideBit = (1 << nPos);
     347         768 :         for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
     348             :         {
     349         640 :             sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
     350         640 :             if (!(nAttrMask & nHideBit))
     351             :             {
     352          64 :                 return static_cast<sal_uInt16>(nPos - nC);
     353             :             }
     354             :         }
     355             :     }
     356             : 
     357         152 :     return static_cast<sal_uInt16>(nPos);
     358             : }
     359             : 
     360             : /**
     361             :  * @descr:   Get the additional information, "Division name" or "Section Name" from document
     362             :  *      variable frib according to numbering position. Whether we should add a
     363             :  *      Division/Section name or not is determined by the hidelevels of the frib.
     364             :  * @param:   nPos position of the numbering.
     365             :  * @return:  Division or Section name.
     366             :  */
     367         216 : OUString LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos)
     368             : {
     369         432 :     OUString aRet, aEmpty;
     370         216 :     sal_uInt16 nHideBit = (1 << nPos);
     371         216 :     bool bDivisionName = false;
     372         216 :     bool bSectionName = false;
     373             : 
     374         216 :     LwpFrib* pParaFrib = m_pBulletPara->GetFribs().GetFribs();
     375         216 :     if (!pParaFrib)
     376             :     {
     377           0 :         return aEmpty;
     378             :     }
     379             : 
     380        4536 :     while (pParaFrib)
     381             :     {
     382        4104 :         if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
     383             :         {
     384           0 :             ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
     385           0 :             if (!pMoInfo)
     386             :             {
     387           0 :                 return aEmpty;
     388             :             }
     389           0 :             sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
     390           0 :             sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
     391             : 
     392           0 :             if (~nHideLevels & nHideBit)
     393             :             {
     394           0 :                 if (nType == 0x000D)
     395             :                 {
     396           0 :                     bDivisionName = true;
     397             :                 }
     398           0 :                 else if (nType == 0x000E)
     399             :                 {
     400           0 :                     bSectionName= true;
     401             :                 }
     402             :             }
     403             :         }
     404        4104 :         pParaFrib = pParaFrib->GetNext();
     405             :     }
     406             : 
     407         216 :     if (bDivisionName)
     408             :     {
     409           0 :         aRet += this->GetDivisionName();
     410             :     }
     411         216 :     if (bSectionName)
     412             :     {
     413           0 :         aRet += this->GetSectionName();
     414             :     }
     415             : 
     416         432 :     return aRet;
     417             : }
     418             : 
     419           0 : OUString LwpSilverBullet::GetDivisionName()
     420             : {
     421           0 :     OUString aRet;
     422             : 
     423           0 :     if (!m_pFoundry)
     424             :     {
     425           0 :         return aRet;
     426             :     }
     427             : 
     428           0 :     LwpDocument* pDoc = m_pFoundry->GetDocument();
     429           0 :     if (pDoc)
     430             :     {
     431           0 :         LwpObjectID& rID = pDoc->GetDivInfoID();
     432           0 :         if (!rID.IsNull())
     433             :         {
     434           0 :             LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(rID.obj(VO_DIVISIONINFO).get());
     435           0 :             if (pInfo)
     436           0 :                 aRet = pInfo->GetDivName();
     437             :         }
     438             :     }
     439             : 
     440           0 :     return aRet;
     441             : }
     442             : 
     443           0 : OUString LwpSilverBullet::GetSectionName()
     444             : {
     445           0 :     OUString aEmpty;
     446           0 :     LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
     447           0 :     if (!pStory)
     448             :     {
     449           0 :         return aEmpty;
     450             :     }
     451             : 
     452           0 :     return pStory->GetSectionName();
     453             : }
     454             : 
     455          48 : bool LwpSilverBullet::HasName()
     456             : {
     457          48 :     LwpAtomHolder& rName = this->GetName();
     458          48 :     return (!rName.str().isEmpty());
     459             : }
     460             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10