mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
19c0b319e9
commit
79f7b42994
@ -276,60 +276,60 @@ class CanonicalFragmentIdentifier
|
|||||||
r = this.decode(cfi, doc)
|
r = this.decode(cfi, doc)
|
||||||
if not r
|
if not r
|
||||||
return null
|
return null
|
||||||
node = r.node
|
node = r.node
|
||||||
ndoc = node.ownerDocument
|
ndoc = node.ownerDocument
|
||||||
if not ndoc
|
if not ndoc
|
||||||
log("CFI node has no owner document: #{ cfi } #{ node }")
|
log("CFI node has no owner document: #{ cfi } #{ node }")
|
||||||
return null
|
|
||||||
|
|
||||||
nwin = ndoc.defaultView
|
|
||||||
x = null
|
|
||||||
y = null
|
|
||||||
|
|
||||||
if typeof(r.offset) == "number"
|
|
||||||
# Character offset
|
|
||||||
range = ndoc.createRange()
|
|
||||||
if r.forward
|
|
||||||
try_list = [{start:0, end:0, a:0.5}, {start:0, end:1, a:1}, {start:-1, end:0, a:0}]
|
|
||||||
else
|
|
||||||
try_list = [{start:0, end:0, a:0.5}, {start:-1, end:0, a:0}, {start:0, end:1, a:1}]
|
|
||||||
k = 0
|
|
||||||
a = null
|
|
||||||
rects = null
|
|
||||||
node_len = node.nodeValue.length
|
|
||||||
until rects or rects.length or k >= try_list.length
|
|
||||||
t = try_list[k++]
|
|
||||||
start_offset = r.offset + t.start
|
|
||||||
end_offset = r.offset + t.end
|
|
||||||
a = t.a
|
|
||||||
if start_offset < 0 or end_offset >= node_len
|
|
||||||
continue
|
|
||||||
range.setStart(node, start_offset)
|
|
||||||
range.setEnd(node, end_offset)
|
|
||||||
rects = range.getClientRects()
|
|
||||||
|
|
||||||
if not rects or not rects.length
|
|
||||||
log("Could not find caret position: rects: #{ rects } offset: #{ r.offset }")
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
rect = rects[0]
|
|
||||||
x = (a*rect.left + (1-a)*rect.right)
|
|
||||||
y = (rect.top + rect.bottom)/2
|
|
||||||
else
|
|
||||||
x = node.offsetLeft - nwin.scrollX
|
|
||||||
y = node.offsetTop - nwin.scrollY
|
|
||||||
if typeof(r.x) == "number" and node.offsetWidth
|
|
||||||
x += (r.x*node.offsetWidth)/100
|
|
||||||
y += (r.y*node.offsetHeight)/100
|
|
||||||
|
|
||||||
until ndoc == doc
|
|
||||||
node = nwin.frameElement
|
|
||||||
ndoc = node.ownerDocument
|
|
||||||
nwin = ndoc.defaultView
|
nwin = ndoc.defaultView
|
||||||
x += node.offsetLeft - nwin.scrollX
|
x = null
|
||||||
y += node.offsetTop - nwin.scrollY
|
y = null
|
||||||
|
|
||||||
{x:x, y:y, node:r.node, time:r.time}
|
if typeof(r.offset) == "number"
|
||||||
|
# Character offset
|
||||||
|
range = ndoc.createRange()
|
||||||
|
if r.forward
|
||||||
|
try_list = [{start:0, end:0, a:0.5}, {start:0, end:1, a:1}, {start:-1, end:0, a:0}]
|
||||||
|
else
|
||||||
|
try_list = [{start:0, end:0, a:0.5}, {start:-1, end:0, a:0}, {start:0, end:1, a:1}]
|
||||||
|
k = 0
|
||||||
|
a = null
|
||||||
|
rects = null
|
||||||
|
node_len = node.nodeValue.length
|
||||||
|
until rects or rects.length or k >= try_list.length
|
||||||
|
t = try_list[k++]
|
||||||
|
start_offset = r.offset + t.start
|
||||||
|
end_offset = r.offset + t.end
|
||||||
|
a = t.a
|
||||||
|
if start_offset < 0 or end_offset >= node_len
|
||||||
|
continue
|
||||||
|
range.setStart(node, start_offset)
|
||||||
|
range.setEnd(node, end_offset)
|
||||||
|
rects = range.getClientRects()
|
||||||
|
|
||||||
|
if not rects or not rects.length
|
||||||
|
log("Could not find caret position: rects: #{ rects } offset: #{ r.offset }")
|
||||||
|
return null
|
||||||
|
|
||||||
|
rect = rects[0]
|
||||||
|
x = (a*rect.left + (1-a)*rect.right)
|
||||||
|
y = (rect.top + rect.bottom)/2
|
||||||
|
else
|
||||||
|
x = node.offsetLeft - nwin.scrollX
|
||||||
|
y = node.offsetTop - nwin.scrollY
|
||||||
|
if typeof(r.x) == "number" and node.offsetWidth
|
||||||
|
x += (r.x*node.offsetWidth)/100
|
||||||
|
y += (r.y*node.offsetHeight)/100
|
||||||
|
|
||||||
|
until ndoc == doc
|
||||||
|
node = nwin.frameElement
|
||||||
|
ndoc = node.ownerDocument
|
||||||
|
nwin = ndoc.defaultView
|
||||||
|
x += node.offsetLeft - nwin.scrollX
|
||||||
|
y += node.offsetTop - nwin.scrollY
|
||||||
|
|
||||||
|
{x:x, y:y, node:r.node, time:r.time}
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user