LCOV - code coverage report
Current view: top level - editeng/source/items - bulitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 56 205 27.3 %
Date: 2014-11-03 Functions: 15 26 57.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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/stream.hxx>
      21             : #include <vcl/outdev.hxx>
      22             : 
      23             : #include <editeng/bulletitem.hxx>
      24             : #include <editeng/editrids.hrc>
      25             : 
      26             : #include <tools/tenccvt.hxx>
      27             : #include <vcl/dibtools.hxx>
      28             : 
      29             : #define BULITEM_VERSION     ((sal_uInt16)2)
      30             : 
      31             : 
      32             : 
      33      315656 : TYPEINIT1(SvxBulletItem,SfxPoolItem);
      34             : 
      35             : 
      36             : 
      37           0 : void SvxBulletItem::StoreFont( SvStream& rStream, const vcl::Font& rFont )
      38             : {
      39             :     sal_uInt16 nTemp;
      40             : 
      41           0 :     WriteColor( rStream, rFont.GetColor() );
      42           0 :     nTemp = (sal_uInt16)rFont.GetFamily(); rStream.WriteUInt16( nTemp );
      43             : 
      44           0 :     nTemp = (sal_uInt16)GetSOStoreTextEncoding((rtl_TextEncoding)rFont.GetCharSet());
      45           0 :     rStream.WriteUInt16( nTemp );
      46             : 
      47           0 :     nTemp = (sal_uInt16)rFont.GetPitch(); rStream.WriteUInt16( nTemp );
      48           0 :     nTemp = (sal_uInt16)rFont.GetAlign(); rStream.WriteUInt16( nTemp );
      49           0 :     nTemp = (sal_uInt16)rFont.GetWeight(); rStream.WriteUInt16( nTemp );
      50           0 :     nTemp = (sal_uInt16)rFont.GetUnderline(); rStream.WriteUInt16( nTemp );
      51           0 :     nTemp = (sal_uInt16)rFont.GetStrikeout(); rStream.WriteUInt16( nTemp );
      52           0 :     nTemp = (sal_uInt16)rFont.GetItalic(); rStream.WriteUInt16( nTemp );
      53             : 
      54             :     // UNICODE: rStream << rFont.GetName();
      55           0 :     rStream.WriteUniOrByteString(rFont.GetName(), rStream.GetStreamCharSet());
      56             : 
      57           0 :     rStream.WriteUChar( rFont.IsOutline() );
      58           0 :     rStream.WriteUChar( rFont.IsShadow() );
      59           0 :     rStream.WriteUChar( rFont.IsTransparent() );
      60           0 : }
      61             : 
      62             : 
      63             : 
      64           0 : vcl::Font SvxBulletItem::CreateFont( SvStream& rStream, sal_uInt16 nVer )
      65             : {
      66           0 :     vcl::Font aFont;
      67           0 :     Color aColor;
      68           0 :     ReadColor( rStream, aColor );    aFont.SetColor( aColor );
      69             :     sal_uInt16 nTemp;
      70           0 :     rStream.ReadUInt16( nTemp ); aFont.SetFamily((FontFamily)nTemp);
      71             : 
      72           0 :     rStream.ReadUInt16( nTemp );
      73           0 :     nTemp = (sal_uInt16)GetSOLoadTextEncoding((rtl_TextEncoding)nTemp);
      74           0 :     aFont.SetCharSet((rtl_TextEncoding)nTemp);
      75             : 
      76           0 :     rStream.ReadUInt16( nTemp ); aFont.SetPitch((FontPitch)nTemp);
      77           0 :     rStream.ReadUInt16( nTemp ); aFont.SetAlign((FontAlign)nTemp);
      78           0 :     rStream.ReadUInt16( nTemp ); aFont.SetWeight((FontWeight)nTemp);
      79           0 :     rStream.ReadUInt16( nTemp ); aFont.SetUnderline((FontUnderline)nTemp);
      80           0 :     rStream.ReadUInt16( nTemp ); aFont.SetStrikeout((FontStrikeout)nTemp);
      81           0 :     rStream.ReadUInt16( nTemp ); aFont.SetItalic((FontItalic)nTemp);
      82             : 
      83             :     // UNICODE: rStream >> aName; aFont.SetName( aName );
      84           0 :     OUString aName = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
      85           0 :     aFont.SetName( aName );
      86             : 
      87           0 :     if( nVer == 1 )
      88             :     {
      89           0 :         sal_Int32 nHeight(0), nWidth(0);
      90           0 :         rStream.ReadInt32( nHeight ); rStream.ReadInt32( nWidth ); Size aSize( nWidth, nHeight );
      91           0 :         aFont.SetSize( aSize );
      92             :     }
      93             : 
      94             :     bool bTemp;
      95           0 :     rStream.ReadCharAsBool( bTemp ); aFont.SetOutline( bTemp );
      96           0 :     rStream.ReadCharAsBool( bTemp ); aFont.SetShadow( bTemp );
      97           0 :     rStream.ReadCharAsBool( bTemp ); aFont.SetTransparent( bTemp );
      98           0 :     return aFont;
      99             : }
     100             : 
     101             : 
     102             : 
     103             : 
     104         978 : SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
     105             : {
     106         978 :     SetDefaultFont_Impl();
     107         978 :     SetDefaults_Impl();
     108         978 :     nValidMask = 0xFFFF;
     109         978 : }
     110             : 
     111           0 : SvxBulletItem::SvxBulletItem( SvStream& rStrm, sal_uInt16 _nWhich )
     112             :     : SfxPoolItem(_nWhich)
     113             :     , pGraphicObject(NULL)
     114             :     , nStart(0)
     115             :     , nStyle(0)
     116             :     , nScale(0)
     117           0 :     , nJustify(0)
     118             : {
     119           0 :     rStrm.ReadUInt16( nStyle );
     120             : 
     121           0 :     if( nStyle != BS_BMP )
     122           0 :         aFont = CreateFont( rStrm, BULITEM_VERSION );
     123             :     else
     124             :     {
     125             :         // Safe Load with Test on empty Bitmap
     126           0 :         Bitmap          aBmp;
     127           0 :         const sal_Size    nOldPos = rStrm.Tell();
     128             :         // Ignore Errorcode when reading Bitmap,
     129             :         // see comment in SvxBulletItem::Store()
     130           0 :         bool bOldError = rStrm.GetError() ? sal_True : sal_False;
     131           0 :         ReadDIB(aBmp, rStrm, true);
     132             : 
     133           0 :         if ( !bOldError && rStrm.GetError() )
     134             :         {
     135           0 :             rStrm.ResetError();
     136             :         }
     137             : 
     138           0 :         if( aBmp.IsEmpty() )
     139             :         {
     140           0 :             rStrm.Seek( nOldPos );
     141           0 :             nStyle = BS_NONE;
     142             :         }
     143             :         else
     144           0 :             pGraphicObject = new GraphicObject( aBmp );
     145             :     }
     146             : 
     147           0 :     sal_Int32 nTmp(0);
     148           0 :     rStrm.ReadInt32( nTmp ); nWidth = nTmp;
     149           0 :     rStrm.ReadUInt16( nStart );
     150           0 :     rStrm.ReadUChar( nJustify );
     151             : 
     152           0 :     char cTmpSymbol(0);
     153           0 :     rStrm.ReadChar( cTmpSymbol );
     154             :     //convert single byte to unicode
     155           0 :     cSymbol = OUString(&cTmpSymbol, 1, aFont.GetCharSet()).toChar();
     156             : 
     157           0 :     rStrm.ReadUInt16( nScale );
     158             : 
     159             :     // UNICODE: rStrm >> aPrevText;
     160           0 :     aPrevText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     161             : 
     162             :     // UNICODE: rStrm >> aFollowText;
     163           0 :     aFollowText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     164             : 
     165           0 :     nValidMask = 0xFFFF;
     166           0 : }
     167             : 
     168        1296 : SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
     169             : {
     170        1296 :     aFont           = rItem.aFont;
     171        1296 :     pGraphicObject  = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
     172        1296 :     aPrevText       = rItem.aPrevText;
     173        1296 :     aFollowText     = rItem.aFollowText;
     174        1296 :     nStart          = rItem.nStart;
     175        1296 :     nStyle          = rItem.nStyle;
     176        1296 :     nWidth          = rItem.nWidth;
     177        1296 :     nScale          = rItem.nScale;
     178        1296 :     cSymbol         = rItem.cSymbol;
     179        1296 :     nJustify        = rItem.nJustify;
     180        1296 :     nValidMask      = rItem.nValidMask;
     181        1296 : }
     182             : 
     183             : 
     184             : 
     185        6016 : SvxBulletItem::~SvxBulletItem()
     186             : {
     187        2274 :     if( pGraphicObject )
     188           0 :         delete pGraphicObject;
     189        3742 : }
     190             : 
     191             : 
     192             : 
     193        1296 : SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
     194             : {
     195        1296 :     return new SvxBulletItem( *this );
     196             : }
     197             : 
     198             : 
     199             : 
     200           0 : SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
     201             : {
     202           0 :     return new SvxBulletItem( rStrm, Which() );
     203             : }
     204             : 
     205             : 
     206             : 
     207         978 : void SvxBulletItem::SetDefaultFont_Impl()
     208             : {
     209         978 :     aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, 0 );
     210         978 :     aFont.SetAlign( ALIGN_BOTTOM);
     211         978 :     aFont.SetTransparent( true );
     212         978 : }
     213             : 
     214             : 
     215             : 
     216         978 : void SvxBulletItem::SetDefaults_Impl()
     217             : {
     218         978 :     pGraphicObject  = NULL;
     219         978 :     nWidth          = 1200;  // 1.2cm
     220         978 :     nStart          = 1;
     221         978 :     nStyle          = BS_123;
     222         978 :     nJustify        = BJ_HLEFT | BJ_VCENTER;
     223         978 :     cSymbol         = ' ';
     224         978 :     nScale          = 75;
     225         978 : }
     226             : 
     227             : 
     228             : 
     229       21408 : sal_uInt16 SvxBulletItem::GetVersion( sal_uInt16 /*nVersion*/ ) const
     230             : {
     231       21408 :     return BULITEM_VERSION;
     232             : }
     233             : 
     234             : 
     235             : 
     236           0 : void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
     237             : {
     238           0 :     vcl::Font _aFont = GetFont();
     239           0 :     vcl::Font aNewFont = rCopyFrom.GetFont();
     240           0 :     if ( rCopyFrom.IsValid( VALID_FONTNAME ) )
     241             :     {
     242           0 :         _aFont.SetName( aNewFont.GetName() );
     243           0 :         _aFont.SetFamily( aNewFont.GetFamily() );
     244           0 :         _aFont.SetStyleName( aNewFont.GetStyleName() );
     245             :     }
     246           0 :     if ( rCopyFrom.IsValid( VALID_FONTCOLOR ) )
     247           0 :         _aFont.SetColor( aNewFont.GetColor() );
     248           0 :     if ( rCopyFrom.IsValid( VALID_SYMBOL ) )
     249           0 :         SetSymbol( rCopyFrom.GetSymbol() );
     250           0 :     if ( rCopyFrom.IsValid( VALID_BITMAP ) )
     251           0 :         SetGraphicObject( rCopyFrom.GetGraphicObject() );
     252           0 :     if ( rCopyFrom.IsValid( VALID_SCALE ) )
     253           0 :         SetScale( rCopyFrom.GetScale() );
     254           0 :     if ( rCopyFrom.IsValid( VALID_START ) )
     255           0 :         SetStart( rCopyFrom.GetStart() );
     256           0 :     if ( rCopyFrom.IsValid( VALID_STYLE ) )
     257           0 :         SetStyle( rCopyFrom.GetStyle() );
     258           0 :     if ( rCopyFrom.IsValid( VALID_PREVTEXT ) )
     259           0 :         SetPrevText( rCopyFrom.GetPrevText() );
     260           0 :     if ( rCopyFrom.IsValid( VALID_FOLLOWTEXT ) )
     261           0 :         SetFollowText( rCopyFrom.GetFollowText() );
     262             : 
     263           0 :     SetFont( _aFont );
     264           0 : }
     265             : 
     266             : 
     267             : 
     268             : 
     269        7356 : bool SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
     270             : {
     271             :     DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
     272        7356 :     const SvxBulletItem& rBullet = static_cast<const SvxBulletItem&>(rItem);
     273             :     // Compare with ValidMask, otherwise no put possible in a AttrSet if the
     274             :     // item differs only in terms of the ValidMask from an existing one.
     275       22068 :     if( nValidMask != rBullet.nValidMask    ||
     276       14712 :         nStyle != rBullet.nStyle            ||
     277       14712 :         nScale != rBullet.nScale            ||
     278       14712 :         nJustify != rBullet.nJustify        ||
     279       14712 :         nWidth != rBullet.nWidth            ||
     280       14712 :         nStart != rBullet.nStart            ||
     281       14712 :         cSymbol != rBullet.cSymbol          ||
     282       22068 :         aPrevText != rBullet.aPrevText      ||
     283        7356 :         aFollowText != rBullet.aFollowText )
     284           0 :             return false;
     285             : 
     286        7356 :     if( ( nStyle != BS_BMP ) && ( aFont != rBullet.aFont ) )
     287        3047 :         return false;
     288             : 
     289        4309 :     if( nStyle == BS_BMP )
     290             :     {
     291           0 :         if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
     292           0 :             return false;
     293             : 
     294           0 :         if( ( pGraphicObject && rBullet.pGraphicObject ) &&
     295           0 :             ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
     296           0 :               ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
     297             :         {
     298           0 :             return false;
     299             :         }
     300             :     }
     301             : 
     302        4309 :     return true;
     303             : }
     304             : 
     305             : 
     306             : 
     307           0 : SvStream& SvxBulletItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
     308             : {
     309             :     // Correction for empty bitmap
     310           0 :     if( ( nStyle == BS_BMP ) &&
     311           0 :         ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
     312             :     {
     313           0 :         if( pGraphicObject )
     314             :         {
     315           0 :             delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
     316           0 :             const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
     317             :         }
     318             : 
     319           0 :         const_cast< SvxBulletItem* >( this )->nStyle = BS_NONE;
     320             :     }
     321             : 
     322           0 :     rStrm.WriteUInt16( nStyle );
     323             : 
     324           0 :     if( nStyle != BS_BMP )
     325           0 :         StoreFont( rStrm, aFont );
     326             :     else
     327             :     {
     328           0 :         sal_Size _nStart = rStrm.Tell();
     329             : 
     330             :         // Small preliminary estimate of the size ...
     331           0 :         sal_uInt16 nFac = ( rStrm.GetCompressMode() != COMPRESSMODE_NONE ) ? 3 : 1;
     332           0 :         const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
     333           0 :         sal_uLong nBytes = aBmp.GetSizeBytes();
     334           0 :         if ( nBytes < sal_uLong(0xFF00*nFac) )
     335             :         {
     336           0 :             WriteDIB(aBmp, rStrm, false, true);
     337             :         }
     338             : 
     339           0 :         sal_Size nEnd = rStrm.Tell();
     340             :         // Item can not write with an overhead more than 64K or SfxMultiRecord
     341             :         // will crash. Then prefer to forego on the bitmap, it is only
     342             :         // important for the outliner and only for <= 5.0.
     343             :         // When reading, the stream-operator makes note of the bitmap and the
     344             :         // fact that there is none. This is now the case how it works with
     345             :         // large bitmap created from another file format, which do not occupy a
     346             :         // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
     347             :         // have problem loading it, but does not crash.
     348             : 
     349           0 :         if ( (nEnd-_nStart) > 0xFF00 )
     350           0 :             rStrm.Seek( _nStart );
     351             :     }
     352           0 :     rStrm.WriteInt32( nWidth );
     353           0 :     rStrm.WriteUInt16( nStart );
     354           0 :     rStrm.WriteUChar( nJustify );
     355           0 :     rStrm.WriteChar( OUStringToOString(OUString(cSymbol), aFont.GetCharSet()).toChar() );
     356           0 :     rStrm.WriteUInt16( nScale );
     357             : 
     358             :     // UNICODE: rStrm << aPrevText;
     359           0 :     rStrm.WriteUniOrByteString(aPrevText, rStrm.GetStreamCharSet());
     360             : 
     361             :     // UNICODE: rStrm << aFollowText;
     362           0 :     rStrm.WriteUniOrByteString(aFollowText, rStrm.GetStreamCharSet());
     363             : 
     364           0 :     return rStrm;
     365             : }
     366             : 
     367             : 
     368             : 
     369           0 : OUString SvxBulletItem::GetFullText() const
     370             : {
     371           0 :     OUStringBuffer aStr(aPrevText);
     372           0 :     aStr.append(cSymbol);
     373           0 :     aStr.append(aFollowText);
     374           0 :     return aStr.makeStringAndClear();
     375             : }
     376             : 
     377             : 
     378             : 
     379           0 : bool SvxBulletItem::GetPresentation
     380             : (
     381             :     SfxItemPresentation /*ePres*/,
     382             :     SfxMapUnit          /*eCoreUnit*/,
     383             :     SfxMapUnit          /*ePresUnit*/,
     384             :     OUString&           rText, const IntlWrapper *
     385             : )   const
     386             : {
     387           0 :     rText = GetFullText();
     388           0 :     return true;
     389             : }
     390             : 
     391             : 
     392             : 
     393           0 : const GraphicObject& SvxBulletItem::GetGraphicObject() const
     394             : {
     395           0 :     if( pGraphicObject )
     396           0 :         return *pGraphicObject;
     397             :     else
     398             :     {
     399           0 :         static const GraphicObject aDefaultObject;
     400           0 :         return aDefaultObject;
     401             :     }
     402             : }
     403             : 
     404             : 
     405             : 
     406           0 : void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
     407             : {
     408           0 :     if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
     409             :     {
     410           0 :         if( pGraphicObject )
     411             :         {
     412           0 :             delete pGraphicObject;
     413           0 :             pGraphicObject = NULL;
     414             :         }
     415             :     }
     416             :     else
     417             :     {
     418           0 :         delete pGraphicObject;
     419           0 :         pGraphicObject = new GraphicObject( rGraphicObject );
     420             :     }
     421         669 : }
     422             : 
     423             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10