Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
staffanm committed Mar 6, 2018
1 parent 386aba6 commit cbeff88
Show file tree
Hide file tree
Showing 6 changed files with 494 additions and 486 deletions.
8 changes: 1 addition & 7 deletions ferenda/pdfanalyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,7 @@ def paginate(self, paginatepath=None, force=False):
physical = "%s#page=%s" % (page.src.split(os.sep)[-1], page.number)
pageskip = page.number - lastpagenumber
lastpagenumber = page.number
if isinstance(currentpage, int):
currentpage += pageskip
elif util.is_roman(currentpage):
lower = currentpage.islower()
currentpage = util.to_roman(util.from_roman(currentpage)+pageskip, lower=lower)
if lower:
currentpage = currentpage.lower()
currentpage = util.increment(currentpage, pageskip)
pageguess = self.guess_pagenumber(page, currentpage)
if pageguess is None:
if len(page) > 0:
Expand Down
8 changes: 4 additions & 4 deletions ferenda/pdfreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def _parse_xml_make_textbox(self, element, nextelement, after_footnote, lastbox,
nextfont = self.fontspec[int(nextelement.get('font'))] if nextelement is not None and nextelement.get('font') else None
if self.detect_footnotes:
if (len(textelements) and
textelements[0].strip().isdigit() and
(textelements[0].strip().isdigit() and
# check both previous box and next (for catching footnote markers in the foooter)
(lastfont and
lastfont.family == thisfont['family'] and
Expand All @@ -658,7 +658,7 @@ def _parse_xml_make_textbox(self, element, nextelement, after_footnote, lastbox,
thisfont['size'] < nextfont['size'] and
-5 < int(nextelement.get("left")) - (int(element.get("left")) + int(element.get("width"))) < 10 and # is really close to
0 < (int(nextelement.get("top")) + int(nextelement.get("height"))) - (int(element.get("top")) + int(element.get("height"))) < 20) # is slightly lower than
):
)):
# this must be a footnote -- alter tag to show that it
# should be rendered with superscript
if textelements[0].tag is None:
Expand All @@ -670,12 +670,12 @@ def _parse_xml_make_textbox(self, element, nextelement, after_footnote, lastbox,

# is it in the main text, ie immediately
# following the last textbox? Then append it to that textbox
if abs(lastbox.right - int(attribs['left'])) < 3:
if lastbox and abs(lastbox.right - int(attribs['left'])) < 3:
# return a Box that the caller will merge with current
attribs['fontid'] = attribs.pop('font')
attribs['merge-with-current'] = True
return Textbox(textelements, **attribs)
elif min([x.left for x in page]) - int(attribs['left']) < 3:
elif min([x.left for x in page] + [0]) - int(attribs['left']) < 3:
# then create a new textbox and let
# the after_footnote magic append more
# textboxes to it. Note: we don't use
Expand Down
Loading

0 comments on commit cbeff88

Please sign in to comment.