LCOV - code coverage report
Current view: top level - libreoffice/lotuswordpro/source/filter - lwpfribtext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 72 211 34.1 %
Date: 2012-12-27 Functions: 12 16 75.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 "lwpfribtext.hxx"
      66             : #include "lwpcharsetmgr.hxx"
      67             : #include "lwphyperlinkmgr.hxx"
      68             : #include "lwptools.hxx"
      69             : #include "xfilter/xfstylemanager.hxx"
      70             : #include "xfilter/xftextspan.hxx"
      71             : #include "xfilter/xfbookmark.hxx"
      72             : #include "xfilter/xfentry.hxx"
      73             : #include "xfilter/xftextcontent.hxx"
      74             : #include "xfilter/xfcrossref.hxx"
      75             : #include "xfilter/xfpagenumber.hxx"
      76             : #include "xfilter/xfdocfield.hxx"
      77             : #include "xfilter/xfdatestyle.hxx"
      78             : #include "xfilter/xftimestyle.hxx"
      79             : #include "xfilter/xfdate.hxx"
      80             : #include "xfilter/xfannotation.hxx"
      81             : 
      82         410 : LwpFribText::LwpFribText( LwpPara *pPara, sal_Bool bNoUnicode )
      83         410 :     : LwpFrib(pPara), m_bNoUnicode(bNoUnicode)
      84         410 : {}
      85             : 
      86         410 : void LwpFribText::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
      87             : {
      88         410 :     if( len>=1 )
      89             :     {
      90             :         rtl_TextEncoding rEncode;
      91         410 :         if(m_bNoUnicode)
      92             :         {
      93           6 :             rEncode = RTL_TEXTENCODING_ISO_8859_1;
      94             :         }
      95             :         else
      96             :         {
      97         404 :             if (m_pModifiers && m_pModifiers->CodePage)
      98             :                 rEncode = LwpCharSetMgr::GetInstance()->
      99          29 :                                               GetTextCharEncoding(m_pModifiers->CodePage);
     100             :             else
     101         375 :                 rEncode = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
     102             :         }
     103         410 :         LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
     104             :     }
     105         410 : }
     106             : 
     107         189 : void LwpFribText::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
     108             : {
     109         189 :     if (!pStory)
     110         189 :         return;
     111         189 :     LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
     112         189 :     if (pHyperlink->GetHyperlinkFlag())
     113           0 :         LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
     114             :     else
     115         189 :         LwpFrib::ConvertChars(pXFPara,GetText());
     116             : }
     117             : 
     118             : /**
     119             :  * @short:   Reading mothed of paranumber frib.
     120             :  * @param:   pObjStrm wordpro object stream.
     121             :  * @param:   len length of the frib
     122             :  */
     123         109 : void LwpFribParaNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
     124             : {
     125         109 :     m_nStyleID = pObjStrm->QuickReaduInt16();
     126         109 :     m_nNumberChar = pObjStrm->QuickReaduInt16();
     127         109 :     m_nLevel = pObjStrm->QuickReaduInt16();
     128         109 :     m_nStart = pObjStrm->QuickReaduInt16();
     129         109 : }
     130             : 
     131             : /**
     132             :  * @short:   default constructor of LwpFribDocVar
     133             :  */
     134           6 : LwpFribDocVar::LwpFribDocVar(LwpPara* pPara)
     135           6 :     : LwpFrib(pPara), m_nType(0), m_pName(new LwpAtomHolder)
     136             : {
     137           6 : }
     138             : /**
     139             :  * @short:   destructor of LwpFribDocVar
     140             :  */
     141          18 : LwpFribDocVar::~LwpFribDocVar()
     142             : {
     143           6 :     if (m_pName)
     144             :     {
     145           6 :         delete m_pName;
     146           6 :         m_pName = NULL;
     147             :     }
     148          12 : }
     149             : /**
     150             :  * @short:   Reading mothed of document variable frib.
     151             :  * @param:   pObjStrm wordpro object stream.
     152             :  * @param:   len length of the frib
     153             :  */
     154           6 : void LwpFribDocVar::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
     155             : {
     156           6 :     m_nType = pObjStrm->QuickReaduInt16();
     157           6 :     m_pName->Read(pObjStrm);
     158           6 : }
     159             : 
     160             : /**
     161             :  * @short:   register style for doc field (text style,date style)
     162             :  * @param:
     163             :  * @param:
     164             :  */
     165           6 : void LwpFribDocVar::RegisterStyle(LwpFoundry* pFoundry)
     166             : {
     167           6 :     LwpFrib::RegisterStyle(pFoundry);
     168             : 
     169           6 :     switch(m_nType)
     170             :     {
     171             :     case DATECREATED:
     172             :     case DATELASTREVISION:
     173             :     {
     174             : //      m_TimeStyle = LwpTools::RegisterDefaultTimeStyle();
     175           0 :         RegisterDefaultTimeStyle();
     176             :     }
     177           0 :         break;
     178             :     case TOTALEDITTIME:
     179           0 :         RegisterTotalTimeStyle();
     180           0 :         break;
     181             :     default:
     182           6 :         break;
     183             :     }
     184           6 : }
     185             : 
     186             : /**
     187             :  * @short:   register default time style for doc field
     188             :  * @param:
     189             :  * @param:
     190             :  */
     191           0 : void LwpFribDocVar::RegisterDefaultTimeStyle()
     192             : {
     193           0 :     XFDateStyle* pDateStyle = new XFDateStyle;//use the default format
     194             : 
     195           0 :     pDateStyle->AddMonth();
     196           0 :     pDateStyle->AddText(A2OUSTR("/"));
     197           0 :     pDateStyle->AddMonthDay();
     198           0 :     pDateStyle->AddText(A2OUSTR("/"));
     199           0 :     pDateStyle->AddYear();
     200           0 :     pDateStyle->AddText(A2OUSTR(","));
     201           0 :     pDateStyle->AddHour();
     202           0 :     pDateStyle->AddText(A2OUSTR(":"));
     203           0 :     pDateStyle->AddMinute();
     204           0 :     pDateStyle->AddText(A2OUSTR(":"));
     205           0 :     pDateStyle->AddSecond(sal_True,0);
     206             : 
     207           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     208           0 :     m_TimeStyle = pXFStyleManager->AddStyle(pDateStyle)->GetStyleName();
     209           0 : }
     210           0 : void LwpFribDocVar::RegisterTotalTimeStyle()
     211             : {
     212           0 :     XFTimeStyle* pTimeStyle = new XFTimeStyle;//use the default format
     213           0 :     pTimeStyle->SetTruncate(sal_False);
     214           0 :     pTimeStyle->AddMinute();
     215           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     216           0 :     m_TimeStyle = pXFStyleManager->AddStyle(pTimeStyle)->GetStyleName();
     217           0 : }
     218             : 
     219             : /**
     220             :  * @short:   convert the doc info field
     221             :  * @param:
     222             :  * @param:
     223             :  */
     224           4 : void LwpFribDocVar::XFConvert(XFContentContainer* pXFPara)
     225             : {
     226           4 :     XFContent* pContent=NULL;
     227           4 :     switch(m_nType)
     228             :     {
     229             :     case FILENAME:
     230             :     {
     231           2 :         pContent = new XFFileName;
     232           2 :         static_cast<XFFileName*>(pContent)->SetType(A2OUSTR("FileName"));
     233           2 :         break;
     234             :     }
     235             :     case PATH:
     236             :     {
     237           0 :         pContent = new XFFileName;
     238           0 :         static_cast<XFFileName*>(pContent)->SetType(A2OUSTR("Path"));
     239           0 :         break;
     240             :     }
     241             :     case DESCRIPTION:
     242           0 :         pContent = new XFDescription;
     243           0 :         break;
     244             :     case DATECREATED:
     245             :     {
     246           0 :         pContent = new XFCreateTime;
     247           0 :         pContent->SetStyleName(m_TimeStyle);
     248           0 :         break;
     249             :     }
     250             :     case DATELASTREVISION:
     251             :     {
     252           0 :         pContent = new XFLastEditTime;
     253           0 :         pContent->SetStyleName(m_TimeStyle);
     254           0 :         break;
     255             :     }
     256             :     case NUMPAGES:
     257           2 :         pContent = new XFPageCount;
     258           2 :         break;
     259             :     case NUMWORDS:
     260           0 :         pContent = new XFWordCount;
     261           0 :         break;
     262             :     case NUMCHARS:
     263           0 :         pContent = new XFCharCount;
     264           0 :         break;
     265             :     case TOTALEDITTIME:
     266             :     {
     267           0 :         pContent = new XFTotalEditTime;
     268           0 :         pContent->SetStyleName(m_TimeStyle);
     269           0 :         break;
     270             :     }
     271             :     case KEYWORDS:
     272           0 :         pContent = new XFKeywords;
     273           0 :         break;
     274             :     case CREATEDBY:
     275           0 :         pContent = new XFInitialCreator;
     276           0 :         break;
     277             :     case DOCSIZE:
     278             :     {
     279             : /*      pContent = new XFAnnotation;
     280             :         XFTextContent* pSpan = new XFTextContent();
     281             :         pSpan->SetText(A2OUSTR("Document Size is Here"));
     282             :         XFParagraph* pPara = new XFParagraph;
     283             :         pPara->Add(pSpan);
     284             :         static_cast<XFAnnotation*>(pContent)->Add(pPara);
     285             :         break;
     286             : */
     287           0 :         OUString text = A2OUSTR("<Document Size>");
     288           0 :         LwpFrib::ConvertChars(pXFPara,text);
     289           0 :         return;
     290             :     }
     291             :     case SMARTMASTER:
     292             :     {
     293           0 :         OUString text = A2OUSTR("<Smart master>");
     294           0 :         LwpFrib::ConvertChars(pXFPara,text);
     295           0 :         return;
     296             :     }
     297             :     case DIVISIONNAME:
     298             :     {
     299           0 :         OUString text = A2OUSTR("<Division name>");
     300           0 :         LwpFrib::ConvertChars(pXFPara,text);
     301           0 :         return;
     302             :     }
     303             :     case SECTIONNAME:
     304             :     {
     305           0 :         OUString text = A2OUSTR("<Section name>");
     306           0 :         LwpFrib::ConvertChars(pXFPara,text);
     307           0 :         return;
     308             :     }
     309             :     case VERSIONCREATEBY:
     310             :     {
     311           0 :         OUString text = A2OUSTR("<Version Creat by>");
     312           0 :         LwpFrib::ConvertChars(pXFPara,text);
     313           0 :         return;
     314             :     }
     315             :     case VERSIONCREATEDATE:
     316             :     {
     317           0 :         OUString text = A2OUSTR("<Version Creat date>");
     318           0 :         LwpFrib::ConvertChars(pXFPara,text);
     319           0 :         return;
     320             :     }
     321             :     case VERSIONOTHEREDITORS:
     322             :     {
     323           0 :         OUString text = A2OUSTR("<Version other Editors>");
     324           0 :         LwpFrib::ConvertChars(pXFPara,text);
     325           0 :         return;
     326             :     }
     327             :     case VERSIONNAME:
     328             :     {
     329           0 :         OUString text = A2OUSTR("<Version Name>");
     330           0 :         LwpFrib::ConvertChars(pXFPara,text);
     331           0 :         return;
     332             :     }
     333             :     case VERSIONNUMBER:
     334             :     {
     335           0 :         OUString text = A2OUSTR("<Version Numbers>");
     336           0 :         LwpFrib::ConvertChars(pXFPara,text);
     337           0 :         return;
     338             :     }
     339             :     case ALLVERSIONNAME:
     340             :     {
     341           0 :         OUString text = A2OUSTR("<All Version Name>");
     342           0 :         LwpFrib::ConvertChars(pXFPara,text);
     343           0 :         return;
     344             :     }
     345             :     case VERSIONREMARK:
     346             :     {
     347           0 :         OUString text = A2OUSTR("<Version Remark>");
     348           0 :         LwpFrib::ConvertChars(pXFPara,text);
     349           0 :         return;
     350             :     }
     351             :     case DOCUMENTCATEGORY:
     352             :     {
     353           0 :         OUString text = A2OUSTR("<Document Category>");
     354           0 :         LwpFrib::ConvertChars(pXFPara,text);
     355           0 :         return;
     356             :     }
     357             :     case VERSIONLASTDATE:
     358             :     {
     359           0 :         OUString text = A2OUSTR("<Version Last Modify Date>");
     360           0 :         LwpFrib::ConvertChars(pXFPara,text);
     361           0 :         return;
     362             :     }
     363             :     case VERSIONLASTEDITOR:
     364             :     {
     365           0 :         OUString text = A2OUSTR("<Version Last Editor>");
     366           0 :         LwpFrib::ConvertChars(pXFPara,text);
     367           0 :         return;
     368             :     }
     369             :     case LASTEDIT:
     370             :     {
     371           0 :         OUString text = A2OUSTR("<Last Editor>");
     372           0 :         LwpFrib::ConvertChars(pXFPara,text);
     373           0 :         return;
     374             :     }
     375             :     case OTHEREDITORS:
     376             :     {
     377           0 :         OUString text = A2OUSTR("<Other Editors>");
     378           0 :         LwpFrib::ConvertChars(pXFPara,text);
     379           0 :         return;
     380             :     }
     381             :     case NUMOFREVISION:
     382             :     {
     383           0 :         OUString text = A2OUSTR("<Number of Revision>");
     384           0 :         LwpFrib::ConvertChars(pXFPara,text);
     385           0 :         return;
     386             :     }
     387             :     default:
     388           0 :         return;
     389             :     }
     390           4 :     if (m_ModFlag)//(m_pModifiers)
     391             :     {
     392           0 :         XFTextSpan *pSpan = new XFTextSpan;
     393           0 :         pSpan->SetStyleName(GetStyleName());
     394           0 :         pSpan->Add(pContent);
     395           0 :         pXFPara->Add(pSpan);
     396             :     }
     397             :     else
     398           4 :         pXFPara->Add(pContent);
     399             : 
     400             : }
     401             : /**
     402             :  * @short:   Read unicode
     403             :  * @param:
     404             :  * @param:
     405             :  */
     406           0 : void LwpFribUnicode::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
     407             : {
     408           0 :     if(len>1)
     409             :     {
     410             :         rtl_TextEncoding rEncode;
     411             : 
     412           0 :         if (m_pModifiers && m_pModifiers->CodePage)
     413             :                 rEncode = LwpCharSetMgr::GetInstance()->
     414           0 :                                           GetTextCharEncoding(m_pModifiers->CodePage);
     415             :         else
     416           0 :                 rEncode = LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
     417             : 
     418           0 :         LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
     419             : 
     420             :     }
     421             :     else
     422           0 :         pObjStrm->SeekRel(len);
     423           0 : }
     424             : 
     425           0 : void LwpFribUnicode::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
     426             : {
     427           0 :     if (!pStory)
     428           0 :         return;
     429           0 :     LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
     430           0 :     if (pHyperlink->GetHyperlinkFlag())
     431           0 :         LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
     432             :     else
     433           0 :         LwpFrib::ConvertChars(pXFPara,GetText());
     434             : }
     435             : 
     436             : /**
     437             :  * @short:   Read page number
     438             :  * @param:
     439             :  * @param:
     440             :  */
     441           5 : void LwpFribPageNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
     442             : {
     443           5 :     m_nNumStyle = pObjStrm->QuickReaduInt16();
     444           5 :     m_aBefText.Read(pObjStrm);
     445           5 :     m_aAfterText.Read(pObjStrm);
     446           5 :     m_nStartNum = pObjStrm->QuickReaduInt16();
     447           5 :     m_nStartOnPage = pObjStrm->QuickReaduInt16();
     448           5 :     m_nFlag = pObjStrm->QuickReaduInt16();
     449           5 : }
     450             : 
     451           3 : void LwpFribPageNumber::XFConvert(XFContentContainer* pXFPara)
     452             : {
     453           3 :     if (m_nNumStyle == 0x0)
     454           3 :         return;
     455           3 :     XFPageNumber* pNum = new XFPageNumber;
     456             : //  pNum->SetSelect(A2OUSTR("current"));
     457           3 :     switch(m_nNumStyle)
     458             :     {
     459             :     case 0x01:
     460           3 :         pNum->SetNumFmt(A2OUSTR("1"));
     461           3 :         break;
     462             :     case 0x02:
     463           0 :         pNum->SetNumFmt(A2OUSTR("A"));
     464           0 :         break;
     465             :     case 0x03:
     466           0 :         pNum->SetNumFmt(A2OUSTR("a"));
     467           0 :         break;
     468             :     case 0x04:
     469           0 :         pNum->SetNumFmt(A2OUSTR("I"));
     470           0 :         break;
     471             :     case 0x05:
     472           0 :         pNum->SetNumFmt(A2OUSTR("i"));
     473           0 :         break;
     474             :     }
     475           3 :     OUString styleName = GetStyleName();
     476           3 :     if (!m_aBefText.str().isEmpty())
     477             :     {
     478           0 :         OUString textStr = m_aBefText.str();
     479           0 :         XFTextSpan *pBef = new XFTextSpan(textStr,styleName);
     480           0 :         pXFPara->Add(pBef);
     481             :     }
     482           3 :     if (m_ModFlag)//(m_pModifiers)
     483             :     {
     484           0 :         XFTextSpan *pSpan = new XFTextSpan;
     485           0 :         pSpan->SetStyleName(styleName);
     486           0 :         pSpan->Add(pNum);
     487           0 :         pXFPara->Add(pSpan);
     488             :     }
     489             :     else
     490           3 :         pXFPara->Add(pNum);
     491           3 :     if (!m_aAfterText.str().isEmpty())
     492             :     {
     493           0 :         OUString textStr = m_aAfterText.str();
     494           0 :         XFTextSpan *pAfter = new XFTextSpan(textStr,styleName);
     495           0 :         pXFPara->Add(pAfter);
     496           3 :     }
     497             : }
     498             : 
     499             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10