def _destinations_in_two_columns(pdf, destinations, cutoff=3):
"""
Check if the named destinations are organized along two columns (heuristic)
@param pdf: a PdfFileReader object
@param destinations:
'cutoff' is used to tune the heuristic: if 'cutoff' destinations in the
would-be second column start at the same position, return True
"""
# iterator for the x coordinates of refs in the would-be second column
xpositions = (_destination_position(pdf, dest)[3] for (_, dest)
in destinations
if _destination_position(pdf, dest)[1] == 1)
xpos_count = {}
for xpos in xpositions:
xpos_count[xpos] = xpos_count.get(xpos, 0) + 1
if xpos_count[xpos] >= cutoff:
return True
return False
评论列表
文章目录