hocr: avoid division by zero

Issue #253 - PDF that produces the error is not available, but if font_width
is zero, chances are the text is nonprinting characters, so suppress it.
This commit is contained in:
James R. Barlow
2018-04-14 17:24:21 -07:00
parent 7fc897e6dc
commit 2482296e2b
+5 -2
View File
@@ -322,8 +322,11 @@ class HocrTransform():
dy = baseline_y2 - cursor[1]
text.moveCursor(dx, dy)
text.setHorizScale(100 * box_width / font_width)
text.textOut(elemtxt)
# If reportlab tells us this word is 0 units wide, our best seems
# to be to suppress this text
if font_width > 0:
text.setHorizScale(100 * box_width / font_width)
text.textOut(elemtxt)
pdf.drawText(text)