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 <tools/vcompat.hxx>
22 #include <tools/GenericTypeSerializer.hxx>
23
24 #include <vcl/graphictools.hxx>
25
Transform()26 SvtGraphicFill::Transform::Transform()
27 {
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;
30 }
31
SvtGraphicStroke()32 SvtGraphicStroke::SvtGraphicStroke() :
33 maPath(),
34 maStartArrow(),
35 maEndArrow(),
36 mfTransparency(),
37 mfStrokeWidth(),
38 maCapType(),
39 maJoinType(),
40 mfMiterLimit( 3.0 ),
41 maDashArray()
42 {
43 }
44
SvtGraphicStroke(const tools::Polygon & rPath,const tools::PolyPolygon & rStartArrow,const tools::PolyPolygon & rEndArrow,double fTransparency,double fStrokeWidth,CapType aCap,JoinType aJoin,double fMiterLimit,const DashArray & rDashArray)45 SvtGraphicStroke::SvtGraphicStroke( const tools::Polygon& rPath,
46 const tools::PolyPolygon& rStartArrow,
47 const tools::PolyPolygon& rEndArrow,
48 double fTransparency,
49 double fStrokeWidth,
50 CapType aCap,
51 JoinType aJoin,
52 double fMiterLimit,
53 const DashArray& rDashArray ) :
54 maPath( rPath ),
55 maStartArrow( rStartArrow ),
56 maEndArrow( rEndArrow ),
57 mfTransparency( fTransparency ),
58 mfStrokeWidth( fStrokeWidth ),
59 maCapType( aCap ),
60 maJoinType( aJoin ),
61 mfMiterLimit( fMiterLimit ),
62 maDashArray( rDashArray )
63 {
64 }
65
getPath(tools::Polygon & rPath) const66 void SvtGraphicStroke::getPath( tools::Polygon& rPath ) const
67 {
68 rPath = maPath;
69 }
70
getStartArrow(tools::PolyPolygon & rPath) const71 void SvtGraphicStroke::getStartArrow( tools::PolyPolygon& rPath ) const
72 {
73 rPath = maStartArrow;
74 }
75
getEndArrow(tools::PolyPolygon & rPath) const76 void SvtGraphicStroke::getEndArrow( tools::PolyPolygon& rPath ) const
77 {
78 rPath = maEndArrow;
79 }
80
81
getDashArray(DashArray & rDashArray) const82 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
83 {
84 rDashArray = maDashArray;
85 }
86
setPath(const tools::Polygon & rPoly)87 void SvtGraphicStroke::setPath( const tools::Polygon& rPoly )
88 {
89 maPath = rPoly;
90 }
91
setStartArrow(const tools::PolyPolygon & rPoly)92 void SvtGraphicStroke::setStartArrow( const tools::PolyPolygon& rPoly )
93 {
94 maStartArrow = rPoly;
95 }
96
setEndArrow(const tools::PolyPolygon & rPoly)97 void SvtGraphicStroke::setEndArrow( const tools::PolyPolygon& rPoly )
98 {
99 maEndArrow = rPoly;
100 }
101
scale(double fXScale,double fYScale)102 void SvtGraphicStroke::scale( double fXScale, double fYScale )
103 {
104 // Clearly scaling stroke-width for fat lines is rather a problem
105 maPath.Scale( fXScale, fYScale );
106
107 double fScale = sqrt (fabs (fXScale * fYScale) ); // clearly not ideal.
108 mfStrokeWidth *= fScale;
109 mfMiterLimit *= fScale;
110
111 maStartArrow.Scale( fXScale, fYScale );
112 maEndArrow.Scale( fXScale, fYScale );
113 }
114
WriteSvtGraphicStroke(SvStream & rOStm,const SvtGraphicStroke & rClass)115 SvStream& WriteSvtGraphicStroke( SvStream& rOStm, const SvtGraphicStroke& rClass )
116 {
117 VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
118
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 );
129
130 rOStm.WriteUInt32( rClass.maDashArray.size() );
131 size_t i;
132 for(i=0; i<rClass.maDashArray.size(); ++i)
133 rOStm.WriteDouble( rClass.maDashArray[i] );
134
135 return rOStm;
136 }
137
ReadSvtGraphicStroke(SvStream & rIStm,SvtGraphicStroke & rClass)138 SvStream& ReadSvtGraphicStroke( SvStream& rIStm, SvtGraphicStroke& rClass )
139 {
140 VersionCompat aCompat( rIStm, StreamMode::READ );
141
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 );
147 sal_uInt16 nTmp;
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 );
153
154 sal_uInt32 nSize;
155 rIStm.ReadUInt32( nSize );
156 rClass.maDashArray.resize(nSize);
157 size_t i;
158 for(i=0; i<rClass.maDashArray.size(); ++i)
159 rIStm.ReadDouble( rClass.maDashArray[i] );
160
161 return rIStm;
162 }
163
SvtGraphicFill()164 SvtGraphicFill::SvtGraphicFill() :
165 maPath(),
166 maFillColor( COL_BLACK ),
167 mfTransparency(),
168 maFillRule(),
169 maFillType(),
170 maFillTransform(),
171 mbTiling( false ),
172 maHatchType(),
173 maHatchColor( COL_BLACK ),
174 maGradientType(),
175 maGradient1stColor( COL_BLACK ),
176 maGradient2ndColor( COL_BLACK ),
177 maGradientStepCount( gradientStepsInfinite ),
178 maFillGraphic()
179 {
180 }
181
SvtGraphicFill(const tools::PolyPolygon & rPath,Color aFillColor,double fTransparency,FillRule aFillRule,FillType aFillType,const Transform & aFillTransform,bool bTiling,HatchType aHatchType,Color aHatchColor,GradientType aGradientType,Color aGradient1stColor,Color aGradient2ndColor,sal_Int32 aGradientStepCount,const Graphic & aFillGraphic)182 SvtGraphicFill::SvtGraphicFill( const tools::PolyPolygon& rPath,
183 Color aFillColor,
184 double fTransparency,
185 FillRule aFillRule,
186 FillType aFillType,
187 const Transform& aFillTransform,
188 bool bTiling,
189 HatchType aHatchType,
190 Color aHatchColor,
191 GradientType aGradientType,
192 Color aGradient1stColor,
193 Color aGradient2ndColor,
194 sal_Int32 aGradientStepCount,
195 const Graphic& aFillGraphic ) :
196 maPath( rPath ),
197 maFillColor( aFillColor ),
198 mfTransparency( fTransparency ),
199 maFillRule( aFillRule ),
200 maFillType( aFillType ),
201 maFillTransform( aFillTransform ),
202 mbTiling( bTiling ),
203 maHatchType( aHatchType ),
204 maHatchColor( aHatchColor ),
205 maGradientType( aGradientType ),
206 maGradient1stColor( aGradient1stColor ),
207 maGradient2ndColor( aGradient2ndColor ),
208 maGradientStepCount( aGradientStepCount ),
209 maFillGraphic( aFillGraphic )
210 {
211 }
212
getPath(tools::PolyPolygon & rPath) const213 void SvtGraphicFill::getPath( tools::PolyPolygon& rPath ) const
214 {
215 rPath = maPath;
216 }
217
218
getTransform(Transform & rTrans) const219 void SvtGraphicFill::getTransform( Transform& rTrans ) const
220 {
221 rTrans = maFillTransform;
222 }
223
224
getGraphic(Graphic & rGraphic) const225 void SvtGraphicFill::getGraphic( Graphic& rGraphic ) const
226 {
227 rGraphic = maFillGraphic;
228 }
229
setPath(const tools::PolyPolygon & rPath)230 void SvtGraphicFill::setPath( const tools::PolyPolygon& rPath )
231 {
232 maPath = rPath;
233 }
234
WriteSvtGraphicFill(SvStream & rOStm,const SvtGraphicFill & rClass)235 SvStream& WriteSvtGraphicFill( SvStream& rOStm, const SvtGraphicFill& rClass )
236 {
237 VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
238
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 );
247 int i;
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 );
261
262 return rOStm;
263 }
264
ReadSvtGraphicFill(SvStream & rIStm,SvtGraphicFill & rClass)265 SvStream& ReadSvtGraphicFill( SvStream& rIStm, SvtGraphicFill& rClass )
266 {
267 VersionCompat aCompat( rIStm, StreamMode::READ );
268
269 rClass.maPath.Read( rIStm );
270
271 tools::GenericTypeSerializer aSerializer(rIStm);
272 aSerializer.readColor(rClass.maFillColor);
273 rIStm.ReadDouble( rClass.mfTransparency );
274 sal_uInt16 nTmp;
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 );
292
293 return rIStm;
294 }
295
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
297