mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibGfx: Add ascent, descent and line gap to FontPixelMetrics
These are the main values we need in LibWeb to perform inline layout.
This commit is contained in:
parent
7850628ff1
commit
56a284713d
4 changed files with 27 additions and 10 deletions
|
@ -379,6 +379,9 @@ FontPixelMetrics BitmapFont::pixel_metrics() const
|
|||
.x_height = (float)x_height(),
|
||||
.advance_of_ascii_zero = (float)glyph_width('0'),
|
||||
.glyph_spacing = (float)glyph_spacing(),
|
||||
.ascent = (float)m_baseline,
|
||||
.descent = (float)(m_glyph_height - m_baseline),
|
||||
.line_gap = (float)pixel_size() * 0.4f, // FIXME: Do something nicer here.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,17 @@ struct FontPixelMetrics {
|
|||
float x_height { 0 };
|
||||
float advance_of_ascii_zero { 0 };
|
||||
float glyph_spacing { 0 };
|
||||
|
||||
// Number of pixels the font extends above the baseline.
|
||||
float ascent { 0 };
|
||||
|
||||
// Number of pixels the font descends below the baseline.
|
||||
float descent { 0 };
|
||||
|
||||
// Line gap specified by font.
|
||||
float line_gap { 0 };
|
||||
|
||||
float line_spacing() const { return roundf(ascent) + roundf(descent) + roundf(line_gap); }
|
||||
};
|
||||
|
||||
class Font : public RefCounted<Font> {
|
||||
|
|
|
@ -526,17 +526,16 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3
|
|||
return adopt_ref(*new Font(move(buffer), move(head), move(name), move(hhea), move(maxp), move(hmtx), move(cmap), move(loca), move(glyf), move(os2), move(kern)));
|
||||
}
|
||||
|
||||
ScaledFontMetrics Font::metrics(float x_scale, float y_scale) const
|
||||
ScaledFontMetrics Font::metrics([[maybe_unused]] float x_scale, float y_scale) const
|
||||
{
|
||||
auto ascender = m_hhea.ascender() * y_scale;
|
||||
auto descender = m_hhea.descender() * y_scale;
|
||||
auto line_gap = m_hhea.line_gap() * y_scale;
|
||||
auto advance_width_max = m_hhea.advance_width_max() * x_scale;
|
||||
|
||||
return ScaledFontMetrics {
|
||||
.ascender = (int)roundf(ascender),
|
||||
.descender = (int)roundf(descender),
|
||||
.line_gap = (int)roundf(line_gap),
|
||||
.advance_width_max = (int)roundf(advance_width_max),
|
||||
.ascender = ascender,
|
||||
.descender = descender,
|
||||
.line_gap = line_gap,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -726,11 +725,16 @@ u8 ScaledFont::glyph_fixed_width() const
|
|||
|
||||
Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const
|
||||
{
|
||||
auto metrics = m_font->metrics(m_x_scale, m_y_scale);
|
||||
|
||||
return Gfx::FontPixelMetrics {
|
||||
.size = (float)pixel_size(),
|
||||
.x_height = (float)x_height(),
|
||||
.advance_of_ascii_zero = (float)glyph_width('0'),
|
||||
.glyph_spacing = (float)glyph_spacing(),
|
||||
.ascent = metrics.ascender,
|
||||
.descent = -metrics.descender,
|
||||
.line_gap = metrics.line_gap,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -23,10 +23,9 @@
|
|||
namespace TTF {
|
||||
|
||||
struct ScaledFontMetrics {
|
||||
int ascender;
|
||||
int descender;
|
||||
int line_gap;
|
||||
int advance_width_max;
|
||||
float ascender { 0 };
|
||||
float descender { 0 };
|
||||
float line_gap { 0 };
|
||||
|
||||
int height() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue