9
9
#include < LibWeb/Bindings/FontFacePrototype.h>
10
10
#include < LibWeb/Bindings/Intrinsics.h>
11
11
#include < LibWeb/CSS/FontFace.h>
12
+ #include < LibWeb/CSS/Parser/Parser.h>
12
13
#include < LibWeb/WebIDL/Promise.h>
13
14
14
15
namespace Web ::CSS {
15
16
16
17
JS_DEFINE_ALLOCATOR (FontFace);
17
18
19
+ template <CSS::PropertyID PropertyID>
20
+ RefPtr<CSS::StyleValue const > parse_property_string (JS::Realm& realm, StringView value)
21
+ {
22
+ auto maybe_parser = CSS::Parser::Parser::create (CSS::Parser::ParsingContext (realm), value);
23
+ if (maybe_parser.is_error ())
24
+ return {};
25
+
26
+ return maybe_parser.release_value ().parse_as_css_value (PropertyID);
27
+ }
28
+
18
29
JS::NonnullGCPtr<FontFace> FontFace::construct_impl (JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const & descriptors)
19
30
{
20
31
return realm.heap ().allocate <FontFace>(realm, realm, move (family), move (source), descriptors);
21
32
}
22
33
23
- FontFace::FontFace (JS::Realm& realm, String, FontFaceSource, FontFaceDescriptors const &)
34
+ FontFace::FontFace (JS::Realm& realm, String font_family , FontFaceSource, FontFaceDescriptors const & descriptors )
24
35
: Bindings::PlatformObject(realm)
25
36
{
37
+ // FIXME: Validate these values the same way as the setters
38
+ m_family = move (font_family);
39
+ m_style = descriptors.style ;
40
+ m_weight = descriptors.weight ;
41
+ m_stretch = descriptors.stretch ;
42
+ m_unicode_range = descriptors.unicode_range ;
43
+ m_feature_settings = descriptors.feature_settings ;
44
+ m_variation_settings = descriptors.variation_settings ;
45
+ m_display = descriptors.display ;
46
+ m_ascent_override = descriptors.ascent_override ;
47
+ m_descent_override = descriptors.descent_override ;
48
+ m_line_gap_override = descriptors.line_gap_override ;
26
49
}
27
50
28
51
void FontFace::initialize (JS::Realm& realm)
@@ -32,6 +55,114 @@ void FontFace::initialize(JS::Realm& realm)
32
55
WEB_SET_PROTOTYPE_FOR_INTERFACE (FontFace);
33
56
}
34
57
58
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-family
59
+ WebIDL::ExceptionOr<void > FontFace::set_family (String const & string)
60
+ {
61
+ auto property = parse_property_string<CSS::PropertyID::FontFamily>(realm (), string);
62
+ if (!property)
63
+ return WebIDL::SyntaxError::create (realm (), " FontFace.family setter: Invalid font descriptor" _fly_string);
64
+
65
+ if (m_is_css_connected) {
66
+ // FIXME: Propagate to the CSSFontFaceRule and update the font-family property
67
+ }
68
+
69
+ m_family = property->to_string ();
70
+
71
+ return {};
72
+ }
73
+
74
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-style
75
+ WebIDL::ExceptionOr<void > FontFace::set_style (String const & string)
76
+ {
77
+ auto property = parse_property_string<CSS::PropertyID::FontStyle>(realm (), string);
78
+ if (!property)
79
+ return WebIDL::SyntaxError::create (realm (), " FontFace.style setter: Invalid font descriptor" _fly_string);
80
+
81
+ if (m_is_css_connected) {
82
+ // FIXME: Propagate to the CSSFontFaceRule and update the font-style property
83
+ }
84
+
85
+ m_style = property->to_string ();
86
+
87
+ return {};
88
+ }
89
+
90
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-weight
91
+ WebIDL::ExceptionOr<void > FontFace::set_weight (String const & string)
92
+ {
93
+ auto property = parse_property_string<CSS::PropertyID::FontWeight>(realm (), string);
94
+ if (!property)
95
+ return WebIDL::SyntaxError::create (realm (), " FontFace.weight setter: Invalid font descriptor" _fly_string);
96
+
97
+ if (m_is_css_connected) {
98
+ // FIXME: Propagate to the CSSFontFaceRule and update the font-weight property
99
+ }
100
+
101
+ m_weight = property->to_string ();
102
+
103
+ return {};
104
+ }
105
+
106
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-stretch
107
+ WebIDL::ExceptionOr<void > FontFace::set_stretch (String const & string)
108
+ {
109
+ auto property = parse_property_string<CSS::PropertyID::FontStretch>(realm (), string);
110
+ if (!property)
111
+ return WebIDL::SyntaxError::create (realm (), " FontFace.stretch setter: Invalid font descriptor" _fly_string);
112
+
113
+ if (m_is_css_connected) {
114
+ // FIXME: Propagate to the CSSFontFaceRule and update the font-stretch property
115
+ }
116
+
117
+ m_stretch = property->to_string ();
118
+
119
+ return {};
120
+ }
121
+
122
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-unicoderange
123
+ WebIDL::ExceptionOr<void > FontFace::set_unicode_range (String const &)
124
+ {
125
+ // FIXME: This *should* work, but the <urange> production is hard to parse
126
+ // from just a value string in our implementation
127
+ return WebIDL::NotSupportedError::create (realm (), " unicode range is not yet implemented" _fly_string);
128
+ }
129
+
130
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-featuresettings
131
+ WebIDL::ExceptionOr<void > FontFace::set_feature_settings (String const &)
132
+ {
133
+ return WebIDL::NotSupportedError::create (realm (), " feature settings is not yet implemented" _fly_string);
134
+ }
135
+
136
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-variationsettings
137
+ WebIDL::ExceptionOr<void > FontFace::set_variation_settings (String const &)
138
+ {
139
+ return WebIDL::NotSupportedError::create (realm (), " variation settings is not yet implemented" _fly_string);
140
+ }
141
+
142
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-display
143
+ WebIDL::ExceptionOr<void > FontFace::set_display (String const &)
144
+ {
145
+ return WebIDL::NotSupportedError::create (realm (), " display is not yet implemented" _fly_string);
146
+ }
147
+
148
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-ascentoverride
149
+ WebIDL::ExceptionOr<void > FontFace::set_ascent_override (String const &)
150
+ {
151
+ return WebIDL::NotSupportedError::create (realm (), " ascent override is not yet implemented" _fly_string);
152
+ }
153
+
154
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-descentoverride
155
+ WebIDL::ExceptionOr<void > FontFace::set_descent_override (String const &)
156
+ {
157
+ return WebIDL::NotSupportedError::create (realm (), " descent override is not yet implemented" _fly_string);
158
+ }
159
+
160
+ // https://drafts.csswg.org/css-font-loading/#dom-fontface-linegapoverride
161
+ WebIDL::ExceptionOr<void > FontFace::set_line_gap_override (String const &)
162
+ {
163
+ return WebIDL::NotSupportedError::create (realm (), " line gap override is not yet implemented" _fly_string);
164
+ }
165
+
35
166
// https://drafts.csswg.org/css-font-loading/#dom-fontface-load
36
167
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> FontFace::load ()
37
168
{
0 commit comments