LCOV - code coverage report
Current view: top level - editeng/source/items - bulitem.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 55 211 26.1 %
Date: 2014-04-11 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      119019 : TYPEINIT1(SvxBulletItem,SfxPoolItem);
      34             : 
      35             : 
      36             : 
      37           0 : void SvxBulletItem::StoreFont( SvStream& rStream, const 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 : Font SvxBulletItem::CreateFont( SvStream& rStream, sal_uInt16 nVer )
      65             : {
      66           0 :     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             :         //#fdo39428 SvStream no longer supports operator>>(long&)
      90           0 :         sal_Int32 nHeight(0), nWidth(0);
      91           0 :         rStream.ReadInt32( nHeight ); rStream.ReadInt32( nWidth ); Size aSize( nWidth, nHeight );
      92           0 :         aFont.SetSize( aSize );
      93             :     }
      94             : 
      95             :     sal_Bool bTemp;
      96           0 :     rStream.ReadUChar( bTemp ); aFont.SetOutline( bTemp );
      97           0 :     rStream.ReadUChar( bTemp ); aFont.SetShadow( bTemp );
      98           0 :     rStream.ReadUChar( bTemp ); aFont.SetTransparent( bTemp );
      99           0 :     return aFont;
     100             : }
     101             : 
     102             : 
     103             : 
     104             : 
     105         365 : SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
     106             : {
     107         365 :     SetDefaultFont_Impl();
     108         365 :     SetDefaults_Impl();
     109         365 :     nValidMask = 0xFFFF;
     110         365 : }
     111             : 
     112             : 
     113             : 
     114           0 : SvxBulletItem::SvxBulletItem( SvStream& rStrm, sal_uInt16 _nWhich )
     115             :     : SfxPoolItem(_nWhich)
     116             :     , pGraphicObject(NULL)
     117           0 :     , nStyle(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 :         sal_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             :     //#fdo39428 SvStream no longer supports operator>>(long&)
     148           0 :     sal_Int32 nTmp(0);
     149           0 :     rStrm.ReadInt32( nTmp ); nWidth = nTmp;
     150           0 :     rStrm.ReadUInt16( nStart );
     151           0 :     rStrm.ReadUChar( nJustify );
     152             : 
     153             :     char cTmpSymbol;
     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             : 
     166           0 :     nValidMask = 0xFFFF;
     167           0 : }
     168             : 
     169             : 
     170             : 
     171         553 : SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
     172             : {
     173         553 :     aFont           = rItem.aFont;
     174         553 :     pGraphicObject  = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
     175         553 :     aPrevText       = rItem.aPrevText;
     176         553 :     aFollowText     = rItem.aFollowText;
     177         553 :     nStart          = rItem.nStart;
     178         553 :     nStyle          = rItem.nStyle;
     179         553 :     nWidth          = rItem.nWidth;
     180         553 :     nScale          = rItem.nScale;
     181         553 :     cSymbol         = rItem.cSymbol;
     182         553 :     nJustify        = rItem.nJustify;
     183         553 :     nValidMask      = rItem.nValidMask;
     184         553 : }
     185             : 
     186             : 
     187             : 
     188        2221 : SvxBulletItem::~SvxBulletItem()
     189             : {
     190         837 :     if( pGraphicObject )
     191           0 :         delete pGraphicObject;
     192        1384 : }
     193             : 
     194             : 
     195             : 
     196         553 : SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
     197             : {
     198         553 :     return new SvxBulletItem( *this );
     199             : }
     200             : 
     201             : 
     202             : 
     203           0 : SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
     204             : {
     205           0 :     return new SvxBulletItem( rStrm, Which() );
     206             : }
     207             : 
     208             : 
     209             : 
     210         365 : void SvxBulletItem::SetDefaultFont_Impl()
     211             : {
     212         365 :     aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, 0 );
     213         365 :     aFont.SetAlign( ALIGN_BOTTOM);
     214         365 :     aFont.SetTransparent( true );
     215         365 : }
     216             : 
     217             : 
     218             : 
     219         365 : void SvxBulletItem::SetDefaults_Impl()
     220             : {
     221         365 :     pGraphicObject  = NULL;
     222         365 :     nWidth          = 1200;  // 1.2cm
     223         365 :     nStart          = 1;
     224         365 :     nStyle          = BS_123;
     225         365 :     nJustify        = BJ_HLEFT | BJ_VCENTER;
     226         365 :     cSymbol         = ' ';
     227         365 :     nScale          = 75;
     228         365 : }
     229             : 
     230             : 
     231             : 
     232        6888 : sal_uInt16 SvxBulletItem::GetVersion( sal_uInt16 /*nVersion*/ ) const
     233             : {
     234        6888 :     return BULITEM_VERSION;
     235             : }
     236             : 
     237             : 
     238             : 
     239           0 : void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
     240             : {
     241           0 :     Font _aFont = GetFont();
     242           0 :     Font aNewFont = rCopyFrom.GetFont();
     243           0 :     if ( rCopyFrom.IsValid( VALID_FONTNAME ) )
     244             :     {
     245           0 :         _aFont.SetName( aNewFont.GetName() );
     246           0 :         _aFont.SetFamily( aNewFont.GetFamily() );
     247           0 :         _aFont.SetStyleName( aNewFont.GetStyleName() );
     248             :     }
     249           0 :     if ( rCopyFrom.IsValid( VALID_FONTCOLOR ) )
     250           0 :         _aFont.SetColor( aNewFont.GetColor() );
     251           0 :     if ( rCopyFrom.IsValid( VALID_SYMBOL ) )
     252           0 :         SetSymbol( rCopyFrom.GetSymbol() );
     253           0 :     if ( rCopyFrom.IsValid( VALID_BITMAP ) )
     254           0 :         SetGraphicObject( rCopyFrom.GetGraphicObject() );
     255           0 :     if ( rCopyFrom.IsValid( VALID_SCALE ) )
     256           0 :         SetScale( rCopyFrom.GetScale() );
     257           0 :     if ( rCopyFrom.IsValid( VALID_START ) )
     258           0 :         SetStart( rCopyFrom.GetStart() );
     259           0 :     if ( rCopyFrom.IsValid( VALID_STYLE ) )
     260           0 :         SetStyle( rCopyFrom.GetStyle() );
     261           0 :     if ( rCopyFrom.IsValid( VALID_PREVTEXT ) )
     262           0 :         SetPrevText( rCopyFrom.GetPrevText() );
     263           0 :     if ( rCopyFrom.IsValid( VALID_FOLLOWTEXT ) )
     264           0 :         SetFollowText( rCopyFrom.GetFollowText() );
     265             : 
     266           0 :     SetFont( _aFont );
     267           0 : }
     268             : 
     269             : 
     270             : 
     271             : 
     272        3053 : bool SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
     273             : {
     274             :     DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
     275        3053 :     const SvxBulletItem& rBullet = (const SvxBulletItem&)rItem;
     276             :     // Compare with ValidMask, otherwise no put possible in a AttrSet if the
     277             :     // item differs only in terms of the ValidMask from an existing one.
     278        9159 :     if( nValidMask != rBullet.nValidMask    ||
     279        6106 :         nStyle != rBullet.nStyle            ||
     280        6106 :         nScale != rBullet.nScale            ||
     281        6106 :         nJustify != rBullet.nJustify        ||
     282        6106 :         nWidth != rBullet.nWidth            ||
     283        6106 :         nStart != rBullet.nStart            ||
     284        6106 :         cSymbol != rBullet.cSymbol          ||
     285        9159 :         aPrevText != rBullet.aPrevText      ||
     286        3053 :         aFollowText != rBullet.aFollowText )
     287           0 :             return false;
     288             : 
     289        3053 :     if( ( nStyle != BS_BMP ) && ( aFont != rBullet.aFont ) )
     290        1228 :         return false;
     291             : 
     292        1825 :     if( nStyle == BS_BMP )
     293             :     {
     294           0 :         if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
     295           0 :             return false;
     296             : 
     297           0 :         if( ( pGraphicObject && rBullet.pGraphicObject ) &&
     298           0 :             ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
     299           0 :               ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
     300             :         {
     301           0 :             return false;
     302             :         }
     303             :     }
     304             : 
     305        1825 :     return true;
     306             : }
     307             : 
     308             : 
     309             : 
     310           0 : SvStream& SvxBulletItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
     311             : {
     312             :     // Correction for empty bitmap
     313           0 :     if( ( nStyle == BS_BMP ) &&
     314           0 :         ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
     315             :     {
     316           0 :         if( pGraphicObject )
     317             :         {
     318           0 :             delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
     319           0 :             const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
     320             :         }
     321             : 
     322           0 :         const_cast< SvxBulletItem* >( this )->nStyle = BS_NONE;
     323             :     }
     324             : 
     325           0 :     rStrm.WriteUInt16( nStyle );
     326             : 
     327           0 :     if( nStyle != BS_BMP )
     328           0 :         StoreFont( rStrm, aFont );
     329             :     else
     330             :     {
     331           0 :         sal_Size _nStart = rStrm.Tell();
     332             : 
     333             :         // Small preliminary estimate of the size ...
     334           0 :         sal_uInt16 nFac = ( rStrm.GetCompressMode() != COMPRESSMODE_NONE ) ? 3 : 1;
     335           0 :         const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
     336           0 :         sal_uLong nBytes = aBmp.GetSizeBytes();
     337           0 :         if ( nBytes < sal_uLong(0xFF00*nFac) )
     338             :         {
     339           0 :             WriteDIB(aBmp, rStrm, false, true);
     340             :         }
     341             : 
     342           0 :         sal_Size nEnd = rStrm.Tell();
     343             :         // Item can not write with an overhead more than 64K or SfxMultiRecord
     344             :         // will crash. Then prefer to forego on the bitmap, it is only
     345             :         // important for the outliner and only for <= 5.0.
     346             :         // When reading, the stream-operator makes note of the bitmap and the
     347             :         // fact that there is none. This is now the case how it works with
     348             :         // large bitmap created from another file format, which do not occupy a
     349             :         // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
     350             :         // have problem loading it, but does not crash.
     351             : 
     352           0 :         if ( (nEnd-_nStart) > 0xFF00 )
     353           0 :             rStrm.Seek( _nStart );
     354             :     }
     355           0 :     rStrm.WriteInt32( static_cast<sal_Int32>(nWidth) );
     356           0 :     rStrm.WriteUInt16( nStart );
     357           0 :     rStrm.WriteUChar( nJustify );
     358           0 :     rStrm.WriteChar( OUStringToOString(OUString(cSymbol), aFont.GetCharSet()).toChar() );
     359           0 :     rStrm.WriteUInt16( nScale );
     360             : 
     361             :     // UNICODE: rStrm << aPrevText;
     362           0 :     rStrm.WriteUniOrByteString(aPrevText, rStrm.GetStreamCharSet());
     363             : 
     364             :     // UNICODE: rStrm << aFollowText;
     365           0 :     rStrm.WriteUniOrByteString(aFollowText, rStrm.GetStreamCharSet());
     366             : 
     367           0 :     return rStrm;
     368             : }
     369             : 
     370             : 
     371             : 
     372           0 : OUString SvxBulletItem::GetFullText() const
     373             : {
     374           0 :     OUStringBuffer aStr(aPrevText);
     375           0 :     aStr.append(cSymbol);
     376           0 :     aStr.append(aFollowText);
     377           0 :     return aStr.makeStringAndClear();
     378             : }
     379             : 
     380             : 
     381             : 
     382           0 : SfxItemPresentation SvxBulletItem::GetPresentation
     383             : (
     384             :     SfxItemPresentation ePres,
     385             :     SfxMapUnit          /*eCoreUnit*/,
     386             :     SfxMapUnit          /*ePresUnit*/,
     387             :     OUString&           rText, const IntlWrapper *
     388             : )   const
     389             : {
     390           0 :     SfxItemPresentation eRet = SFX_ITEM_PRESENTATION_NONE;
     391           0 :     switch ( ePres )
     392             :     {
     393             :         case SFX_ITEM_PRESENTATION_NONE:
     394           0 :             rText = OUString();
     395           0 :             eRet = SFX_ITEM_PRESENTATION_NONE;
     396           0 :             break;
     397             : 
     398             :         case SFX_ITEM_PRESENTATION_NAMELESS:
     399             :         case SFX_ITEM_PRESENTATION_COMPLETE:
     400           0 :             rText = GetFullText();
     401           0 :             eRet = SFX_ITEM_PRESENTATION_COMPLETE;
     402           0 :             break;
     403             :         default: ; //prevent warning
     404             :     }
     405           0 :     return eRet;
     406             : }
     407             : 
     408             : 
     409             : 
     410           0 : const GraphicObject& SvxBulletItem::GetGraphicObject() const
     411             : {
     412           0 :     if( pGraphicObject )
     413           0 :         return *pGraphicObject;
     414             :     else
     415             :     {
     416           0 :         static const GraphicObject aDefaultObject;
     417           0 :         return aDefaultObject;
     418             :     }
     419             : }
     420             : 
     421             : 
     422             : 
     423           0 : void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
     424             : {
     425           0 :     if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
     426             :     {
     427           0 :         if( pGraphicObject )
     428             :         {
     429           0 :             delete pGraphicObject;
     430           0 :             pGraphicObject = NULL;
     431             :         }
     432             :     }
     433             :     else
     434             :     {
     435           0 :         delete pGraphicObject;
     436           0 :         pGraphicObject = new GraphicObject( rGraphicObject );
     437             :     }
     438           0 : }
     439             : 
     440             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10