LCOV - code coverage report
Current view: top level - editeng/source/items - bulitem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 49 191 25.7 %
Date: 2015-06-13 12:38:46 Functions: 13 24 54.2 %
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      179738 : 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.WriteBool( rFont.IsOutline() );
      58           0 :     rStream.WriteBool( rFont.IsShadow() );
      59           0 :     rStream.WriteBool( 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         690 : SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
     105             : {
     106         690 :     SetDefaultFont_Impl();
     107         690 :     SetDefaults_Impl();
     108         690 : }
     109             : 
     110           0 : SvxBulletItem::SvxBulletItem( SvStream& rStrm, sal_uInt16 _nWhich )
     111             :     : SfxPoolItem(_nWhich)
     112             :     , pGraphicObject(NULL)
     113             :     , nStart(0)
     114             :     , nStyle(SvxBulletStyle::ABC_BIG)
     115           0 :     , nScale(0)
     116             : {
     117             :     sal_uInt16 nTmp1;
     118           0 :     rStrm.ReadUInt16( nTmp1 );
     119           0 :     nStyle = static_cast<SvxBulletStyle>(nTmp1);
     120             : 
     121           0 :     if( nStyle != SvxBulletStyle::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() != 0;
     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 = SvxBulletStyle::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 :     sal_uInt8 nTmpInt8(0);
     151           0 :     rStrm.ReadUChar( nTmpInt8 ); // used to be nJustify
     152             : 
     153           0 :     char cTmpSymbol(0);
     154           0 :     rStrm.ReadChar( cTmpSymbol );
     155             :     //convert single byte to unicode
     156           0 :     cSymbol = OUString(&cTmpSymbol, 1, aFont.GetCharSet()).toChar();
     157             : 
     158           0 :     rStrm.ReadUInt16( nScale );
     159             : 
     160             :     // UNICODE: rStrm >> aPrevText;
     161           0 :     aPrevText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     162             : 
     163             :     // UNICODE: rStrm >> aFollowText;
     164           0 :     aFollowText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     165           0 : }
     166             : 
     167         917 : SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
     168             : {
     169         917 :     aFont           = rItem.aFont;
     170         917 :     pGraphicObject  = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
     171         917 :     aPrevText       = rItem.aPrevText;
     172         917 :     aFollowText     = rItem.aFollowText;
     173         917 :     nStart          = rItem.nStart;
     174         917 :     nStyle          = rItem.nStyle;
     175         917 :     nWidth          = rItem.nWidth;
     176         917 :     nScale          = rItem.nScale;
     177         917 :     cSymbol         = rItem.cSymbol;
     178         917 : }
     179             : 
     180             : 
     181             : 
     182        4207 : SvxBulletItem::~SvxBulletItem()
     183             : {
     184        1594 :     if( pGraphicObject )
     185           0 :         delete pGraphicObject;
     186        2613 : }
     187             : 
     188             : 
     189             : 
     190         917 : SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
     191             : {
     192         917 :     return new SvxBulletItem( *this );
     193             : }
     194             : 
     195             : 
     196             : 
     197           0 : SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
     198             : {
     199           0 :     return new SvxBulletItem( rStrm, Which() );
     200             : }
     201             : 
     202             : 
     203             : 
     204         690 : void SvxBulletItem::SetDefaultFont_Impl()
     205             : {
     206         690 :     aFont = OutputDevice::GetDefaultFont( DefaultFontType::FIXED, LANGUAGE_SYSTEM, GetDefaultFontFlags::NONE );
     207         690 :     aFont.SetAlign( ALIGN_BOTTOM);
     208         690 :     aFont.SetTransparent( true );
     209         690 : }
     210             : 
     211             : 
     212             : 
     213         690 : void SvxBulletItem::SetDefaults_Impl()
     214             : {
     215         690 :     pGraphicObject  = NULL;
     216         690 :     nWidth          = 1200;  // 1.2cm
     217         690 :     nStart          = 1;
     218         690 :     nStyle          = SvxBulletStyle::N123;
     219         690 :     cSymbol         = ' ';
     220         690 :     nScale          = 75;
     221         690 : }
     222             : 
     223             : 
     224             : 
     225       12732 : sal_uInt16 SvxBulletItem::GetVersion( sal_uInt16 /*nVersion*/ ) const
     226             : {
     227       12732 :     return BULITEM_VERSION;
     228             : }
     229             : 
     230             : 
     231             : 
     232           0 : void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
     233             : {
     234           0 :     vcl::Font _aFont = GetFont();
     235           0 :     vcl::Font aNewFont = rCopyFrom.GetFont();
     236           0 :     _aFont.SetName( aNewFont.GetName() );
     237           0 :     _aFont.SetFamily( aNewFont.GetFamily() );
     238           0 :     _aFont.SetStyleName( aNewFont.GetStyleName() );
     239           0 :     _aFont.SetColor( aNewFont.GetColor() );
     240           0 :     SetSymbol( rCopyFrom.GetSymbol() );
     241           0 :     SetGraphicObject( rCopyFrom.GetGraphicObject() );
     242           0 :     SetScale( rCopyFrom.GetScale() );
     243           0 :     SetStart( rCopyFrom.GetStart() );
     244           0 :     SetStyle( rCopyFrom.GetStyle() );
     245           0 :     SetPrevText( rCopyFrom.GetPrevText() );
     246           0 :     SetFollowText( rCopyFrom.GetFollowText() );
     247           0 :     SetFont( _aFont );
     248           0 : }
     249             : 
     250             : 
     251             : 
     252             : 
     253        6407 : bool SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
     254             : {
     255             :     DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
     256        6407 :     const SvxBulletItem& rBullet = static_cast<const SvxBulletItem&>(rItem);
     257             :     // Compare with ValidMask, otherwise no put possible in a AttrSet if the
     258             :     // item differs only in terms of the ValidMask from an existing one.
     259       19221 :     if( nStyle != rBullet.nStyle            ||
     260       12814 :         nScale != rBullet.nScale            ||
     261       12814 :         nWidth != rBullet.nWidth            ||
     262       12814 :         nStart != rBullet.nStart            ||
     263       12814 :         cSymbol != rBullet.cSymbol          ||
     264       19221 :         aPrevText != rBullet.aPrevText      ||
     265        6407 :         aFollowText != rBullet.aFollowText )
     266           0 :             return false;
     267             : 
     268        6407 :     if( ( nStyle != SvxBulletStyle::BMP ) && ( aFont != rBullet.aFont ) )
     269        2816 :         return false;
     270             : 
     271        3591 :     if( nStyle == SvxBulletStyle::BMP )
     272             :     {
     273           0 :         if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
     274           0 :             return false;
     275             : 
     276           0 :         if( ( pGraphicObject && rBullet.pGraphicObject ) &&
     277           0 :             ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
     278           0 :               ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
     279             :         {
     280           0 :             return false;
     281             :         }
     282             :     }
     283             : 
     284        3591 :     return true;
     285             : }
     286             : 
     287             : 
     288             : 
     289           0 : SvStream& SvxBulletItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
     290             : {
     291             :     // Correction for empty bitmap
     292           0 :     if( ( nStyle == SvxBulletStyle::BMP ) &&
     293           0 :         ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
     294             :     {
     295           0 :         if( pGraphicObject )
     296             :         {
     297           0 :             delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
     298           0 :             const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
     299             :         }
     300             : 
     301           0 :         const_cast< SvxBulletItem* >( this )->nStyle = SvxBulletStyle::NONE;
     302             :     }
     303             : 
     304           0 :     rStrm.WriteUInt16( static_cast<sal_uInt16>(nStyle) );
     305             : 
     306           0 :     if( nStyle != SvxBulletStyle::BMP )
     307           0 :         StoreFont( rStrm, aFont );
     308             :     else
     309             :     {
     310           0 :         sal_Size _nStart = rStrm.Tell();
     311             : 
     312             :         // Small preliminary estimate of the size ...
     313           0 :         sal_uInt16 nFac = ( rStrm.GetCompressMode() != SvStreamCompressFlags::NONE ) ? 3 : 1;
     314           0 :         const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
     315           0 :         sal_uLong nBytes = aBmp.GetSizeBytes();
     316           0 :         if ( nBytes < sal_uLong(0xFF00*nFac) )
     317             :         {
     318           0 :             WriteDIB(aBmp, rStrm, false, true);
     319             :         }
     320             : 
     321           0 :         sal_Size nEnd = rStrm.Tell();
     322             :         // Item can not write with an overhead more than 64K or SfxMultiRecord
     323             :         // will crash. Then prefer to forego on the bitmap, it is only
     324             :         // important for the outliner and only for <= 5.0.
     325             :         // When reading, the stream-operator makes note of the bitmap and the
     326             :         // fact that there is none. This is now the case how it works with
     327             :         // large bitmap created from another file format, which do not occupy a
     328             :         // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
     329             :         // have problem loading it, but does not crash.
     330             : 
     331           0 :         if ( (nEnd-_nStart) > 0xFF00 )
     332           0 :             rStrm.Seek( _nStart );
     333             :     }
     334           0 :     rStrm.WriteInt32( nWidth );
     335           0 :     rStrm.WriteUInt16( nStart );
     336           0 :     rStrm.WriteUChar( 0 ); // used to be nJustify
     337           0 :     rStrm.WriteChar( OUStringToOString(OUString(cSymbol), aFont.GetCharSet()).toChar() );
     338           0 :     rStrm.WriteUInt16( nScale );
     339             : 
     340             :     // UNICODE: rStrm << aPrevText;
     341           0 :     rStrm.WriteUniOrByteString(aPrevText, rStrm.GetStreamCharSet());
     342             : 
     343             :     // UNICODE: rStrm << aFollowText;
     344           0 :     rStrm.WriteUniOrByteString(aFollowText, rStrm.GetStreamCharSet());
     345             : 
     346           0 :     return rStrm;
     347             : }
     348             : 
     349             : 
     350             : 
     351           0 : OUString SvxBulletItem::GetFullText() const
     352             : {
     353           0 :     OUStringBuffer aStr(aPrevText);
     354           0 :     aStr.append(cSymbol);
     355           0 :     aStr.append(aFollowText);
     356           0 :     return aStr.makeStringAndClear();
     357             : }
     358             : 
     359             : 
     360             : 
     361           0 : bool SvxBulletItem::GetPresentation
     362             : (
     363             :     SfxItemPresentation /*ePres*/,
     364             :     SfxMapUnit          /*eCoreUnit*/,
     365             :     SfxMapUnit          /*ePresUnit*/,
     366             :     OUString&           rText, const IntlWrapper *
     367             : )   const
     368             : {
     369           0 :     rText = GetFullText();
     370           0 :     return true;
     371             : }
     372             : 
     373             : 
     374             : 
     375           0 : const GraphicObject& SvxBulletItem::GetGraphicObject() const
     376             : {
     377           0 :     if( pGraphicObject )
     378           0 :         return *pGraphicObject;
     379             :     else
     380             :     {
     381           0 :         static const GraphicObject aDefaultObject;
     382           0 :         return aDefaultObject;
     383             :     }
     384             : }
     385             : 
     386             : 
     387             : 
     388           0 : void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
     389             : {
     390           0 :     if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
     391             :     {
     392           0 :         if( pGraphicObject )
     393             :         {
     394           0 :             delete pGraphicObject;
     395           0 :             pGraphicObject = NULL;
     396             :         }
     397             :     }
     398             :     else
     399             :     {
     400           0 :         delete pGraphicObject;
     401           0 :         pGraphicObject = new GraphicObject( rGraphicObject );
     402             :     }
     403           0 : }
     404             : 
     405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11