1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/stream.hxx>
21 #include <vcl/outdev.hxx>
23 #include <editeng/bulletitem.hxx>
24 #include <editeng/editrids.hrc>
26 #include <tools/tenccvt.hxx>
27 #include <vcl/dibtools.hxx>
29 #define BULITEM_VERSION ((sal_uInt16)2)
33 TYPEINIT1(SvxBulletItem
,SfxPoolItem
);
37 void SvxBulletItem::StoreFont( SvStream
& rStream
, const vcl::Font
& rFont
)
41 WriteColor( rStream
, rFont
.GetColor() );
42 nTemp
= (sal_uInt16
)rFont
.GetFamily(); rStream
.WriteUInt16( nTemp
);
44 nTemp
= (sal_uInt16
)GetSOStoreTextEncoding((rtl_TextEncoding
)rFont
.GetCharSet());
45 rStream
.WriteUInt16( nTemp
);
47 nTemp
= (sal_uInt16
)rFont
.GetPitch(); rStream
.WriteUInt16( nTemp
);
48 nTemp
= (sal_uInt16
)rFont
.GetAlign(); rStream
.WriteUInt16( nTemp
);
49 nTemp
= (sal_uInt16
)rFont
.GetWeight(); rStream
.WriteUInt16( nTemp
);
50 nTemp
= (sal_uInt16
)rFont
.GetUnderline(); rStream
.WriteUInt16( nTemp
);
51 nTemp
= (sal_uInt16
)rFont
.GetStrikeout(); rStream
.WriteUInt16( nTemp
);
52 nTemp
= (sal_uInt16
)rFont
.GetItalic(); rStream
.WriteUInt16( nTemp
);
54 // UNICODE: rStream << rFont.GetName();
55 rStream
.WriteUniOrByteString(rFont
.GetName(), rStream
.GetStreamCharSet());
57 rStream
.WriteBool( rFont
.IsOutline() );
58 rStream
.WriteBool( rFont
.IsShadow() );
59 rStream
.WriteBool( rFont
.IsTransparent() );
64 vcl::Font
SvxBulletItem::CreateFont( SvStream
& rStream
, sal_uInt16 nVer
)
68 ReadColor( rStream
, aColor
); aFont
.SetColor( aColor
);
70 rStream
.ReadUInt16( nTemp
); aFont
.SetFamily((FontFamily
)nTemp
);
72 rStream
.ReadUInt16( nTemp
);
73 nTemp
= (sal_uInt16
)GetSOLoadTextEncoding((rtl_TextEncoding
)nTemp
);
74 aFont
.SetCharSet((rtl_TextEncoding
)nTemp
);
76 rStream
.ReadUInt16( nTemp
); aFont
.SetPitch((FontPitch
)nTemp
);
77 rStream
.ReadUInt16( nTemp
); aFont
.SetAlign((FontAlign
)nTemp
);
78 rStream
.ReadUInt16( nTemp
); aFont
.SetWeight((FontWeight
)nTemp
);
79 rStream
.ReadUInt16( nTemp
); aFont
.SetUnderline((FontUnderline
)nTemp
);
80 rStream
.ReadUInt16( nTemp
); aFont
.SetStrikeout((FontStrikeout
)nTemp
);
81 rStream
.ReadUInt16( nTemp
); aFont
.SetItalic((FontItalic
)nTemp
);
83 // UNICODE: rStream >> aName; aFont.SetName( aName );
84 OUString aName
= rStream
.ReadUniOrByteString(rStream
.GetStreamCharSet());
85 aFont
.SetName( aName
);
89 sal_Int32
nHeight(0), nWidth(0);
90 rStream
.ReadInt32( nHeight
); rStream
.ReadInt32( nWidth
); Size
aSize( nWidth
, nHeight
);
91 aFont
.SetSize( aSize
);
95 rStream
.ReadCharAsBool( bTemp
); aFont
.SetOutline( bTemp
);
96 rStream
.ReadCharAsBool( bTemp
); aFont
.SetShadow( bTemp
);
97 rStream
.ReadCharAsBool( bTemp
); aFont
.SetTransparent( bTemp
);
104 SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich
) : SfxPoolItem( _nWhich
)
106 SetDefaultFont_Impl();
110 SvxBulletItem::SvxBulletItem( SvStream
& rStrm
, sal_uInt16 _nWhich
)
111 : SfxPoolItem(_nWhich
)
112 , pGraphicObject(NULL
)
114 , nStyle(SvxBulletStyle::ABC_BIG
)
118 rStrm
.ReadUInt16( nTmp1
);
119 nStyle
= static_cast<SvxBulletStyle
>(nTmp1
);
121 if( nStyle
!= SvxBulletStyle::BMP
)
122 aFont
= CreateFont( rStrm
, BULITEM_VERSION
);
125 // Safe Load with Test on empty Bitmap
127 const sal_Size nOldPos
= rStrm
.Tell();
128 // Ignore Errorcode when reading Bitmap,
129 // see comment in SvxBulletItem::Store()
130 bool bOldError
= rStrm
.GetError() != 0;
131 ReadDIB(aBmp
, rStrm
, true);
133 if ( !bOldError
&& rStrm
.GetError() )
140 rStrm
.Seek( nOldPos
);
141 nStyle
= SvxBulletStyle::NONE
;
144 pGraphicObject
= new GraphicObject( aBmp
);
148 rStrm
.ReadInt32( nTmp
); nWidth
= nTmp
;
149 rStrm
.ReadUInt16( nStart
);
150 sal_uInt8
nTmpInt8(0);
151 rStrm
.ReadUChar( nTmpInt8
); // used to be nJustify
154 rStrm
.ReadChar( cTmpSymbol
);
155 //convert single byte to unicode
156 cSymbol
= OUString(&cTmpSymbol
, 1, aFont
.GetCharSet()).toChar();
158 rStrm
.ReadUInt16( nScale
);
160 // UNICODE: rStrm >> aPrevText;
161 aPrevText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
163 // UNICODE: rStrm >> aFollowText;
164 aFollowText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
167 SvxBulletItem::SvxBulletItem( const SvxBulletItem
& rItem
) : SfxPoolItem( rItem
)
170 pGraphicObject
= ( rItem
.pGraphicObject
? new GraphicObject( *rItem
.pGraphicObject
) : NULL
);
171 aPrevText
= rItem
.aPrevText
;
172 aFollowText
= rItem
.aFollowText
;
173 nStart
= rItem
.nStart
;
174 nStyle
= rItem
.nStyle
;
175 nWidth
= rItem
.nWidth
;
176 nScale
= rItem
.nScale
;
177 cSymbol
= rItem
.cSymbol
;
182 SvxBulletItem::~SvxBulletItem()
185 delete pGraphicObject
;
190 SfxPoolItem
* SvxBulletItem::Clone( SfxItemPool
* /*pPool*/ ) const
192 return new SvxBulletItem( *this );
197 SfxPoolItem
* SvxBulletItem::Create( SvStream
& rStrm
, sal_uInt16
/*nVersion*/ ) const
199 return new SvxBulletItem( rStrm
, Which() );
204 void SvxBulletItem::SetDefaultFont_Impl()
206 aFont
= OutputDevice::GetDefaultFont( DefaultFontType::FIXED
, LANGUAGE_SYSTEM
, GetDefaultFontFlags::NONE
);
207 aFont
.SetAlign( ALIGN_BOTTOM
);
208 aFont
.SetTransparent( true );
213 void SvxBulletItem::SetDefaults_Impl()
215 pGraphicObject
= NULL
;
216 nWidth
= 1200; // 1.2cm
218 nStyle
= SvxBulletStyle::N123
;
225 sal_uInt16
SvxBulletItem::GetVersion( sal_uInt16
/*nVersion*/ ) const
227 return BULITEM_VERSION
;
232 void SvxBulletItem::CopyValidProperties( const SvxBulletItem
& rCopyFrom
)
234 vcl::Font _aFont
= GetFont();
235 vcl::Font aNewFont
= rCopyFrom
.GetFont();
236 _aFont
.SetName( aNewFont
.GetName() );
237 _aFont
.SetFamily( aNewFont
.GetFamily() );
238 _aFont
.SetStyleName( aNewFont
.GetStyleName() );
239 _aFont
.SetColor( aNewFont
.GetColor() );
240 SetSymbol( rCopyFrom
.GetSymbol() );
241 SetGraphicObject( rCopyFrom
.GetGraphicObject() );
242 SetScale( rCopyFrom
.GetScale() );
243 SetStart( rCopyFrom
.GetStart() );
244 SetStyle( rCopyFrom
.GetStyle() );
245 SetPrevText( rCopyFrom
.GetPrevText() );
246 SetFollowText( rCopyFrom
.GetFollowText() );
253 bool SvxBulletItem::operator==( const SfxPoolItem
& rItem
) const
255 DBG_ASSERT(rItem
.ISA(SvxBulletItem
),"operator==Types not matching");
256 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 if( nStyle
!= rBullet
.nStyle
||
260 nScale
!= rBullet
.nScale
||
261 nWidth
!= rBullet
.nWidth
||
262 nStart
!= rBullet
.nStart
||
263 cSymbol
!= rBullet
.cSymbol
||
264 aPrevText
!= rBullet
.aPrevText
||
265 aFollowText
!= rBullet
.aFollowText
)
268 if( ( nStyle
!= SvxBulletStyle::BMP
) && ( aFont
!= rBullet
.aFont
) )
271 if( nStyle
== SvxBulletStyle::BMP
)
273 if( ( pGraphicObject
&& !rBullet
.pGraphicObject
) || ( !pGraphicObject
&& rBullet
.pGraphicObject
) )
276 if( ( pGraphicObject
&& rBullet
.pGraphicObject
) &&
277 ( ( *pGraphicObject
!= *rBullet
.pGraphicObject
) ||
278 ( pGraphicObject
->GetPrefSize() != rBullet
.pGraphicObject
->GetPrefSize() ) ) )
289 SvStream
& SvxBulletItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
291 // Correction for empty bitmap
292 if( ( nStyle
== SvxBulletStyle::BMP
) &&
293 ( !pGraphicObject
|| ( GRAPHIC_NONE
== pGraphicObject
->GetType() ) || ( GRAPHIC_DEFAULT
== pGraphicObject
->GetType() ) ) )
297 delete( const_cast< SvxBulletItem
* >( this )->pGraphicObject
);
298 const_cast< SvxBulletItem
* >( this )->pGraphicObject
= NULL
;
301 const_cast< SvxBulletItem
* >( this )->nStyle
= SvxBulletStyle::NONE
;
304 rStrm
.WriteUInt16( static_cast<sal_uInt16
>(nStyle
) );
306 if( nStyle
!= SvxBulletStyle::BMP
)
307 StoreFont( rStrm
, aFont
);
310 sal_Size _nStart
= rStrm
.Tell();
312 // Small preliminary estimate of the size ...
313 sal_uInt16 nFac
= ( rStrm
.GetCompressMode() != SvStreamCompressFlags::NONE
) ? 3 : 1;
314 const Bitmap
aBmp( pGraphicObject
->GetGraphic().GetBitmap() );
315 sal_uLong nBytes
= aBmp
.GetSizeBytes();
316 if ( nBytes
< sal_uLong(0xFF00*nFac
) )
318 WriteDIB(aBmp
, rStrm
, false, true);
321 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.
331 if ( (nEnd
-_nStart
) > 0xFF00 )
332 rStrm
.Seek( _nStart
);
334 rStrm
.WriteInt32( nWidth
);
335 rStrm
.WriteUInt16( nStart
);
336 rStrm
.WriteUChar( 0 ); // used to be nJustify
337 rStrm
.WriteChar( OUStringToOString(OUString(cSymbol
), aFont
.GetCharSet()).toChar() );
338 rStrm
.WriteUInt16( nScale
);
340 // UNICODE: rStrm << aPrevText;
341 rStrm
.WriteUniOrByteString(aPrevText
, rStrm
.GetStreamCharSet());
343 // UNICODE: rStrm << aFollowText;
344 rStrm
.WriteUniOrByteString(aFollowText
, rStrm
.GetStreamCharSet());
351 OUString
SvxBulletItem::GetFullText() const
353 OUStringBuffer
aStr(aPrevText
);
354 aStr
.append(cSymbol
);
355 aStr
.append(aFollowText
);
356 return aStr
.makeStringAndClear();
361 bool SvxBulletItem::GetPresentation
363 SfxItemPresentation
/*ePres*/,
364 SfxMapUnit
/*eCoreUnit*/,
365 SfxMapUnit
/*ePresUnit*/,
366 OUString
& rText
, const IntlWrapper
*
369 rText
= GetFullText();
375 const GraphicObject
& SvxBulletItem::GetGraphicObject() const
378 return *pGraphicObject
;
381 static const GraphicObject aDefaultObject
;
382 return aDefaultObject
;
388 void SvxBulletItem::SetGraphicObject( const GraphicObject
& rGraphicObject
)
390 if( ( GRAPHIC_NONE
== rGraphicObject
.GetType() ) || ( GRAPHIC_DEFAULT
== rGraphicObject
.GetType() ) )
394 delete pGraphicObject
;
395 pGraphicObject
= NULL
;
400 delete pGraphicObject
;
401 pGraphicObject
= new GraphicObject( rGraphicObject
);
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */