LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpfont.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 174 205 84.9 %
Date: 2014-11-03 Functions: 34 38 89.5 %
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             : #include "lwpglobalmgr.hxx"
      57             : #include "lwpfont.hxx"
      58             : #include "xfilter/xfstylemanager.hxx"
      59             : #include "xfilter/xffontfactory.hxx"
      60             : 
      61          50 : void LwpFontAttrEntry::Read(LwpObjectStream *pStrm)
      62             : {
      63          50 :     m_nAttrBits = pStrm->QuickReaduInt16();
      64          50 :     m_nAttrOverrideBits = pStrm->QuickReaduInt16();
      65          50 :     m_nAttrApplyBits = pStrm->QuickReaduInt16();
      66          50 :     m_nAttrOverrideBits2 = pStrm->QuickReaduInt8();
      67          50 :     m_nAttrApplyBits2 = pStrm->QuickReaduInt8();
      68          50 :     m_nCase = pStrm->QuickReaduInt8();
      69          50 :     m_nUnder = pStrm->QuickReaduInt8();
      70          50 :     pStrm->SkipExtra();
      71          50 : }
      72             : 
      73             : #include "xfilter/xfdefs.hxx"
      74         208 : void LwpFontAttrEntry::Override( rtl::Reference<XFFont> const & pFont )
      75             : {
      76         208 :     if (IsBoldOverridden())
      77         178 :         pFont->SetBold(Is(BOLD));
      78             : 
      79         208 :     if (IsItalicOverridden())
      80         146 :         pFont->SetItalic(Is(ITALIC));
      81             : 
      82         208 :     if (IsStrikeThruOverridden())
      83             :     {
      84         122 :         if(Is(STRIKETHRU))
      85             :         {
      86           2 :             pFont->SetCrossout(enumXFCrossoutSignel);
      87             :         }
      88             :         else
      89             :         {
      90         120 :             pFont->SetCrossout(enumXFCrossoutNone);
      91             :         }
      92             :     }
      93             : 
      94         208 :     if (IsSuperOverridden())
      95             :     {
      96         124 :         if(Is(SUPERSCRIPT))
      97           2 :             pFont->SetPosition(true);
      98             :     }
      99             : 
     100         208 :     if (IsSubOverridden())
     101             :     {
     102         124 :         if(Is(SUBSCRIPT))
     103           2 :             pFont->SetPosition(false);
     104             :     }
     105             : 
     106         208 :     if (IsUnderlineOverridden())
     107             :     {
     108         122 :         switch(m_nUnder)
     109             :         {
     110             :             case UNDER_SINGLE:
     111           2 :                 pFont->SetUnderline(enumXFUnderlineSingle);
     112           2 :                 break;
     113             :             case UNDER_DOUBLE:
     114           0 :                 pFont->SetUnderline(enumXFUnderlineDouble);
     115           0 :                 break;
     116             :             case UNDER_WORD_SINGLE:
     117           0 :                 pFont->SetUnderline(enumXFUnderlineSingle, true);
     118           0 :                 break;
     119             :             case UNDER_WORD_DOUBLE:
     120           0 :                 pFont->SetUnderline(enumXFUnderlineSingle, true);
     121           0 :                 break;
     122             :             case UNDER_DONTCARE:    //fall through
     123             :             case UNDER_OFF:         //fall through
     124             :             case UNDER_STYLE:       //fall through
     125             :             default:
     126         120 :                 break;
     127             :                 //do nothing;
     128             :         }
     129             :     }
     130             : 
     131         208 :     if (IsCaseOverridden())
     132             :     {
     133         120 :         switch(m_nCase)
     134             :         {
     135             :         case CASE_UPPER:
     136           0 :             pFont->SetTransform(enumXFTransformUpper);
     137           0 :             break;
     138             :         case CASE_LOWER:
     139           0 :             pFont->SetTransform(enumXFTransformLower);
     140           0 :             break;
     141             :         case CASE_NORMAL:
     142         120 :             pFont->SetTransform(enumXFTransformNone);
     143         120 :             break;
     144             :         case CASE_INITCAPS:
     145           0 :             pFont->SetTransform(enumXFTransformCapitalize);
     146           0 :             break;
     147             :         case CASE_STYLE:        //fall through
     148             :         case CASE_DONTCARE: //fall through
     149             :         default:
     150             :             //do nothing
     151             :             ;
     152             :         }
     153             :     }
     154             : 
     155             :     //Please note that, put the SmallCaps setting after the case setting,
     156             :     //for SmallCaps has higher priority than LowerCase but low
     157         208 :     if (IsSmallCapsOverridden())
     158             :     {
     159         120 :         if( pFont->GetTransform()!=enumXFTransformUpper )   //SmallCaps should not override upper case
     160             :         {
     161         120 :             if(Is(SMALLCAPS))
     162           0 :                 pFont->SetTransform(enumXFTransformSmallCaps);
     163             :         }
     164             :     }
     165             : 
     166             :     // TODO: tightness
     167             :     //if (IsTightnessOverridden())
     168             :     //  pFont->SetTightness(cTightness);*/
     169         208 : }
     170             : 
     171         814 : bool LwpFontAttrEntry::Is(sal_uInt16 Attr)
     172             : {
     173         814 :     return (0 != (m_nAttrBits & Attr));
     174             : }
     175             : 
     176         208 : bool LwpFontAttrEntry::IsBoldOverridden()
     177             : {
     178         208 :     return (0 != (m_nAttrOverrideBits & BOLD));
     179             : }
     180             : 
     181         208 : bool LwpFontAttrEntry::IsItalicOverridden()
     182             : {
     183         208 :     return (0 != (m_nAttrOverrideBits & ITALIC));
     184             : }
     185         208 : bool LwpFontAttrEntry::IsStrikeThruOverridden()
     186             : {
     187         208 :     return (0 != (m_nAttrOverrideBits & STRIKETHRU));
     188             : }
     189         208 : bool LwpFontAttrEntry::IsSmallCapsOverridden()
     190             : {
     191         208 :     return (0 != (m_nAttrOverrideBits & SMALLCAPS));
     192             : }
     193         208 : bool LwpFontAttrEntry::IsSuperOverridden()
     194             : {
     195         208 :     return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
     196             : 
     197             : }
     198         208 : bool LwpFontAttrEntry::IsSubOverridden()
     199             : {
     200         208 :     return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
     201             : 
     202             : }
     203             : 
     204         208 : bool LwpFontAttrEntry::IsUnderlineOverridden()
     205             : {
     206         208 :     return (0 != (m_nAttrOverrideBits2 & UNDER));
     207             : }
     208         208 : bool LwpFontAttrEntry::IsCaseOverridden()
     209             : {
     210         208 :     return (0 != (m_nAttrOverrideBits2 & CASE));
     211             : }
     212             : 
     213          52 : void LwpFontTableEntry::Read(LwpObjectStream *pStrm)
     214             : {
     215          52 :     m_WindowsFaceName.Read(pStrm);
     216             : 
     217             :     // use the m_WindowsFaceName to set the m_FaceName temporarily
     218          52 :     m_FaceName = m_WindowsFaceName;
     219             : 
     220             :     //Skip the panoseNumber
     221             :     //m_PanoseNumber.Read(pStrm);
     222          52 :     LwpPanoseNumber thePanoseToSkip;
     223          52 :     thePanoseToSkip.Read(pStrm);
     224             : 
     225          52 :     pStrm->SkipExtra();
     226             : 
     227          52 :     RegisterFontDecl();
     228          52 : }
     229             : 
     230         576 : OUString LwpFontTableEntry::GetFaceName()
     231             : {
     232         576 :     return (m_WindowsFaceName.str());
     233             : }
     234             : 
     235          52 : void LwpFontTableEntry::RegisterFontDecl()
     236             : {
     237         104 :     if(m_FaceName.str().isEmpty()) return;
     238          44 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     239          44 :     XFFontDecl aFontDecl1( m_FaceName.str(), m_FaceName.str(), false );
     240          44 :     pXFStyleManager->AddFontDecl(aFontDecl1);
     241             : }
     242             : 
     243          18 : LwpFontTable::LwpFontTable()
     244             :     : m_nCount(0)
     245          18 :     , m_pFontEntries(NULL)
     246          18 : {}
     247             : 
     248          18 : void LwpFontTable::Read(LwpObjectStream *pStrm)
     249             : {
     250          18 :     m_pFontEntries = NULL;
     251          18 :     m_nCount = pStrm->QuickReaduInt16();
     252          18 :     if(m_nCount>0)
     253             :     {
     254           8 :         m_pFontEntries = new LwpFontTableEntry[m_nCount];
     255          60 :         for(sal_uInt16 i=0; i<m_nCount; i++)
     256             :         {
     257          52 :             m_pFontEntries[i].Read(pStrm);
     258             :         }
     259             :     }
     260          18 :     pStrm->SkipExtra();
     261          18 : }
     262             : 
     263         576 : OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
     264             : {
     265             :     assert(index <= m_nCount && index > 0);
     266         576 :     return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
     267             : }
     268             : 
     269          18 : LwpFontTable::~LwpFontTable()
     270             : {
     271          18 :     if(m_pFontEntries)
     272             :     {
     273           8 :         delete [] m_pFontEntries;
     274           8 :         m_pFontEntries = NULL;
     275             :     }
     276          18 : }
     277             : 
     278         162 : void LwpFontNameEntry::Read(LwpObjectStream *pStrm)
     279             : {
     280             :     //Read CFontDescriptionOverrideBase
     281         162 :     m_nOverrideBits = pStrm->QuickReaduInt8();
     282         162 :     m_nApplyBits = pStrm->QuickReaduInt8();
     283         162 :     m_nPointSize = pStrm->QuickReaduInt32();
     284         162 :     m_nOverstrike = pStrm->QuickReaduInt16();
     285         162 :     m_nTightness = pStrm->QuickReaduInt16();
     286         162 :     m_Color.Read(pStrm);
     287         162 :     m_BackColor.Read(pStrm);
     288         162 :     pStrm->SkipExtra();
     289             : 
     290             :     //Read data of LwpFontNameEntry
     291         162 :     m_nFaceName = pStrm->QuickReaduInt16();
     292         162 :     m_nAltFaceName = pStrm->QuickReaduInt16();
     293         162 :     pStrm->SkipExtra();
     294         162 : }
     295             : #include "xfilter/xfcolor.hxx"
     296         500 : void LwpFontNameEntry::Override(rtl::Reference<XFFont> const & pFont)
     297             : {
     298         500 :     if (IsPointSizeOverridden())
     299         472 :         pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
     300             : 
     301         500 :     if (IsColorOverridden() && m_Color.IsValidColor())
     302             :     {
     303         190 :         XFColor aColor(m_Color.To24Color());
     304         190 :         pFont->SetColor(aColor);
     305             :     }
     306             : 
     307         500 :     if (IsBackgroundColorOverridden() )
     308             :     {
     309         120 :         if (m_BackColor.IsValidColor())
     310             :         {
     311           0 :             XFColor aColor(m_BackColor.To24Color());
     312           0 :             pFont->SetBackColor( aColor );
     313             :         }
     314         120 :         else if (m_BackColor.IsTransparent())
     315             :         {
     316         120 :             pFont->SetBackColorTransparent();
     317             :         }
     318             :     }
     319             : 
     320             :     // TODO: tightness
     321             :     //if (IsTightnessOverridden())
     322             :     //  pFont->SetTightness(cTightness);
     323         500 : }
     324             : 
     325         500 : bool LwpFontNameEntry::IsFaceNameOverridden()
     326             : {
     327         500 :     return (0 != (m_nOverrideBits & FACENAME));
     328             : }
     329             : 
     330         500 : bool LwpFontNameEntry::IsAltFaceNameOverridden()
     331             : {
     332         500 :     return (0 != (m_nOverrideBits & ALTFACENAME));
     333             : }
     334             : 
     335         500 : bool LwpFontNameEntry::IsPointSizeOverridden()
     336             : {
     337         500 :     return (0 != (m_nOverrideBits & POINTSIZE));
     338             : }
     339             : 
     340         500 : bool LwpFontNameEntry::IsColorOverridden()
     341             : {
     342         500 :     return (0 != (m_nOverrideBits & COLOR));
     343             : }
     344             : 
     345         500 : bool LwpFontNameEntry::IsBackgroundColorOverridden()
     346             : {
     347         500 :     return (0 != (m_nOverrideBits & BKCOLOR));
     348             : }
     349             : 
     350             : //TODO
     351             : //sal_Bool LwpFontNameEntry::IsTightnessOverridden()
     352             : //{
     353             : //    return (0 != (m_nOverrideBits & TIGHTNESS));
     354             : //}
     355             : 
     356             : //sal_Bool LwpFontNameEntry::IsAnythingOverridden()
     357             : //{
     358             : //    return (0 != (m_nOverrideBits & ALL_BITS));
     359             : //}
     360             : 
     361          18 : LwpFontNameManager::LwpFontNameManager()
     362             :     : m_nCount(0)
     363          18 :     , m_pFontNames(NULL)
     364          18 : {}
     365             : 
     366          36 : LwpFontNameManager::~LwpFontNameManager()
     367             : {
     368          18 :     if(m_pFontNames)
     369             :     {
     370           8 :         delete [] m_pFontNames;
     371           8 :         m_pFontNames = NULL;
     372             :     }
     373          18 : }
     374             : 
     375          18 : void LwpFontNameManager::Read(LwpObjectStream *pStrm)
     376             : {
     377          18 :     m_nCount = pStrm->QuickReaduInt16();
     378          18 :     if(m_nCount>0)
     379             :     {
     380           8 :         m_pFontNames = new LwpFontNameEntry[m_nCount];
     381         170 :         for(sal_uInt16 i=0; i<m_nCount; i++)
     382             :         {
     383         162 :             m_pFontNames[i].Read(pStrm);
     384             :         }
     385             :     }
     386          18 :     m_FontTbl.Read(pStrm);
     387          18 :     pStrm->SkipExtra();
     388          18 : }
     389             : 
     390         516 : void    LwpFontNameManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
     391             :     //index: start from 1
     392             : {
     393         516 :     if (index > m_nCount || index < 1)
     394         532 :         return ;
     395             : 
     396         500 :     m_pFontNames[index-1].Override(pFont);
     397         500 :     if(m_pFontNames[index-1].IsFaceNameOverridden())
     398         456 :         pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
     399         500 :     if(m_pFontNames[index-1].IsAltFaceNameOverridden())
     400         120 :         pFont->SetFontNameAsia(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetAltFaceID()));
     401             : }
     402           0 : OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
     403             : {
     404           0 :     sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
     405           0 :     return (m_FontTbl.GetFaceName(nameindex));
     406             : }
     407             : 
     408          18 : void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
     409             : {
     410          18 :     m_nCount = pStrm->QuickReaduInt16();
     411          18 :     m_pFontAttrs = new LwpFontAttrEntry[m_nCount];
     412             : 
     413          68 :     for(sal_uInt16 i=0; i<m_nCount; i++)
     414             :     {
     415          50 :         m_pFontAttrs[i].Read(pStrm);
     416             :     }
     417          18 :     pStrm->SkipExtra();
     418          18 : }
     419             : 
     420         516 : void    LwpFontAttrManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
     421             :     //index: start from 1
     422             : {
     423         516 :     if (index > m_nCount || index < 1)
     424         824 :         return ;
     425             : 
     426         208 :     m_pFontAttrs[index-1].Override(pFont);
     427             : }
     428             : 
     429          18 : LwpFontAttrManager::~LwpFontAttrManager()
     430             : {
     431          18 :     if(m_pFontAttrs)
     432          18 :         delete []m_pFontAttrs;
     433          18 : }
     434             : 
     435          18 : void LwpFontManager::Read(LwpObjectStream *pStrm)
     436             : {
     437          18 :     m_FNMgr.Read(pStrm);
     438          18 :     m_AttrMgr.Read(pStrm);
     439          18 :     pStrm->SkipExtra();
     440             : 
     441          18 : }
     442             : 
     443             : #include "xfilter/xftextstyle.hxx"
     444             : 
     445             : /*
     446             : VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
     447             : 1. Construct the text style based on the fontID
     448             : 2. Add the style to XFStyleManager, and return the <office:styles> style name
     449             : 3. Add it to LwpParaStyleMap.
     450             : Note: A temporary method for only font support phase. The next AddStyle should be used later.
     451             : // To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
     452             : */
     453             : /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
     454             : {
     455             :     XFTextStyle* pStyle = new XFTextStyle();        //to be deleted by XFStyleManager
     456             :     AddStyle(styleObjID, fontID, styleName, pStyle);
     457             : }*/
     458             : 
     459             : /*
     460             : VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its style to XFStyleManager based on the fontID
     461             : 1. Construct the text style based on the fontID
     462             : 2. Add the style to XFStyleManager, and return the <office:styles> style name
     463             : 3. Add it to LwpParaStyleMap.
     464             : Prerequisite: pStyle has been created and the paragraph properties has been set to it.
     465             : //To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
     466             : */
     467             : /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
     468             : {
     469             :     assert(pStyle);
     470             :     XFFont* pFont = CreateFont(fontID);
     471             :     pStyle->SetFont(pFont);
     472             :     pStyle->SetStyleName(styleName);
     473             :     XFStyleManager::AddStyle(pStyle);
     474             :     m_StyleList.insert(LwpParaStyleMap::value_type(styleObjID, styleName));
     475             : }*/
     476             : 
     477             : /*
     478             : Create XFFont based on the fotID
     479             : */
     480         516 : rtl::Reference<XFFont> LwpFontManager::CreateFont(sal_uInt32 fontID)
     481             : {
     482         516 :     rtl::Reference<XFFont> pFont = new XFFont();
     483         516 :     m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
     484         516 :     m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
     485         516 :     return pFont;
     486             : }
     487             : 
     488             : /*
     489             : Called XFFont based on the override result of two font ids.
     490             : Refer to CFontManager::OverrideID
     491             : */
     492             : //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
     493           0 : rtl::Reference<XFFont> LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
     494             : {
     495           0 :     rtl::Reference<XFFont> pFont = new XFFont();   //To be deleted by XFFontFactory
     496           0 :     if(fontID)
     497             :     {
     498           0 :         Override(fontID, pFont);
     499             :     }
     500           0 :     if(overID)
     501             :     {
     502           0 :         Override(overID, pFont);
     503             :     }
     504           0 :     return pFont;
     505             : }
     506             : 
     507           0 : void LwpFontManager::Override(sal_uInt32 fontID, rtl::Reference<XFFont> const & pFont)
     508             : {
     509           0 :     m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
     510           0 :     m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
     511           0 : }
     512             : 
     513           0 : OUString LwpFontManager::GetNameByID(sal_uInt32 fontID)
     514             : {
     515           0 :     return ( m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID)) );//use font id for bullet?
     516             : }
     517             : 
     518             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10