LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter/xfilter - xfstylemanager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 163 199 81.9 %
Date: 2015-06-13 12:38:46 Functions: 11 12 91.7 %
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             :  * Style manager for the filter.
      59             :  ************************************************************************/
      60             : 
      61             : #include <sal/config.h>
      62             : 
      63             : #include <xfparastyle.hxx>
      64             : #include "xfstylemanager.hxx"
      65             : #include <xftextstyle.hxx>
      66             : #include "ixfstyle.hxx"
      67             : 
      68           6 : XFStyleManager::XFStyleManager() : s_aStdArrowStyles( "arrow" ), s_aTextStyles( "T" ),
      69             :     s_aParaStyles( "P" ),s_aListStyles( "L" ),s_aSectionStyles( "Sect" ),
      70             :     s_aPageMasters( "PM" ),s_aMasterpages( "MP" ),s_aDateStyles( "N" ),
      71             :     s_aGraphicsStyles( "fr" ),s_aTableStyles( "table" ),s_aTableCellStyles( "cell" ),
      72           6 :     s_aTableRowStyles( "row" ),s_aTableColStyles( "col" ),s_pOutlineStyle(NULL)
      73             : {
      74           6 : }
      75             : 
      76          12 : XFStyleManager::~XFStyleManager()
      77             : {
      78           6 :     Reset();
      79           6 : }
      80             : 
      81           6 : void    XFStyleManager::Reset()
      82             : {
      83           6 :     if( s_pOutlineStyle )
      84             :     {
      85           0 :         delete s_pOutlineStyle;
      86           0 :         s_pOutlineStyle = NULL;
      87             :     }
      88             : 
      89           6 :     s_aStdTextStyles.Reset();
      90           6 :     s_aStdParaStyles.Reset();
      91           6 :     s_aStdStrokeDashStyles.Reset();
      92           6 :     s_aStdAreaStyles.Reset();
      93           6 :     s_aStdArrowStyles.Reset();
      94           6 :     s_aTextStyles.Reset();
      95           6 :     s_aParaStyles.Reset();
      96           6 :     s_aListStyles.Reset();
      97           6 :     s_aSectionStyles.Reset();
      98           6 :     s_aPageMasters.Reset();
      99           6 :     s_aMasterpages.Reset();
     100           6 :     s_aDateStyles.Reset();
     101           6 :     s_aGraphicsStyles.Reset();
     102           6 :     s_aConfigManager.Reset();
     103             :     //must clear all static containers.
     104           6 :     s_aFontDecls.clear();
     105           6 : }
     106             : 
     107          22 : void    XFStyleManager::AddFontDecl(XFFontDecl& aFontDecl)
     108             : {
     109          22 :     s_aFontDecls.push_back(aFontDecl);
     110          22 : }
     111             : 
     112         620 : IXFStyleRet XFStyleManager::AddStyle(IXFStyle *pStyle)
     113             : {
     114         620 :     IXFStyleRet aRet;
     115             : 
     116             :     assert(pStyle);
     117         620 :     OUString   name;
     118             : 
     119         620 :     name = pStyle->GetStyleName();
     120             : 
     121         620 :     if( pStyle->GetStyleFamily() == enumXFStyleText )
     122             :     {
     123         180 :         if( !name.isEmpty() )
     124             :         {
     125           0 :             aRet = s_aStdTextStyles.AddStyle(pStyle);
     126             :         }
     127             :         else
     128             :         {
     129         180 :             aRet = s_aTextStyles.AddStyle(pStyle);
     130             :         }
     131             :     }
     132         440 :     else if( pStyle->GetStyleFamily() == enumXFStylePara )
     133             :     {
     134         257 :         if( !name.isEmpty() )
     135             :         {
     136          68 :             aRet = s_aStdParaStyles.AddStyle(pStyle);
     137             :         }
     138             :         else
     139             :         {
     140         189 :             aRet = s_aParaStyles.AddStyle(pStyle);
     141             :         }
     142             :     }
     143         183 :     else if( pStyle->GetStyleFamily() == enumXFStyleDefaultPara )
     144             :     {
     145           4 :         aRet = s_aStdParaStyles.AddStyle(pStyle);
     146             :     }
     147         179 :     else if( pStyle->GetStyleFamily() == enumXFStyleList )
     148             :     {
     149          14 :         aRet = s_aListStyles.AddStyle(pStyle);
     150             :     }
     151         165 :     else if( pStyle->GetStyleFamily() == enumXFStyleSection )
     152             :     {
     153           0 :         aRet = s_aSectionStyles.AddStyle(pStyle);
     154             :     }
     155         165 :     else if( pStyle->GetStyleFamily() == enumXFStylePageMaster )
     156             :     {
     157           8 :         aRet = s_aPageMasters.AddStyle(pStyle);
     158             :     }
     159         157 :     else if( pStyle->GetStyleFamily() == enumXFStyleMasterPage )
     160             :     {
     161             :         //Master page don't need name.
     162           8 :         aRet = s_aMasterpages.AddStyle(pStyle);
     163             :     }
     164         149 :     else if( pStyle->GetStyleFamily() == enumXFStyleDate )
     165             :     {
     166           3 :         aRet = s_aDateStyles.AddStyle(pStyle);
     167             :     }
     168         146 :     else if( pStyle->GetStyleFamily() == enumXFStyleTime )
     169             :     {
     170           0 :         aRet = s_aDateStyles.AddStyle(pStyle);
     171             :     }
     172         146 :     else if( pStyle->GetStyleFamily() == enumXFStyleNumber )
     173             :     {
     174          24 :         aRet = s_aDateStyles.AddStyle(pStyle);
     175             :     }
     176         122 :     else if( pStyle->GetStyleFamily() == enumXFStylePercent )
     177             :     {
     178           0 :         aRet = s_aDateStyles.AddStyle(pStyle);
     179             :     }
     180         122 :     else if( pStyle->GetStyleFamily() == enumXFStyleCurrency )
     181             :     {
     182           0 :         aRet = s_aDateStyles.AddStyle(pStyle);
     183             :     }
     184         122 :     else if( pStyle->GetStyleFamily() == enumXFStyleGraphics )
     185             :     {
     186          31 :         aRet = s_aGraphicsStyles.AddStyle(pStyle);
     187             :     }
     188          91 :     else if( pStyle->GetStyleFamily() == enumXFStyleTable )
     189             :     {
     190           1 :         aRet = s_aTableStyles.AddStyle(pStyle);
     191             :     }
     192          90 :     else if( pStyle->GetStyleFamily() == enumXFStyleTableCell )
     193             :     {
     194          72 :         aRet = s_aTableCellStyles.AddStyle(pStyle);
     195             :     }
     196          18 :     else if( pStyle->GetStyleFamily() == enumXFStyleTableRow )
     197             :     {
     198           1 :         aRet = s_aTableRowStyles.AddStyle(pStyle);
     199             :     }
     200          17 :     else if( pStyle->GetStyleFamily() == enumXFStyleTableCol )
     201             :     {
     202           1 :         aRet = s_aTableColStyles.AddStyle(pStyle);
     203             :     }
     204          16 :     else if( pStyle->GetStyleFamily() == enumXFStyleOutline )
     205             :     {
     206           0 :         if( s_pOutlineStyle )
     207           0 :             delete s_pOutlineStyle;
     208           0 :         s_pOutlineStyle = pStyle;
     209             :     }
     210          16 :     else if( pStyle->GetStyleFamily() == enumXFStyleStrokeDash )
     211             :     {
     212           0 :         aRet = s_aStdStrokeDashStyles.AddStyle(pStyle);
     213             :     }
     214          16 :     else if( pStyle->GetStyleFamily() == enumXFStyleArea )
     215             :     {
     216           0 :         aRet = s_aStdAreaStyles.AddStyle(pStyle);
     217             :     }
     218          16 :     else if( pStyle->GetStyleFamily() == enumXFStyleArrow )
     219             :     {
     220          16 :         aRet = s_aStdArrowStyles.AddStyle(pStyle);
     221             :     }
     222           0 :     else if (pStyle->GetStyleFamily() == enumXFStyleRuby)
     223             :     {
     224           0 :         aRet = s_aRubyStyles.AddStyle(pStyle);
     225             :     }
     226             : 
     227         620 :     return aRet;
     228             : }
     229             : 
     230           8 : IXFStyle*   XFStyleManager::FindStyle(const OUString& name)
     231             : {
     232           8 :     IXFStyle *pStyle = FindParaStyle(name);
     233           8 :     if( pStyle )
     234           0 :         return pStyle;
     235           8 :     pStyle = FindTextStyle(name);
     236           8 :     if( pStyle )
     237           0 :         return pStyle;
     238           8 :     pStyle = s_aListStyles.FindStyle(name);
     239           8 :     if( pStyle )
     240           0 :         return pStyle;
     241           8 :     pStyle = s_aSectionStyles.FindStyle(name);
     242           8 :     if( pStyle )
     243           0 :         return pStyle;
     244           8 :     pStyle = s_aPageMasters.FindStyle(name);
     245           8 :     if( pStyle )
     246           0 :         return pStyle;
     247           8 :     pStyle = s_aMasterpages.FindStyle(name);
     248           8 :     if( pStyle )
     249           0 :         return pStyle;
     250           8 :     pStyle = s_aDateStyles.FindStyle(name);
     251           8 :     if( pStyle )
     252           0 :         return pStyle;
     253           8 :     pStyle = s_aGraphicsStyles.FindStyle(name);
     254           8 :     if( pStyle )
     255           0 :         return pStyle;
     256           8 :     pStyle = s_aTableStyles.FindStyle(name);
     257           8 :     if( pStyle )
     258           0 :         return pStyle;
     259           8 :     pStyle = s_aTableCellStyles.FindStyle(name);
     260           8 :     if( pStyle )
     261           0 :         return pStyle;
     262           8 :     pStyle = s_aTableRowStyles.FindStyle(name);
     263           8 :     if( pStyle )
     264           0 :         return pStyle;
     265           8 :     pStyle = s_aTableColStyles.FindStyle(name);
     266           8 :     if( pStyle )
     267           0 :         return pStyle;
     268           8 :     if(s_pOutlineStyle && s_pOutlineStyle->GetStyleName() == name )
     269           0 :         return s_pOutlineStyle;
     270           8 :     pStyle = s_aStdStrokeDashStyles.FindStyle(name);
     271           8 :     if( pStyle )
     272           0 :         return pStyle;
     273           8 :     pStyle = s_aStdAreaStyles.FindStyle(name);
     274           8 :     if( pStyle )
     275           0 :         return pStyle;
     276           8 :     pStyle = s_aStdArrowStyles.FindStyle(name);
     277           8 :     if( pStyle )
     278           0 :         return pStyle;
     279             : 
     280           8 :     return NULL;
     281             : }
     282             : 
     283         321 : XFParaStyle*    XFStyleManager::FindParaStyle(const OUString& name)
     284             : {
     285         321 :     IXFStyle *pStyle = s_aParaStyles.FindStyle(name);
     286         321 :     if( pStyle )
     287         197 :         return static_cast<XFParaStyle*>(pStyle);
     288             :     else
     289         124 :         return static_cast<XFParaStyle*>(s_aStdParaStyles.FindStyle(name));
     290             : }
     291             : 
     292           8 : XFTextStyle*    XFStyleManager::FindTextStyle(const OUString& name)
     293             : {
     294           8 :     IXFStyle *pStyle = s_aTextStyles.FindStyle(name);
     295           8 :     if( pStyle )
     296           0 :         return static_cast<XFTextStyle*>(pStyle);
     297             :     else
     298           8 :         return static_cast<XFTextStyle*>(s_aStdTextStyles.FindStyle(name));
     299             : }
     300             : 
     301           0 : void    XFStyleManager::SetLineNumberConfig(XFLineNumberConfig *pLNConf)
     302             : {
     303           0 :     s_aConfigManager.SetLineNumberConfig(pLNConf);
     304           0 : }
     305             : 
     306           4 : void    XFStyleManager::SetFootnoteConfig(XFFootnoteConfig *pFNConfig)
     307             : {
     308           4 :     s_aConfigManager.SetFootnoteConfig(pFNConfig);
     309           4 : }
     310             : 
     311           4 : void    XFStyleManager::SetEndnoteConfig(XFEndnoteConfig *pENConfig)
     312             : {
     313           4 :     s_aConfigManager.SetEndnoteConfig(pENConfig);
     314           4 : }
     315             : 
     316           3 : void    XFStyleManager::ToXml(IXFStream *pStrm)
     317             : {
     318           3 :     std::vector<XFFontDecl>::iterator   itDecl;
     319           3 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     320             : 
     321           3 :     pAttrList->Clear();
     322           3 :     pStrm->StartElement( "office:font-decls" );
     323             : 
     324             :     //font declarations:
     325          20 :     for( itDecl = s_aFontDecls.begin(); itDecl != s_aFontDecls.end(); ++itDecl )
     326             :     {
     327          17 :         XFFontDecl &f = *itDecl;
     328             : 
     329          17 :         pAttrList->Clear();
     330          17 :         pAttrList->AddAttribute( "style:name", f.GetFontName() );
     331          17 :         pAttrList->AddAttribute( "fo:font-family", f.GetFontFamily() );
     332          17 :         if( f.GetFontPitchFixed() )
     333           0 :             pAttrList->AddAttribute( "style:font-pitch", "fixed" );
     334             :         else
     335          17 :             pAttrList->AddAttribute( "style:font-pitch", "variable" );
     336          17 :         pStrm->StartElement( "style:font-decl" );
     337          17 :         pStrm->EndElement( "style:font-decl" );
     338             :     }
     339             : 
     340           3 :     pStrm->EndElement( "office:font-decls" );
     341             : 
     342             :     //office:styles:
     343           3 :     pAttrList->Clear();
     344           3 :     pStrm->StartElement( "office:styles" );
     345             : 
     346           3 :     s_aStdParaStyles.ToXml(pStrm);
     347           3 :     s_aStdTextStyles.ToXml(pStrm);
     348           3 :     s_aStdStrokeDashStyles.ToXml(pStrm);
     349           3 :     s_aStdAreaStyles.ToXml(pStrm);
     350           3 :     s_aStdArrowStyles.ToXml(pStrm);
     351             :     //date,time styles:
     352           3 :     s_aDateStyles.ToXml(pStrm);
     353           3 :     s_aConfigManager.ToXml(pStrm);
     354             :     //for optimist.
     355           3 :     s_aListStyles.ToXml(pStrm);
     356             : 
     357           3 :     if( s_pOutlineStyle )
     358           0 :         s_pOutlineStyle->ToXml(pStrm);
     359             : 
     360           3 :     pStrm->EndElement( "office:styles" );
     361             : 
     362             :     //automatic styles:
     363           3 :     pAttrList->Clear();
     364           3 :     pStrm->StartElement( "office:automatic-styles" );
     365             : 
     366           3 :     s_aTableStyles.ToXml(pStrm);
     367           3 :     s_aTableCellStyles.ToXml(pStrm);
     368           3 :     s_aTableRowStyles.ToXml(pStrm);
     369           3 :     s_aTableColStyles.ToXml(pStrm);
     370           3 :     s_aParaStyles.ToXml(pStrm);
     371           3 :     s_aTextStyles.ToXml(pStrm);
     372           3 :     s_aSectionStyles.ToXml(pStrm);
     373           3 :     s_aPageMasters.ToXml(pStrm);
     374           3 :     s_aRubyStyles.ToXml(pStrm);
     375             :     //graphics:
     376           3 :     s_aGraphicsStyles.ToXml(pStrm);
     377             : 
     378           3 :     pStrm->EndElement( "office:automatic-styles" );
     379             : 
     380             :     //master:styles
     381           3 :     pAttrList->Clear();
     382           3 :     pStrm->StartElement( "office:master-styles" );
     383             :     //masters pages:
     384           3 :     s_aMasterpages.ToXml(pStrm);
     385             : 
     386           3 :     pStrm->EndElement( "office:master-styles" );
     387           3 : }
     388             : 
     389             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11