LibreOffice Module vcl (master)  1
graphictools.cxx
Go to the documentation of this file.
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 <vcl/TypeSerializer.hxx>
23 #include <vcl/graphictools.hxx>
24 
26 {
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;
29 }
30 
33  mfStrokeWidth(),
34  maCapType(),
35  maJoinType(),
36  mfMiterLimit( 3.0 )
37 {
38 }
39 
41  const tools::PolyPolygon& rStartArrow,
42  const tools::PolyPolygon& rEndArrow,
43  double fTransparency,
44  double fStrokeWidth,
45  CapType aCap,
46  JoinType aJoin,
47  double fMiterLimit,
48  DashArray&& rDashArray ) :
49  maPath( rPath ),
50  maStartArrow( rStartArrow ),
51  maEndArrow( rEndArrow ),
52  mfTransparency( fTransparency ),
53  mfStrokeWidth( fStrokeWidth ),
54  maCapType( aCap ),
55  maJoinType( aJoin ),
56  mfMiterLimit( fMiterLimit ),
57  maDashArray( std::move(rDashArray) )
58 {
59 }
60 
62 {
63  rPath = maPath;
64 }
65 
67 {
68  rPath = maStartArrow;
69 }
70 
72 {
73  rPath = maEndArrow;
74 }
75 
76 
77 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
78 {
79  rDashArray = maDashArray;
80 }
81 
83 {
84  maPath = rPoly;
85 }
86 
88 {
89  maStartArrow = rPoly;
90 }
91 
93 {
94  maEndArrow = rPoly;
95 }
96 
97 void SvtGraphicStroke::scale( double fXScale, double fYScale )
98 {
99  // Clearly scaling stroke-width for fat lines is rather a problem
100  maPath.Scale( fXScale, fYScale );
101 
102  double fScale = sqrt (fabs (fXScale * fYScale) ); // clearly not ideal.
103  mfStrokeWidth *= fScale;
104  mfMiterLimit *= fScale;
105 
106  maStartArrow.Scale( fXScale, fYScale );
107  maEndArrow.Scale( fXScale, fYScale );
108 }
109 
111 {
112  VersionCompatWrite aCompat( rOStm, 1 );
113 
114  rClass.maPath.Write( rOStm );
115  rClass.maStartArrow.Write( rOStm );
116  rClass.maEndArrow.Write( rOStm );
117  rOStm.WriteDouble( rClass.mfTransparency );
118  rOStm.WriteDouble( rClass.mfStrokeWidth );
119  sal_uInt16 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maCapType );
120  rOStm.WriteUInt16( nTmp );
121  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maJoinType );
122  rOStm.WriteUInt16( nTmp );
123  rOStm.WriteDouble( rClass.mfMiterLimit );
124 
125  rOStm.WriteUInt32( rClass.maDashArray.size() );
126  size_t i;
127  for(i=0; i<rClass.maDashArray.size(); ++i)
128  rOStm.WriteDouble( rClass.maDashArray[i] );
129 
130  return rOStm;
131 }
132 
134 {
135  VersionCompatRead aCompat( rIStm );
136 
137  rClass.maPath.Read( rIStm );
138  rClass.maStartArrow.Read( rIStm );
139  rClass.maEndArrow.Read( rIStm );
140  rIStm.ReadDouble( rClass.mfTransparency );
141  rIStm.ReadDouble( rClass.mfStrokeWidth );
142  sal_uInt16 nTmp;
143  rIStm.ReadUInt16( nTmp );
144  rClass.maCapType = SvtGraphicStroke::CapType(nTmp);
145  rIStm.ReadUInt16( nTmp );
146  rClass.maJoinType = SvtGraphicStroke::JoinType(nTmp);
147  rIStm.ReadDouble( rClass.mfMiterLimit );
148 
149  sal_uInt32 nSize;
150  rIStm.ReadUInt32( nSize );
151  rClass.maDashArray.resize(nSize);
152  size_t i;
153  for(i=0; i<rClass.maDashArray.size(); ++i)
154  rIStm.ReadDouble( rClass.maDashArray[i] );
155 
156  return rIStm;
157 }
158 
161  mfTransparency(),
162  maFillRule(),
163  maFillType(),
164  mbTiling( false ),
165  maHatchType(),
166  maHatchColor( COL_BLACK ),
167  maGradientType(),
168  maGradient1stColor( COL_BLACK ),
169  maGradient2ndColor( COL_BLACK ),
170  maGradientStepCount( gradientStepsInfinite )
171 {
172 }
173 
175  Color aFillColor,
176  double fTransparency,
177  FillRule aFillRule,
178  FillType aFillType,
179  const Transform& aFillTransform,
180  bool bTiling,
181  HatchType aHatchType,
182  Color aHatchColor,
183  GradientType aGradientType,
184  Color aGradient1stColor,
185  Color aGradient2ndColor,
186  sal_Int32 aGradientStepCount,
187  const Graphic& aFillGraphic ) :
188  maPath( rPath ),
189  maFillColor( aFillColor ),
190  mfTransparency( fTransparency ),
191  maFillRule( aFillRule ),
192  maFillType( aFillType ),
193  maFillTransform( aFillTransform ),
194  mbTiling( bTiling ),
195  maHatchType( aHatchType ),
196  maHatchColor( aHatchColor ),
197  maGradientType( aGradientType ),
198  maGradient1stColor( aGradient1stColor ),
199  maGradient2ndColor( aGradient2ndColor ),
200  maGradientStepCount( aGradientStepCount ),
201  maFillGraphic( aFillGraphic )
202 {
203 }
204 
206 {
207  rPath = maPath;
208 }
209 
210 
212 {
213  rTrans = maFillTransform;
214 }
215 
216 
217 void SvtGraphicFill::getGraphic( Graphic& rGraphic ) const
218 {
219  rGraphic = maFillGraphic;
220 }
221 
223 {
224  maPath = rPath;
225 }
226 
228 {
229  VersionCompatWrite aCompat( rOStm, 1 );
230 
231  rClass.maPath.Write( rOStm );
232  TypeSerializer aSerializer(rOStm);
233  aSerializer.writeColor(rClass.maFillColor);
234  rOStm.WriteDouble( rClass.mfTransparency );
235  sal_uInt16 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillRule );
236  rOStm.WriteUInt16( nTmp );
237  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillType );
238  rOStm.WriteUInt16( nTmp );
239  int i;
241  rOStm.WriteDouble( rClass.maFillTransform.matrix[i] );
242  nTmp = sal_uInt16(rClass.mbTiling);
243  rOStm.WriteUInt16( nTmp );
244  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maHatchType );
245  rOStm.WriteUInt16( nTmp );
246  aSerializer.writeColor(rClass.maHatchColor);
247  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maGradientType );
248  rOStm.WriteUInt16( nTmp );
249  aSerializer.writeColor(rClass.maGradient1stColor);
250  aSerializer.writeColor(rClass.maGradient2ndColor);
251  rOStm.WriteInt32( rClass.maGradientStepCount );
252  aSerializer.writeGraphic(rClass.maFillGraphic);
253 
254  return rOStm;
255 }
256 
258 {
259  VersionCompatRead aCompat( rIStm );
260 
261  rClass.maPath.Read( rIStm );
262 
263  TypeSerializer aSerializer(rIStm);
264  aSerializer.readColor(rClass.maFillColor);
265  rIStm.ReadDouble( rClass.mfTransparency );
266  sal_uInt16 nTmp;
267  rIStm.ReadUInt16( nTmp );
268  rClass.maFillRule = SvtGraphicFill::FillRule( nTmp );
269  rIStm.ReadUInt16( nTmp );
270  rClass.maFillType = SvtGraphicFill::FillType( nTmp );
271  for (int i = 0; i < SvtGraphicFill::Transform::MatrixSize; ++i)
272  rIStm.ReadDouble( rClass.maFillTransform.matrix[i] );
273  rIStm.ReadUInt16( nTmp );
274  rClass.mbTiling = nTmp;
275  rIStm.ReadUInt16( nTmp );
276  rClass.maHatchType = SvtGraphicFill::HatchType( nTmp );
277  aSerializer.readColor(rClass.maHatchColor);
278  rIStm.ReadUInt16( nTmp );
280  aSerializer.readColor(rClass.maGradient1stColor);
281  aSerializer.readColor(rClass.maGradient2ndColor);
282  rIStm.ReadInt32( rClass.maGradientStepCount );
283  aSerializer.readGraphic(rClass.maFillGraphic);
284 
285  return rIStm;
286 }
287 
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CapType
Style for open stroke ends.
Any maPath
void setStartArrow(const tools::PolyPolygon &)
Set the polygon that is put at the start of the line.
void readGraphic(Graphic &rGraphic)
void getTransform(Transform &) const
Get transformation applied to hatch, gradient or texture during fill.
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & WriteInt32(sal_Int32 nInt32)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
Color maGradient1stColor
void Write(SvStream &rOStream) const
SvStream & WriteSvtGraphicStroke(SvStream &rOStm, const SvtGraphicStroke &rClass)
void getGraphic(Graphic &) const
Get the texture graphic used.
Encapsulates geometry and associated attributes of a graphical 'pen stroke'.
FillRule
Type of fill algorithm used.
void Scale(double fScaleX, double fScaleY)
DashArray maDashArray
FillType
Type of filling used.
GradientType
Type of gradient used.
HatchType
Type of hatching used.
SvStream & ReadSvtGraphicStroke(SvStream &rIStm, SvtGraphicStroke &rClass)
void Write(SvStream &rOStream) const
SvStream & ReadSvtGraphicFill(SvStream &rIStm, SvtGraphicFill &rClass)
void Scale(double fScaleX, double fScaleY)
void Read(SvStream &rIStream)
void scale(double fScaleX, double fScaleY)
Affine scaling in both X and Y dimensions.
double matrix[MatrixSize]
SvStream & WriteUInt32(sal_uInt32 nUInt32)
HatchType maHatchType
void setPath(const tools::PolyPolygon &rPath)
Set path to fill.
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
GradientType maGradientType
int i
tools::PolyPolygon maPath
Transform maFillTransform
tools::Polygon maPath
void getPath(tools::Polygon &) const
Query path to stroke.
SvStream & ReadDouble(double &rDouble)
void getStartArrow(tools::PolyPolygon &) const
Get the polygon that is put at the start of the line.
SvStream & ReadInt32(sal_Int32 &rInt32)
SvStream & WriteSvtGraphicFill(SvStream &rOStm, const SvtGraphicFill &rClass)
uno::Sequence< double > maFillColor
sal_Int32 maGradientStepCount
void setEndArrow(const tools::PolyPolygon &)
Set the polygon that is put at the end of the line.
void getDashArray(DashArray &) const
Get an array of "on" and "off" lengths for stroke dashing.
tools::PolyPolygon maEndArrow
FillType maFillType
JoinType
Style for joins of individual stroke segments.
::std::vector< double > DashArray
Color maGradient2ndColor
FillRule maFillRule
Graphic maFillGraphic
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
void setPath(const tools::Polygon &)
Set path to stroke.
Encapsulates geometry and associated attributes of a filled area.
SvStream & WriteDouble(const double &rDouble)
void getEndArrow(tools::PolyPolygon &) const
Get the polygon that is put at the end of the line.
void getPath(tools::PolyPolygon &) const
Query path to fill.
void writeColor(const Color &rColor)
void writeGraphic(const Graphic &rGraphic)
tools::PolyPolygon maStartArrow
Homogeneous 2D transformation matrix.
void readColor(Color &rColor)
void Read(SvStream &rIStream)