Skip to content

Commit

Permalink
Interpet font Descent as a negative number even if specified as positive
Browse files Browse the repository at this point in the history
The PDF RM specifies that Descent should be negative. Fonts that claim
to have a positive Descent (not that it would make sense) always seem
to be wrong about this claim.
  • Loading branch information
James R. Barlow committed Nov 4, 2018
1 parent 1ea9446 commit 2ede124
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pdfminer/pdffont.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ def __init__(self, descriptor, widths, default_width=None):
self.leading = num_value(descriptor.get('Leading', 0))
self.bbox = list_value(descriptor.get('FontBBox', (0, 0, 0, 0)))
self.hscale = self.vscale = .001

# PDF RM 9.8.1 specifies /Descent should always be a negative number.
# PScript5.dll seems to produce Descent with a positive number, but
# text analysis will be wrong if this is taken as correct. So force
# descent to negative.
if self.descent > 0:
self.descent = -self.descent
return

def __repr__(self):
Expand All @@ -503,9 +510,11 @@ def decode(self, bytes):
return bytearray(bytes) # map(ord, bytes)

def get_ascent(self):
"""Ascent above the baseline, in text space units"""
return self.ascent * self.vscale

def get_descent(self):
"""Descent below the baseline, in text space units; always negative"""
return self.descent * self.vscale

def get_width(self):
Expand Down

0 comments on commit 2ede124

Please sign in to comment.