Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret font Descent as a negative number even if specified as positive #203

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you group all the code for self.descent? 11 lines above the numeric value is parsed and the additional logic is here.

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