Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / source / gdi / graphictools.cxx
blobd8889bb718954836faee7f432d1720a796cdb828
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>
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() :
32 maPath(),
33 maStartArrow(),
34 maEndArrow(),
35 mfTransparency(),
36 mfStrokeWidth(),
37 maCapType(),
38 maJoinType(),
39 mfMiterLimit( 3.0 ),
40 maDashArray()
44 SvtGraphicStroke::SvtGraphicStroke( const tools::Polygon& rPath,
45 const tools::PolyPolygon& rStartArrow,
46 const tools::PolyPolygon& rEndArrow,
47 double fTransparency,
48 double fStrokeWidth,
49 CapType aCap,
50 JoinType aJoin,
51 double fMiterLimit,
52 const DashArray& rDashArray ) :
53 maPath( rPath ),
54 maStartArrow( rStartArrow ),
55 maEndArrow( rEndArrow ),
56 mfTransparency( fTransparency ),
57 mfStrokeWidth( fStrokeWidth ),
58 maCapType( aCap ),
59 maJoinType( aJoin ),
60 mfMiterLimit( fMiterLimit ),
61 maDashArray( rDashArray )
65 void SvtGraphicStroke::getPath( tools::Polygon& rPath ) const
67 rPath = maPath;
70 void SvtGraphicStroke::getStartArrow( tools::PolyPolygon& rPath ) const
72 rPath = maStartArrow;
75 void SvtGraphicStroke::getEndArrow( tools::PolyPolygon& rPath ) const
77 rPath = maEndArrow;
81 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
83 rDashArray = maDashArray;
86 void SvtGraphicStroke::setPath( const tools::Polygon& rPoly )
88 maPath = rPoly;
91 void SvtGraphicStroke::setStartArrow( const tools::PolyPolygon& rPoly )
93 maStartArrow = rPoly;
96 void SvtGraphicStroke::setEndArrow( const tools::PolyPolygon& rPoly )
98 maEndArrow = 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() );
130 size_t i;
131 for(i=0; i<rClass.maDashArray.size(); ++i)
132 rOStm.WriteDouble( rClass.maDashArray[i] );
134 return rOStm;
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 );
146 sal_uInt16 nTmp;
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 );
153 sal_uInt32 nSize;
154 rIStm.ReadUInt32( nSize );
155 rClass.maDashArray.resize(nSize);
156 size_t i;
157 for(i=0; i<rClass.maDashArray.size(); ++i)
158 rIStm.ReadDouble( rClass.maDashArray[i] );
160 return rIStm;
163 SvtGraphicFill::SvtGraphicFill() :
164 maPath(),
165 maFillColor( COL_BLACK ),
166 mfTransparency(),
167 maFillRule(),
168 maFillType(),
169 maFillTransform(),
170 mbTiling( false ),
171 maHatchType(),
172 maHatchColor( COL_BLACK ),
173 maGradientType(),
174 maGradient1stColor( COL_BLACK ),
175 maGradient2ndColor( COL_BLACK ),
176 maGradientStepCount( gradientStepsInfinite ),
177 maFillGraphic()
181 SvtGraphicFill::SvtGraphicFill( const tools::PolyPolygon& rPath,
182 Color aFillColor,
183 double fTransparency,
184 FillRule aFillRule,
185 FillType aFillType,
186 const Transform& aFillTransform,
187 bool bTiling,
188 HatchType aHatchType,
189 Color aHatchColor,
190 GradientType aGradientType,
191 Color aGradient1stColor,
192 Color aGradient2ndColor,
193 sal_Int32 aGradientStepCount,
194 const Graphic& aFillGraphic ) :
195 maPath( rPath ),
196 maFillColor( aFillColor ),
197 mfTransparency( fTransparency ),
198 maFillRule( aFillRule ),
199 maFillType( aFillType ),
200 maFillTransform( aFillTransform ),
201 mbTiling( bTiling ),
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
214 rPath = maPath;
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 )
231 maPath = 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 );
245 int i;
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 );
260 return rOStm;
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 );
270 sal_uInt16 nTmp;
271 rIStm.ReadUInt16( nTmp );
272 rClass.maFillRule = SvtGraphicFill::FillRule( nTmp );
273 rIStm.ReadUInt16( nTmp );
274 rClass.maFillType = SvtGraphicFill::FillType( nTmp );
275 int i;
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 );
290 return rIStm;
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */