mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:47:45 +00:00
Make a preparation pass for variable-width fonts.
This commit is contained in:
parent
b85fe0bd07
commit
0a86366c71
9 changed files with 72 additions and 32 deletions
|
@ -86,7 +86,7 @@ GlyphMapWidget::~GlyphMapWidget()
|
|||
|
||||
int GlyphMapWidget::preferred_width() const
|
||||
{
|
||||
return columns() * (font().glyph_width() + m_horizontal_spacing) + 2;
|
||||
return columns() * (font().max_glyph_width() + m_horizontal_spacing) + 2;
|
||||
}
|
||||
|
||||
int GlyphMapWidget::preferred_height() const
|
||||
|
@ -109,9 +109,9 @@ Rect GlyphMapWidget::get_outer_rect(byte glyph) const
|
|||
int row = glyph / columns();
|
||||
int column = glyph % columns();
|
||||
return {
|
||||
column * (font().glyph_width() + m_horizontal_spacing) + 1,
|
||||
column * (font().max_glyph_width() + m_horizontal_spacing) + 1,
|
||||
row * (font().glyph_height() + m_vertical_spacing) + 1,
|
||||
font().glyph_width() + m_horizontal_spacing,
|
||||
font().max_glyph_width() + m_horizontal_spacing,
|
||||
font().glyph_height() + m_horizontal_spacing
|
||||
};
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ void GlyphMapWidget::paint_event(GPaintEvent&)
|
|||
Rect inner_rect(
|
||||
outer_rect.x() + m_horizontal_spacing / 2,
|
||||
outer_rect.y() + m_vertical_spacing / 2,
|
||||
font().glyph_width(),
|
||||
font().max_glyph_width(),
|
||||
font().glyph_height()
|
||||
);
|
||||
if (glyph == m_selected_glyph) {
|
||||
|
@ -184,9 +184,9 @@ void GlyphEditorWidget::paint_event(GPaintEvent&)
|
|||
painter.draw_rect(rect(), Color::Black);
|
||||
|
||||
for (int y = 0; y < font().glyph_height(); ++y)
|
||||
painter.draw_line({ 0, y * m_scale }, { font().glyph_width() * m_scale, y * m_scale }, Color::Black);
|
||||
painter.draw_line({ 0, y * m_scale }, { font().max_glyph_width() * m_scale, y * m_scale }, Color::Black);
|
||||
|
||||
for (int x = 0; x < font().glyph_width(); ++x)
|
||||
for (int x = 0; x < font().max_glyph_width(); ++x)
|
||||
painter.draw_line({ x * m_scale, 0 }, { x * m_scale, font().glyph_height() * m_scale }, Color::Black);
|
||||
|
||||
painter.translate(1, 1);
|
||||
|
@ -194,7 +194,7 @@ void GlyphEditorWidget::paint_event(GPaintEvent&)
|
|||
auto bitmap = font().glyph_bitmap(m_glyph);
|
||||
|
||||
for (int y = 0; y < font().glyph_height(); ++y) {
|
||||
for (int x = 0; x < font().glyph_width(); ++x) {
|
||||
for (int x = 0; x < font().max_glyph_width(); ++x) {
|
||||
Rect rect { x * m_scale, y * m_scale, m_scale, m_scale };
|
||||
if (bitmap.bit_at(x, y))
|
||||
painter.fill_rect(rect, Color::Black);
|
||||
|
@ -239,7 +239,7 @@ void GlyphEditorWidget::draw_at_mouse(const GMouseEvent& event)
|
|||
|
||||
int GlyphEditorWidget::preferred_width() const
|
||||
{
|
||||
return font().glyph_width() * m_scale + 1;
|
||||
return font().max_glyph_width() * m_scale + 1;
|
||||
}
|
||||
|
||||
int GlyphEditorWidget::preferred_height() const
|
||||
|
|
|
@ -619,7 +619,7 @@ void Terminal::set_size(word columns, word rows)
|
|||
for (size_t i = 0; i < rows; ++i)
|
||||
m_lines[i] = new Line(columns);
|
||||
|
||||
m_pixel_width = m_columns * font().glyph_width() + m_inset * 2;
|
||||
m_pixel_width = m_columns * font().glyph_width('x') + m_inset * 2;
|
||||
m_pixel_height = (m_rows * (font().glyph_height() + m_line_spacing)) + (m_inset * 2) - m_line_spacing;
|
||||
|
||||
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
|
@ -639,14 +639,14 @@ void Terminal::set_size(word columns, word rows)
|
|||
Rect Terminal::glyph_rect(word row, word column)
|
||||
{
|
||||
int y = row * m_line_height;
|
||||
int x = column * font().glyph_width();
|
||||
return { x + m_inset, y + m_inset, font().glyph_width(), font().glyph_height() };
|
||||
int x = column * font().glyph_width('x');
|
||||
return { x + m_inset, y + m_inset, font().glyph_width('x'), font().glyph_height() };
|
||||
}
|
||||
|
||||
Rect Terminal::row_rect(word row)
|
||||
{
|
||||
int y = row * m_line_height;
|
||||
Rect rect = { m_inset, y + m_inset, font().glyph_width() * m_columns, font().glyph_height() };
|
||||
Rect rect = { m_inset, y + m_inset, font().glyph_width('x') * m_columns, font().glyph_height() };
|
||||
rect.inflate(0, m_line_spacing);
|
||||
return rect;
|
||||
}
|
||||
|
@ -798,13 +798,13 @@ void Terminal::force_repaint()
|
|||
|
||||
void Terminal::resize_event(GResizeEvent& event)
|
||||
{
|
||||
int new_columns = event.size().width() / m_font->glyph_width();
|
||||
int new_columns = event.size().width() / m_font->glyph_width('x');
|
||||
int new_rows = event.size().height() / m_line_height;
|
||||
set_size(new_columns, new_rows);
|
||||
}
|
||||
|
||||
void Terminal::apply_size_increments_to_window(GWindow& window)
|
||||
{
|
||||
window.set_size_increment({ font().glyph_width(), m_line_height });
|
||||
window.set_size_increment({ font().glyph_width('x'), m_line_height });
|
||||
window.set_base_size({ m_inset * 2, m_inset * 2});
|
||||
}
|
||||
|
|
|
@ -151,4 +151,6 @@ private:
|
|||
|
||||
float m_opacity { 0.8f };
|
||||
bool m_needs_background_fill { true };
|
||||
|
||||
int m_glyph_width { 0 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue