LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpfont.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 205 0.0 %
Date: 2014-04-14 Functions: 0 38 0.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             : #include "lwpglobalmgr.hxx"
      57             : #include "lwpfont.hxx"
      58             : #include "xfilter/xfstylemanager.hxx"
      59             : #include "xfilter/xffontfactory.hxx"
      60             : 
      61           0 : void LwpFontAttrEntry::Read(LwpObjectStream *pStrm)
      62             : {
      63           0 :     m_nAttrBits = pStrm->QuickReaduInt16();
      64           0 :     m_nAttrOverrideBits = pStrm->QuickReaduInt16();
      65           0 :     m_nAttrApplyBits = pStrm->QuickReaduInt16();
      66           0 :     m_nAttrOverrideBits2 = pStrm->QuickReaduInt8();
      67           0 :     m_nAttrApplyBits2 = pStrm->QuickReaduInt8();
      68           0 :     m_nCase = pStrm->QuickReaduInt8();
      69           0 :     m_nUnder = pStrm->QuickReaduInt8();
      70           0 :     pStrm->SkipExtra();
      71           0 : }
      72             : 
      73             : #include "xfilter/xfdefs.hxx"
      74           0 : void LwpFontAttrEntry::Override( XFFont*pFont )
      75             : {
      76           0 :     if (IsBoldOverridden())
      77           0 :         pFont->SetBold(Is(BOLD));
      78             : 
      79           0 :     if (IsItalicOverridden())
      80           0 :         pFont->SetItalic(Is(ITALIC));
      81             : 
      82           0 :     if (IsStrikeThruOverridden())
      83             :     {
      84           0 :         if(Is(STRIKETHRU))
      85             :         {
      86           0 :             pFont->SetCrossout(enumXFCrossoutSignel);
      87             :         }
      88             :         else
      89             :         {
      90           0 :             pFont->SetCrossout(enumXFCrossoutNone);
      91             :         }
      92             :     }
      93             : 
      94           0 :     if (IsSuperOverridden())
      95             :     {
      96           0 :         if(Is(SUPERSCRIPT))
      97           0 :             pFont->SetPosition(sal_True);
      98             :     }
      99             : 
     100           0 :     if (IsSubOverridden())
     101             :     {
     102           0 :         if(Is(SUBSCRIPT))
     103           0 :             pFont->SetPosition(sal_False);
     104             :     }
     105             : 
     106           0 :     if (IsUnderlineOverridden())
     107             :     {
     108           0 :         switch(m_nUnder)
     109             :         {
     110             :             case UNDER_SINGLE:
     111           0 :                 pFont->SetUnderline(enumXFUnderlineSingle);
     112           0 :                 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           0 :                 break;
     127             :                 //do nothing;
     128             :         }
     129             :     }
     130             : 
     131           0 :     if (IsCaseOverridden())
     132             :     {
     133           0 :         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           0 :             pFont->SetTransform(enumXFTransformNone);
     143           0 :             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           0 :     if (IsSmallCapsOverridden())
     158             :     {
     159           0 :         if( pFont->GetTransform()!=enumXFTransformUpper )   //SmallCaps should not override upper case
     160             :         {
     161           0 :             if(Is(SMALLCAPS))
     162           0 :                 pFont->SetTransform(enumXFTransformSmallCaps);
     163             :         }
     164             :     }
     165             : 
     166             :     // TODO: tightness
     167             :     //if (IsTightnessOverridden())
     168             :     //  pFont->SetTightness(cTightness);*/
     169           0 : }
     170             : 
     171           0 : sal_Bool LwpFontAttrEntry::Is(sal_uInt16 Attr)
     172             : {
     173           0 :     return (0 != (m_nAttrBits & Attr));
     174             : }
     175             : 
     176           0 : sal_Bool LwpFontAttrEntry::IsBoldOverridden()
     177             : {
     178           0 :     return (0 != (m_nAttrOverrideBits & BOLD));
     179             : }
     180             : 
     181           0 : sal_Bool LwpFontAttrEntry::IsItalicOverridden()
     182             : {
     183           0 :     return (0 != (m_nAttrOverrideBits & ITALIC));
     184             : }
     185           0 : sal_Bool LwpFontAttrEntry::IsStrikeThruOverridden()
     186             : {
     187           0 :     return (0 != (m_nAttrOverrideBits & STRIKETHRU));
     188             : }
     189           0 : sal_Bool LwpFontAttrEntry::IsSmallCapsOverridden()
     190             : {
     191           0 :     return (0 != (m_nAttrOverrideBits & SMALLCAPS));
     192             : }
     193           0 : sal_Bool LwpFontAttrEntry::IsSuperOverridden()
     194             : {
     195           0 :     return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
     196             : 
     197             : }
     198           0 : sal_Bool LwpFontAttrEntry::IsSubOverridden()
     199             : {
     200           0 :     return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
     201             : 
     202             : }
     203             : 
     204           0 : sal_Bool LwpFontAttrEntry::IsUnderlineOverridden()
     205             : {
     206           0 :     return (0 != (m_nAttrOverrideBits2 & UNDER));
     207             : }
     208           0 : sal_Bool LwpFontAttrEntry::IsCaseOverridden()
     209             : {
     210           0 :     return (0 != (m_nAttrOverrideBits2 & CASE));
     211             : }
     212             : 
     213           0 : void LwpFontTableEntry::Read(LwpObjectStream *pStrm)
     214             : {
     215           0 :     m_WindowsFaceName.Read(pStrm);
     216             : 
     217             :     // use the m_WindowsFaceName to set the m_FaceName temporarily
     218           0 :     m_FaceName = m_WindowsFaceName;
     219             : 
     220             :     //Skip the panoseNumber
     221             :     //m_PanoseNumber.Read(pStrm);
     222           0 :     LwpPanoseNumber thePanoseToSkip;
     223           0 :     thePanoseToSkip.Read(pStrm);
     224             : 
     225           0 :     pStrm->SkipExtra();
     226             : 
     227           0 :     RegisterFontDecl();
     228           0 : }
     229             : 
     230           0 : OUString LwpFontTableEntry::GetFaceName()
     231             : {
     232           0 :     return (m_WindowsFaceName.str());
     233             : }
     234             : 
     235           0 : void LwpFontTableEntry::RegisterFontDecl()
     236             : {
     237           0 :     if(m_FaceName.str().isEmpty()) return;
     238           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     239           0 :     XFFontDecl aFontDecl1( m_FaceName.str(), m_FaceName.str(), false );
     240           0 :     pXFStyleManager->AddFontDecl(aFontDecl1);
     241             : }
     242             : 
     243           0 : LwpFontTable::LwpFontTable()
     244             :     : m_nCount(0)
     245           0 :     , m_pFontEntries(NULL)
     246           0 : {}
     247             : 
     248           0 : void LwpFontTable::Read(LwpObjectStream *pStrm)
     249             : {
     250           0 :     m_pFontEntries = NULL;
     251           0 :     m_nCount = pStrm->QuickReaduInt16();
     252           0 :     if(m_nCount>0)
     253             :     {
     254           0 :         m_pFontEntries = new LwpFontTableEntry[m_nCount];
     255           0 :         for(sal_uInt16 i=0; i<m_nCount; i++)
     256             :         {
     257           0 :             m_pFontEntries[i].Read(pStrm);
     258             :         }
     259             :     }
     260           0 :     pStrm->SkipExtra();
     261           0 : }
     262             : 
     263           0 : OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
     264             : {
     265             :     assert(index <= m_nCount && index > 0);
     266           0 :     return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
     267             : }
     268             : 
     269           0 : LwpFontTable::~LwpFontTable()
     270             : {
     271           0 :     if(m_pFontEntries)
     272             :     {
     273           0 :         delete [] m_pFontEntries;
     274           0 :         m_pFontEntries = NULL;
     275             :     }
     276           0 : }
     277             : 
     278           0 : void LwpFontNameEntry::Read(LwpObjectStream *pStrm)
     279             : {
     280             :     //Read CFontDescriptionOverrideBase
     281           0 :     m_nOverrideBits = pStrm->QuickReaduInt8();
     282           0 :     m_nApplyBits = pStrm->QuickReaduInt8();
     283           0 :     m_nPointSize = pStrm->QuickReaduInt32();
     284           0 :     m_nOverstrike = pStrm->QuickReaduInt16();
     285           0 :     m_nTightness = pStrm->QuickReaduInt16();
     286           0 :     m_Color.Read(pStrm);
     287           0 :     m_BackColor.Read(pStrm);
     288           0 :     pStrm->SkipExtra();
     289             : 
     290             :     //Read data of LwpFontNameEntry
     291           0 :     m_nFaceName = pStrm->QuickReaduInt16();
     292           0 :     m_nAltFaceName = pStrm->QuickReaduInt16();
     293           0 :     pStrm->SkipExtra();
     294           0 : }
     295             : #include "xfilter/xfcolor.hxx"
     296           0 : void LwpFontNameEntry::Override(XFFont* pFont)
     297             : {
     298           0 :     if (IsPointSizeOverridden())
     299           0 :         pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
     300             : 
     301           0 :     if (IsColorOverridden() && m_Color.IsValidColor())
     302             :     {
     303           0 :         XFColor aColor(m_Color.To24Color());
     304           0 :         pFont->SetColor(aColor);
     305             :     }
     306             : 
     307           0 :     if (IsBackgroundColorOverridden() )
     308             :     {
     309           0 :         if (m_BackColor.IsValidColor())
     310             :         {
     311           0 :             XFColor aColor(m_BackColor.To24Color());
     312           0 :             pFont->SetBackColor( aColor );
     313             :         }
     314           0 :         else if (m_BackColor.IsTransparent())
     315             :         {
     316           0 :             pFont->SetBackColorTransparent();
     317             :         }
     318             :     }
     319             : 
     320             :     // TODO: tightness
     321             :     //if (IsTightnessOverridden())
     322             :     //  pFont->SetTightness(cTightness);
     323           0 : }
     324             : 
     325           0 : sal_Bool LwpFontNameEntry::IsFaceNameOverridden()
     326             : {
     327           0 :     return (0 != (m_nOverrideBits & FACENAME));
     328             : }
     329             : 
     330           0 : sal_Bool LwpFontNameEntry::IsAltFaceNameOverridden()
     331             : {
     332           0 :     return (0 != (m_nOverrideBits & ALTFACENAME));
     333             : }
     334             : 
     335           0 : sal_Bool LwpFontNameEntry::IsPointSizeOverridden()
     336             : {
     337           0 :     return (0 != (m_nOverrideBits & POINTSIZE));
     338             : }
     339             : 
     340           0 : sal_Bool LwpFontNameEntry::IsColorOverridden()
     341             : {
     342           0 :     return (0 != (m_nOverrideBits & COLOR));
     343             : }
     344             : 
     345           0 : sal_Bool LwpFontNameEntry::IsBackgroundColorOverridden()
     346             : {
     347           0 :     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           0 : LwpFontNameManager::LwpFontNameManager()
     362             :     : m_nCount(0)
     363           0 :     , m_pFontNames(NULL)
     364           0 : {}
     365             : 
     366           0 : LwpFontNameManager::~LwpFontNameManager()
     367             : {
     368           0 :     if(m_pFontNames)
     369             :     {
     370           0 :         delete [] m_pFontNames;
     371           0 :         m_pFontNames = NULL;
     372             :     }
     373           0 : }
     374             : 
     375           0 : void LwpFontNameManager::Read(LwpObjectStream *pStrm)
     376             : {
     377           0 :     m_nCount = pStrm->QuickReaduInt16();
     378           0 :     if(m_nCount>0)
     379             :     {
     380           0 :         m_pFontNames = new LwpFontNameEntry[m_nCount];
     381           0 :         for(sal_uInt16 i=0; i<m_nCount; i++)
     382             :         {
     383           0 :             m_pFontNames[i].Read(pStrm);
     384             :         }
     385             :     }
     386           0 :     m_FontTbl.Read(pStrm);
     387           0 :     pStrm->SkipExtra();
     388           0 : }
     389             : 
     390           0 : void    LwpFontNameManager::Override(sal_uInt16 index, XFFont* pFont)
     391             :     //index: start from 1
     392             : {
     393           0 :     if (index > m_nCount || index < 1)
     394           0 :         return ;
     395             : 
     396           0 :     m_pFontNames[index-1].Override(pFont);
     397           0 :     if(m_pFontNames[index-1].IsFaceNameOverridden())
     398           0 :         pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
     399           0 :     if(m_pFontNames[index-1].IsAltFaceNameOverridden())
     400           0 :         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           0 : void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
     409             : {
     410           0 :     m_nCount = pStrm->QuickReaduInt16();
     411           0 :     m_pFontAttrs = new LwpFontAttrEntry[m_nCount];
     412             : 
     413           0 :     for(sal_uInt16 i=0; i<m_nCount; i++)
     414             :     {
     415           0 :         m_pFontAttrs[i].Read(pStrm);
     416             :     }
     417           0 :     pStrm->SkipExtra();
     418           0 : }
     419             : 
     420           0 : void    LwpFontAttrManager::Override(sal_uInt16 index, XFFont* pFont)
     421             :     //index: start from 1
     422             : {
     423           0 :     if (index > m_nCount || index < 1)
     424           0 :         return ;
     425             : 
     426           0 :     m_pFontAttrs[index-1].Override(pFont);
     427             : }
     428             : 
     429           0 : LwpFontAttrManager::~LwpFontAttrManager()
     430             : {
     431           0 :     if(m_pFontAttrs)
     432           0 :         delete []m_pFontAttrs;
     433           0 : }
     434             : 
     435           0 : void LwpFontManager::Read(LwpObjectStream *pStrm)
     436             : {
     437           0 :     m_FNMgr.Read(pStrm);
     438           0 :     m_AttrMgr.Read(pStrm);
     439           0 :     pStrm->SkipExtra();
     440             : 
     441           0 : }
     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           0 : XFFont* LwpFontManager::CreateFont(sal_uInt32 fontID)
     481             : {
     482           0 :     XFFont* pFont = new XFFont();
     483           0 :     m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
     484           0 :     m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
     485           0 :     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 : XFFont* LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
     494             : {
     495           0 :     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, XFFont* 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