mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
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:
parent
0d03257e69
commit
f50bf00814
8 changed files with 20 additions and 22 deletions
|
@ -9,9 +9,8 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Gfx {
|
||||||
|
|
||||||
// https://www.w3.org/TR/css-syntax-3/#urange-syntax
|
|
||||||
class UnicodeRange {
|
class UnicodeRange {
|
||||||
public:
|
public:
|
||||||
UnicodeRange(u32 min_code_point, u32 max_code_point)
|
UnicodeRange(u32 min_code_point, u32 max_code_point)
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
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_font_family(move(font_family))
|
||||||
, m_weight(weight)
|
, m_weight(weight)
|
||||||
, m_slope(slope)
|
, m_slope(slope)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <AK/FlyString.h>
|
#include <AK/FlyString.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <LibWeb/CSS/UnicodeRange.h>
|
#include <LibGfx/Font/UnicodeRange.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ public:
|
||||||
Optional<FlyString> format;
|
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;
|
~FontFace() = default;
|
||||||
|
|
||||||
FlyString font_family() const { return m_font_family; }
|
FlyString font_family() const { return m_font_family; }
|
||||||
Optional<int> weight() const { return m_weight; }
|
Optional<int> weight() const { return m_weight; }
|
||||||
Optional<int> slope() const { return m_slope; }
|
Optional<int> slope() const { return m_slope; }
|
||||||
Vector<Source> const& sources() const { return m_sources; }
|
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
|
// FIXME: font-stretch, font-feature-settings
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -36,7 +36,7 @@ private:
|
||||||
Optional<int> m_weight { 0 };
|
Optional<int> m_weight { 0 };
|
||||||
Optional<int> m_slope { 0 };
|
Optional<int> m_slope { 0 };
|
||||||
Vector<Source> m_sources;
|
Vector<Source> m_sources;
|
||||||
Vector<UnicodeRange> m_unicode_ranges;
|
Vector<Gfx::UnicodeRange> m_unicode_ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ Optional<Ratio> Parser::parse_ratio(TokenStream<ComponentValue>& tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/css-syntax-3/#urange-syntax
|
// 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();
|
auto transaction = tokens.begin_transaction();
|
||||||
tokens.skip_whitespace();
|
tokens.skip_whitespace();
|
||||||
|
@ -1687,7 +1687,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>&
|
||||||
|| component_value.is(Token::Type::Whitespace);
|
|| 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);
|
auto maybe_unicode_range = parse_unicode_range(text);
|
||||||
if (maybe_unicode_range.has_value()) {
|
if (maybe_unicode_range.has_value()) {
|
||||||
local_transaction.commit();
|
local_transaction.commit();
|
||||||
|
@ -1769,9 +1769,9 @@ Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>&
|
||||||
return {};
|
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
|
// https://www.w3.org/TR/css-syntax-3/#maximum-allowed-code-point
|
||||||
constexpr u32 maximum_allowed_code_point = 0x10FFFF;
|
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.
|
// 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.
|
// 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;
|
Optional<FlyString> font_family;
|
||||||
Vector<FontFace::Source> src;
|
Vector<FontFace::Source> src;
|
||||||
Vector<UnicodeRange> unicode_range;
|
Vector<Gfx::UnicodeRange> unicode_range;
|
||||||
Optional<int> weight;
|
Optional<int> weight;
|
||||||
Optional<int> slope;
|
Optional<int> slope;
|
||||||
|
|
||||||
|
@ -4237,7 +4237,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (declaration.name().equals_ignoring_ascii_case("unicode-range"sv)) {
|
if (declaration.name().equals_ignoring_ascii_case("unicode-range"sv)) {
|
||||||
Vector<UnicodeRange> unicode_ranges;
|
Vector<Gfx::UnicodeRange> unicode_ranges;
|
||||||
bool unicode_range_invalid = false;
|
bool unicode_range_invalid = false;
|
||||||
TokenStream all_tokens { declaration.values() };
|
TokenStream all_tokens { declaration.values() };
|
||||||
auto range_token_lists = parse_a_comma_separated_list_of_component_values(all_tokens);
|
auto range_token_lists = parse_a_comma_separated_list_of_component_values(all_tokens);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibGfx/Font/UnicodeRange.h>
|
||||||
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||||||
#include <LibWeb/CSS/FontFace.h>
|
#include <LibWeb/CSS/FontFace.h>
|
||||||
#include <LibWeb/CSS/GeneralEnclosed.h>
|
#include <LibWeb/CSS/GeneralEnclosed.h>
|
||||||
|
@ -31,7 +32,6 @@
|
||||||
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||||
#include <LibWeb/CSS/Supports.h>
|
#include <LibWeb/CSS/Supports.h>
|
||||||
#include <LibWeb/CSS/UnicodeRange.h>
|
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
@ -176,8 +176,8 @@ private:
|
||||||
Optional<Length> parse_length(ComponentValue const&);
|
Optional<Length> parse_length(ComponentValue const&);
|
||||||
[[nodiscard]] Optional<LengthOrCalculated> parse_source_size_value(ComponentValue const&);
|
[[nodiscard]] Optional<LengthOrCalculated> parse_source_size_value(ComponentValue const&);
|
||||||
Optional<Ratio> parse_ratio(TokenStream<ComponentValue>&);
|
Optional<Ratio> parse_ratio(TokenStream<ComponentValue>&);
|
||||||
Optional<UnicodeRange> parse_unicode_range(TokenStream<ComponentValue>&);
|
Optional<Gfx::UnicodeRange> parse_unicode_range(TokenStream<ComponentValue>&);
|
||||||
Optional<UnicodeRange> parse_unicode_range(StringView);
|
Optional<Gfx::UnicodeRange> parse_unicode_range(StringView);
|
||||||
Optional<GridSize> parse_grid_size(ComponentValue const&);
|
Optional<GridSize> parse_grid_size(ComponentValue const&);
|
||||||
Optional<GridMinMax> parse_min_max(Vector<ComponentValue> const&);
|
Optional<GridMinMax> parse_min_max(Vector<ComponentValue> const&);
|
||||||
Optional<GridRepeat> parse_repeat(Vector<ComponentValue> const&);
|
Optional<GridRepeat> parse_repeat(Vector<ComponentValue> const&);
|
||||||
|
|
|
@ -128,9 +128,9 @@ void serialize_a_local(StringBuilder& builder, StringView path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: No spec currently exists for serializing a <'unicode-range'>.
|
// 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());
|
return serialize_a_string(builder, unicode_range.to_string());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibGfx/Color.h>
|
#include <LibGfx/Color.h>
|
||||||
#include <LibWeb/CSS/UnicodeRange.h>
|
#include <LibGfx/Font/UnicodeRange.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ void serialize_an_identifier(StringBuilder&, StringView ident);
|
||||||
void serialize_a_string(StringBuilder&, StringView string);
|
void serialize_a_string(StringBuilder&, StringView string);
|
||||||
void serialize_a_url(StringBuilder&, StringView url);
|
void serialize_a_url(StringBuilder&, StringView url);
|
||||||
void serialize_a_local(StringBuilder&, StringView path);
|
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);
|
void serialize_a_srgb_value(StringBuilder&, Color color);
|
||||||
|
|
||||||
String escape_a_character(u32 character);
|
String escape_a_character(u32 character);
|
||||||
|
|
|
@ -186,7 +186,6 @@ class TimeStyleValue;
|
||||||
class Transformation;
|
class Transformation;
|
||||||
class TransformationStyleValue;
|
class TransformationStyleValue;
|
||||||
class URLStyleValue;
|
class URLStyleValue;
|
||||||
class UnicodeRange;
|
|
||||||
class UnresolvedStyleValue;
|
class UnresolvedStyleValue;
|
||||||
class UnsetStyleValue;
|
class UnsetStyleValue;
|
||||||
class VisualViewport;
|
class VisualViewport;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue