Skip to content

Commit

Permalink
Round and test ascent and descent
Browse files Browse the repository at this point in the history
Related to #2368.
  • Loading branch information
liZe committed Feb 1, 2025
1 parent a3e676d commit 44c97c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,12 @@ def generate_rdf_metadata(*args, **kwargs):
pdf_bytes = pdf_document.write_pdf(
pdf_variant='pdf/a-3b', pdf_identifier=b'example-bytes', uncompressed_pdf=True)
assert b'TEST_METADATA' in pdf_bytes


@assert_no_logs
def test_font_descent_ascent():
pdf = FakeHTML(string='''
<html style="font-family: weasyprint">abc
''').write_pdf()
assert b'/Descent -200' in pdf
assert b'/Ascent 800' in pdf
8 changes: 4 additions & 4 deletions weasyprint/pdf/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def __init__(self, pango_font, description, font_size):
# Set ascent and descent.
if self.font_size:
pango_metrics = pango.pango_font_get_metrics(pango_font, ffi.NULL)
self.ascent = int(
self.ascent = int(round(
pango.pango_font_metrics_get_ascent(pango_metrics) * FROM_UNITS /
self.font_size * 1000)
self.descent = -int(
self.font_size * 1000))
self.descent = -int(round(
pango.pango_font_metrics_get_descent(pango_metrics) * FROM_UNITS /
self.font_size * 1000)
self.font_size * 1000))
else:
self.ascent = self.descent = 0

Expand Down

0 comments on commit 44c97c1

Please sign in to comment.