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

Generated by: LCOV version 1.11