ScriptForge - Methods about data arrays
[LibreOffice.git] / vcl / source / gdi / graphictools.cxx
blob8308da0415f581652fc8d1493927586c4f90d010
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <utility>
23 #include <vcl/TypeSerializer.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() :
33 mfTransparency(),
34 mfStrokeWidth(),
35 maCapType(),
36 maJoinType(),
37 mfMiterLimit( 3.0 )
41 SvtGraphicStroke::SvtGraphicStroke( tools::Polygon aPath,
42 tools::PolyPolygon aStartArrow,
43 tools::PolyPolygon aEndArrow,
44 double fTransparency,
45 double fStrokeWidth,
46 CapType aCap,
47 JoinType aJoin,
48 double fMiterLimit,
49 DashArray&& rDashArray ) :
50 maPath(std::move( aPath )),
51 maStartArrow(std::move( aStartArrow )),
52 maEndArrow(std::move( aEndArrow )),
53 mfTransparency( fTransparency ),
54 mfStrokeWidth( fStrokeWidth ),
55 maCapType( aCap ),
56 maJoinType( aJoin ),
57 mfMiterLimit( fMiterLimit ),
58 maDashArray( std::move(rDashArray) )
62 void SvtGraphicStroke::getPath( tools::Polygon& rPath ) const
64 rPath = maPath;
67 void SvtGraphicStroke::getStartArrow( tools::PolyPolygon& rPath ) const
69 rPath = maStartArrow;
72 void SvtGraphicStroke::getEndArrow( tools::PolyPolygon& rPath ) const
74 rPath = maEndArrow;
78 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
80 rDashArray = maDashArray;
83 void SvtGraphicStroke::setPath( const tools::Polygon& rPoly )
85 maPath = rPoly;
88 void SvtGraphicStroke::setStartArrow( const tools::PolyPolygon& rPoly )
90 maStartArrow = rPoly;
93 void SvtGraphicStroke::setEndArrow( const tools::PolyPolygon& rPoly )
95 maEndArrow = rPoly;
98 void SvtGraphicStroke::scale( double fXScale, double fYScale )
100 // Clearly scaling stroke-width for fat lines is rather a problem
101 maPath.Scale( fXScale, fYScale );
103 double fScale = sqrt (fabs (fXScale * fYScale) ); // clearly not ideal.
104 mfStrokeWidth *= fScale;
105 mfMiterLimit *= fScale;
107 maStartArrow.Scale( fXScale, fYScale );
108 maEndArrow.Scale( fXScale, fYScale );
111 SvStream& WriteSvtGraphicStroke( SvStream& rOStm, const SvtGraphicStroke& rClass )
113 VersionCompatWrite aCompat( rOStm, 1 );
115 rClass.maPath.Write( rOStm );
116 rClass.maStartArrow.Write( rOStm );
117 rClass.maEndArrow.Write( rOStm );
118 rOStm.WriteDouble( rClass.mfTransparency );
119 rOStm.WriteDouble( rClass.mfStrokeWidth );
120 sal_uInt16 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maCapType );
121 rOStm.WriteUInt16( nTmp );
122 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maJoinType );
123 rOStm.WriteUInt16( nTmp );
124 rOStm.WriteDouble( rClass.mfMiterLimit );
126 rOStm.WriteUInt32( rClass.maDashArray.size() );
127 size_t i;
128 for(i=0; i<rClass.maDashArray.size(); ++i)
129 rOStm.WriteDouble( rClass.maDashArray[i] );
131 return rOStm;
134 SvStream& ReadSvtGraphicStroke( SvStream& rIStm, SvtGraphicStroke& rClass )
136 VersionCompatRead aCompat( rIStm );
138 rClass.maPath.Read( rIStm );
139 rClass.maStartArrow.Read( rIStm );
140 rClass.maEndArrow.Read( rIStm );
141 rIStm.ReadDouble( rClass.mfTransparency );
142 rIStm.ReadDouble( rClass.mfStrokeWidth );
143 sal_uInt16 nTmp;
144 rIStm.ReadUInt16( nTmp );
145 rClass.maCapType = SvtGraphicStroke::CapType(nTmp);
146 rIStm.ReadUInt16( nTmp );
147 rClass.maJoinType = SvtGraphicStroke::JoinType(nTmp);
148 rIStm.ReadDouble( rClass.mfMiterLimit );
150 sal_uInt32 nSize;
151 rIStm.ReadUInt32( nSize );
152 rClass.maDashArray.resize(nSize);
153 size_t i;
154 for(i=0; i<rClass.maDashArray.size(); ++i)
155 rIStm.ReadDouble( rClass.maDashArray[i] );
157 return rIStm;
160 SvtGraphicFill::SvtGraphicFill() :
161 maFillColor( COL_BLACK ),
162 mfTransparency(),
163 maFillRule(),
164 maFillType(),
165 mbTiling( false ),
166 maHatchType(),
167 maHatchColor( COL_BLACK ),
168 maGradientType(),
169 maGradient1stColor( COL_BLACK ),
170 maGradient2ndColor( COL_BLACK ),
171 maGradientStepCount( gradientStepsInfinite )
175 SvtGraphicFill::SvtGraphicFill( tools::PolyPolygon aPath,
176 Color aFillColor,
177 double fTransparency,
178 FillRule aFillRule,
179 FillType aFillType,
180 const Transform& aFillTransform,
181 bool bTiling,
182 HatchType aHatchType,
183 Color aHatchColor,
184 GradientType aGradientType,
185 Color aGradient1stColor,
186 Color aGradient2ndColor,
187 sal_Int32 aGradientStepCount,
188 Graphic aFillGraphic ) :
189 maPath(std::move( aPath )),
190 maFillColor( aFillColor ),
191 mfTransparency( fTransparency ),
192 maFillRule( aFillRule ),
193 maFillType( aFillType ),
194 maFillTransform( aFillTransform ),
195 mbTiling( bTiling ),
196 maHatchType( aHatchType ),
197 maHatchColor( aHatchColor ),
198 maGradientType( aGradientType ),
199 maGradient1stColor( aGradient1stColor ),
200 maGradient2ndColor( aGradient2ndColor ),
201 maGradientStepCount( aGradientStepCount ),
202 maFillGraphic(std::move( aFillGraphic ))
206 void SvtGraphicFill::getPath( tools::PolyPolygon& rPath ) const
208 rPath = maPath;
212 void SvtGraphicFill::getTransform( Transform& rTrans ) const
214 rTrans = maFillTransform;
218 void SvtGraphicFill::getGraphic( Graphic& rGraphic ) const
220 rGraphic = maFillGraphic;
223 void SvtGraphicFill::setPath( const tools::PolyPolygon& rPath )
225 maPath = rPath;
228 SvStream& WriteSvtGraphicFill( SvStream& rOStm, const SvtGraphicFill& rClass )
230 VersionCompatWrite aCompat( rOStm, 1 );
232 rClass.maPath.Write( rOStm );
233 TypeSerializer aSerializer(rOStm);
234 aSerializer.writeColor(rClass.maFillColor);
235 rOStm.WriteDouble( rClass.mfTransparency );
236 sal_uInt16 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillRule );
237 rOStm.WriteUInt16( nTmp );
238 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillType );
239 rOStm.WriteUInt16( nTmp );
240 int i;
241 for(i=0; i<SvtGraphicFill::Transform::MatrixSize; ++i)
242 rOStm.WriteDouble( rClass.maFillTransform.matrix[i] );
243 nTmp = sal_uInt16(rClass.mbTiling);
244 rOStm.WriteUInt16( nTmp );
245 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maHatchType );
246 rOStm.WriteUInt16( nTmp );
247 aSerializer.writeColor(rClass.maHatchColor);
248 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maGradientType );
249 rOStm.WriteUInt16( nTmp );
250 aSerializer.writeColor(rClass.maGradient1stColor);
251 aSerializer.writeColor(rClass.maGradient2ndColor);
252 rOStm.WriteInt32( rClass.maGradientStepCount );
253 aSerializer.writeGraphic(rClass.maFillGraphic);
255 return rOStm;
258 SvStream& ReadSvtGraphicFill( SvStream& rIStm, SvtGraphicFill& rClass )
260 VersionCompatRead aCompat( rIStm );
262 rClass.maPath.Read( rIStm );
264 TypeSerializer aSerializer(rIStm);
265 aSerializer.readColor(rClass.maFillColor);
266 rIStm.ReadDouble( rClass.mfTransparency );
267 sal_uInt16 nTmp;
268 rIStm.ReadUInt16( nTmp );
269 rClass.maFillRule = SvtGraphicFill::FillRule( nTmp );
270 rIStm.ReadUInt16( nTmp );
271 rClass.maFillType = SvtGraphicFill::FillType( nTmp );
272 for (int i = 0; i < SvtGraphicFill::Transform::MatrixSize; ++i)
273 rIStm.ReadDouble( rClass.maFillTransform.matrix[i] );
274 rIStm.ReadUInt16( nTmp );
275 rClass.mbTiling = nTmp;
276 rIStm.ReadUInt16( nTmp );
277 rClass.maHatchType = SvtGraphicFill::HatchType( nTmp );
278 aSerializer.readColor(rClass.maHatchColor);
279 rIStm.ReadUInt16( nTmp );
280 rClass.maGradientType = SvtGraphicFill::GradientType( nTmp );
281 aSerializer.readColor(rClass.maGradient1stColor);
282 aSerializer.readColor(rClass.maGradient2ndColor);
283 rIStm.ReadInt32( rClass.maGradientStepCount );
284 aSerializer.readGraphic(rClass.maFillGraphic);
286 return rIStm;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */