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 
32  maPath(),
33  maStartArrow(),
34  maEndArrow(),
36  mfStrokeWidth(),
37  maCapType(),
38  maJoinType(),
39  mfMiterLimit( 3.0 ),
40  maDashArray()
41 {
42 }
43 
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 )
62 {
63 }
64 
66 {
67  rPath = maPath;
68 }
69 
71 {
72  rPath = maStartArrow;
73 }
74 
76 {
77  rPath = maEndArrow;
78 }
79 
80 
81 void SvtGraphicStroke::getDashArray( DashArray& rDashArray ) const
82 {
83  rDashArray = maDashArray;
84 }
85 
87 {
88  maPath = rPoly;
89 }
90 
92 {
93  maStartArrow = rPoly;
94 }
95 
97 {
98  maEndArrow = rPoly;
99 }
100 
101 void SvtGraphicStroke::scale( double fXScale, double fYScale )
102 {
103  // Clearly scaling stroke-width for fat lines is rather a problem
104  maPath.Scale( fXScale, fYScale );
105 
106  double fScale = sqrt (fabs (fXScale * fYScale) ); // clearly not ideal.
107  mfStrokeWidth *= fScale;
108  mfMiterLimit *= fScale;
109 
110  maStartArrow.Scale( fXScale, fYScale );
111  maEndArrow.Scale( fXScale, fYScale );
112 }
113 
115 {
116  VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
117 
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 );
128 
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] );
133 
134  return rOStm;
135 }
136 
138 {
139  VersionCompat aCompat( rIStm, StreamMode::READ );
140 
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 );
152 
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] );
159 
160  return rIStm;
161 }
162 
164  maPath(),
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()
178 {
179 }
180 
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 )
209 {
210 }
211 
213 {
214  rPath = maPath;
215 }
216 
217 
219 {
220  rTrans = maFillTransform;
221 }
222 
223 
224 void SvtGraphicFill::getGraphic( Graphic& rGraphic ) const
225 {
226  rGraphic = maFillGraphic;
227 }
228 
230 {
231  maPath = rPath;
232 }
233 
235 {
236  VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
237 
238  rClass.maPath.Write( rOStm );
239  TypeSerializer aSerializer(rOStm);
240  aSerializer.writeColor(rClass.maFillColor);
241  rOStm.WriteDouble( rClass.mfTransparency );
242  sal_uInt16 nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillRule );
243  rOStm.WriteUInt16( nTmp );
244  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maFillType );
245  rOStm.WriteUInt16( nTmp );
246  int i;
248  rOStm.WriteDouble( rClass.maFillTransform.matrix[i] );
249  nTmp = sal_uInt16(rClass.mbTiling);
250  rOStm.WriteUInt16( nTmp );
251  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maHatchType );
252  rOStm.WriteUInt16( nTmp );
253  aSerializer.writeColor(rClass.maHatchColor);
254  nTmp = sal::static_int_cast<sal_uInt16>( rClass.maGradientType );
255  rOStm.WriteUInt16( nTmp );
256  aSerializer.writeColor(rClass.maGradient1stColor);
257  aSerializer.writeColor(rClass.maGradient2ndColor);
258  rOStm.WriteInt32( rClass.maGradientStepCount );
259  aSerializer.writeGraphic(rClass.maFillGraphic);
260 
261  return rOStm;
262 }
263 
265 {
266  VersionCompat aCompat( rIStm, StreamMode::READ );
267 
268  rClass.maPath.Read( rIStm );
269 
270  TypeSerializer aSerializer(rIStm);
271  aSerializer.readColor(rClass.maFillColor);
272  rIStm.ReadDouble( rClass.mfTransparency );
273  sal_uInt16 nTmp;
274  rIStm.ReadUInt16( nTmp );
275  rClass.maFillRule = SvtGraphicFill::FillRule( nTmp );
276  rIStm.ReadUInt16( nTmp );
277  rClass.maFillType = SvtGraphicFill::FillType( nTmp );
278  for (int i = 0; i < SvtGraphicFill::Transform::MatrixSize; ++i)
279  rIStm.ReadDouble( rClass.maFillTransform.matrix[i] );
280  rIStm.ReadUInt16( nTmp );
281  rClass.mbTiling = nTmp;
282  rIStm.ReadUInt16( nTmp );
283  rClass.maHatchType = SvtGraphicFill::HatchType( nTmp );
284  aSerializer.readColor(rClass.maHatchColor);
285  rIStm.ReadUInt16( nTmp );
287  aSerializer.readColor(rClass.maGradient1stColor);
288  aSerializer.readColor(rClass.maGradient2ndColor);
289  rIStm.ReadInt32( rClass.maGradientStepCount );
290  aSerializer.readGraphic(rClass.maFillGraphic);
291 
292  return rIStm;
293 }
294 
295 /* 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)