mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibWeb: Migrate ListItemMarkerBox's text from ByteString to String
This commit is contained in:
parent
8b52a354fa
commit
b987d53926
Notes:
github-actions[bot]
2025-02-11 09:40:28 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/b987d539260 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3528
5 changed files with 16 additions and 15 deletions
|
@ -75,14 +75,14 @@ static String generate_a_counter_representation(CSSStyleValue const& counter_sty
|
|||
return MUST(String::formatted("{}", value));
|
||||
case ListStyleType::LowerAlpha:
|
||||
case ListStyleType::LowerLatin:
|
||||
return MUST(String::from_byte_string(ByteString::bijective_base_from(value - 1).to_lowercase()));
|
||||
return String::bijective_base_from(value - 1, String::Case::Lower);
|
||||
case ListStyleType::UpperAlpha:
|
||||
case ListStyleType::UpperLatin:
|
||||
return MUST(String::from_byte_string(ByteString::bijective_base_from(value - 1)));
|
||||
return String::bijective_base_from(value - 1, String::Case::Upper);
|
||||
case ListStyleType::LowerRoman:
|
||||
return MUST(String::from_byte_string(ByteString::roman_number_from(value).to_lowercase()));
|
||||
return String::roman_number_from(value, String::Case::Lower);
|
||||
case ListStyleType::UpperRoman:
|
||||
return MUST(String::from_byte_string(ByteString::roman_number_from(value)));
|
||||
return String::roman_number_from(value, String::Case::Upper);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1210,12 +1210,12 @@ void BlockFormattingContext::ensure_sizes_correct_for_left_offset_calculation(Li
|
|||
|
||||
auto default_marker_width = max(4, marker.first_available_font().pixel_size_rounded_up() - 4);
|
||||
|
||||
auto marker_text = marker.text().value_or("");
|
||||
auto marker_text = marker.text().value_or({});
|
||||
if (marker_text.is_empty()) {
|
||||
marker_state.set_content_width(image_width + default_marker_width);
|
||||
} else {
|
||||
// FIXME: Use per-code-point fonts to measure text.
|
||||
auto text_width = marker.first_available_font().width(marker_text);
|
||||
auto text_width = marker.first_available_font().width(marker_text.code_points());
|
||||
marker_state.set_content_width(image_width + CSSPixels::nearest_value_for(text_width));
|
||||
}
|
||||
|
||||
|
|
|
@ -26,25 +26,25 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
|
|||
case CSS::ListStyleType::DisclosureOpen:
|
||||
break;
|
||||
case CSS::ListStyleType::Decimal:
|
||||
m_text = ByteString::formatted("{}.", m_index);
|
||||
m_text = MUST(String::formatted("{}.", m_index));
|
||||
break;
|
||||
case CSS::ListStyleType::DecimalLeadingZero:
|
||||
// This is weird, but in accordance to spec.
|
||||
m_text = m_index < 10 ? ByteString::formatted("0{}.", m_index) : ByteString::formatted("{}.", m_index);
|
||||
m_text = m_index < 10 ? MUST(String::formatted("0{}.", m_index)) : MUST(String::formatted("{}.", m_index));
|
||||
break;
|
||||
case CSS::ListStyleType::LowerAlpha:
|
||||
case CSS::ListStyleType::LowerLatin:
|
||||
m_text = ByteString::bijective_base_from(m_index - 1).to_lowercase();
|
||||
m_text = String::bijective_base_from(m_index - 1, String::Case::Lower);
|
||||
break;
|
||||
case CSS::ListStyleType::UpperAlpha:
|
||||
case CSS::ListStyleType::UpperLatin:
|
||||
m_text = ByteString::bijective_base_from(m_index - 1);
|
||||
m_text = String::bijective_base_from(m_index - 1, String::Case::Upper);
|
||||
break;
|
||||
case CSS::ListStyleType::LowerRoman:
|
||||
m_text = ByteString::roman_number_from(m_index).to_lowercase();
|
||||
m_text = String::roman_number_from(m_index, String::Case::Lower);
|
||||
break;
|
||||
case CSS::ListStyleType::UpperRoman:
|
||||
m_text = ByteString::roman_number_from(m_index);
|
||||
m_text = String::roman_number_from(m_index, String::Case::Upper);
|
||||
break;
|
||||
case CSS::ListStyleType::None:
|
||||
break;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -19,7 +20,7 @@ public:
|
|||
explicit ListItemMarkerBox(DOM::Document&, CSS::ListStyleType, CSS::ListStylePosition, size_t index, GC::Ref<CSS::ComputedProperties>);
|
||||
virtual ~ListItemMarkerBox() override;
|
||||
|
||||
Optional<ByteString> const& text() const { return m_text; }
|
||||
Optional<String> const& text() const { return m_text; }
|
||||
|
||||
virtual GC::Ptr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
|
@ -34,7 +35,7 @@ private:
|
|||
CSS::ListStylePosition m_list_style_position { CSS::ListStylePosition::Outside };
|
||||
size_t m_index;
|
||||
|
||||
Optional<ByteString> m_text {};
|
||||
Optional<String> m_text {};
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -117,7 +117,7 @@ void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
break;
|
||||
// FIXME: This should use proper text layout logic!
|
||||
// This does not line up with the text in the <li> element which looks very sad :(
|
||||
context.display_list_recorder().draw_text(device_enclosing.to_type<int>(), MUST(String::from_byte_string(*text)), layout_box().scaled_font(context), Gfx::TextAlignment::Center, color);
|
||||
context.display_list_recorder().draw_text(device_enclosing.to_type<int>(), *text, layout_box().scaled_font(context), Gfx::TextAlignment::Center, color);
|
||||
break;
|
||||
}
|
||||
case CSS::ListStyleType::None:
|
||||
|
|
Loading…
Add table
Reference in a new issue