mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:57:35 +00:00
LibGfx: Make Font::width() return a float
This commit is contained in:
parent
b9d2b8f7b2
commit
3407ab0fd1
25 changed files with 40 additions and 40 deletions
|
@ -175,7 +175,7 @@ void CardPainter::paint_card_front(Gfx::Bitmap& bitmap, Cards::Suit suit, Cards:
|
|||
paint_rect.set_height(paint_rect.height() / 2);
|
||||
paint_rect.shrink(10, 6);
|
||||
|
||||
auto text_rect = Gfx::IntRect { 4, 6, font.width("10"sv), font.glyph_height() };
|
||||
auto text_rect = Gfx::IntRect { 4, 6, static_cast<int>(ceilf(font.width("10"sv))), font.glyph_height() };
|
||||
painter.draw_text(text_rect, card_rank_label(rank), font, Gfx::TextAlignment::Center, suit_color);
|
||||
|
||||
painter.draw_bitmap(
|
||||
|
|
|
@ -109,10 +109,10 @@ void Breadcrumbbar::append_segment(DeprecatedString text, Gfx::Bitmap const* ico
|
|||
auto button_width = min(button_text_width + icon_width + icon_padding + 16, max_button_width);
|
||||
auto shrunken_width = icon_width + icon_padding + (icon ? 4 : 16);
|
||||
|
||||
button.set_max_size(button_width, 16 + 8);
|
||||
button.set_max_size(static_cast<int>(ceilf(button_width)), 16 + 8);
|
||||
button.set_min_size(shrunken_width, 16 + 8);
|
||||
|
||||
Segment segment { icon, text, data, button_width, shrunken_width, button.make_weak_ptr<GUI::Button>() };
|
||||
Segment segment { icon, text, data, static_cast<int>(ceilf(button_width)), shrunken_width, button.make_weak_ptr<GUI::Button>() };
|
||||
|
||||
m_segments.append(move(segment));
|
||||
relayout();
|
||||
|
|
|
@ -108,7 +108,7 @@ void Button::paint_event(PaintEvent& event)
|
|||
content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());
|
||||
}
|
||||
|
||||
Gfx::IntRect text_rect { 0, 0, font.width(text()), font.glyph_height() };
|
||||
Gfx::IntRect text_rect { 0, 0, static_cast<int>(ceilf(font.width(text()))), font.glyph_height() };
|
||||
if (text_rect.width() > content_rect.width())
|
||||
text_rect.set_width(content_rect.width());
|
||||
text_rect.align_within(content_rect, text_alignment());
|
||||
|
|
|
@ -43,7 +43,7 @@ void GroupBox::paint_event(PaintEvent& event)
|
|||
Gfx::StylePainter::paint_frame(painter, frame_rect, palette(), Gfx::FrameShape::Box, Gfx::FrameShadow::Sunken, 2);
|
||||
|
||||
if (!m_title.is_empty()) {
|
||||
Gfx::IntRect text_rect { 6, 1, font().width(m_title) + 6, font().glyph_height() };
|
||||
Gfx::IntRect text_rect { 6, 1, static_cast<int>(ceilf(font().width(m_title) + 6)), font().glyph_height() };
|
||||
painter.fill_rect(text_rect, palette().button());
|
||||
painter.draw_text(text_rect, m_title, Gfx::TextAlignment::Center, palette().button_text());
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ void HeaderView::paint_horizontal(Painter& painter)
|
|||
painter.draw_text(text_rect, text, font(), section_data.alignment, palette().button_text());
|
||||
|
||||
if (is_key_column && (m_table_view.sort_order() != SortOrder::None)) {
|
||||
Gfx::IntPoint offset { text_rect.x() + font().width(text) + sorting_arrow_offset, sorting_arrow_offset };
|
||||
Gfx::IntPoint offset { text_rect.x() + static_cast<int>(ceilf(font().width(text))) + sorting_arrow_offset, sorting_arrow_offset };
|
||||
auto coordinates = m_table_view.sort_order() == SortOrder::Ascending
|
||||
? ascending_arrow_coordinates.span()
|
||||
: descending_arrow_coordinates.span();
|
||||
|
|
|
@ -79,7 +79,7 @@ void LinkLabel::paint_event(PaintEvent& event)
|
|||
GUI::Painter painter(*this);
|
||||
|
||||
if (m_hovered)
|
||||
painter.draw_line({ 0, rect().bottom() }, { font().width(text()), rect().bottom() }, palette().link());
|
||||
painter.draw_line({ 0, rect().bottom() }, { static_cast<int>(ceilf(font().width(text()))), rect().bottom() }, palette().link());
|
||||
|
||||
if (is_focused())
|
||||
painter.draw_focus_rect(text_rect(), palette().focus_outline());
|
||||
|
|
|
@ -46,7 +46,7 @@ void RadioButton::paint_event(PaintEvent& event)
|
|||
|
||||
Gfx::StylePainter::paint_radio_button(painter, circle_rect, palette(), is_checked(), is_being_pressed());
|
||||
|
||||
Gfx::IntRect text_rect { circle_rect.right() + 7, 0, font().width(text()), font().glyph_height() };
|
||||
Gfx::IntRect text_rect { circle_rect.right() + 7, 0, static_cast<int>(ceilf(font().width(text()))), font().glyph_height() };
|
||||
text_rect.center_vertically_within(rect());
|
||||
paint_text(painter, text_rect, font(), Gfx::TextAlignment::TopLeft);
|
||||
|
||||
|
|
|
@ -452,7 +452,7 @@ Gfx::IntRect TabWidget::close_button_rect(size_t index) const
|
|||
|
||||
int TabWidget::TabData::width(Gfx::Font const& font) const
|
||||
{
|
||||
auto width = 16 + font.width(title) + (icon ? (16 + 4) : 0);
|
||||
auto width = 16 + static_cast<int>(ceilf(font.width(title))) + (icon ? (16 + 4) : 0);
|
||||
// NOTE: This needs to always be an odd number, because the button rect
|
||||
// includes 3px of light and shadow on the left and right edges. If
|
||||
// the button rect width is not an odd number, the area left for the
|
||||
|
|
|
@ -188,7 +188,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const
|
|||
auto node_text = index.data().to_deprecated_string();
|
||||
Gfx::IntRect rect = {
|
||||
x_offset, y_offset,
|
||||
icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), row_height()
|
||||
static_cast<int>(ceilf(icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding())), row_height()
|
||||
};
|
||||
Gfx::IntRect toggle_rect;
|
||||
if (row_count_at_index > 0) {
|
||||
|
|
|
@ -335,9 +335,9 @@ int BitmapFont::glyph_or_emoji_width_for_variable_width_font(u32 code_point) con
|
|||
return glyph_height() * emoji->width() / emoji->height();
|
||||
}
|
||||
|
||||
int BitmapFont::width(StringView view) const { return unicode_view_width(Utf8View(view)); }
|
||||
int BitmapFont::width(Utf8View const& view) const { return unicode_view_width(view); }
|
||||
int BitmapFont::width(Utf32View const& view) const { return unicode_view_width(view); }
|
||||
float BitmapFont::width(StringView view) const { return unicode_view_width(Utf8View(view)); }
|
||||
float BitmapFont::width(Utf8View const& view) const { return unicode_view_width(view); }
|
||||
float BitmapFont::width(Utf32View const& view) const { return unicode_view_width(view); }
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const
|
||||
|
|
|
@ -88,9 +88,9 @@ public:
|
|||
update_x_height();
|
||||
}
|
||||
|
||||
int width(StringView) const override;
|
||||
int width(Utf8View const&) const override;
|
||||
int width(Utf32View const&) const override;
|
||||
virtual float width(StringView) const override;
|
||||
virtual float width(Utf8View const&) const override;
|
||||
virtual float width(Utf32View const&) const override;
|
||||
|
||||
DeprecatedString name() const override { return m_name; }
|
||||
void set_name(DeprecatedString name) { m_name = move(name); }
|
||||
|
|
|
@ -140,9 +140,9 @@ public:
|
|||
virtual u8 baseline() const = 0;
|
||||
virtual u8 mean_line() const = 0;
|
||||
|
||||
virtual int width(StringView) const = 0;
|
||||
virtual int width(Utf8View const&) const = 0;
|
||||
virtual int width(Utf32View const&) const = 0;
|
||||
virtual float width(StringView) const = 0;
|
||||
virtual float width(Utf8View const&) const = 0;
|
||||
virtual float width(Utf32View const&) const = 0;
|
||||
|
||||
virtual DeprecatedString name() const = 0;
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
int ScaledFont::width(StringView view) const { return unicode_view_width(Utf8View(view)); }
|
||||
int ScaledFont::width(Utf8View const& view) const { return unicode_view_width(view); }
|
||||
int ScaledFont::width(Utf32View const& view) const { return unicode_view_width(view); }
|
||||
float ScaledFont::width(StringView view) const { return unicode_view_width(Utf8View(view)); }
|
||||
float ScaledFont::width(Utf8View const& view) const { return unicode_view_width(view); }
|
||||
float ScaledFont::width(Utf32View const& view) const { return unicode_view_width(view); }
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE int ScaledFont::unicode_view_width(T const& view) const
|
||||
ALWAYS_INLINE float ScaledFont::unicode_view_width(T const& view) const
|
||||
{
|
||||
if (view.is_empty())
|
||||
return 0;
|
||||
|
|
|
@ -54,9 +54,9 @@ public:
|
|||
virtual u8 glyph_fixed_width() const override;
|
||||
virtual u8 baseline() const override { return m_point_height; } // FIXME: Read from font
|
||||
virtual u8 mean_line() const override { return m_point_height; } // FIXME: Read from font
|
||||
virtual int width(StringView) const override;
|
||||
virtual int width(Utf8View const&) const override;
|
||||
virtual int width(Utf32View const&) const override;
|
||||
virtual float width(StringView) const override;
|
||||
virtual float width(Utf8View const&) const override;
|
||||
virtual float width(Utf32View const&) const override;
|
||||
virtual DeprecatedString name() const override { return DeprecatedString::formatted("{} {}", family(), variant()); }
|
||||
virtual bool is_fixed_width() const override { return m_font->is_fixed_width(); }
|
||||
virtual u8 glyph_spacing() const override { return 0; }
|
||||
|
@ -75,7 +75,7 @@ private:
|
|||
mutable HashMap<u32, RefPtr<Gfx::Bitmap>> m_cached_glyph_bitmaps;
|
||||
|
||||
template<typename T>
|
||||
int unicode_view_width(T const& view) const;
|
||||
float unicode_view_width(T const& view) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -2443,7 +2443,7 @@ void Gfx::Painter::draw_ui_text(Gfx::IntRect const& rect, StringView text, Gfx::
|
|||
Optional<size_t> underline_offset;
|
||||
auto name_to_draw = parse_ampersand_string(text, &underline_offset);
|
||||
|
||||
Gfx::IntRect text_rect { 0, 0, font.width(name_to_draw), static_cast<int>(ceilf(font.pixel_size())) };
|
||||
Gfx::IntRect text_rect { 0, 0, static_cast<int>(ceilf(font.width(name_to_draw))), static_cast<int>(ceilf(font.pixel_size())) };
|
||||
text_rect.align_within(rect, text_alignment);
|
||||
|
||||
draw_text(text_rect, name_to_draw, font, text_alignment, color);
|
||||
|
|
|
@ -205,7 +205,7 @@ void CanvasRenderingContext2D::fill_text(DeprecatedString const& text, float x,
|
|||
auto& drawing_state = this->drawing_state();
|
||||
|
||||
// FIXME: painter only supports integer rects for text right now, so this effectively chops off any fractional position
|
||||
auto text_rect = Gfx::IntRect(x, y, max_width.has_value() ? max_width.value() : painter->font().width(text), painter->font().pixel_size());
|
||||
auto text_rect = Gfx::IntRect(x, y, max_width.has_value() ? static_cast<float>(max_width.value()) : painter->font().width(text), painter->font().pixel_size());
|
||||
auto transformed_rect = drawing_state.transform.map(text_rect);
|
||||
painter->draw_text(transformed_rect, text, Gfx::TextAlignment::TopLeft, drawing_state.fill_style);
|
||||
did_draw(transformed_rect.to_type<float>());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue