/src/serenity/Userland/Libraries/LibWeb/CSS/FontFace.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibGfx/Font/VectorFont.h> |
10 | | #include <LibURL/URL.h> |
11 | | #include <LibWeb/Bindings/FontFacePrototype.h> |
12 | | #include <LibWeb/Bindings/PlatformObject.h> |
13 | | #include <LibWeb/CSS/ParsedFontFace.h> |
14 | | |
15 | | namespace Web::CSS { |
16 | | |
17 | | struct FontFaceDescriptors { |
18 | | String style = "normal"_string; |
19 | | String weight = "normal"_string; |
20 | | String stretch = "normal"_string; |
21 | | String unicode_range = "U+0-10FFFF"_string; |
22 | | String feature_settings = "normal"_string; |
23 | | String variation_settings = "normal"_string; |
24 | | String display = "auto"_string; |
25 | | String ascent_override = "normal"_string; |
26 | | String descent_override = "normal"_string; |
27 | | String line_gap_override = "normal"_string; |
28 | | }; |
29 | | |
30 | | class FontFace final : public Bindings::PlatformObject { |
31 | | WEB_PLATFORM_OBJECT(FontFace, Bindings::PlatformObject); |
32 | | JS_DECLARE_ALLOCATOR(FontFace); |
33 | | |
34 | | public: |
35 | | using FontFaceSource = Variant<String, JS::Handle<WebIDL::BufferSource>>; |
36 | | |
37 | | [[nodiscard]] static JS::NonnullGCPtr<FontFace> construct_impl(JS::Realm&, String family, FontFaceSource source, FontFaceDescriptors const& descriptors); |
38 | | virtual ~FontFace() override; |
39 | | |
40 | 0 | String family() const { return m_family; } |
41 | | WebIDL::ExceptionOr<void> set_family(String const&); |
42 | | |
43 | 0 | String style() const { return m_style; } |
44 | | WebIDL::ExceptionOr<void> set_style(String const&); |
45 | | |
46 | 0 | String weight() const { return m_weight; } |
47 | | WebIDL::ExceptionOr<void> set_weight(String const&); |
48 | | |
49 | 0 | String stretch() const { return m_stretch; } |
50 | | WebIDL::ExceptionOr<void> set_stretch(String const&); |
51 | | |
52 | 0 | String unicode_range() const { return m_unicode_range; } |
53 | | WebIDL::ExceptionOr<void> set_unicode_range(String const&); |
54 | | |
55 | 0 | String feature_settings() const { return m_feature_settings; } |
56 | | WebIDL::ExceptionOr<void> set_feature_settings(String const&); |
57 | | |
58 | 0 | String variation_settings() const { return m_variation_settings; } |
59 | | WebIDL::ExceptionOr<void> set_variation_settings(String const&); |
60 | | |
61 | 0 | String display() const { return m_display; } |
62 | | WebIDL::ExceptionOr<void> set_display(String const&); |
63 | | |
64 | 0 | String ascent_override() const { return m_ascent_override; } |
65 | | WebIDL::ExceptionOr<void> set_ascent_override(String const&); |
66 | | |
67 | 0 | String descent_override() const { return m_descent_override; } |
68 | | WebIDL::ExceptionOr<void> set_descent_override(String const&); |
69 | | |
70 | 0 | String line_gap_override() const { return m_line_gap_override; } |
71 | | WebIDL::ExceptionOr<void> set_line_gap_override(String const&); |
72 | | |
73 | 0 | bool is_css_connected() const { return m_is_css_connected; } |
74 | | |
75 | 0 | Bindings::FontFaceLoadStatus status() const { return m_status; } |
76 | | |
77 | | JS::NonnullGCPtr<JS::Promise> load(); |
78 | | JS::NonnullGCPtr<JS::Promise> loaded() const; |
79 | | |
80 | | void load_font_source(); |
81 | | |
82 | 0 | JS::NonnullGCPtr<WebIDL::Promise> font_status_promise() { return m_font_status_promise; } |
83 | | |
84 | | private: |
85 | | FontFace(JS::Realm&, JS::NonnullGCPtr<WebIDL::Promise> font_status_promise, Vector<ParsedFontFace::Source> urls, ByteBuffer data, String family, FontFaceDescriptors const& descriptors); |
86 | | |
87 | | virtual void initialize(JS::Realm&) override; |
88 | | virtual void visit_edges(Visitor&) override; |
89 | | |
90 | | // FIXME: Should we be storing StyleValues instead? |
91 | | String m_family; |
92 | | String m_style; |
93 | | String m_weight; |
94 | | String m_stretch; |
95 | | String m_unicode_range; |
96 | | Vector<Gfx::UnicodeRange> m_unicode_ranges; |
97 | | String m_feature_settings; |
98 | | String m_variation_settings; |
99 | | String m_display; |
100 | | String m_ascent_override; |
101 | | String m_descent_override; |
102 | | String m_line_gap_override; |
103 | | |
104 | | // https://drafts.csswg.org/css-font-loading/#dom-fontface-status |
105 | | Bindings::FontFaceLoadStatus m_status { Bindings::FontFaceLoadStatus::Unloaded }; |
106 | | |
107 | | JS::NonnullGCPtr<WebIDL::Promise> m_font_status_promise; // [[FontStatusPromise]] |
108 | | Vector<ParsedFontFace::Source> m_urls; // [[Urls]] |
109 | | ByteBuffer m_binary_data; // [[Data]] |
110 | | |
111 | | RefPtr<Gfx::VectorFont> m_parsed_font; |
112 | | RefPtr<Core::Promise<NonnullRefPtr<Gfx::VectorFont>>> m_font_load_promise; |
113 | | |
114 | | // https://drafts.csswg.org/css-font-loading/#css-connected |
115 | | bool m_is_css_connected { false }; |
116 | | }; |
117 | | |
118 | | } |