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>
23 
24 #include <vcl/graphictools.hxx>
25 
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 
33  maPath(),
34  maStartArrow(),
35  maEndArrow(),
37  mfStrokeWidth(),
38  maCapType(),
39  maJoinType(),
40  mfMiterLimit( 3.0 ),
41  maDashArray()
42 {
43 }
44 
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 
67 {
68  rPath = maPath;
69 }
70 
72 {
73  rPath = maStartArrow;
74 }
75 
77 {
78  rPath = maEndArrow;
79 }
80 
81 
82 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
83 {
84  rDashArray = maDashArray;
85 }
86 
88 {
89  maPath = rPoly;
90 }
91 
93 {
94  maStartArrow = rPoly;
95 }
96 
98 {
99  maEndArrow = rPoly;
100 }
101 
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 
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 
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 
165  maPath(),
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 
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 
214 {
215  rPath = maPath;
216 }
217 
218 
220 {
221  rTrans = maFillTransform;
222 }
223 
224 
225 void SvtGraphicFill::getGraphic( Graphic& rGraphic ) const
226 {
227  rGraphic = maFillGraphic;
228 }
229 
231 {
232  maPath = rPath;
233 }
234 
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;
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 
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 );
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: */
CapType
Style for open stroke ends.
void setStartArrow(const tools::PolyPolygon &)
Set the polygon that is put at the start of the line.
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
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 ReadGraphic(SvStream &rIStream, Graphic &rGraphic)
Definition: graph.cxx:539
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
tools::PolyPolygon maPath
int i
void WriteGraphic(SvStream &rOStream, const Graphic &rGraphic)
Definition: graph.cxx:545
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
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)
tools::PolyPolygon maStartArrow
Homogeneous 2D transformation matrix.
void readColor(Color &rColor)
void Read(SvStream &rIStream)