Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
78a93b37
Commit
78a93b37
authored
Apr 20, 2016
by
Christof Dorner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3234 from hypothesis/fix-pdf-anchoring-off-by-one-error
Fix an off-by-one error in PDF anchoring code
parents
8137324b
d395f557
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletion
+27
-1
pdf.coffee
h/static/scripts/annotator/anchoring/pdf.coffee
+27
-1
No files found.
h/static/scripts/annotator/anchoring/pdf.coffee
View file @
78a93b37
...
...
@@ -62,8 +62,34 @@ findPage = (offset) ->
index
=
0
total
=
0
# We call `count` once for each page, in order. The passed offset is found on
# the first page where the cumulative length of the text content exceeds the
# offset value.
#
# When we find the page the offset is on, we return an object containing the
# page index, the offset at the start of that page, and the textContent of
# that page.
#
# To understand this a little better, here's a worked example. Imagine a
# document with the following page lengths:
#
# Page 0 has length 100
# Page 1 has length 50
# Page 2 has length 50
#
# Then here are the pages that various offsets are found on:
#
# offset | index
# --------------
# 0 | 0
# 99 | 0
# 100 | 1
# 101 | 1
# 149 | 1
# 150 | 2
#
count
=
(
textContent
)
->
if
total
+
textContent
.
length
>
=
offset
if
total
+
textContent
.
length
>
offset
offset
=
total
return
Promise
.
resolve
({
index
,
offset
,
textContent
})
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment