LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter/xfilter - xffont.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 107 152 70.4 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.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             : /*************************************************************************
      57             :  * @file
      58             :  * Font object to serial to xml filter.
      59             :  ************************************************************************/
      60             : #include "xffont.hxx"
      61             : 
      62         258 : XFFont::XFFont()
      63             :     : m_nFontSize(0)
      64             :     , m_nFontSizeAsia(0)
      65             :     , m_nFontSizeComplex(0)
      66             :     , m_bItalic(false)
      67             :     , m_bItalicAsia(false)
      68             :     , m_bItalicComplex(false)
      69             :     , m_bBold(false)
      70             :     , m_bBoldAsia(false)
      71             :     , m_bBoldComplex(false)
      72             :     , m_eUnderline(enumXFUnderlineNone)
      73             :     , m_eCrossout(enumXFCrossoutNone)
      74             :     , m_eRelief(enumXFReliefNone)
      75             :     , m_eTransform(enumXFTransformNone)
      76             :     , m_eEmphasize(enumXFEmphasizeNone)
      77             :     , m_bWordByWord(false)
      78             :     , m_bEmphasizeTop(true)
      79             :     , m_bOutline(false)
      80             :     , m_bShadow(false)
      81             :     , m_bBlink(false)
      82             :     , m_nPosition(33)
      83             :     , m_nScale(58)
      84             :     , m_fCharSpace(0)
      85             :     , m_nWidthScale(100)
      86             :     , m_nFlag(0)
      87         258 :     , m_bTransparent(false)
      88             : {
      89         258 : }
      90             : /*
      91             :     The Following variable are to  be compared:
      92             :         OUString   m_strFontName;
      93             :         OUString   m_strFontNameAsia;
      94             :         OUString   m_strFontNameComplex;
      95             :         sal_Int16       m_nFontSize;
      96             :         sal_Int16       m_nFontSizeAsia;
      97             :         sal_Int16       m_nFontSizeComplex;
      98             :         sal_Bool        m_bItalic;
      99             :         sal_Bool        m_bItalicAsia;
     100             :         sal_Bool        m_bItalicComplex;
     101             :         sal_Bool        m_bBold;
     102             :         sal_Bool        m_bBoldAsia;
     103             :         sal_Bool        m_bBoldComplex;
     104             :         sal_Int16       m_nUnderline;
     105             :         sal_uInt32      m_nUnderlineColor;
     106             : 
     107             :         sal_uInt32      m_nFlag;
     108             : */
     109        3891 : bool operator==(XFFont& f1, XFFont& f2)
     110             : {
     111             :     //The most possible entry be first:
     112        3891 :     if( f1.m_nFlag != f2.m_nFlag )
     113        2788 :         return false;
     114             : 
     115        3251 :     if( f1.m_strFontName != f2.m_strFontName ||
     116        2148 :         f1.m_strFontNameAsia != f2.m_strFontNameAsia ||
     117        1045 :         f1.m_strFontNameComplex != f2.m_strFontNameComplex
     118             :         )
     119          58 :         return false;
     120             : 
     121        1722 :     if( f1.m_nFontSize != f2.m_nFontSize ||
     122        1354 :         f1.m_nFontSizeAsia != f2.m_nFontSizeAsia ||
     123         677 :         f1.m_nFontSizeComplex != f2.m_nFontSizeComplex
     124             :         )
     125         368 :         return false;
     126             : 
     127        1354 :     if( f1.m_bItalic != f2.m_bItalic ||
     128        1354 :         f1.m_bItalicAsia != f2.m_bItalicAsia ||
     129         677 :         f1.m_bItalicComplex != f2.m_bItalicComplex
     130             :         )
     131           0 :         return false;
     132             : 
     133        1350 :     if( f1.m_bBold != f2.m_bBold ||
     134        1346 :         f1.m_bBoldAsia != f2.m_bBoldAsia ||
     135         673 :         f1.m_bBoldComplex != f2.m_bBoldComplex
     136             :         )
     137           4 :         return false;
     138             : 
     139         673 :     if( f1.m_nFlag&XFFONT_FLAG_UNDERLINE )
     140             :     {
     141           0 :         if( f1.m_eUnderline != f2.m_eUnderline )
     142           0 :             return false;
     143             :     }
     144             : 
     145         673 :     if( f1.m_nFlag&XFFONT_FLAG_UNDERLINECOLOR )
     146             :     {
     147           0 :         if( f1.m_aUnderlineColor != f2.m_aUnderlineColor )
     148           0 :             return false;
     149             :     }
     150             : 
     151         673 :     if( f1.m_nFlag&XFFONT_FLAG_CROSSOUT )
     152             :     {
     153         375 :         if( f1.m_eCrossout != f2.m_eCrossout )
     154           0 :             return false;
     155             :     }
     156             : 
     157         673 :     if( f1.m_nFlag&XFFONT_FLAG_RELIEF )
     158             :     {
     159           0 :         if( f1.m_eRelief != f2.m_eRelief )
     160           0 :             return false;
     161             :     }
     162             : 
     163         673 :     if( f1.m_nFlag&XFFONT_FLAG_TRANSFORM )
     164             :     {
     165         375 :         if( f1.m_eTransform != f2.m_eTransform )
     166           0 :             return false;
     167             :     }
     168             : 
     169         673 :     if( f1.m_nFlag&XFFONT_FLAG_EMPHASIZE )
     170             :     {
     171           0 :         if( f1.m_eEmphasize != f2.m_eEmphasize )
     172           0 :             return false;
     173           0 :         if( f1.m_bEmphasizeTop != f2.m_bEmphasizeTop )
     174           0 :             return false;
     175             :     }
     176             : 
     177         673 :     if( f1.m_bWordByWord != f2.m_bWordByWord )
     178           0 :         return false;
     179             : 
     180         673 :     if( f1.m_nFlag&XFFONT_FLAG_OUTLINE )
     181             :     {
     182           0 :         if( f1.m_bOutline != f2.m_bOutline )
     183           0 :             return false;
     184             :     }
     185             : 
     186         673 :     if( f1.m_nFlag&XFFONT_FLAG_SHADOW )
     187             :     {
     188           0 :         if( f1.m_bShadow != f2.m_bShadow )
     189           0 :             return false;
     190             :     }
     191             : 
     192         673 :     if( f1.m_nFlag&XFFONT_FLAG_BLINK )
     193             :     {
     194           0 :         if( f1.m_bBlink != f2.m_bBlink )
     195           0 :             return false;
     196             :     }
     197             : 
     198         673 :     if( f1.m_nFlag&XFFONT_FLAG_POSITION )
     199             :     {
     200           2 :         if( f1.m_nPosition != f2.m_nPosition )
     201           2 :             return false;
     202             :     }
     203             : 
     204         671 :     if( f1.m_nFlag&XFFONT_FLAG_SCALE )
     205             :     {
     206           0 :         if( f1.m_nScale != f2.m_nScale )
     207           0 :             return false;
     208             :     }
     209             : 
     210         671 :     if( f1.m_nFlag&XFFONT_FLAG_CHARSPACE )
     211             :     {
     212           0 :         if( f1.m_fCharSpace != f2.m_fCharSpace )
     213           0 :             return false;
     214             :     }
     215             : 
     216         671 :     if( f1.m_nFlag&XFFONT_FLAG_WIDTHSCALE )
     217             :     {
     218           0 :         if( f1.m_nWidthScale != f2.m_nWidthScale )
     219           0 :             return false;
     220             :     }
     221             : 
     222         671 :     if( f1.m_nFlag&XFFONT_FLAG_COLOR )
     223             :     {
     224         399 :         if( f1.m_aColor != f2.m_aColor )
     225           0 :             return false;
     226             :     }
     227             : 
     228         671 :     if( f1.m_nFlag&XFFONT_FLAG_BGCOLOR )
     229             :     {
     230         375 :         if( f1.m_aBackColor != f2.m_aBackColor )
     231           0 :             return false;
     232             :     }
     233             : 
     234         671 :     return true;
     235             : }
     236             : 
     237         886 : bool operator!=(XFFont& f1, XFFont& f2)
     238             : {
     239         886 :     return !(f1==f2);
     240             : }
     241             : 
     242         100 : void XFFont::ToXml(IXFStream *pStrm)
     243             : {
     244         100 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     245             : 
     246         100 :     if( m_nFlag & XFFONT_FLAG_NAME )
     247             :     {
     248          88 :         pAttrList->AddAttribute("style:font-name",m_strFontName );
     249             :     }
     250             : 
     251         100 :     if( m_nFlag & XFFONT_FLAG_NAME_ASIA )
     252             :     {
     253          88 :         pAttrList->AddAttribute("style:font-name-asian",m_strFontNameAsia );
     254             :     }
     255             : 
     256         100 :     if( m_nFlag & XFFONT_FLAG_NAME_COMPLEX )
     257             :     {
     258          88 :         pAttrList->AddAttribute("style:font-name-complex", m_strFontNameComplex);
     259             :     }
     260             : 
     261             :     //font size:
     262         100 :     if( (m_nFlag & XFFONT_FLAG_SIZE) && m_nFontSize != 0 )
     263             :     {
     264          86 :         OUString strSize = OUString::number(m_nFontSize);
     265          86 :         strSize += "pt";
     266          86 :         pAttrList->AddAttribute("fo:font-size",strSize);
     267             :     }
     268         100 :     if( (m_nFlag & XFFONT_FLAG_SIZE_ASIA) && m_nFontSizeAsia )
     269             :     {
     270          86 :         OUString strSize = OUString::number(m_nFontSizeAsia);
     271          86 :         strSize += "pt";
     272          86 :         pAttrList->AddAttribute("style:font-size-asian",strSize);
     273             :     }
     274         100 :     if( (m_nFlag & XFFONT_FLAG_SIZE_COMPLEX) && m_nFontSizeComplex )
     275             :     {
     276          86 :         OUString strSize = OUString::number(m_nFontSizeComplex);
     277          86 :         strSize += "pt";
     278          86 :         pAttrList->AddAttribute("style:font-size-complex",strSize);
     279             :     }
     280             : 
     281             :     //italic flag:
     282         100 :     if( ( m_nFlag & XFFONT_FLAG_ITALIC) && m_bItalic )
     283             :     {
     284           3 :         pAttrList->AddAttribute("fo:font-style", "italic");
     285             :     }
     286         100 :     if( (m_nFlag & XFFONT_FLAG_ITALIC_ASIA) && m_bItalicAsia )
     287             :     {
     288           3 :         pAttrList->AddAttribute("style:font-style-asian", "italic");
     289             :     }
     290         100 :     if( (m_nFlag & XFFONT_FLAG_ITALIC_COMPLEX) && m_bItalicComplex )
     291             :     {
     292           3 :         pAttrList->AddAttribute("style:font-style-complex", "italic");
     293             :     }
     294             : 
     295             :     //Bold flag:
     296         100 :     if( (m_nFlag & XFFONT_FLAG_BOLD) && m_bBold )
     297             :     {
     298          13 :         pAttrList->AddAttribute("fo:font-weight", "bold");
     299             :     }
     300         100 :     if( (m_nFlag & XFFONT_FLAG_BOLD_ASIA) && m_bBoldAsia )
     301             :     {
     302          13 :         pAttrList->AddAttribute("style:font-weight-asian", "bold");
     303             :     }
     304         100 :     if( (m_nFlag & XFFONT_FLAG_BOLD_ASIA) && m_bBoldComplex )
     305             :     {
     306          13 :         pAttrList->AddAttribute("style:font-weight-complex", "bold");
     307             :     }
     308             :     //underline:
     309         100 :     if( (m_nFlag & XFFONT_FLAG_UNDERLINE) && m_eUnderline )
     310             :     {
     311           1 :         pAttrList->AddAttribute("style:text-underline", GetUnderlineName(m_eUnderline) );
     312           1 :         if( (m_nFlag & XFFONT_FLAG_UNDERLINECOLOR) )
     313             :         {
     314           0 :             pAttrList->AddAttribute( "style:text-underline-color", m_aUnderlineColor.ToString() );
     315             :         }
     316             :         else
     317           1 :             pAttrList->AddAttribute( "style:text-underline-color", "font-color" );
     318             :     }
     319             : 
     320             :     //enumCrossoutType  m_eCrossout;
     321         100 :     if( (m_nFlag & XFFONT_FLAG_CROSSOUT) && m_eCrossout )
     322             :     {
     323           1 :         pAttrList->AddAttribute("style:text-crossing-out", GetCrossoutName(m_eCrossout) );
     324             :     }
     325             : 
     326         100 :     if( m_nFlag & XFFONT_FLAG_UNDERLINE || m_nFlag & XFFONT_FLAG_CROSSOUT )
     327             :     {
     328          73 :         if( m_bWordByWord )
     329           0 :             pAttrList->AddAttribute("fo:score-spaces", "false" );
     330             :         else
     331          73 :             pAttrList->AddAttribute("fo:score-spaces", "true" );
     332             :     }
     333             : 
     334         100 :     if( (m_nFlag & XFFONT_FLAG_RELIEF) && m_eRelief )
     335             :     {
     336           0 :         pAttrList->AddAttribute("style:font-relief", GetReliefName(m_eRelief) );
     337             :     }
     338             : 
     339         100 :     if( (m_nFlag & XFFONT_FLAG_TRANSFORM) && m_eTransform )
     340             :     {
     341             :         //enumTransformSmallCap is different:
     342           0 :         if( m_eTransform == enumXFTransformSmallCaps )
     343           0 :             pAttrList->AddAttribute("fo:font-variant", GetTransformName(m_eTransform) );
     344             :         else
     345           0 :             pAttrList->AddAttribute("fo:text-transform", GetTransformName(m_eTransform) );
     346             :     }
     347             : 
     348         100 :     if( (m_nFlag & XFFONT_FLAG_EMPHASIZE) && m_eEmphasize )
     349             :     {
     350           0 :         OUString empha = GetEmphasizeName(m_eEmphasize);
     351           0 :         empha += " ";
     352           0 :         if( m_bEmphasizeTop )
     353           0 :             empha += "above";
     354           0 :         pAttrList->AddAttribute("style:text-emphasize", empha );
     355             :     }
     356             : 
     357         100 :     if( (m_nFlag & XFFONT_FLAG_OUTLINE) && m_bOutline )
     358             :     {
     359           0 :         pAttrList->AddAttribute("style:text-outline", "true" );
     360             :     }
     361             : 
     362         100 :     if( (m_nFlag & XFFONT_FLAG_SHADOW) && m_bShadow )
     363             :     {
     364           0 :         pAttrList->AddAttribute("fo:text-shadow", "1pt 1pt" );
     365             :     }
     366             : 
     367         100 :     if( (m_nFlag & XFFONT_FLAG_BLINK) && m_bBlink )
     368             :     {
     369           0 :         pAttrList->AddAttribute("style:text-blinking", "true" );
     370             :     }
     371             : 
     372             :     //position & sacle:
     373         200 :     if( ((m_nFlag & XFFONT_FLAG_SCALE) && m_nScale>0 ) ||
     374         102 :         ((m_nFlag & XFFONT_FLAG_POSITION) && m_nPosition != 0)
     375             :         )
     376             :     {
     377           2 :         OUString tmp;
     378           2 :         tmp = OUString::number(m_nPosition) + "% ";
     379           2 :         tmp += OUString::number(m_nScale) + "%";
     380           2 :         pAttrList->AddAttribute("style:text-position", tmp );
     381             :     }
     382             : 
     383             :     //char space:
     384         100 :     if( (m_nFlag & XFFONT_FLAG_CHARSPACE) && m_fCharSpace != 0 )
     385             :     {
     386           0 :         pAttrList->AddAttribute("fo:letter-spacing", OUString::number(m_fCharSpace)+"cm" );
     387             :     }
     388             : 
     389         100 :     if( (m_nFlag&XFFONT_FLAG_WIDTHSCALE) && m_nWidthScale != 100 )
     390             :     {
     391           0 :         pAttrList->AddAttribute("style:text-scale", OUString::number(m_nWidthScale)+"%" );
     392             :     }
     393             : 
     394             :     //Color:
     395         100 :     if( (m_nFlag & XFFONT_FLAG_COLOR) )
     396             :     {
     397          83 :         pAttrList->AddAttribute( "fo:color", m_aColor.ToString() );
     398             :     }
     399             : 
     400         100 :     if( (m_nFlag & XFFONT_FLAG_BGCOLOR) )
     401             :     {
     402          71 :         if (m_bTransparent)
     403          71 :             pAttrList->AddAttribute( "style:text-background-color", "transparent");
     404             :         else
     405           0 :             pAttrList->AddAttribute( "style:text-background-color", m_aBackColor.ToString() );
     406             :     }
     407         100 : }
     408             : 
     409             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11