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

Generated by: LCOV version 1.10