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

Generated by: LCOV version 1.10