Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / gdi / graphictools.cxx
blob4be1b43fadb77f27ad37cb856e1926c1b16bfba6
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 <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() :
33 maPath(),
34 maStartArrow(),
35 maEndArrow(),
36 mfTransparency(),
37 mfStrokeWidth(),
38 maCapType(),
39 maJoinType(),
40 mfMiterLimit( 3.0 ),
41 maDashArray()
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 )
66 void SvtGraphicStroke::getPath( tools::Polygon& rPath ) const
68 rPath = maPath;
71 void SvtGraphicStroke::getStartArrow( tools::PolyPolygon& rPath ) const
73 rPath = maStartArrow;
76 void SvtGraphicStroke::getEndArrow( tools::PolyPolygon& rPath ) const
78 rPath = maEndArrow;
82 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
84 rDashArray = maDashArray;
87 void SvtGraphicStroke::setPath( const tools::Polygon& rPoly )
89 maPath = rPoly;
92 void SvtGraphicStroke::setStartArrow( const tools::PolyPolygon& rPoly )
94 maStartArrow = rPoly;
97 void SvtGraphicStroke::setEndArrow( const tools::PolyPolygon& rPoly )
99 maEndArrow = 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() );
131 size_t i;
132 for(i=0; i<rClass.maDashArray.size(); ++i)
133 rOStm.WriteDouble( rClass.maDashArray[i] );
135 return rOStm;
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 );
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 );
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] );
161 return rIStm;
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()
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 )
213 void SvtGraphicFill::getPath( tools::PolyPolygon& rPath ) const
215 rPath = maPath;
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 )
232 maPath = 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 );
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 );
262 return rOStm;
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 );
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 );
293 return rIStm;
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */