1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <tools/stream.hxx>
#include <tools/vcompat.hxx>
#include <vcl/lineinfo.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dlinegeometry.hxx>
#include <numeric>
ImplLineInfo::ImplLineInfo()
: mnWidth(0)
, mnDashLen(0)
, mnDotLen(0)
, mnDistance(0)
, meLineJoin(basegfx::B2DLineJoin::Round)
, meLineCap(css::drawing::LineCap_BUTT)
, meStyle(LineStyle::Solid)
, mnDashCount(0)
, mnDotCount(0)
{
}
inline bool ImplLineInfo::operator==( const ImplLineInfo& rB ) const
{
return(meStyle == rB.meStyle
&& mnWidth == rB.mnWidth
&& mnDashCount == rB.mnDashCount
&& mnDashLen == rB.mnDashLen
&& mnDotCount == rB.mnDotCount
&& mnDotLen == rB.mnDotLen
&& mnDistance == rB.mnDistance
&& meLineJoin == rB.meLineJoin
&& meLineCap == rB.meLineCap);
}
LineInfo::LineInfo( LineStyle eStyle, sal_Int32 nWidth ) : mpImplLineInfo()
{
mpImplLineInfo->meStyle = eStyle;
mpImplLineInfo->mnWidth = nWidth;
}
LineInfo::LineInfo( const LineInfo& ) = default;
LineInfo::LineInfo( LineInfo&& ) = default;
LineInfo::~LineInfo() = default;
LineInfo& LineInfo::operator=( const LineInfo& ) = default;
LineInfo& LineInfo::operator=( LineInfo&& ) = default;
bool LineInfo::operator==( const LineInfo& rLineInfo ) const
{
return mpImplLineInfo == rLineInfo.mpImplLineInfo;
}
void LineInfo::SetStyle( LineStyle eStyle )
{
mpImplLineInfo->meStyle = eStyle;
}
void LineInfo::SetWidth( sal_Int32 nWidth )
{
mpImplLineInfo->mnWidth = nWidth;
}
void LineInfo::SetDashCount( sal_uInt16 nDashCount )
{
mpImplLineInfo->mnDashCount = nDashCount;
}
void LineInfo::SetDashLen( sal_Int32 nDashLen )
{
mpImplLineInfo->mnDashLen = nDashLen;
}
void LineInfo::SetDotCount( sal_uInt16 nDotCount )
{
mpImplLineInfo->mnDotCount = nDotCount;
}
void LineInfo::SetDotLen( sal_Int32 nDotLen )
{
mpImplLineInfo->mnDotLen = nDotLen;
}
void LineInfo::SetDistance( sal_Int32 nDistance )
{
mpImplLineInfo->mnDistance = nDistance;
}
void LineInfo::SetLineJoin(basegfx::B2DLineJoin eLineJoin)
{
if(eLineJoin != mpImplLineInfo->meLineJoin)
{
mpImplLineInfo->meLineJoin = eLineJoin;
}
}
void LineInfo::SetLineCap(css::drawing::LineCap eLineCap)
{
if(eLineCap != mpImplLineInfo->meLineCap)
{
mpImplLineInfo->meLineCap = eLineCap;
}
}
bool LineInfo::IsDefault() const
{
return( !mpImplLineInfo->mnWidth
&& ( LineStyle::Solid == mpImplLineInfo->meStyle )
&& ( css::drawing::LineCap_BUTT == mpImplLineInfo->meLineCap));
}
SvStream& ReadLineInfo( SvStream& rIStm, LineInfo& rLineInfo )
{
VersionCompat aCompat( rIStm, StreamMode::READ );
sal_uInt16 nTmp16(0);
sal_Int32 nTmp32(0);
rIStm.ReadUInt16( nTmp16 ); rLineInfo.mpImplLineInfo->meStyle = static_cast<LineStyle>(nTmp16);
rIStm.ReadInt32( nTmp32 );
rLineInfo.mpImplLineInfo->mnWidth = nTmp32;
if( aCompat.GetVersion() >= 2 )
{
// version 2
rIStm.ReadUInt16( rLineInfo.mpImplLineInfo->mnDashCount ).ReadInt32( nTmp32 );
rLineInfo.mpImplLineInfo->mnDashLen = nTmp32;
rIStm.ReadUInt16( rLineInfo.mpImplLineInfo->mnDotCount ).ReadInt32( nTmp32 );
rLineInfo.mpImplLineInfo->mnDotLen = nTmp32;
rIStm.ReadInt32( nTmp32 );
rLineInfo.mpImplLineInfo->mnDistance = nTmp32;
}
if( aCompat.GetVersion() >= 3 )
{
// version 3
rIStm.ReadUInt16( nTmp16 ); rLineInfo.mpImplLineInfo->meLineJoin = static_cast<basegfx::B2DLineJoin>(nTmp16);
}
if( aCompat.GetVersion() >= 4 )
{
// version 4
rIStm.ReadUInt16( nTmp16 ); rLineInfo.mpImplLineInfo->meLineCap = static_cast<css::drawing::LineCap>(nTmp16);
}
return rIStm;
}
SvStream& WriteLineInfo( SvStream& rOStm, const LineInfo& rLineInfo )
{
VersionCompat aCompat( rOStm, StreamMode::WRITE, 4 );
// version 1
rOStm.WriteUInt16( static_cast<sal_uInt16>(rLineInfo.mpImplLineInfo->meStyle) )
.WriteInt32( rLineInfo.mpImplLineInfo->mnWidth );
// since version2
rOStm.WriteUInt16( rLineInfo.mpImplLineInfo->mnDashCount )
.WriteInt32( rLineInfo.mpImplLineInfo->mnDashLen );
rOStm.WriteUInt16( rLineInfo.mpImplLineInfo->mnDotCount )
.WriteInt32( rLineInfo.mpImplLineInfo->mnDotLen );
rOStm.WriteInt32( rLineInfo.mpImplLineInfo->mnDistance );
// since version3
rOStm.WriteUInt16( static_cast<sal_uInt16>(rLineInfo.mpImplLineInfo->meLineJoin) );
// since version4
rOStm.WriteUInt16( static_cast<sal_uInt16>(rLineInfo.mpImplLineInfo->meLineCap) );
return rOStm;
}
void LineInfo::applyToB2DPolyPolygon(
basegfx::B2DPolyPolygon& io_rLinePolyPolygon,
basegfx::B2DPolyPolygon& o_rFillPolyPolygon) const
{
o_rFillPolyPolygon.clear();
if(io_rLinePolyPolygon.count())
{
if(LineStyle::Dash == GetStyle())
{
::std::vector< double > fDotDashArray;
const double fDashLen(GetDashLen());
const double fDotLen(GetDotLen());
const double fDistance(GetDistance());
for(sal_uInt16 a(0); a < GetDashCount(); a++)
{
fDotDashArray.push_back(fDashLen);
fDotDashArray.push_back(fDistance);
}
for(sal_uInt16 b(0); b < GetDotCount(); b++)
{
fDotDashArray.push_back(fDotLen);
fDotDashArray.push_back(fDistance);
}
const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0));
if(fAccumulated > 0.0)
{
basegfx::B2DPolyPolygon aResult;
for(auto const& rPolygon : io_rLinePolyPolygon)
{
basegfx::B2DPolyPolygon aLineTraget;
basegfx::utils::applyLineDashing(
rPolygon,
fDotDashArray,
&aLineTraget);
aResult.append(aLineTraget);
}
io_rLinePolyPolygon = aResult;
}
}
if(GetWidth() > 1 && io_rLinePolyPolygon.count())
{
const double fHalfLineWidth((GetWidth() * 0.5) + 0.5);
for(auto const& rPolygon : io_rLinePolyPolygon)
{
o_rFillPolyPolygon.append(basegfx::utils::createAreaGeometry(
rPolygon,
fHalfLineWidth,
GetLineJoin(),
GetLineCap()));
}
io_rLinePolyPolygon.clear();
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|