srctree

Robin Linden parent 322d8283 5e3b12a3
style: Parse the text-transform property

css/property_id.cpp added: 61, removed: 4, total 57
@@ -160,6 +160,9 @@ std::map<css::PropertyId, std::string_view> const initial_values{
{css::PropertyId::TextDecorationLine, "none"sv},
{css::PropertyId::TextDecorationStyle, "solid"sv},
 
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform#formal_definition
{css::PropertyId::TextTransform, "none"sv},
 
// https://developer.mozilla.org/en-US/docs/Web/CSS/border-color#formal_definition
{css::PropertyId::BorderBottomColor, "currentcolor"sv},
{css::PropertyId::BorderLeftColor, "currentcolor"sv},
 
style/styled_node.cpp added: 61, removed: 4, total 57
@@ -439,6 +439,36 @@ std::vector<TextDecorationLine> StyledNode::get_text_decoration_line_property()
return lines;
}
 
std::optional<TextTransform> StyledNode::get_text_transform_property() const {
auto raw = get_raw_property(css::PropertyId::TextTransform);
if (raw == "none") {
return TextTransform::None;
}
 
if (raw == "capitalize") {
return TextTransform::Capitalize;
}
 
if (raw == "uppercase") {
return TextTransform::Uppercase;
}
 
if (raw == "lowercase") {
return TextTransform::Lowercase;
}
 
if (raw == "full-width") {
return TextTransform::FullWidth;
}
 
if (raw == "full-size-kana") {
return TextTransform::FullSizeKana;
}
 
spdlog::warn("Unhandled text-transform value '{}'", raw);
return std::nullopt;
}
 
static constexpr int kDefaultFontSize{16};
// https://drafts.csswg.org/css-fonts-4/#absolute-size-mapping
constexpr int kMediumFontSize = kDefaultFontSize;
 
style/styled_node.h added: 61, removed: 4, total 57
@@ -73,6 +73,15 @@ enum class TextDecorationLine : std::uint8_t {
Blink,
};
 
enum class TextTransform : std::uint8_t {
None,
Capitalize,
Uppercase,
Lowercase,
FullWidth,
FullSizeKana,
};
 
enum class WhiteSpace : std::uint8_t {
Normal,
Pre,
@@ -131,6 +140,8 @@ struct StyledNode {
return get_font_weight_property();
} else if constexpr (T == css::PropertyId::TextDecorationLine) {
return get_text_decoration_line_property();
} else if constexpr (T == css::PropertyId::TextTransform) {
return get_text_transform_property();
} else if constexpr (T == css::PropertyId::WhiteSpace) {
return get_white_space_property();
} else {
@@ -150,6 +161,7 @@ private:
int get_font_size_property() const;
std::optional<FontWeight> get_font_weight_property() const;
std::vector<TextDecorationLine> get_text_decoration_line_property() const;
std::optional<TextTransform> get_text_transform_property() const;
std::optional<WhiteSpace> get_white_space_property() const;
};
 
 
style/styled_node_test.cpp added: 61, removed: 4, total 57
@@ -395,6 +395,18 @@ int main() {
expect_property_eq<css::PropertyId::TextDecorationLine>("unhandled!", std::vector<style::TextDecorationLine>{});
});
 
etest::test("get_property, text-transform", [] {
using enum style::TextTransform;
expect_property_eq<css::PropertyId::TextTransform>("none", None);
expect_property_eq<css::PropertyId::TextTransform>("capitalize", Capitalize);
expect_property_eq<css::PropertyId::TextTransform>("uppercase", Uppercase);
expect_property_eq<css::PropertyId::TextTransform>("lowercase", Lowercase);
expect_property_eq<css::PropertyId::TextTransform>("full-width", FullWidth);
expect_property_eq<css::PropertyId::TextTransform>("full-size-kana", FullSizeKana);
 
expect_property_eq<css::PropertyId::TextTransform>("unhandled!", std::nullopt);
});
 
etest::test("get_property, white-space", [] {
expect_property_eq<css::PropertyId::WhiteSpace>("normal", style::WhiteSpace::Normal);
expect_property_eq<css::PropertyId::WhiteSpace>("pre", style::WhiteSpace::Pre);