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 <tools/vcompat.hxx>
22 #include <tools/GenericTypeSerializer.hxx>
24 #include <vcl/graphictools.hxx>
26 SvtGraphicFill::Transform::Transform()
28 matrix
[0] = 1.0; matrix
[1] = 0.0; matrix
[2] = 0.0;
29 matrix
[3] = 0.0; matrix
[4] = 1.0; matrix
[5] = 0.0;
32 SvtGraphicStroke::SvtGraphicStroke() :
45 SvtGraphicStroke::SvtGraphicStroke( const tools::Polygon
& rPath
,
46 const tools::PolyPolygon
& rStartArrow
,
47 const tools::PolyPolygon
& rEndArrow
,
53 const DashArray
& rDashArray
) :
55 maStartArrow( rStartArrow
),
56 maEndArrow( rEndArrow
),
57 mfTransparency( fTransparency
),
58 mfStrokeWidth( fStrokeWidth
),
61 mfMiterLimit( fMiterLimit
),
62 maDashArray( rDashArray
)
66 void SvtGraphicStroke::getPath( tools::Polygon
& rPath
) const
71 void SvtGraphicStroke::getStartArrow( tools::PolyPolygon
& rPath
) const
76 void SvtGraphicStroke::getEndArrow( tools::PolyPolygon
& rPath
) const
82 void SvtGraphicStroke::getDashArray( DashArray
& rDashArray
) const
84 rDashArray
= maDashArray
;
87 void SvtGraphicStroke::setPath( const tools::Polygon
& rPoly
)
92 void SvtGraphicStroke::setStartArrow( const tools::PolyPolygon
& rPoly
)
97 void SvtGraphicStroke::setEndArrow( const tools::PolyPolygon
& rPoly
)
102 void SvtGraphicStroke::scale( double fXScale
, double fYScale
)
104 // Clearly scaling stroke-width for fat lines is rather a problem
105 maPath
.Scale( fXScale
, fYScale
);
107 double fScale
= sqrt (fabs (fXScale
* fYScale
) ); // clearly not ideal.
108 mfStrokeWidth
*= fScale
;
109 mfMiterLimit
*= fScale
;
111 maStartArrow
.Scale( fXScale
, fYScale
);
112 maEndArrow
.Scale( fXScale
, fYScale
);
115 SvStream
& WriteSvtGraphicStroke( SvStream
& rOStm
, const SvtGraphicStroke
& rClass
)
117 VersionCompat
aCompat( rOStm
, StreamMode::WRITE
, 1 );
119 rClass
.maPath
.Write( rOStm
);
120 rClass
.maStartArrow
.Write( rOStm
);
121 rClass
.maEndArrow
.Write( rOStm
);
122 rOStm
.WriteDouble( rClass
.mfTransparency
);
123 rOStm
.WriteDouble( rClass
.mfStrokeWidth
);
124 sal_uInt16 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maCapType
);
125 rOStm
.WriteUInt16( nTmp
);
126 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maJoinType
);
127 rOStm
.WriteUInt16( nTmp
);
128 rOStm
.WriteDouble( rClass
.mfMiterLimit
);
130 rOStm
.WriteUInt32( rClass
.maDashArray
.size() );
132 for(i
=0; i
<rClass
.maDashArray
.size(); ++i
)
133 rOStm
.WriteDouble( rClass
.maDashArray
[i
] );
138 SvStream
& ReadSvtGraphicStroke( SvStream
& rIStm
, SvtGraphicStroke
& rClass
)
140 VersionCompat
aCompat( rIStm
, StreamMode::READ
);
142 rClass
.maPath
.Read( rIStm
);
143 rClass
.maStartArrow
.Read( rIStm
);
144 rClass
.maEndArrow
.Read( rIStm
);
145 rIStm
.ReadDouble( rClass
.mfTransparency
);
146 rIStm
.ReadDouble( rClass
.mfStrokeWidth
);
148 rIStm
.ReadUInt16( nTmp
);
149 rClass
.maCapType
= SvtGraphicStroke::CapType(nTmp
);
150 rIStm
.ReadUInt16( nTmp
);
151 rClass
.maJoinType
= SvtGraphicStroke::JoinType(nTmp
);
152 rIStm
.ReadDouble( rClass
.mfMiterLimit
);
155 rIStm
.ReadUInt32( nSize
);
156 rClass
.maDashArray
.resize(nSize
);
158 for(i
=0; i
<rClass
.maDashArray
.size(); ++i
)
159 rIStm
.ReadDouble( rClass
.maDashArray
[i
] );
164 SvtGraphicFill::SvtGraphicFill() :
166 maFillColor( COL_BLACK
),
173 maHatchColor( COL_BLACK
),
175 maGradient1stColor( COL_BLACK
),
176 maGradient2ndColor( COL_BLACK
),
177 maGradientStepCount( gradientStepsInfinite
),
182 SvtGraphicFill::SvtGraphicFill( const tools::PolyPolygon
& rPath
,
184 double fTransparency
,
187 const Transform
& aFillTransform
,
189 HatchType aHatchType
,
191 GradientType aGradientType
,
192 Color aGradient1stColor
,
193 Color aGradient2ndColor
,
194 sal_Int32 aGradientStepCount
,
195 const Graphic
& aFillGraphic
) :
197 maFillColor( aFillColor
),
198 mfTransparency( fTransparency
),
199 maFillRule( aFillRule
),
200 maFillType( aFillType
),
201 maFillTransform( aFillTransform
),
203 maHatchType( aHatchType
),
204 maHatchColor( aHatchColor
),
205 maGradientType( aGradientType
),
206 maGradient1stColor( aGradient1stColor
),
207 maGradient2ndColor( aGradient2ndColor
),
208 maGradientStepCount( aGradientStepCount
),
209 maFillGraphic( aFillGraphic
)
213 void SvtGraphicFill::getPath( tools::PolyPolygon
& rPath
) const
219 void SvtGraphicFill::getTransform( Transform
& rTrans
) const
221 rTrans
= maFillTransform
;
225 void SvtGraphicFill::getGraphic( Graphic
& rGraphic
) const
227 rGraphic
= maFillGraphic
;
230 void SvtGraphicFill::setPath( const tools::PolyPolygon
& rPath
)
235 SvStream
& WriteSvtGraphicFill( SvStream
& rOStm
, const SvtGraphicFill
& rClass
)
237 VersionCompat
aCompat( rOStm
, StreamMode::WRITE
, 1 );
239 rClass
.maPath
.Write( rOStm
);
240 tools::GenericTypeSerializer
aSerializer(rOStm
);
241 aSerializer
.writeColor(rClass
.maFillColor
);
242 rOStm
.WriteDouble( rClass
.mfTransparency
);
243 sal_uInt16 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maFillRule
);
244 rOStm
.WriteUInt16( nTmp
);
245 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maFillType
);
246 rOStm
.WriteUInt16( nTmp
);
248 for(i
=0; i
<SvtGraphicFill::Transform::MatrixSize
; ++i
)
249 rOStm
.WriteDouble( rClass
.maFillTransform
.matrix
[i
] );
250 nTmp
= sal_uInt16(rClass
.mbTiling
);
251 rOStm
.WriteUInt16( nTmp
);
252 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maHatchType
);
253 rOStm
.WriteUInt16( nTmp
);
254 aSerializer
.writeColor(rClass
.maHatchColor
);
255 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maGradientType
);
256 rOStm
.WriteUInt16( nTmp
);
257 aSerializer
.writeColor(rClass
.maGradient1stColor
);
258 aSerializer
.writeColor(rClass
.maGradient2ndColor
);
259 rOStm
.WriteInt32( rClass
.maGradientStepCount
);
260 WriteGraphic( rOStm
, rClass
.maFillGraphic
);
265 SvStream
& ReadSvtGraphicFill( SvStream
& rIStm
, SvtGraphicFill
& rClass
)
267 VersionCompat
aCompat( rIStm
, StreamMode::READ
);
269 rClass
.maPath
.Read( rIStm
);
271 tools::GenericTypeSerializer
aSerializer(rIStm
);
272 aSerializer
.readColor(rClass
.maFillColor
);
273 rIStm
.ReadDouble( rClass
.mfTransparency
);
275 rIStm
.ReadUInt16( nTmp
);
276 rClass
.maFillRule
= SvtGraphicFill::FillRule( nTmp
);
277 rIStm
.ReadUInt16( nTmp
);
278 rClass
.maFillType
= SvtGraphicFill::FillType( nTmp
);
279 for (int i
= 0; i
< SvtGraphicFill::Transform::MatrixSize
; ++i
)
280 rIStm
.ReadDouble( rClass
.maFillTransform
.matrix
[i
] );
281 rIStm
.ReadUInt16( nTmp
);
282 rClass
.mbTiling
= nTmp
;
283 rIStm
.ReadUInt16( nTmp
);
284 rClass
.maHatchType
= SvtGraphicFill::HatchType( nTmp
);
285 aSerializer
.readColor(rClass
.maHatchColor
);
286 rIStm
.ReadUInt16( nTmp
);
287 rClass
.maGradientType
= SvtGraphicFill::GradientType( nTmp
);
288 aSerializer
.readColor(rClass
.maGradient1stColor
);
289 aSerializer
.readColor(rClass
.maGradient2ndColor
);
290 rIStm
.ReadInt32( rClass
.maGradientStepCount
);
291 ReadGraphic( rIStm
, rClass
.maFillGraphic
);
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */