Coverage Report

Created: 2026-07-20 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwpg/src/lib/WPGDashArray.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwpg
3
 * Version: MPL 2.0 / LGPLv2.1+
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
 * Major Contributor(s):
10
 * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
11
 *
12
 * For minor contributions see the git repository.
13
 *
14
 * Alternatively, the contents of this file may be used under the terms
15
 * of the GNU Lesser General Public License Version 2.1 or later
16
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
17
 * applicable instead of those above.
18
 *
19
 * For further information visit http://libwpg.sourceforge.net
20
 */
21
22
/* "This product is not manufactured, approved, or supported by
23
 * Corel Corporation or Corel Corporation Limited."
24
 */
25
26
#include "WPGDashArray.h"
27
28
#include <vector>
29
30
namespace libwpg
31
{
32
class WPGDashArrayPrivate
33
{
34
public:
35
0
  WPGDashArrayPrivate() : dashes(), dots1(0), dots2(0),
36
0
    dots1len(0.0), dots2len(0.0), gap(0.0) {}
37
  void _recalculateDots();
38
  std::vector<double> dashes;
39
  int dots1;
40
  int dots2;
41
  double dots1len;
42
  double dots2len;
43
  double gap;
44
};
45
}
46
47
void libwpg::WPGDashArrayPrivate::_recalculateDots()
48
0
{
49
0
  dots1 = dots2 = 0,
50
0
  dots1len = dots2len = gap = 0.0;
51
52
0
  if (dashes.size() >= 2)
53
0
  {
54
0
    dots1len = dashes[0];
55
0
    gap = dashes[1];
56
0
  }
57
58
0
  auto count = unsigned(dashes.size() / 2);
59
0
  unsigned i = 0;
60
0
  for (; i < count;)
61
0
  {
62
0
    if (dots1len <= dashes[2*i] && dots1len >= dashes[2*i])
63
0
      dots1++;
64
0
    else
65
0
      break;
66
0
    gap = gap < dashes[2*i+1] ?  dashes[2*i+1] : gap;
67
0
    i++;
68
0
  }
69
0
  if (i < count)
70
0
  {
71
0
    dots2len = dashes[2*i];
72
0
    gap = gap < dashes[2*i+1] ? dashes[2*i+1] : gap;
73
0
  }
74
0
  for (; i < count;)
75
0
  {
76
0
    if (dots2len <= dashes[2*i] && dots2len >= dashes[2*i])
77
0
      dots2++;
78
0
    else
79
0
      break;
80
0
    gap = gap < dashes[2*i+1] ? dashes[2*i+1] : gap;
81
0
    i++;
82
0
  }
83
0
  if (!dots2)
84
0
  {
85
0
    dots2 = dots1;
86
0
    dots2len = dots1len;
87
0
  }
88
0
}
89
90
91
0
libwpg::WPGDashArray::WPGDashArray() : d(new libwpg::WPGDashArrayPrivate())
92
0
{
93
0
  d->_recalculateDots();
94
0
}
95
96
libwpg::WPGDashArray::~WPGDashArray()
97
0
{
98
0
}
99
100
libwpg::WPGDashArray::WPGDashArray(const libwpg::WPGDashArray &dash):
101
0
  d(new libwpg::WPGDashArrayPrivate())
102
0
{
103
0
  d->dashes = dash.d->dashes;
104
0
  d->_recalculateDots();
105
0
}
106
107
libwpg::WPGDashArray &libwpg::WPGDashArray::operator=(const libwpg::WPGDashArray &dash)
108
0
{
109
0
  if (this != &dash)
110
0
  {
111
0
    d->dashes = dash.d->dashes;
112
0
    d->_recalculateDots();
113
0
  }
114
0
  return *this;
115
0
}
116
117
int libwpg::WPGDashArray::getDots1() const
118
0
{
119
0
  return d->dots1;
120
0
}
121
122
double libwpg::WPGDashArray::getDots1Length() const
123
0
{
124
0
  return d->dots1len;
125
0
}
126
127
int libwpg::WPGDashArray::getDots2() const
128
0
{
129
0
  return d->dots2;
130
0
}
131
132
double libwpg::WPGDashArray::getDots2Length() const
133
0
{
134
0
  return d->dots2len;
135
0
}
136
137
double libwpg::WPGDashArray::getDistance() const
138
0
{
139
0
  return d->gap;
140
0
}
141
142
void libwpg::WPGDashArray::add(double p)
143
0
{
144
0
  d->dashes.push_back(p);
145
0
  d->_recalculateDots();
146
0
}
147
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */