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