LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter/xfilter - xfstylecont.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 97 118 82.2 %
Date: 2015-06-13 12:38:46 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):
      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         748 : XFStyleContainer::~XFStyleContainer()
      86             : {
      87         374 :     std::vector<IXFStyle*>::iterator it;
      88         432 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
      89             :     {
      90          58 :         IXFStyle *pStyle = *it;
      91          58 :         delete pStyle;
      92             :     }
      93         374 : }
      94             : 
      95         281 : void    XFStyleContainer::Reset()
      96             : {
      97         281 :     std::vector<IXFStyle*>::iterator it;
      98             : 
      99         514 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     100             :     {
     101         233 :         IXFStyle *pStyle = *it;
     102         233 :         delete pStyle;
     103             :     }
     104         281 :     m_aStyles.clear();
     105         281 : }
     106             : 
     107         651 : IXFStyleRet XFStyleContainer::AddStyle(IXFStyle *pStyle)
     108             : {
     109         651 :     IXFStyleRet aRet;
     110             : 
     111         651 :     IXFStyle    *pConStyle = NULL;
     112         651 :     OUString   name;
     113             : 
     114         651 :     if( !pStyle )
     115           0 :         return aRet;
     116             :     //no matter we want to delete the style or not,XFFont object should be saved first.
     117         651 :     ManageStyleFont(pStyle);
     118             : 
     119         651 :     if( pStyle->GetStyleName().isEmpty() )
     120         579 :         pConStyle = FindSameStyle(pStyle);
     121             : 
     122         651 :     if( pConStyle )//such a style has exist:
     123             :     {
     124         360 :         delete pStyle;
     125         360 :         aRet.m_pStyle = pConStyle;
     126         360 :         aRet.m_bOrigDeleted = true;
     127         360 :         return aRet;;
     128             :     }
     129             :     else
     130             :     {
     131         291 :         if( pStyle->GetStyleName().isEmpty() )
     132             :         {
     133         219 :             name = m_strStyleNamePrefix + OUString::number(m_aStyles.size()+1);
     134         219 :             pStyle->SetStyleName(name);
     135             :         }
     136             :         else
     137             :         {
     138          72 :             name = pStyle->GetStyleName();
     139             :             //for name conflict
     140          72 :             if(FindStyle( name))
     141             :             {
     142           0 :                 name = name + OUString::number(m_aStyles.size()+1);
     143           0 :                 pStyle->SetStyleName(name);
     144             :             }
     145             :         }
     146             : 
     147         291 :         m_aStyles.push_back(pStyle);
     148             :         //transform the font object to XFFontFactory
     149         291 :         aRet.m_pStyle = pStyle;
     150         291 :         return aRet;
     151         651 :     }
     152             : }
     153             : 
     154         579 : IXFStyle*   XFStyleContainer::FindSameStyle(IXFStyle *pStyle)
     155             : {
     156         579 :     std::vector<IXFStyle*>::iterator it;
     157        2248 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     158             :     {
     159        2029 :         IXFStyle *pConStyle = *it;
     160             :         assert(pConStyle);
     161        2029 :         if( pConStyle->Equal(pStyle) )
     162         360 :             return pConStyle;
     163             :     }
     164             : 
     165         219 :     return NULL;
     166             : }
     167             : 
     168         637 : IXFStyle*   XFStyleContainer::FindStyle(const OUString& name)
     169             : {
     170         637 :     std::vector<IXFStyle*>::iterator it;
     171        4633 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     172             :     {
     173        4309 :         IXFStyle *pConStyle = *it;
     174             :         assert(pConStyle);
     175        4309 :         if( pConStyle->GetStyleName() == name )
     176         313 :             return pConStyle;
     177             :     }
     178             : 
     179         324 :     return NULL;
     180             : }
     181             : 
     182           0 : const IXFStyle* XFStyleContainer::Item(size_t index) const
     183             : {
     184             :     assert(index<m_aStyles.size());
     185           0 :     if (index < m_aStyles.size())
     186             :     {
     187           0 :         return m_aStyles[index];
     188             :     }
     189           0 :     return NULL;
     190             : }
     191             : 
     192          63 : void    XFStyleContainer::ToXml(IXFStream *pStrm)
     193             : {
     194          63 :     std::vector<IXFStyle*>::iterator it;
     195             : 
     196         272 :     for( it = m_aStyles.begin(); it != m_aStyles.end(); ++it )
     197             :     {
     198         209 :         IXFStyle *pStyle = *it;
     199             :         assert(pStyle);
     200         209 :         pStyle->ToXml(pStrm);
     201             :     }
     202          63 : }
     203             : 
     204         651 : void    XFStyleContainer::ManageStyleFont(IXFStyle *pStyle)
     205             : {
     206         651 :     rtl::Reference<XFFont> pStyleFont;
     207        1302 :     rtl::Reference<XFFont> pFactoryFont;
     208             : 
     209         651 :     if( !pStyle )
     210           0 :         return;
     211             : 
     212         651 :     if( pStyle->GetStyleFamily() == enumXFStyleText )
     213             :     {
     214         180 :         XFTextStyle *pTS = static_cast<XFTextStyle*>(pStyle);
     215         180 :         pStyleFont = pTS->GetFont();
     216         180 :         if( !pStyleFont.is() )
     217           0 :             return;
     218         180 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     219         180 :         XFFontFactory* pFontFactory = pGlobal->GetXFFontFactory();
     220         180 :         pFactoryFont = pFontFactory->FindSameFont(pStyleFont);
     221             :         //this font has been exists in the factory:
     222         180 :         if( pFactoryFont.is() )
     223             :         {
     224         148 :             pTS->SetFont(pFactoryFont);
     225             :         }
     226             :         else
     227             :         {
     228          32 :             pFontFactory->AddFont(pStyleFont);
     229             :         }
     230             :     }
     231         471 :     else if( pStyle->GetStyleFamily() == enumXFStylePara )
     232             :     {
     233         257 :         XFParaStyle *pPS = static_cast<XFParaStyle*>(pStyle);
     234         257 :         pStyleFont = pPS->GetFont();
     235         257 :         if( !pStyleFont.is() )
     236           0 :             return;
     237         257 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     238         257 :         XFFontFactory* pFontFactory = pGlobal->GetXFFontFactory();
     239         257 :         pFactoryFont = pFontFactory->FindSameFont(pStyleFont);
     240             :         //this font has been exists in the factory:
     241         257 :         if( pFactoryFont.is() )
     242             :         {
     243         225 :             pPS->SetFont(pFactoryFont);
     244             :         }
     245             :         else
     246             :         {
     247          32 :             pFontFactory->AddFont(pStyleFont);
     248             :         }
     249         651 :     }
     250             : }
     251             : 
     252         157 : bool operator==(XFStyleContainer& b1, XFStyleContainer& b2)
     253             : {
     254         157 :     if( b1.m_strStyleNamePrefix != b2.m_strStyleNamePrefix )
     255           0 :         return false;
     256         157 :     if( b1.m_aStyles.size() != b2.m_aStyles.size() )
     257           5 :         return false;
     258         152 :     for( size_t i=0; i<b1.m_aStyles.size(); ++i )
     259             :     {
     260           2 :         IXFStyle *pS1 = b1.m_aStyles[i];
     261           2 :         IXFStyle *pS2 = b2.m_aStyles[i];
     262             : 
     263           2 :         if( pS1 )
     264             :         {
     265           2 :             if( !pS2 )
     266           0 :                 return false;
     267           2 :             if( !pS1->Equal(pS2) )
     268           2 :                 return false;
     269             :         }
     270             :         else
     271             :         {
     272           0 :             if( pS2 )
     273           0 :                 return false;
     274             :         }
     275             :     }
     276         150 :     return true;
     277             : }
     278             : 
     279         157 : bool operator!=(XFStyleContainer& b1, XFStyleContainer& b2)
     280             : {
     281         157 :     return !(b1==b2);
     282             : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11