Photon 1.0.0
Loading...
Searching...
No Matches
gradient.h
Go to the documentation of this file.
1#ifndef LITEHTML_GRADIENT_H
2#define LITEHTML_GRADIENT_H
3
4namespace litehtml
5{
18 static_assert(gradient_side_left == (1 << background_position_left), "parse_bg_position is also used to parse radial gradient position");
19
26
27#define radial_extent_strings "closest-corner;closest-side;farthest-corner;farthest-side"
36
37#define color_space_strings \
38 "srgb;"\
39 "srgb-linear;"\
40 "display-p3;"\
41 "a98-rgb;"\
42 "prophoto-rgb;"\
43 "rec2020;"\
44 "lab;"\
45 "oklab;"\
46 "xyz;"\
47 "xyz-d50;"\
48 "xyz-d65;"\
49 "hsl;"\
50 "hwb;"\
51 "lch;"\
52 "oklch"
53
77
78#define hue_interpolation_strings "shorter;longer;increasing;decreasing"
87
89 {
90 public:
91 // https://drafts.csswg.org/css-images-4/#typedef-color-stop-list
92 // color_stop represents <linear-color-stop> | <linear-color-hint> | <angular-color-stop> | <angular-color-hint>
93 // <linear-color-stop> = <color> <length-percentage>{1,2}?
94 // <linear-color-hint> = <length-percentage>
95 // <angular-color-stop> = <color> <angle-percentage>{1,2}?
96 // <angular-color-hint> = <angle-percentage>
97 // If two lengths/angles are specified they create two color-stops with the same color.
113
114 string_id m_type;
115 uint32_t m_side;
116 float angle;
117 vector<color_stop> m_colors;
127
128
129 explicit gradient(string_id type = empty_id)
130 {
131 m_type = type;
132
133 // linear gradient: m_side default is gradient_side_none (use angle)
134 // radial,conic gradient: m_side default is gradient_side_x_center | gradient_side_y_center (see parse_gradient)
136 // linear gradient angle, used when m_side == gradient_side_none
137 angle = 180; // to bottom
138 // radial,conic position (together with m_side)
141
142 // actual default depends on the number of radii provided, see parse_radial_gradient_shape_size_position_interpolation
144
145 // <radial-size> https://drafts.csswg.org/css-images-3/#valdef-radial-gradient-radial-size
146 // if radius is specified radial_extent will be set to none, see parse_radial_size
150
152
153 // If the host syntax does not define what color space interpolation should take place in, it defaults to Oklab.
155 // Unless otherwise specified, if no specific hue interpolation algorithm is selected by the host syntax, the default is shorter.
157 }
158
159 bool is_empty() const
160 {
161 return m_type == empty_id || m_colors.empty();
162 }
163
164 bool is_linear() const { return m_type == _linear_gradient_ || m_type == _repeating_linear_gradient_; }
165 bool is_radial() const { return m_type == _radial_gradient_ || m_type == _repeating_radial_gradient_; }
166 bool is_conic() const { return m_type == _conic_gradient_ || m_type == _repeating_conic_gradient_; }
167
169 };
170
171 class image
172 {
173 public:
181 string url;
183
185
186 bool is_empty() const
187 {
188 switch (type)
189 {
190 case type_none:
191 return true;
192 case type_url:
193 return url.empty();
194 case type_gradient:
195 return m_gradient.is_empty();
196 }
197 return true;
198 }
199 };
200
201 bool parse_gradient(const css_token& token, gradient& gradient, document_container* container);
202}
203
204#endif //LITEHTML_GRADIENT_H
Definition css_length.h:22
void predef(int val)
Definition css_length.h:79
Definition gradient.h:99
bool is_color_hint
Definition gradient.h:101
web_color color
Definition gradient.h:102
optional< float > angle
Definition gradient.h:104
color_stop(css_length length)
Definition gradient.h:110
color_stop(web_color color, css_length length)
Definition gradient.h:108
color_stop()
Definition gradient.h:106
color_stop(web_color color, float angle)
Definition gradient.h:109
optional< css_length > length
Definition gradient.h:103
color_stop(float angle)
Definition gradient.h:111
color_stop(web_color color)
Definition gradient.h:107
Definition gradient.h:89
bool is_radial() const
Definition gradient.h:165
uint32_t m_side
Definition gradient.h:115
string_id m_type
Definition gradient.h:114
float conic_from_angle
Definition gradient.h:124
float angle
Definition gradient.h:116
hue_interpolation_t hue_interpolation
Definition gradient.h:126
css_length position_x
Definition gradient.h:118
css_length position_y
Definition gradient.h:119
bool is_linear() const
Definition gradient.h:164
color_space_t color_space
Definition gradient.h:125
vector< color_stop > m_colors
Definition gradient.h:117
radial_extent_t radial_extent
Definition gradient.h:121
static gradient transparent
Definition gradient.h:168
bool is_conic() const
Definition gradient.h:166
bool is_empty() const
Definition gradient.h:159
radial_shape_t radial_shape
Definition gradient.h:120
css_length radial_radius_y
Definition gradient.h:123
css_length radial_radius_x
Definition gradient.h:122
gradient(string_id type=empty_id)
Definition gradient.h:129
Definition gradient.h:172
bool is_empty() const
Definition gradient.h:186
image()
Definition gradient.h:184
type type
Definition gradient.h:180
type
Definition gradient.h:175
@ type_url
Definition gradient.h:177
@ type_none
Definition gradient.h:176
@ type_gradient
Definition gradient.h:178
string url
Definition gradient.h:181
gradient m_gradient
Definition gradient.h:182
Definition url.h:41
type
Definition core.h:681
Definition background.h:12
@ background_position_left
Definition types.h:552
radial_shape_t
Definition gradient.h:21
@ radial_shape_circle
Definition gradient.h:23
@ radial_shape_ellipse
Definition gradient.h:24
@ radial_shape_none
Definition gradient.h:22
bool parse_gradient(const css_token &token, gradient &gradient, document_container *container)
Definition gradient.cpp:92
radial_extent_t
Definition gradient.h:29
@ radial_extent_closest_side
Definition gradient.h:32
@ radial_extent_closest_corner
Definition gradient.h:31
@ radial_extent_farthest_side
Definition gradient.h:34
@ radial_extent_farthest_corner
Definition gradient.h:33
@ radial_extent_none
Definition gradient.h:30
const string_id empty_id
Definition string_id.cpp:35
color_space_t
Definition gradient.h:55
@ color_space_xyz_d65
Definition gradient.h:69
@ color_space_hwb
Definition gradient.h:73
@ color_space_xyz
Definition gradient.h:67
@ color_space_polar_start
Definition gradient.h:72
@ color_space_oklch
Definition gradient.h:75
@ color_space_rec2020
Definition gradient.h:64
@ color_space_lab
Definition gradient.h:65
@ color_space_none
Definition gradient.h:56
@ color_space_a98_rgb
Definition gradient.h:62
@ color_space_xyz_d50
Definition gradient.h:68
@ color_space_srgb
Definition gradient.h:59
@ color_space_display_p3
Definition gradient.h:61
@ color_space_lch
Definition gradient.h:74
@ color_space_prophoto_rgb
Definition gradient.h:63
@ color_space_hsl
Definition gradient.h:72
@ color_space_oklab
Definition gradient.h:66
@ color_space_srgb_linear
Definition gradient.h:60
hue_interpolation_t
Definition gradient.h:80
@ hue_interpolation_shorter
Definition gradient.h:82
@ hue_interpolation_decreasing
Definition gradient.h:85
@ hue_interpolation_none
Definition gradient.h:81
@ hue_interpolation_longer
Definition gradient.h:83
@ hue_interpolation_increasing
Definition gradient.h:84
gradient_side
Definition gradient.h:7
@ gradient_side_top
Definition gradient.h:11
@ gradient_side_x_center
Definition gradient.h:13
@ gradient_side_y_length
Definition gradient.h:16
@ gradient_side_none
Definition gradient.h:8
@ gradient_side_bottom
Definition gradient.h:12
@ gradient_side_left
Definition gradient.h:9
@ gradient_side_y_center
Definition gradient.h:14
@ gradient_side_right
Definition gradient.h:10
@ gradient_side_x_length
Definition gradient.h:15
Definition Bitmap.h:10
Definition web_color.h:9