Scale BoundingBox and Text elements to account for additional space.

Here we are manually scaling the pt width used for the BoundingBox and
the Text element when manually adding whitespace to account for
limitations of the PDF.js viewer. This fixes an initial regression
noticed when selecting text elements in Chrome and PDFium. The width
of the Text element and BoundBox had not been adjusted for the
additional whitespace so the highlighting was offset slightly.
This commit is contained in:
Tucker Barbour
2018-03-02 11:18:47 +00:00
parent 422e619978
commit 9fd9c7a51f
+5 -3
View File
@@ -196,14 +196,16 @@ class HocrTransform():
if len(elemtxt) == 0:
continue
pxl_coords = self.element_coordinates(elem)
pt = self.pt_from_pixel(pxl_coords)
# if the advanced option `--interword-spaces` is true, append a space
# to the end of each text element to allow simpler PDF viewers such
# as PDF.js to better recognize words in search and copy and paste
if interwordSpaces:
elemtxt += ' '
pxl_coords = self.element_coordinates(elem)
pt = self.pt_from_pixel(pxl_coords)
pt = Rect._make((pt.x1, pt.y1,
pt.x2 + pdf.stringWidth(' ', fontname, pt.y2 - pt.y1), pt.y2))
# draw the bbox border
if showBoundingboxes: