LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter/xfilter - xfstylecont.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 101 125 80.8 %
Date: 2014-04-11 Functions: 10 14 71.4 %
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             :  * Font object to serial to xml filter.
      59             :  ************************************************************************/
      60             : #include "xfstylecont.hxx"
      61             : #include "ixfstyle.hxx"
      62             : #include "xffont.hxx"
      63             : #include "xftextstyle.hxx"
      64             : #include "xfparastyle.hxx"
      65             : #include "xffontfactory.hxx"
      66             : #include "../lwpglobalmgr.hxx"
      67             : 
      68          78 : XFStyleContainer::XFStyleContainer(const OUString& strStyleNamePrefix)
      69          78 :     :m_strStyleNamePrefix(strStyleNamePrefix)
      70             : {
      71          78 : }
      72             : 
      73           0 : XFStyleContainer::XFStyleContainer(const XFStyleContainer& other):IXFObject(other),
      74           0 :     m_aStyles(other.m_aStyles), m_strStyleNamePrefix(other.m_strStyleNamePrefix)
      75             : {
      76           0 : }
      77             : 
      78           0 : XFStyleContainer& XFStyleContainer::operator=(const XFStyleContainer& other)
      79             : {
      80           0 :     this->m_strStyleNamePrefix = other.m_strStyleNamePrefix;
      81           0 :     this->m_aStyles = other.m_aStyles;
      82           0 :     return *this;
      83             : }
      84             : 
      85         754 : XFStyleContainer::~XFStyleContainer()
      86             : {
      87         377 :     std::vector<IXFStyle*>::iterator it;
      88         440 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
      89             :     {
      90          63 :         IXFStyle *pStyle = *it;
      91          63 :         if( pStyle )
      92          63 :             delete pStyle;
      93             :     }
      94         377 : }
      95             : 
      96         284 : void    XFStyleContainer::Reset()
      97             : {
      98         284 :     std::vector<IXFStyle*>::iterator it;
      99             : 
     100         518 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     101             :     {
     102         234 :         IXFStyle *pStyle = *it;
     103         234 :         if( pStyle )
     104         234 :             delete pStyle;
     105             :     }
     106         284 :     m_aStyles.clear();
     107         284 : }
     108             : 
     109         665 : IXFStyle*   XFStyleContainer::AddStyle(IXFStyle *pStyle)
     110             : {
     111         665 :     IXFStyle    *pConStyle = NULL;
     112         665 :     OUString   name;
     113             : 
     114         665 :     if( !pStyle )
     115           0 :         return NULL;
     116             :     //no matter we want to delete the style or not,XFFont object should be saved first.
     117         665 :     ManageStyleFont(pStyle);
     118             : 
     119         665 :     if( pStyle->GetStyleName().isEmpty() )
     120         593 :         pConStyle = FindSameStyle(pStyle);
     121             : 
     122         665 :     if( pConStyle )//such a style has exist:
     123             :     {
     124         368 :         delete pStyle;
     125         368 :         return pConStyle;
     126             :     }
     127             :     else
     128             :     {
     129         297 :         if( pStyle->GetStyleName().isEmpty() )
     130             :         {
     131         225 :             name = m_strStyleNamePrefix + OUString::number(m_aStyles.size()+1);
     132         225 :             pStyle->SetStyleName(name);
     133             :         }
     134             :         else
     135             :         {
     136          72 :             name = pStyle->GetStyleName();
     137             :             //for name conflict
     138          72 :             if(FindStyle( name))
     139             :             {
     140           0 :                 name = name + OUString::number(m_aStyles.size()+1);
     141           0 :                 pStyle->SetStyleName(name);
     142             :             }
     143             :         }
     144             : 
     145         297 :         m_aStyles.push_back(pStyle);
     146             :         //transform the font object to XFFontFactory
     147             : 
     148         297 :         return pStyle;
     149         665 :     }
     150             : }
     151             : 
     152         593 : IXFStyle*   XFStyleContainer::FindSameStyle(IXFStyle *pStyle)
     153             : {
     154         593 :     std::vector<IXFStyle*>::iterator it;
     155        2318 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     156             :     {
     157        2093 :         IXFStyle *pConStyle = *it;
     158        2093 :         if( !pConStyle )
     159           0 :             continue;
     160             : 
     161        2093 :         if( pConStyle->Equal(pStyle) )
     162         368 :             return pConStyle;
     163             :     }
     164             : 
     165         225 :     return NULL;
     166             : }
     167             : 
     168         646 : IXFStyle*   XFStyleContainer::FindStyle(const OUString& name)
     169             : {
     170         646 :     std::vector<IXFStyle*>::iterator it;
     171        4717 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     172             :     {
     173        4390 :         IXFStyle *pConStyle = *it;
     174        4390 :         if( !pConStyle )
     175           0 :             continue;
     176             : 
     177        4390 :         if( pConStyle->GetStyleName() == name )
     178         319 :             return pConStyle;
     179             :     }
     180             : 
     181         327 :     return NULL;
     182             : }
     183             : 
     184           0 : const IXFStyle* XFStyleContainer::Item(size_t index) const
     185             : {
     186             :     assert(index<m_aStyles.size());
     187           0 :     if (index < m_aStyles.size())
     188             :     {
     189           0 :         return m_aStyles[index];
     190             :     }
     191           0 :     return NULL;
     192             : }
     193             : 
     194          63 : void    XFStyleContainer::ToXml(IXFStream *pStrm)
     195             : {
     196          63 :     std::vector<IXFStyle*>::iterator it;
     197             : 
     198         278 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     199             :     {
     200         215 :         IXFStyle *pStyle = *it;
     201             : 
     202             :         assert(pStyle);
     203         215 :         if( !pStyle )
     204           0 :             continue;
     205             : 
     206         215 :         pStyle->ToXml(pStrm);
     207             :     }
     208          63 : }
     209             : 
     210         665 : void    XFStyleContainer::ManageStyleFont(IXFStyle *pStyle)
     211             : {
     212         665 :     XFFont *pStyleFont = NULL;
     213         665 :     XFFont *pFactoryFont = NULL;
     214             : 
     215         665 :     if( !pStyle )
     216           0 :         return;
     217             : 
     218         665 :     if( pStyle->GetStyleFamily() == enumXFStyleText )
     219             :     {
     220         180 :         XFTextStyle *pTS = (XFTextStyle*)pStyle;
     221         180 :         pStyleFont = pTS->GetFont();
     222         180 :         if( !pStyleFont )
     223           0 :             return;
     224         180 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     225         180 :         XFFontFactory* pFontFactory = pGlobal->GetXFFontFactory();
     226         180 :         pFactoryFont = pFontFactory->FindSameFont(pStyleFont);
     227             :         //this font has been exists in the factory:
     228         180 :         if( pFactoryFont )
     229             :         {
     230         148 :             pTS->SetFont(pFactoryFont);
     231         148 :             if( pStyleFont != pFactoryFont )
     232         148 :                 delete pStyleFont;
     233             :         }
     234             :         else
     235             :         {
     236          32 :             pFontFactory->AddFont(pStyleFont);
     237             :         }
     238             :     }
     239         485 :     else if( pStyle->GetStyleFamily() == enumXFStylePara )
     240             :     {
     241         260 :         XFParaStyle *pPS = (XFParaStyle*)pStyle;
     242         260 :         pStyleFont = pPS->GetFont();
     243         260 :         if( !pStyleFont )
     244           0 :             return;
     245         260 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     246         260 :         XFFontFactory* pFontFactory = pGlobal->GetXFFontFactory();
     247         260 :         pFactoryFont = pFontFactory->FindSameFont(pStyleFont);
     248             :         //this font has been exists in the factory:
     249         260 :         if( pFactoryFont )
     250             :         {
     251         228 :             pPS->SetFont(pFactoryFont);
     252         228 :             if( pFactoryFont != pStyleFont )
     253          36 :                 delete pStyleFont;
     254             :         }
     255             :         else
     256             :         {
     257          32 :             pFontFactory->AddFont(pStyleFont);
     258             :         }
     259             :     }
     260             : }
     261             : 
     262         159 : bool operator==(XFStyleContainer& b1, XFStyleContainer& b2)
     263             : {
     264         159 :     if( b1.m_strStyleNamePrefix != b2.m_strStyleNamePrefix )
     265           0 :         return false;
     266         159 :     if( b1.m_aStyles.size() != b2.m_aStyles.size() )
     267           5 :         return false;
     268         154 :     for( size_t i=0; i<b1.m_aStyles.size(); ++i )
     269             :     {
     270           2 :         IXFStyle *pS1 = b1.m_aStyles[i];
     271           2 :         IXFStyle *pS2 = b2.m_aStyles[i];
     272             : 
     273           2 :         if( pS1 )
     274             :         {
     275           2 :             if( !pS2 )
     276           0 :                 return false;
     277           2 :             if( !pS1->Equal(pS2) )
     278           2 :                 return false;
     279             :         }
     280             :         else
     281             :         {
     282           0 :             if( pS2 )
     283           0 :                 return false;
     284             :         }
     285             :     }
     286         152 :     return true;
     287             : }
     288             : 
     289         159 : bool operator!=(XFStyleContainer& b1, XFStyleContainer& b2)
     290             : {
     291         159 :     return !(b1==b2);
     292             : }
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10