1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: graphictools.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/vcompat.hxx>
35 #include <vcl/graphictools.hxx>
37 static ::rtl::OString
polyToString( const Polygon
& rPoly
)
41 for(nVertex
=0; nVertex
<rPoly
.GetSize(); ++nVertex
)
44 switch( rPoly
.GetFlags(nVertex
) )
57 DBG_ERROR( "SvtGraphicStroke::polyToString invalid flag");
60 aStr
+= ::rtl::OString::valueOf( static_cast< double >( rPoly
[nVertex
].getX() ) );
62 aStr
+= ::rtl::OString::valueOf( static_cast< double >( rPoly
[nVertex
].getY() ) );
69 static ::rtl::OString
polyPolyToString( const PolyPolygon
& rPolyPoly
)
73 for(nPoly
=0; nPoly
<rPolyPoly
.Count(); ++nPoly
)
75 const Polygon
& rPoly
= rPolyPoly
[nPoly
];
78 aStr
+= polyToString( rPoly
);
85 static ::rtl::OString
dashToString( const SvtGraphicStroke::DashArray
& rDashArray
)
91 int i
, nDashes( rDashArray
.size() );
92 for(i
=0; i
<nDashes
; ++i
)
94 aStr
+= ::rtl::OString::valueOf( rDashArray
[i
] );
103 static ::rtl::OString
colorToString( Color aColor
)
108 aStr
+= ::rtl::OString::valueOf( aColor
.GetRed() );
110 aStr
+= ::rtl::OString::valueOf( aColor
.GetGreen() );
112 aStr
+= ::rtl::OString::valueOf( aColor
.GetBlue() );
118 ////////////////////////////////////////////////////////////////////////////
120 SvtGraphicFill::Transform::Transform()
122 matrix
[0] = 1.0; matrix
[1] = 0.0; matrix
[2] = 0.0;
123 matrix
[3] = 0.0; matrix
[4] = 1.0; matrix
[5] = 0.0;
126 ////////////////////////////////////////////////////////////////////////////
128 SvtGraphicStroke::SvtGraphicStroke() :
141 SvtGraphicStroke::SvtGraphicStroke( const Polygon
& rPath
,
142 const PolyPolygon
& rStartArrow
,
143 const PolyPolygon
& rEndArrow
,
144 double fTransparency
,
149 const DashArray
& rDashArray
) :
151 maStartArrow( rStartArrow
),
152 maEndArrow( rEndArrow
),
153 mfTransparency( fTransparency
),
154 mfStrokeWidth( fStrokeWidth
),
157 mfMiterLimit( fMiterLimit
),
158 maDashArray( rDashArray
)
162 void SvtGraphicStroke::getPath( Polygon
& rPath
) const
167 void SvtGraphicStroke::getStartArrow( PolyPolygon
& rPath
) const
169 rPath
= maStartArrow
;
172 void SvtGraphicStroke::getEndArrow( PolyPolygon
& rPath
) const
177 double SvtGraphicStroke::getTransparency() const
179 return mfTransparency
;
182 double SvtGraphicStroke::getStrokeWidth() const
184 return mfStrokeWidth
;
187 SvtGraphicStroke::CapType
SvtGraphicStroke::getCapType() const
192 SvtGraphicStroke::JoinType
SvtGraphicStroke::getJoinType() const
197 double SvtGraphicStroke::getMiterLimit() const
202 void SvtGraphicStroke::getDashArray( DashArray
& rDashArray
) const
204 rDashArray
= maDashArray
;
207 ::rtl::OString
SvtGraphicStroke::toString() const
211 aStr
+= polyToString( maPath
);
213 aStr
+= ::rtl::OString::valueOf( static_cast< double >(getTransparency()) );
215 aStr
+= ::rtl::OString::valueOf( static_cast< double >(getStrokeWidth()) );
217 switch( getCapType() )
232 DBG_ERROR( "SvtGraphicStroke::toString missing cap type");
236 switch( getJoinType() )
255 DBG_ERROR( "SvtGraphicStroke::toString missing join type");
260 if( maStartArrow
.Count() )
263 aStr
+= polyPolyToString( maStartArrow
);
267 if( maEndArrow
.Count() )
270 aStr
+= polyPolyToString( maEndArrow
);
274 aStr
+= dashToString( maDashArray
);
279 void SvtGraphicStroke::setPath( const Polygon
& rPoly
)
284 void SvtGraphicStroke::setStartArrow( const PolyPolygon
& rPoly
)
286 maStartArrow
= rPoly
;
289 void SvtGraphicStroke::setEndArrow( const PolyPolygon
& rPoly
)
294 void SvtGraphicStroke::setTransparency( double fTrans
)
296 mfTransparency
= fTrans
;
299 void SvtGraphicStroke::setStrokeWidth( double fWidth
)
301 mfStrokeWidth
= fWidth
;
304 void SvtGraphicStroke::setCapType( CapType eType
)
309 void SvtGraphicStroke::setJoinType( JoinType eType
)
314 void SvtGraphicStroke::setMiterLimit( double fMiterLimit
)
316 mfMiterLimit
= fMiterLimit
;
319 void SvtGraphicStroke::setDashArray( const DashArray
& rDashArray
)
321 maDashArray
= rDashArray
;
324 SvStream
& operator<<( SvStream
& rOStm
, const SvtGraphicStroke
& rClass
)
326 VersionCompat
aCompat( rOStm
, STREAM_WRITE
, 1 );
328 rClass
.maPath
.Write( rOStm
);
329 rClass
.maStartArrow
.Write( rOStm
);
330 rClass
.maEndArrow
.Write( rOStm
);
331 rOStm
<< rClass
.mfTransparency
;
332 rOStm
<< rClass
.mfStrokeWidth
;
333 UINT16 nTmp
= sal::static_int_cast
<UINT16
>( rClass
.maCapType
);
335 nTmp
= sal::static_int_cast
<UINT16
>( rClass
.maJoinType
);
337 rOStm
<< rClass
.mfMiterLimit
;
339 rOStm
<< static_cast<sal_uInt32
>(rClass
.maDashArray
.size());
341 for(i
=0; i
<rClass
.maDashArray
.size(); ++i
)
342 rOStm
<< rClass
.maDashArray
[i
];
347 SvStream
& operator>>( SvStream
& rIStm
, SvtGraphicStroke
& rClass
)
349 VersionCompat
aCompat( rIStm
, STREAM_READ
);
351 rClass
.maPath
.Read( rIStm
);
352 rClass
.maStartArrow
.Read( rIStm
);
353 rClass
.maEndArrow
.Read( rIStm
);
354 rIStm
>> rClass
.mfTransparency
;
355 rIStm
>> rClass
.mfStrokeWidth
;
358 rClass
.maCapType
= SvtGraphicStroke::CapType(nTmp
);
360 rClass
.maJoinType
= SvtGraphicStroke::JoinType(nTmp
);
361 rIStm
>> rClass
.mfMiterLimit
;
365 rClass
.maDashArray
.resize(nSize
);
367 for(i
=0; i
<rClass
.maDashArray
.size(); ++i
)
368 rIStm
>> rClass
.maDashArray
[i
];
374 /////////////////////////////////////////////////////////////////////////////
376 SvtGraphicFill::SvtGraphicFill() :
378 maFillColor( COL_BLACK
),
384 maHatchColor( COL_BLACK
),
386 maGradient1stColor( COL_BLACK
),
387 maGradient2ndColor( COL_BLACK
),
388 maGradientStepCount( gradientStepsInfinite
),
393 SvtGraphicFill::SvtGraphicFill( const PolyPolygon
& rPath
,
395 double fTransparency
,
398 const Transform
& aFillTransform
,
400 HatchType aHatchType
,
402 GradientType aGradientType
,
403 Color aGradient1stColor
,
404 Color aGradient2ndColor
,
405 int aGradientStepCount
,
406 const Graphic
& aFillGraphic
) :
408 maFillColor( aFillColor
),
409 mfTransparency( fTransparency
),
410 maFillRule( aFillRule
),
411 maFillType( aFillType
),
412 maFillTransform( aFillTransform
),
414 maHatchType( aHatchType
),
415 maHatchColor( aHatchColor
),
416 maGradientType( aGradientType
),
417 maGradient1stColor( aGradient1stColor
),
418 maGradient2ndColor( aGradient2ndColor
),
419 maGradientStepCount( aGradientStepCount
),
420 maFillGraphic( aFillGraphic
)
424 void SvtGraphicFill::getPath( PolyPolygon
& rPath
) const
429 Color
SvtGraphicFill::getFillColor() const
434 double SvtGraphicFill::getTransparency() const
436 return mfTransparency
;
439 SvtGraphicFill::FillRule
SvtGraphicFill::getFillRule() const
444 SvtGraphicFill::FillType
SvtGraphicFill::getFillType() const
449 void SvtGraphicFill::getTransform( Transform
& rTrans
) const
451 rTrans
= maFillTransform
;
454 bool SvtGraphicFill::IsTiling() const
459 bool SvtGraphicFill::isTiling() const
464 SvtGraphicFill::HatchType
SvtGraphicFill::getHatchType() const
469 Color
SvtGraphicFill::getHatchColor() const
474 SvtGraphicFill::GradientType
SvtGraphicFill::getGradientType() const
476 return maGradientType
;
479 Color
SvtGraphicFill::getGradient1stColor() const
481 return maGradient1stColor
;
484 Color
SvtGraphicFill::getGradient2ndColor() const
486 return maGradient2ndColor
;
489 int SvtGraphicFill::getGradientStepCount() const
491 return maGradientStepCount
;
494 void SvtGraphicFill::getGraphic( Graphic
& rGraphic
) const
496 rGraphic
= maFillGraphic
;
499 ::rtl::OString
SvtGraphicFill::toString() const
503 aStr
+= polyPolyToString( maPath
);
505 aStr
+= colorToString( getFillColor() );
507 aStr
+= ::rtl::OString::valueOf( static_cast< double >(getTransparency()) );
509 switch( getFillRule() )
520 DBG_ERROR( "SvtGraphicFill::toString missing fill rule");
524 switch( getFillType() )
543 DBG_ERROR( "SvtGraphicStroke::toString missing fill type");
547 aStr
+= " transform: [ ";
549 for(i
=0; i
<Transform::MatrixSize
; ++i
)
550 aStr
+= ::rtl::OString::valueOf( maFillTransform
.matrix
[i
] );
554 switch( getHatchType() )
569 DBG_ERROR( "SvtGraphicStroke::toString missing hatch type");
574 aStr
+= colorToString( getHatchColor() );
576 aStr
+= " gradient: ";
577 switch( getGradientType() )
587 case gradientRectangular
:
588 aStr
+= "rectangular";
592 DBG_ERROR( "SvtGraphicStroke::toString missing gradient type");
597 aStr
+= colorToString( getGradient1stColor() );
600 aStr
+= colorToString( getGradient2ndColor() );
603 aStr
+= ::rtl::OString::valueOf( (sal_Int32
)getGradientStepCount() );
605 if( maFillGraphic
.GetType() != GRAPHIC_NONE
)
607 aStr
+= " fillgraphic: ";
608 switch( maFillGraphic
.GetType() )
614 case GRAPHIC_GDIMETAFILE
:
618 case GRAPHIC_DEFAULT
:
623 DBG_ERROR( "SvtGraphicStroke::toString missing graphic type");
628 aStr
+= ::rtl::OString::valueOf( static_cast< sal_Int32
>(maFillGraphic
.GetSizeBytes()) );
635 void SvtGraphicFill::setPath( const PolyPolygon
& rPath
)
640 void SvtGraphicFill::setFillColor( Color aFillColor
)
642 maFillColor
= aFillColor
;
645 void SvtGraphicFill::setTransparency( double fTransparency
)
647 mfTransparency
= fTransparency
;
650 void SvtGraphicFill::setFillRule( FillRule aFillRule
)
652 maFillRule
= aFillRule
;
655 void SvtGraphicFill::setFillType( FillType aFillType
)
657 maFillType
= aFillType
;
660 void SvtGraphicFill::setTransform( const Transform
& rTransform
)
662 maFillTransform
= rTransform
;
665 void SvtGraphicFill::setTiling( bool bTiling
)
670 void SvtGraphicFill::setHatchType( HatchType aHatchType
)
672 maHatchType
= aHatchType
;
675 void SvtGraphicFill::setHatchColor( Color aHatchColor
)
677 maHatchColor
= aHatchColor
;
680 void SvtGraphicFill::setGradientType( GradientType aGradType
)
682 maGradientType
= aGradType
;
685 void SvtGraphicFill::setGradient1stColor( Color aColor
)
687 maGradient1stColor
= aColor
;
690 void SvtGraphicFill::setGradient2ndColor( Color aColor
)
692 maGradient2ndColor
= aColor
;
695 void SvtGraphicFill::setGradientStepCount( int aCount
)
697 maGradientStepCount
= aCount
;
700 void SvtGraphicFill::setGraphic( const Graphic
& rGraphic
)
702 maFillGraphic
= rGraphic
;
705 SvStream
& operator<<( SvStream
& rOStm
, const SvtGraphicFill
& rClass
)
707 VersionCompat
aCompat( rOStm
, STREAM_WRITE
, 1 );
709 rClass
.maPath
.Write( rOStm
);
710 rOStm
<< rClass
.maFillColor
;
711 rOStm
<< rClass
.mfTransparency
;
712 UINT16 nTmp
= sal::static_int_cast
<UINT16
>( rClass
.maFillRule
);
714 nTmp
= sal::static_int_cast
<UINT16
>( rClass
.maFillType
);
717 for(i
=0; i
<SvtGraphicFill::Transform::MatrixSize
; ++i
)
718 rOStm
<< rClass
.maFillTransform
.matrix
[i
];
719 nTmp
= rClass
.mbTiling
;
721 nTmp
= sal::static_int_cast
<UINT16
>( rClass
.maHatchType
);
723 rOStm
<< rClass
.maHatchColor
;
724 nTmp
= sal::static_int_cast
<UINT16
>( rClass
.maGradientType
);
726 rOStm
<< rClass
.maGradient1stColor
;
727 rOStm
<< rClass
.maGradient2ndColor
;
728 rOStm
<< rClass
.maGradientStepCount
;
729 rOStm
<< rClass
.maFillGraphic
;
734 SvStream
& operator>>( SvStream
& rIStm
, SvtGraphicFill
& rClass
)
736 VersionCompat
aCompat( rIStm
, STREAM_READ
);
738 rClass
.maPath
.Read( rIStm
);
739 rIStm
>> rClass
.maFillColor
;
740 rIStm
>> rClass
.mfTransparency
;
743 rClass
.maFillRule
= SvtGraphicFill::FillRule( nTmp
);
745 rClass
.maFillType
= SvtGraphicFill::FillType( nTmp
);
747 for(i
=0; i
<SvtGraphicFill::Transform::MatrixSize
; ++i
)
748 rIStm
>> rClass
.maFillTransform
.matrix
[i
];
750 rClass
.mbTiling
= nTmp
;
752 rClass
.maHatchType
= SvtGraphicFill::HatchType( nTmp
);
753 rIStm
>> rClass
.maHatchColor
;
755 rClass
.maGradientType
= SvtGraphicFill::GradientType( nTmp
);
756 rIStm
>> rClass
.maGradient1stColor
;
757 rIStm
>> rClass
.maGradient2ndColor
;
758 rIStm
>> rClass
.maGradientStepCount
;
759 rIStm
>> rClass
.maFillGraphic
;