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>
23 #include <vcl/graphictools.hxx>
25 SvtGraphicFill::Transform::Transform()
27 matrix
[0] = 1.0; matrix
[1] = 0.0; matrix
[2] = 0.0;
28 matrix
[3] = 0.0; matrix
[4] = 1.0; matrix
[5] = 0.0;
31 SvtGraphicStroke::SvtGraphicStroke() :
44 SvtGraphicStroke::SvtGraphicStroke( const tools::Polygon
& rPath
,
45 const tools::PolyPolygon
& rStartArrow
,
46 const tools::PolyPolygon
& rEndArrow
,
52 const DashArray
& rDashArray
) :
54 maStartArrow( rStartArrow
),
55 maEndArrow( rEndArrow
),
56 mfTransparency( fTransparency
),
57 mfStrokeWidth( fStrokeWidth
),
60 mfMiterLimit( fMiterLimit
),
61 maDashArray( rDashArray
)
65 void SvtGraphicStroke::getPath( tools::Polygon
& rPath
) const
70 void SvtGraphicStroke::getStartArrow( tools::PolyPolygon
& rPath
) const
75 void SvtGraphicStroke::getEndArrow( tools::PolyPolygon
& rPath
) const
81 void SvtGraphicStroke::getDashArray( DashArray
& rDashArray
) const
83 rDashArray
= maDashArray
;
86 void SvtGraphicStroke::setPath( const tools::Polygon
& rPoly
)
91 void SvtGraphicStroke::setStartArrow( const tools::PolyPolygon
& rPoly
)
96 void SvtGraphicStroke::setEndArrow( const tools::PolyPolygon
& rPoly
)
101 void SvtGraphicStroke::scale( double fXScale
, double fYScale
)
103 // Clearly scaling stroke-width for fat lines is rather a problem
104 maPath
.Scale( fXScale
, fYScale
);
106 double fScale
= sqrt (fabs (fXScale
* fYScale
) ); // clearly not ideal.
107 mfStrokeWidth
*= fScale
;
108 mfMiterLimit
*= fScale
;
110 maStartArrow
.Scale( fXScale
, fYScale
);
111 maEndArrow
.Scale( fXScale
, fYScale
);
114 SvStream
& WriteSvtGraphicStroke( SvStream
& rOStm
, const SvtGraphicStroke
& rClass
)
116 VersionCompat
aCompat( rOStm
, StreamMode::WRITE
, 1 );
118 rClass
.maPath
.Write( rOStm
);
119 rClass
.maStartArrow
.Write( rOStm
);
120 rClass
.maEndArrow
.Write( rOStm
);
121 rOStm
.WriteDouble( rClass
.mfTransparency
);
122 rOStm
.WriteDouble( rClass
.mfStrokeWidth
);
123 sal_uInt16 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maCapType
);
124 rOStm
.WriteUInt16( nTmp
);
125 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maJoinType
);
126 rOStm
.WriteUInt16( nTmp
);
127 rOStm
.WriteDouble( rClass
.mfMiterLimit
);
129 rOStm
.WriteUInt32( rClass
.maDashArray
.size() );
131 for(i
=0; i
<rClass
.maDashArray
.size(); ++i
)
132 rOStm
.WriteDouble( rClass
.maDashArray
[i
] );
137 SvStream
& ReadSvtGraphicStroke( SvStream
& rIStm
, SvtGraphicStroke
& rClass
)
139 VersionCompat
aCompat( rIStm
, StreamMode::READ
);
141 rClass
.maPath
.Read( rIStm
);
142 rClass
.maStartArrow
.Read( rIStm
);
143 rClass
.maEndArrow
.Read( rIStm
);
144 rIStm
.ReadDouble( rClass
.mfTransparency
);
145 rIStm
.ReadDouble( rClass
.mfStrokeWidth
);
147 rIStm
.ReadUInt16( nTmp
);
148 rClass
.maCapType
= SvtGraphicStroke::CapType(nTmp
);
149 rIStm
.ReadUInt16( nTmp
);
150 rClass
.maJoinType
= SvtGraphicStroke::JoinType(nTmp
);
151 rIStm
.ReadDouble( rClass
.mfMiterLimit
);
154 rIStm
.ReadUInt32( nSize
);
155 rClass
.maDashArray
.resize(nSize
);
157 for(i
=0; i
<rClass
.maDashArray
.size(); ++i
)
158 rIStm
.ReadDouble( rClass
.maDashArray
[i
] );
163 SvtGraphicFill::SvtGraphicFill() :
165 maFillColor( COL_BLACK
),
172 maHatchColor( COL_BLACK
),
174 maGradient1stColor( COL_BLACK
),
175 maGradient2ndColor( COL_BLACK
),
176 maGradientStepCount( gradientStepsInfinite
),
181 SvtGraphicFill::SvtGraphicFill( const tools::PolyPolygon
& rPath
,
183 double fTransparency
,
186 const Transform
& aFillTransform
,
188 HatchType aHatchType
,
190 GradientType aGradientType
,
191 Color aGradient1stColor
,
192 Color aGradient2ndColor
,
193 sal_Int32 aGradientStepCount
,
194 const Graphic
& aFillGraphic
) :
196 maFillColor( aFillColor
),
197 mfTransparency( fTransparency
),
198 maFillRule( aFillRule
),
199 maFillType( aFillType
),
200 maFillTransform( aFillTransform
),
202 maHatchType( aHatchType
),
203 maHatchColor( aHatchColor
),
204 maGradientType( aGradientType
),
205 maGradient1stColor( aGradient1stColor
),
206 maGradient2ndColor( aGradient2ndColor
),
207 maGradientStepCount( aGradientStepCount
),
208 maFillGraphic( aFillGraphic
)
212 void SvtGraphicFill::getPath( tools::PolyPolygon
& rPath
) const
218 void SvtGraphicFill::getTransform( Transform
& rTrans
) const
220 rTrans
= maFillTransform
;
224 void SvtGraphicFill::getGraphic( Graphic
& rGraphic
) const
226 rGraphic
= maFillGraphic
;
229 void SvtGraphicFill::setPath( const tools::PolyPolygon
& rPath
)
234 SvStream
& WriteSvtGraphicFill( SvStream
& rOStm
, const SvtGraphicFill
& rClass
)
236 VersionCompat
aCompat( rOStm
, StreamMode::WRITE
, 1 );
238 rClass
.maPath
.Write( rOStm
);
239 WriteColor( rOStm
, rClass
.maFillColor
);
240 rOStm
.WriteDouble( rClass
.mfTransparency
);
241 sal_uInt16 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maFillRule
);
242 rOStm
.WriteUInt16( nTmp
);
243 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maFillType
);
244 rOStm
.WriteUInt16( nTmp
);
246 for(i
=0; i
<SvtGraphicFill::Transform::MatrixSize
; ++i
)
247 rOStm
.WriteDouble( rClass
.maFillTransform
.matrix
[i
] );
248 nTmp
= sal_uInt16(rClass
.mbTiling
);
249 rOStm
.WriteUInt16( nTmp
);
250 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maHatchType
);
251 rOStm
.WriteUInt16( nTmp
);
252 WriteColor( rOStm
, rClass
.maHatchColor
);
253 nTmp
= sal::static_int_cast
<sal_uInt16
>( rClass
.maGradientType
);
254 rOStm
.WriteUInt16( nTmp
);
255 WriteColor( rOStm
, rClass
.maGradient1stColor
);
256 WriteColor( rOStm
, rClass
.maGradient2ndColor
);
257 rOStm
.WriteInt32( rClass
.maGradientStepCount
);
258 WriteGraphic( rOStm
, rClass
.maFillGraphic
);
263 SvStream
& ReadSvtGraphicFill( SvStream
& rIStm
, SvtGraphicFill
& rClass
)
265 VersionCompat
aCompat( rIStm
, StreamMode::READ
);
267 rClass
.maPath
.Read( rIStm
);
268 ReadColor( rIStm
, rClass
.maFillColor
);
269 rIStm
.ReadDouble( rClass
.mfTransparency
);
271 rIStm
.ReadUInt16( nTmp
);
272 rClass
.maFillRule
= SvtGraphicFill::FillRule( nTmp
);
273 rIStm
.ReadUInt16( nTmp
);
274 rClass
.maFillType
= SvtGraphicFill::FillType( nTmp
);
276 for(i
=0; i
<SvtGraphicFill::Transform::MatrixSize
; ++i
)
277 rIStm
.ReadDouble( rClass
.maFillTransform
.matrix
[i
] );
278 rIStm
.ReadUInt16( nTmp
);
279 rClass
.mbTiling
= nTmp
;
280 rIStm
.ReadUInt16( nTmp
);
281 rClass
.maHatchType
= SvtGraphicFill::HatchType( nTmp
);
282 ReadColor( rIStm
, rClass
.maHatchColor
);
283 rIStm
.ReadUInt16( nTmp
);
284 rClass
.maGradientType
= SvtGraphicFill::GradientType( nTmp
);
285 ReadColor( rIStm
, rClass
.maGradient1stColor
);
286 ReadColor( rIStm
, rClass
.maGradient2ndColor
);
287 rIStm
.ReadInt32( rClass
.maGradientStepCount
);
288 ReadGraphic( rIStm
, rClass
.maFillGraphic
);
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */