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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
#ifndef LH_BORDERS_H
#define LH_BORDERS_H
#include "css_length.h"
#include "types.h"
#include "web_color.h"
namespace litehtml
{
struct css_border
{
css_length width;
border_style style;
web_color color;
css_border()
{
style = border_style_none;
}
css_border(const css_border& val)
{
width = val.width;
style = val.style;
color = val.color;
}
css_border& operator=(const css_border& val)
{
width = val.width;
style = val.style;
color = val.color;
return *this;
}
string to_string() const;
};
struct border
{
int width;
border_style style;
web_color color;
border()
{
width = 0;
}
border(const border& val)
{
width = val.width;
style = val.style;
color = val.color;
}
border(const css_border& val)
{
width = (int) val.width.val();
style = val.style;
color = val.color;
}
border& operator=(const border& val)
{
width = val.width;
style = val.style;
color = val.color;
return *this;
}
border& operator=(const css_border& val)
{
width = (int) val.width.val();
style = val.style;
color = val.color;
return *this;
}
};
struct border_radiuses
{
int top_left_x;
int top_left_y;
int top_right_x;
int top_right_y;
int bottom_right_x;
int bottom_right_y;
int bottom_left_x;
int bottom_left_y;
border_radiuses()
{
top_left_x = 0;
top_left_y = 0;
top_right_x = 0;
top_right_y = 0;
bottom_right_x = 0;
bottom_right_y = 0;
bottom_left_x = 0;
bottom_left_y = 0;
}
border_radiuses(const border_radiuses& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
}
border_radiuses& operator = (const border_radiuses& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
return *this;
}
void operator += (const margins& mg)
{
top_left_x += mg.left;
top_left_y += mg.top;
top_right_x += mg.right;
top_right_y += mg.top;
bottom_right_x += mg.right;
bottom_right_y += mg.bottom;
bottom_left_x += mg.left;
bottom_left_y += mg.bottom;
fix_values();
}
void operator -= (const margins& mg)
{
top_left_x -= mg.left;
top_left_y -= mg.top;
top_right_x -= mg.right;
top_right_y -= mg.top;
bottom_right_x -= mg.right;
bottom_right_y -= mg.bottom;
bottom_left_x -= mg.left;
bottom_left_y -= mg.bottom;
fix_values();
}
void fix_values()
{
if (top_left_x < 0) top_left_x = 0;
if (top_left_y < 0) top_left_y = 0;
if (top_right_x < 0) top_right_x = 0;
if (top_right_y < 0) top_right_y = 0;
if (bottom_right_x < 0) bottom_right_x = 0;
if (bottom_right_y < 0) bottom_right_y = 0;
if (bottom_left_x < 0) bottom_left_x = 0;
if (bottom_left_y < 0) bottom_left_y = 0;
}
void fix_values(int width, int height)
{
fix_values();
int half_width = width / 2;
int half_height = height / 2;
auto fix_one = [&](int& radii_x, int& radii_y)
{
double factor = std::min((double) half_width / (double) radii_x, (double) half_height / (double) radii_y);
radii_x = (int) ((double) radii_x * factor);
radii_y = (int) ((double) radii_y * factor);
};
if(top_left_x > half_width || top_left_y > half_height)
{
fix_one(top_left_x, top_left_y);
}
if(top_right_x > half_width || top_right_y > half_height)
{
fix_one(top_right_x, top_right_y);
}
if(bottom_right_x > half_width || bottom_right_y > half_height)
{
fix_one(bottom_right_x, bottom_right_y);
}
if(bottom_left_x > half_width || bottom_left_y > half_height)
{
fix_one(bottom_left_x, bottom_left_y);
}
}
};
struct css_border_radius
{
css_length top_left_x;
css_length top_left_y;
css_length top_right_x;
css_length top_right_y;
css_length bottom_right_x;
css_length bottom_right_y;
css_length bottom_left_x;
css_length bottom_left_y;
css_border_radius()
{
}
css_border_radius(const css_border_radius& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
}
css_border_radius& operator=(const css_border_radius& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
return *this;
}
border_radiuses calc_percents(int width, int height) const
{
border_radiuses ret;
ret.bottom_left_x = bottom_left_x.calc_percent(width);
ret.bottom_left_y = bottom_left_y.calc_percent(height);
ret.top_left_x = top_left_x.calc_percent(width);
ret.top_left_y = top_left_y.calc_percent(height);
ret.top_right_x = top_right_x.calc_percent(width);
ret.top_right_y = top_right_y.calc_percent(height);
ret.bottom_right_x = bottom_right_x.calc_percent(width);
ret.bottom_right_y = bottom_right_y.calc_percent(height);
ret.fix_values(width, height);
return ret;
}
};
struct css_borders
{
css_border left;
css_border top;
css_border right;
css_border bottom;
css_border_radius radius;
css_borders() = default;
bool is_visible() const
{
return left.width.val() != 0 || right.width.val() != 0 || top.width.val() != 0 || bottom.width.val() != 0;
}
css_borders(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
}
css_borders& operator=(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
return *this;
}
string to_string() const
{
return "left: " + left.to_string() +
", top: " + top.to_string() +
", right: " + top.to_string() +
", bottom: " + bottom.to_string();
}
};
struct borders
{
border left;
border top;
border right;
border bottom;
border_radiuses radius;
borders() = default;
borders(const borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
}
borders(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
}
bool is_visible() const
{
return left.width != 0 || right.width != 0 || top.width != 0 || bottom.width != 0;
}
borders& operator=(const borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
return *this;
}
borders& operator=(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
return *this;
}
};
}
#endif // LH_BORDERS_H
|