Skip to content

Commit

Permalink
Merge pull request #203 from jbarlow83/negative-descent
Browse files Browse the repository at this point in the history
Interpret font Descent as a negative number even if specified as positive
  • Loading branch information
pietermarsman committed Oct 13, 2019
2 parents eae70b9 + 2ede124 commit 63b2e09
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 @@ -489,6 +489,13 @@ def __init__(self, descriptor, widths, default_width=None):
self.leading = num_value(descriptor.get('Leading', 0))
self.bbox = list_value(resolve_all(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 @@ -504,9 +511,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 63b2e09

Please sign in to comment.