LibWeb+LibGfx: Move UnicodeRange from LibWeb to LibGfx

In upcoming changes UnicodeRange is going to be used in LibGfx in
a class that represents font cascade list.
This commit is contained in:
Aliaksandr Kalenik 2023-12-09 23:30:01 +01:00 committed by Andreas Kling
parent 0d03257e69
commit f50bf00814
Notes: sideshowbarker 2024-07-17 21:26:19 +09:00
8 changed files with 20 additions and 22 deletions

View file

@ -9,9 +9,8 @@
#include <AK/Assertions.h>
#include <AK/String.h>
namespace Web::CSS {
namespace Gfx {
// https://www.w3.org/TR/css-syntax-3/#urange-syntax
class UnicodeRange {
public:
UnicodeRange(u32 min_code_point, u32 max_code_point)

View file

@ -9,7 +9,7 @@
namespace Web::CSS {
FontFace::FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<UnicodeRange> unicode_ranges)
FontFace::FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges)
: m_font_family(move(font_family))
, m_weight(weight)
, m_slope(slope)

View file

@ -9,7 +9,7 @@
#include <AK/FlyString.h>
#include <AK/URL.h>
#include <LibWeb/CSS/UnicodeRange.h>
#include <LibGfx/Font/UnicodeRange.h>
namespace Web::CSS {
@ -21,14 +21,14 @@ public:
Optional<FlyString> format;
};
FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<UnicodeRange> unicode_ranges);
FontFace(FlyString font_family, Optional<int> weight, Optional<int> slope, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges);
~FontFace() = default;
FlyString font_family() const { return m_font_family; }
Optional<int> weight() const { return m_weight; }
Optional<int> slope() const { return m_slope; }
Vector<Source> const& sources() const { return m_sources; }
Vector<UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }
Vector<Gfx::UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }
// FIXME: font-stretch, font-feature-settings
private:
@ -36,7 +36,7 @@ private:
Optional<int> m_weight { 0 };
Optional<int> m_slope { 0 };
Vector<Source> m_sources;
Vector<UnicodeRange> m_unicode_ranges;
Vector<Gfx::UnicodeRange> m_unicode_ranges;
};
}

View file

@ -1661,7 +1661,7 @@ Optional<Ratio> Parser::parse_ratio(TokenStream<ComponentValue>& tokens)
}
// https://www.w3.org/TR/css-syntax-3/#urange-syntax
Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>& tokens)
Optional<Gfx::UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>& tokens)
{
auto transaction = tokens.begin_transaction();
tokens.skip_whitespace();
@ -1687,7 +1687,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>&
|| component_value.is(Token::Type::Whitespace);
};
auto create_unicode_range = [&](StringView text, auto& local_transaction) -> Optional<UnicodeRange> {
auto create_unicode_range = [&](StringView text, auto& local_transaction) -> Optional<Gfx::UnicodeRange> {
auto maybe_unicode_range = parse_unicode_range(text);
if (maybe_unicode_range.has_value()) {
local_transaction.commit();
@ -1769,9 +1769,9 @@ Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>&
return {};
}
Optional<UnicodeRange> Parser::parse_unicode_range(StringView text)
Optional<Gfx::UnicodeRange> Parser::parse_unicode_range(StringView text)
{
auto make_valid_unicode_range = [&](u32 start_value, u32 end_value) -> Optional<UnicodeRange> {
auto make_valid_unicode_range = [&](u32 start_value, u32 end_value) -> Optional<Gfx::UnicodeRange> {
// https://www.w3.org/TR/css-syntax-3/#maximum-allowed-code-point
constexpr u32 maximum_allowed_code_point = 0x10FFFF;
@ -1790,7 +1790,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(StringView text)
}
// 3. Otherwise, the <urange> represents a contiguous range of codepoints from start value to end value, inclusive.
return UnicodeRange { start_value, end_value };
return Gfx::UnicodeRange { start_value, end_value };
};
// 1. Skipping the first u token, concatenate the representations of all the tokens in the production together.
@ -4160,7 +4160,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
Optional<FlyString> font_family;
Vector<FontFace::Source> src;
Vector<UnicodeRange> unicode_range;
Vector<Gfx::UnicodeRange> unicode_range;
Optional<int> weight;
Optional<int> slope;
@ -4237,7 +4237,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
continue;
}
if (declaration.name().equals_ignoring_ascii_case("unicode-range"sv)) {
Vector<UnicodeRange> unicode_ranges;
Vector<Gfx::UnicodeRange> unicode_ranges;
bool unicode_range_invalid = false;
TokenStream all_tokens { declaration.values() };
auto range_token_lists = parse_a_comma_separated_list_of_component_values(all_tokens);

View file

@ -10,6 +10,7 @@
#include <AK/Error.h>
#include <AK/RefPtr.h>
#include <AK/Vector.h>
#include <LibGfx/Font/UnicodeRange.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/FontFace.h>
#include <LibWeb/CSS/GeneralEnclosed.h>
@ -31,7 +32,6 @@
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
#include <LibWeb/CSS/Supports.h>
#include <LibWeb/CSS/UnicodeRange.h>
#include <LibWeb/Forward.h>
namespace Web::CSS::Parser {
@ -176,8 +176,8 @@ private:
Optional<Length> parse_length(ComponentValue const&);
[[nodiscard]] Optional<LengthOrCalculated> parse_source_size_value(ComponentValue const&);
Optional<Ratio> parse_ratio(TokenStream<ComponentValue>&);
Optional<UnicodeRange> parse_unicode_range(TokenStream<ComponentValue>&);
Optional<UnicodeRange> parse_unicode_range(StringView);
Optional<Gfx::UnicodeRange> parse_unicode_range(TokenStream<ComponentValue>&);
Optional<Gfx::UnicodeRange> parse_unicode_range(StringView);
Optional<GridSize> parse_grid_size(ComponentValue const&);
Optional<GridMinMax> parse_min_max(Vector<ComponentValue> const&);
Optional<GridRepeat> parse_repeat(Vector<ComponentValue> const&);

View file

@ -128,9 +128,9 @@ void serialize_a_local(StringBuilder& builder, StringView path)
}
// NOTE: No spec currently exists for serializing a <'unicode-range'>.
void serialize_unicode_ranges(StringBuilder& builder, Vector<UnicodeRange> const& unicode_ranges)
void serialize_unicode_ranges(StringBuilder& builder, Vector<Gfx::UnicodeRange> const& unicode_ranges)
{
serialize_a_comma_separated_list(builder, unicode_ranges, [](auto& builder, UnicodeRange unicode_range) -> void {
serialize_a_comma_separated_list(builder, unicode_ranges, [](auto& builder, Gfx::UnicodeRange unicode_range) -> void {
return serialize_a_string(builder, unicode_range.to_string());
});
}

View file

@ -11,7 +11,7 @@
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibGfx/Color.h>
#include <LibWeb/CSS/UnicodeRange.h>
#include <LibGfx/Font/UnicodeRange.h>
namespace Web::CSS {
@ -21,7 +21,7 @@ void serialize_an_identifier(StringBuilder&, StringView ident);
void serialize_a_string(StringBuilder&, StringView string);
void serialize_a_url(StringBuilder&, StringView url);
void serialize_a_local(StringBuilder&, StringView path);
void serialize_unicode_ranges(StringBuilder&, Vector<UnicodeRange> const& unicode_ranges);
void serialize_unicode_ranges(StringBuilder&, Vector<Gfx::UnicodeRange> const& unicode_ranges);
void serialize_a_srgb_value(StringBuilder&, Color color);
String escape_a_character(u32 character);

View file

@ -186,7 +186,6 @@ class TimeStyleValue;
class Transformation;
class TransformationStyleValue;
class URLStyleValue;
class UnicodeRange;
class UnresolvedStyleValue;
class UnsetStyleValue;
class VisualViewport;