Bookmarks: fix sort within one page (#8616)

Accurate sorting of bookmarks located in one page depending on their positions in text.
This commit is contained in:
hius07
2022-01-06 21:54:33 +02:00
committed by GitHub
parent 7163a392a8
commit 00b08d7b54
5 changed files with 90 additions and 20 deletions

View File

@@ -1212,7 +1212,6 @@ function KoptInterface:getTextFromNativePositions(doc, native_boxes, pos0, pos1)
return text_boxes
end
--[[--
Get text boxes from page positions.
--]]
@@ -1239,6 +1238,26 @@ function KoptInterface:getPageBoxesFromPositions(doc, pageno, ppos0, ppos1)
end
end
--[[--
Compare positions within one page.
Returns 1 if positions are ordered (if ppos2 is after ppos1), -1 if not, 0 if same.
Positions of the word boxes containing ppos1 and ppos2 are compared.
--]]
function KoptInterface:comparePositions(doc, ppos1, ppos2)
local box1 = self:getWordFromPosition(doc, ppos1).pbox
local box2 = self:getWordFromPosition(doc, ppos2).pbox
if box1.y == box2.y then
if box1.x == box2.x then
return 0
elseif box1.x > box2.x then
return -1
end
elseif box1.y > box2.y then
return -1
end
return 1
end
--[[--
Get page rect from native rect.
--]]