LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpfrib.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 121 198 61.1 %
Date: 2014-11-03 Functions: 11 14 78.6 %
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 "lwpfrib.hxx"
      65             : #include "lwpcharsetmgr.hxx"
      66             : #include "lwpsection.hxx"
      67             : #include "lwphyperlinkmgr.hxx"
      68             : #include "xfilter/xfhyperlink.hxx"
      69             : #include "xfilter/xfstylemanager.hxx"
      70             : #include "xfilter/xfsection.hxx"
      71             : #include "xfilter/xfsectionstyle.hxx"
      72             : #include "xfilter/xftextspan.hxx"
      73             : #include "xfilter/xftextcontent.hxx"
      74             : #include "lwpfribheader.hxx"
      75             : #include "lwpfribtext.hxx"
      76             : #include "lwpfribtable.hxx"
      77             : #include "lwpfribbreaks.hxx"
      78             : #include "lwpfribframe.hxx"
      79             : #include "lwpfribsection.hxx"
      80             : #include "lwpcharacterstyle.hxx"
      81             : #include "lwpfootnote.hxx"
      82             : #include "lwpnotes.hxx"
      83             : #include "lwpfribmark.hxx"
      84             : #include "lwpchangemgr.hxx"
      85             : #include "lwpdocdata.hxx"
      86             : #include "lwpglobalmgr.hxx"
      87             : 
      88        1728 : LwpFrib::LwpFrib(LwpPara* pPara)
      89             :     : m_pPara(pPara)
      90             :     , m_pNext(NULL)
      91             :     , m_nFribType(0)
      92             :     , m_pModifiers(NULL)
      93             :     , m_ModFlag(false)
      94             :     , m_nRevisionType(0)
      95             :     , m_bRevisionFlag(false)
      96        1728 :     , m_nEditor(0)
      97             : {
      98        1728 : }
      99             : 
     100        3980 : LwpFrib::~LwpFrib()
     101             : {
     102        1728 :     if(m_pModifiers)
     103        1166 :         delete m_pModifiers;
     104        2252 : }
     105             : 
     106        1728 : LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
     107             : {
     108             :     //Read Modifier
     109        1728 :     ModifierInfo* pModInfo = NULL;
     110        1728 :     if(fribtag & FRIB_TAG_MODIFIER)
     111             :     {
     112        1166 :         pModInfo  = new ModifierInfo();
     113        1166 :         pModInfo->CodePage = 0;
     114        1166 :         pModInfo->FontID = 0;
     115        1166 :         pModInfo->RevisionFlag = false;
     116        1166 :         pModInfo->HasCharStyle = false;
     117        1166 :         pModInfo->HasLangOverride = false;
     118        1166 :         pModInfo->HasHighlight = false;
     119        1166 :         ReadModifiers( pObjStrm, pModInfo );
     120             :     }
     121             : 
     122             :     //Read frib data
     123        1728 :     LwpFrib* newFrib = NULL;
     124        1728 :     sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
     125        1728 :     sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
     126        1728 :     switch(fribtype)
     127             :     {
     128             :         case FRIB_TAG_INVALID:  //fall through
     129             :         case FRIB_TAG_EOP:      //fall through
     130             :         default:
     131         524 :             newFrib = new LwpFrib(pPara);
     132         524 :             break;
     133             :         case FRIB_TAG_TEXT:
     134             :         {
     135         816 :             newFrib = new LwpFribText (pPara, (fribtag & FRIB_TAG_NOUNICODE) != 0);
     136         816 :             break;
     137             :         }
     138             :         case FRIB_TAG_TABLE:
     139           2 :             newFrib = new LwpFribTable(pPara);
     140           2 :             break;
     141             :         case FRIB_TAG_TAB:
     142          62 :             newFrib = new LwpFribTab(pPara);
     143          62 :             break;
     144             :         case FRIB_TAG_PAGEBREAK:
     145          18 :             newFrib = new LwpFribPageBreak(pPara);
     146          18 :             break;
     147             :         case FRIB_TAG_FRAME:
     148          52 :             newFrib = new LwpFribFrame(pPara);
     149          52 :             break;
     150             :         case FRIB_TAG_FOOTNOTE:
     151           2 :             newFrib = new LwpFribFootnote(pPara);
     152           2 :             break;
     153             :         case FRIB_TAG_COLBREAK:
     154           0 :             newFrib = new LwpFribColumnBreak(pPara);
     155           0 :             break;
     156             :         case FRIB_TAG_LINEBREAK:
     157           0 :             newFrib = new LwpFribLineBreak(pPara);
     158           0 :             break;
     159             :         case FRIB_TAG_HARDSPACE:
     160           0 :             newFrib = new LwpFribHardSpace(pPara);
     161           0 :             break;
     162             :         case FRIB_TAG_SOFTHYPHEN:
     163           0 :             newFrib = new LwpFribSoftHyphen(pPara);
     164           0 :             break;
     165             :         case FRIB_TAG_PARANUMBER:
     166         218 :             newFrib = new LwpFribParaNumber(pPara);
     167         218 :             break;
     168             :         case FRIB_TAG_UNICODE: //fall through
     169             :         case FRIB_TAG_UNICODE2: //fall through
     170             :         case FRIB_TAG_UNICODE3: //fall through
     171           0 :             newFrib = new LwpFribUnicode(pPara);
     172           0 :             break;
     173             :         case FRIB_TAG_NOTE:
     174           0 :             newFrib = new  LwpFribNote(pPara);
     175           0 :             break;
     176             :         case FRIB_TAG_SECTION:
     177           0 :             newFrib = new LwpFribSection(pPara);
     178           0 :             break;
     179             :         case FRIB_TAG_PAGENUMBER:
     180          10 :             newFrib = new LwpFribPageNumber(pPara);
     181          10 :             break;
     182             :         case FRIB_TAG_DOCVAR:
     183          12 :             newFrib = new LwpFribDocVar(pPara);
     184          12 :             break;
     185             :         case FRIB_TAG_BOOKMARK:
     186           0 :             newFrib = new LwpFribBookMark(pPara);
     187           0 :             break;
     188             :         case FRIB_TAG_FIELD:
     189          12 :             newFrib = new LwpFribField(pPara);
     190          12 :             break;
     191             :         case FRIB_TAG_CHBLOCK:
     192           0 :             newFrib = new LwpFribCHBlock(pPara);
     193           0 :             break;
     194             :         case FRIB_TAG_RUBYMARKER:
     195           0 :             newFrib = new LwpFribRubyMarker(pPara);
     196           0 :             break;
     197             :         case FRIB_TAG_RUBYFRAME:
     198           0 :             newFrib = new LwpFribRubyFrame(pPara);
     199           0 :             break;
     200             :     }
     201             : 
     202             :     //Do not know why the fribTag judgement is necessary, to be checked with
     203        1728 :     if ( fribtag & FRIB_TAG_MODIFIER )
     204             :     {
     205        1166 :         newFrib->SetModifiers(pModInfo);
     206             :     }
     207             : 
     208        1728 :     newFrib->SetType(fribtype);
     209        1728 :     newFrib->SetEditor(editID);
     210        1728 :     newFrib->Read(pObjStrm, friblen);
     211        1728 :     return newFrib;
     212             : }
     213             : 
     214         586 : void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
     215             : {
     216         586 :     pObjStrm->SeekRel(len);
     217         586 : }
     218             : 
     219        1166 : void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
     220             : {
     221        1166 :     if (pModifiers)
     222             :     {
     223        1166 :         m_pModifiers = pModifiers;
     224        1166 :         m_ModFlag = true;
     225        1166 :         if (pModifiers->RevisionFlag)
     226             :         {
     227           0 :             m_bRevisionFlag = true;
     228           0 :             m_nRevisionType = pModifiers->RevisionType;
     229             :         }
     230             :     }
     231        1166 : }
     232             : 
     233         860 : void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
     234             : {
     235         860 :     if (!m_pModifiers)
     236         752 :         return;
     237         608 :     if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighlight)
     238             :     {
     239         248 :         m_ModFlag = false;
     240         248 :         return;
     241             :     }
     242             :     //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
     243             :     //so we can only handle fontid and characstyle, if others ,we should not reg style
     244             :     //note by ,1-27
     245         360 :     rtl::Reference<XFFont> pFont;
     246         360 :     XFTextStyle* pStyle = NULL;
     247         360 :     m_StyleName = "";
     248         360 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     249         360 :     if (m_pModifiers->HasCharStyle)
     250             :     {
     251             :         XFTextStyle* pNamedStyle = static_cast<XFTextStyle*>
     252           0 :                                 (pFoundry->GetStyleManager()->GetStyle(m_pModifiers->CharStyleID));
     253           0 :         if (m_pModifiers->FontID)
     254             :         {
     255           0 :             pStyle = new XFTextStyle();
     256           0 :             *pStyle = *pNamedStyle;
     257           0 :             LwpCharacterStyle* pCharStyle = static_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj().get());
     258             : 
     259           0 :             pStyle->SetStyleName("");
     260           0 :             pFont = pFoundry->GetFontManger().CreateOverrideFont(pCharStyle->GetFinalFontID(),m_pModifiers->FontID);
     261           0 :             pStyle->SetFont(pFont);
     262           0 :             IXFStyle *pNewStyle = pXFStyleManager->AddStyle(pStyle);
     263           0 :             m_StyleName = pNewStyle->GetStyleName();
     264           0 :             if (pNewStyle != pStyle)
     265           0 :                 pStyle = NULL;
     266             :         }
     267             :         else
     268           0 :             m_StyleName =  pNamedStyle->GetStyleName();
     269             :     }
     270             :     else
     271             :     {
     272         360 :         if (m_pModifiers->FontID)
     273             :         {
     274         360 :             pStyle = new XFTextStyle();
     275         360 :             pFont = pFoundry->GetFontManger().CreateFont(m_pModifiers->FontID);
     276         360 :             pStyle->SetFont(pFont);
     277         360 :             IXFStyle *pNewStyle = pXFStyleManager->AddStyle(pStyle);
     278         360 :             m_StyleName = pNewStyle->GetStyleName();
     279         360 :             if (pNewStyle != pStyle)
     280         296 :                 pStyle = NULL;
     281             :         }
     282             :     }
     283             : 
     284         360 :     if (m_pModifiers->HasHighlight)
     285             :     {
     286           0 :         XFColor  aColor = GetHighlightColor();//right yellow
     287           0 :         if (pStyle)//change the style directly
     288           0 :             pStyle->GetFont()->SetBackColor(aColor);
     289             :         else //register a new style
     290             :         {
     291           0 :             pStyle = new XFTextStyle();
     292             : 
     293           0 :             if (!m_StyleName.isEmpty())
     294             :             {
     295           0 :                 XFTextStyle* pOldStyle = pXFStyleManager->FindTextStyle(m_StyleName);
     296           0 :                 *pStyle = *pOldStyle;
     297           0 :                 pStyle->GetFont()->SetBackColor(aColor);
     298             :             }
     299             :             else
     300             :             {
     301           0 :                 pFont = new XFFont;
     302           0 :                 pFont->SetBackColor(aColor);
     303           0 :                 pStyle->SetFont(pFont);
     304             :             }
     305           0 :             m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
     306             :         }
     307         360 :     }
     308             : }
     309             : 
     310        2400 : void LwpFrib::ReadModifiers(LwpObjectStream* pObjStrm,ModifierInfo* pModInfo)
     311             : {
     312             :     for(;;)
     313             :     {
     314             :         bool bFailure;
     315             : 
     316             :         // Get the modifier type
     317        2400 :         sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
     318        2400 :         if (bFailure)
     319        1166 :             break;
     320             : 
     321             :         // Stop when we hit the last modifier
     322        2400 :         if (Modifier == FRIB_MTAG_NONE)
     323        1166 :             break;
     324             : 
     325             :         // Get the modifier length
     326        1234 :         sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
     327        1234 :         if (bFailure)
     328           0 :             break;
     329             : 
     330        1234 :         switch (Modifier)
     331             :         {
     332             :             case FRIB_MTAG_FONT:
     333         608 :                 if (len != sizeof(pModInfo->FontID))
     334             :                 {
     335             :                     OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
     336           0 :                     pObjStrm->SeekRel(len);
     337             :                 }
     338             :                 else
     339         608 :                     pModInfo->FontID = pObjStrm->QuickReaduInt32();
     340         608 :                 break;
     341             :             case FRIB_MTAG_CHARSTYLE:
     342           0 :                 pModInfo->HasCharStyle = true;
     343           0 :                 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
     344           0 :                 break;
     345             :             case FRIB_MTAG_LANGUAGE:
     346           0 :                 pModInfo->HasLangOverride = true;
     347           0 :                 pModInfo->Language.Read(pObjStrm);
     348           0 :                 break;
     349             :             case FRIB_MTAG_CODEPAGE:
     350         104 :                 if (len != sizeof(pModInfo->CodePage))
     351             :                 {
     352             :                     OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
     353           0 :                     pObjStrm->SeekRel(len);
     354             :                 }
     355             :                 else
     356         104 :                     pModInfo->CodePage = pObjStrm->QuickReaduInt16();
     357         104 :                 break;
     358             :             case FRIB_MTAG_ATTRIBUTE:
     359         522 :                 pModInfo->aTxtAttrOverride.Read(pObjStrm);
     360         522 :                 if (pModInfo->aTxtAttrOverride.IsHighlight())
     361           0 :                     pModInfo->HasHighlight = true;
     362         522 :                 break;
     363             :             case FRIB_MTAG_REVISION:
     364           0 :                 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
     365           0 :                 pModInfo->RevisionFlag = true;
     366           0 :                 break;
     367             :             default:
     368           0 :                 pObjStrm->SeekRel(len);
     369           0 :                 break;
     370             :         }
     371             :         // TODO: read the modifier data
     372        1234 :     }
     373        1166 : }
     374             : 
     375             : /**
     376             : *  @descr:   Whether there are other fribs following current frib.
     377             : *  @return:  Ture if having following fribs, or false.
     378             : */
     379          50 : bool LwpFrib::HasNextFrib()
     380             : {
     381          50 :     if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP)
     382          44 :         return false;
     383           6 :     return true;
     384             : }
     385             : 
     386         374 : void LwpFrib::ConvertChars(XFContentContainer* pXFPara,const OUString& text)
     387             : {
     388         374 :     if (m_ModFlag)
     389             :     {
     390         174 :         OUString strStyleName = GetStyleName();
     391         174 :         XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
     392         174 :         pXFPara->Add(pSpan);
     393             :     }
     394             :     else
     395             :     {
     396         200 :         XFTextContent *pSpan = new XFTextContent();
     397         200 :         pSpan->SetText(text);
     398         200 :         pXFPara->Add(pSpan);
     399             :     }
     400         374 : }
     401             : 
     402           0 : void LwpFrib::ConvertHyperLink(XFContentContainer* pXFPara,LwpHyperlinkMgr* pHyperlink,const OUString& text)
     403             : {
     404           0 :     XFHyperlink* pHyper = new XFHyperlink;
     405           0 :     pHyper->SetHRef(pHyperlink->GetHyperlink());
     406           0 :     pHyper->SetText(text);
     407           0 :     pHyper->SetStyleName(GetStyleName());
     408           0 :     pXFPara->Add(pHyper);
     409           0 : }
     410             : 
     411             : /**
     412             : *  @descr:   Get the current frib font style
     413             : *  @return:  XFFont pointer
     414             : */
     415          50 : rtl::Reference<XFFont> LwpFrib::GetFont()
     416             : {
     417          50 :     rtl::Reference<XFFont> pFont;
     418          50 :     if(m_pModifiers&&m_pModifiers->FontID)
     419             :     {
     420          20 :         LwpFoundry* pFoundry = m_pPara->GetFoundry();
     421          20 :         pFont = pFoundry->GetFontManger().CreateFont(m_pModifiers->FontID);
     422             :     }
     423             :     else
     424             :     {
     425          30 :         XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
     426          30 :         pFont = pXFParaStyle->GetFont();
     427             :     }
     428          50 :     return pFont;
     429             : }
     430             : 
     431           0 : OUString LwpFrib::GetEditor()
     432             : {
     433           0 :     LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     434           0 :     return pGlobal->GetEditorName(m_nEditor);
     435             : }
     436             : 
     437           0 : XFColor LwpFrib::GetHighlightColor()
     438             : {
     439           0 :     LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     440           0 :     return pGlobal->GetHighlightColor(m_nEditor);
     441             : }
     442             : 
     443             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10