Coverage Report

Created: 2026-09-23 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wt/src/Wt/WPen.C
Line
Count
Source
1
/*
2
 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
3
 *
4
 * See the LICENSE file for terms of use.
5
 */
6
7
#include "Wt/WPen.h"
8
9
#include "Wt/WLogger.h"
10
#include "Wt/WStringStream.h"
11
12
#include "Wt/Json/Array.h"
13
#include "Wt/Json/Object.h"
14
#include "Wt/Json/Value.h"
15
16
namespace Wt {
17
18
LOGGER("WPen");
19
20
WPen::WPen()
21
0
  : penStyle_(PenStyle::SolidLine),
22
0
    penCapStyle_(PenCapStyle::Square),
23
0
    penJoinStyle_(PenJoinStyle::Bevel),
24
0
    width_(0),
25
0
    color_(StandardColor::Black)
26
0
{ }
27
28
WPen::WPen(PenStyle style)
29
0
  : penStyle_(style),
30
0
    penCapStyle_(PenCapStyle::Square),
31
0
    penJoinStyle_(PenJoinStyle::Bevel),
32
0
    width_(0),
33
0
    color_(StandardColor::Black)
34
0
{ }
35
36
WPen::WPen(const WColor& color)
37
0
  : penStyle_(PenStyle::SolidLine),
38
0
    penCapStyle_(PenCapStyle::Square),
39
0
    penJoinStyle_(PenJoinStyle::Bevel),
40
0
    width_(0),
41
0
    color_(color)
42
0
{ }
43
44
WPen::WPen(StandardColor color)
45
0
  : penStyle_(PenStyle::SolidLine),
46
0
    penCapStyle_(PenCapStyle::Square),
47
0
    penJoinStyle_(PenJoinStyle::Bevel),
48
0
    width_(0),
49
0
    color_(WColor(color))
50
0
{ }
51
52
WPen::WPen(const WGradient& gradient)
53
0
  : penStyle_(PenStyle::SolidLine),
54
0
    penCapStyle_(PenCapStyle::Square),
55
0
    penJoinStyle_(PenJoinStyle::Bevel),
56
0
    width_(0),
57
0
    color_(StandardColor::Black)
58
0
{
59
0
  gradient_ = gradient;
60
0
}
61
62
WPen::WPen(const WPen& other)
63
0
  : WJavaScriptExposableObject(other),
64
0
    penStyle_(other.penStyle_),
65
0
    penCapStyle_(other.penCapStyle_),
66
0
    penJoinStyle_(other.penJoinStyle_),
67
0
    width_(other.width_),
68
0
    color_(other.color_)
69
0
{
70
0
  if (other.isJavaScriptBound()) {
71
0
    assignBinding(other);
72
0
  }
73
0
}
74
75
#ifdef WT_TARGET_JAVA
76
WPen WPen::clone() const
77
{
78
  WPen result;
79
  if (isJavaScriptBound()) result.assignBinding(*this);
80
  result.penStyle_ = penStyle_;
81
  result.penCapStyle_ = penCapStyle_;
82
  result.penJoinStyle_ = penJoinStyle_;
83
  result.width_ = width_;
84
  result.color_ = WColor(color_.red(), color_.green(), color_.blue(), color_.alpha());
85
  return result;
86
}
87
#endif // WT_TARGET_JAVA
88
89
void WPen::setStyle(PenStyle style)
90
0
{
91
0
  checkModifiable();
92
0
  penStyle_ = style;
93
0
}
94
95
void WPen::setCapStyle(PenCapStyle style)
96
0
{
97
0
  checkModifiable();
98
0
  penCapStyle_ = style;
99
0
}
100
101
void WPen::setJoinStyle(PenJoinStyle style)
102
0
{
103
0
  checkModifiable();
104
0
  penJoinStyle_ = style;
105
0
}
106
107
void WPen::setWidth(const WLength& width)
108
0
{
109
0
  checkModifiable();
110
0
  width_ = width;
111
0
}
112
113
void WPen::setColor(const WColor& color)
114
0
{
115
0
  checkModifiable();
116
0
  color_ = color;
117
0
  gradient_ = WGradient();
118
0
}
119
120
void WPen::setGradient(const WGradient& gradient)
121
0
{
122
0
  checkModifiable();
123
0
  gradient_ = gradient;
124
0
}
125
126
WPen& WPen::operator=(const WPen& rhs)
127
0
{
128
0
  WJavaScriptExposableObject::operator=(rhs);
129
130
0
  penStyle_ = rhs.penStyle_;
131
0
  penCapStyle_ = rhs.penCapStyle_;
132
0
  penJoinStyle_ = rhs.penJoinStyle_;
133
0
  width_ = rhs.width_;
134
0
  color_ = rhs.color_;
135
0
  gradient_ = rhs.gradient_;
136
137
0
  return *this;
138
0
}
139
140
bool WPen::operator==(const WPen& other) const
141
0
{
142
0
  return
143
0
       sameBindingAs(other)
144
0
    && penStyle_ == other.penStyle_
145
0
    && penCapStyle_ == other.penCapStyle_
146
0
    && penJoinStyle_ == other.penJoinStyle_
147
0
    && width_ == other.width_
148
0
    && color_ == other.color_
149
0
    && gradient_ == other.gradient_;
150
0
}
151
152
bool WPen::operator!=(const WPen& other) const
153
0
{
154
0
  return !(*this == other);
155
0
}
156
157
void WPen::assignFromJSON(const Json::Value &value)
158
0
{
159
0
  try {
160
0
#ifndef WT_TARGET_JAVA
161
0
    const Json::Object &o = value;
162
0
    const Json::Value &color = o.get("color");
163
0
    const Json::Array &col = color;
164
#else
165
    const Json::Object &o = static_cast<const Json::Object &>(value);
166
    const Json::Value &color = o.get("color");
167
    const Json::Array &col = static_cast<const Json::Array &>(color);
168
#endif
169
0
    if (col.size() == 4 &&
170
0
        !col[0].toNumber().isNull() &&
171
0
        !col[1].toNumber().isNull() &&
172
0
        !col[2].toNumber().isNull() &&
173
0
        !col[3].toNumber().isNull()) {
174
0
      color_ = WColor(col[0].toNumber().orIfNull(0),
175
0
                      col[1].toNumber().orIfNull(0),
176
0
                      col[2].toNumber().orIfNull(0),
177
0
                      col[3].toNumber().orIfNull(255));
178
0
    } else {
179
0
      LOG_ERROR("Couldn't convert JSON to WPen");
180
0
    }
181
0
  } catch (std::exception &e) {
182
0
    LOG_ERROR("Couldn't convert JSON to WPen: " + std::string(e.what()));
183
0
  }
184
0
}
185
186
std::string WPen::jsValue() const
187
0
{
188
0
  WStringStream ss;
189
0
  ss << "{\"color\":["
190
0
    << color_.red() << ","
191
0
    << color_.green() << ","
192
0
    << color_.blue() << ","
193
0
    << color_.alpha() << "]}";
194
0
  return ss.str();
195
0
}
196
197
}