LibPDF: Make truetype ascent adjustment more local

It's only used in this function.

No behavior change.
This commit is contained in:
Nico Weber 2024-02-25 09:23:59 -05:00 committed by Andreas Kling
parent 4e0fe9d9d0
commit 84d1e3956f
Notes: sideshowbarker 2024-07-17 06:28:38 +09:00

View File

@ -76,8 +76,11 @@ void TrueTypeFont::set_font_size(float font_size)
m_font = m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
}
static void do_draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint position, float width, u32 unicode, Gfx::Font const& font, ColorOrStyle const& style)
static void do_draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u32 unicode, Gfx::Font const& font, ColorOrStyle const& style)
{
// Undo shift in Glyf::Glyph::append_simple_path() via OpenType::Font::rasterize_glyph().
auto position = point.translated(0, -font.pixel_metrics().ascent);
if (style.has<Color>()) {
painter.draw_glyph(position, unicode, font, style.get<Color>());
} else {
@ -92,9 +95,6 @@ PDFErrorOr<void> TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint
{
auto style = renderer.state().paint_style;
// Undo shift in Glyf::Glyph::append_simple_path() via OpenType::Font::rasterize_glyph().
auto position = point.translated(0, -m_font->pixel_metrics().ascent);
// 5.5.5 Character Encoding, Encodings for TrueType Fonts
u32 unicode;
@ -129,7 +129,7 @@ PDFErrorOr<void> TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint
auto char_name = effective_encoding->get_name(char_code);
u32 unicode = glyph_name_to_unicode(char_name).value_or(char_code);
if (m_font->contains_glyph(unicode)) {
do_draw_glyph(painter, position, width, unicode, *m_font, style);
do_draw_glyph(painter, point, width, unicode, *m_font, style);
return {};
}
@ -159,7 +159,7 @@ PDFErrorOr<void> TrueTypeFont::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint
unicode = glyph_name_to_unicode(char_name).value_or(char_code);
}
do_draw_glyph(painter, position, width, unicode, *m_font, style);
do_draw_glyph(painter, point, width, unicode, *m_font, style);
return {};
}