|
|
|
@ -100,7 +100,7 @@ end
|
|
|
|
|
--[[
|
|
|
|
|
auto detect bbox
|
|
|
|
|
--]]
|
|
|
|
|
function KoptInterface:getAutoBBox(doc, pageno)
|
|
|
|
|
function KoptInterface:getAutoBBox(doc, pageno)
|
|
|
|
|
local native_size = Document.getNativePageDimensions(doc, pageno)
|
|
|
|
|
local bbox = {
|
|
|
|
|
x0 = 0, y0 = 0,
|
|
|
|
@ -113,8 +113,9 @@ function KoptInterface:getAutoBBox(doc, pageno)
|
|
|
|
|
if not cached then
|
|
|
|
|
local page = doc._document:openPage(pageno)
|
|
|
|
|
local kc = self:createContext(doc, pageno, bbox)
|
|
|
|
|
--DEBUGBT()
|
|
|
|
|
bbox.x0, bbox.y0, bbox.x1, bbox.y1 = page:getAutoBBox(kc)
|
|
|
|
|
DEBUG("Auto detected bbox", bbox)
|
|
|
|
|
--DEBUG("Auto detected bbox", bbox)
|
|
|
|
|
Cache:insert(hash, CacheItem:new{ autobbox = bbox })
|
|
|
|
|
page:close()
|
|
|
|
|
kc:free()
|
|
|
|
@ -212,6 +213,8 @@ function KoptInterface:getRFPageDimensions(doc, pageno, zoom, rotation)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, render_mode)
|
|
|
|
|
--DEBUG("log memory usage at renderPage")
|
|
|
|
|
--self:logMemoryUsage(pageno)
|
|
|
|
|
if doc.configurable.text_wrap == 1 then
|
|
|
|
|
return self:renderreflowedPage(doc, pageno, rect, zoom, rotation, render_mode)
|
|
|
|
|
else
|
|
|
|
@ -240,7 +243,7 @@ function KoptInterface:renderreflowedPage(doc, pageno, rect, zoom, rotation, ren
|
|
|
|
|
end
|
|
|
|
|
local page = doc._document:openPage(pageno)
|
|
|
|
|
-- prepare cache item with contained blitbuffer
|
|
|
|
|
local tile = CacheItem:new{
|
|
|
|
|
local tile = TileCacheItem:new{
|
|
|
|
|
size = fullwidth * fullheight / 2 + 64, -- estimation
|
|
|
|
|
excerpt = Geom:new{ w = fullwidth, h = fullheight },
|
|
|
|
|
pageno = pageno,
|
|
|
|
@ -604,7 +607,6 @@ end
|
|
|
|
|
get word and word box from position in native page
|
|
|
|
|
]]--
|
|
|
|
|
function KoptInterface:getWordFromNativePosition(doc, boxes, pos)
|
|
|
|
|
DEBUG("boxes", boxes)
|
|
|
|
|
local native_word_box = self:getWordFromBoxes(boxes, pos)
|
|
|
|
|
local word_box = {
|
|
|
|
|
word = native_word_box.word,
|
|
|
|
@ -726,7 +728,7 @@ end
|
|
|
|
|
helper functions
|
|
|
|
|
--]]
|
|
|
|
|
function KoptInterface:logReflowDuration(pageno, dur)
|
|
|
|
|
local file = io.open("reflowlog.txt", "a+")
|
|
|
|
|
local file = io.open("reflow_dur_log.txt", "a+")
|
|
|
|
|
if file then
|
|
|
|
|
if file:seek("end") == 0 then -- write the header only once
|
|
|
|
|
file:write("PAGE\tDUR\n")
|
|
|
|
@ -735,3 +737,25 @@ function KoptInterface:logReflowDuration(pageno, dur)
|
|
|
|
|
file:close()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function KoptInterface:logMemoryUsage(pageno)
|
|
|
|
|
local status_file = io.open("/proc/self/status", "r")
|
|
|
|
|
local log_file = io.open("reflow_mem_log.txt", "a+")
|
|
|
|
|
local data = -1
|
|
|
|
|
if status_file then
|
|
|
|
|
for line in status_file:lines() do
|
|
|
|
|
local s, n
|
|
|
|
|
s, n = line:gsub("VmData:%s-(%d+) kB", "%1")
|
|
|
|
|
if n ~= 0 then data = tonumber(s) end
|
|
|
|
|
if data ~= -1 then break end
|
|
|
|
|
end
|
|
|
|
|
status_file:close()
|
|
|
|
|
end
|
|
|
|
|
if log_file then
|
|
|
|
|
if log_file:seek("end") == 0 then -- write the header only once
|
|
|
|
|
log_file:write("PAGE\tMEM\n")
|
|
|
|
|
end
|
|
|
|
|
log_file:write(string.format("%s\t%s\n", pageno, data))
|
|
|
|
|
log_file:close()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|