mod: prefix global variables width and height with G_

pull/2/merge
Qingping Hou 12 years ago
parent f0042714d9
commit ecd56a3745

@ -25,7 +25,7 @@ function CREReader:open(filename)
end
local style_sheet = "./data/"..file_type..".css"
ok, self.doc = pcall(cre.openDocument, filename, style_sheet,
width, height)
G_width, G_height)
if not ok then
return false, self.doc -- will contain error message
end
@ -81,6 +81,8 @@ end
----------------------------------------------------
function CREReader:goto(pos, pos_type)
local prev_xpointer = self.doc:getXPointer()
local width, height = G_width, G_height
if pos_type == "xpointer" then
self.doc:gotoXPointer(pos)
pos = self.doc:getCurrentPos()
@ -125,11 +127,11 @@ function CREReader:gotoTocEntry(entry)
end
function CREReader:nextView()
return self.pos + height - self.pan_overlap_vertical
return self.pos + G_height - self.pan_overlap_vertical
end
function CREReader:prevView()
return self.pos - height + self.pan_overlap_vertical
return self.pos - G_height + self.pan_overlap_vertical
end
----------------------------------------------------
@ -174,10 +176,10 @@ end
----------------------------------------------------
-- used in CREReader:showMenu()
function CREReader:_drawReadingInfo()
local ypos = height - 50
local ypos = G_height - 50
local load_percent = self.percent/100
fb.bb:paintRect(0, ypos, width, 50, 0)
fb.bb:paintRect(0, ypos, G_width, 50, 0)
ypos = ypos + 15
local face, fhash = Font:getFaceAndHash(22)
@ -189,7 +191,7 @@ function CREReader:_drawReadingInfo()
"Position: "..load_percent.."%".." "..cur_section, true)
ypos = ypos + 15
blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15,
blitbuffer.progressBar(fb.bb, 10, ypos, G_width - 20, 15,
5, 4, load_percent/100, 8)
end
@ -254,7 +256,7 @@ function CREReader:adjustCreReaderCommands()
item_array = face_list,
}
local item_no = fonts_menu:choose(0, height)
local item_no = fonts_menu:choose(0, G_height)
print(face_list[item_no])
if item_no then
cr.doc:setFontFace(face_list[item_no])

@ -66,13 +66,13 @@ function DJVUReader:_isEntireWordInScreenHeightRange(w)
(self.cur_full_height - (w.y1 * self.globalzoom) >=
-self.offset_y) and
(self.cur_full_height - (w.y0 * self.globalzoom) <=
-self.offset_y + height)
-self.offset_y + G_height)
end
function DJVUReader:_isEntireWordInScreenWidthRange(w)
return (w ~= nil) and
(w.x0 * self.globalzoom >= -self.offset_x) and
(w.x1 * self.globalzoom <= -self.offset_x + width)
(w.x1 * self.globalzoom <= -self.offset_x + G_width)
end
-- make sure at least part of the word can be seen in screen
@ -81,9 +81,9 @@ function DJVUReader:_isWordInScreenRange(w)
(self.cur_full_height - (w.y0 * self.globalzoom) >=
-self.offset_y) and
(self.cur_full_height - (w.y1 * self.globalzoom) <=
-self.offset_y + height) and
-self.offset_y + G_height) and
(w.x1 * self.globalzoom >= -self.offset_x) and
(w.x0 * self.globalzoom <= -self.offset_x + width)
(w.x0 * self.globalzoom <= -self.offset_x + G_width)
end
function DJVUReader:toggleTextHighLight(word_list)

@ -164,7 +164,7 @@ function FileSearcher:addAllCommands()
"invoke search inputbox",
function(self)
old_keywords = self.keywords
self.keywords = InputBox:input(height-100, 100,
self.keywords = InputBox:input(G_height - 100, 100,
"Search:", old_keywords)
if self.keywords then
self:setSearchResult(self.keywords)
@ -181,7 +181,7 @@ function FileSearcher:addAllCommands()
menu_title = "Fonts Menu",
item_array = Font.fonts,
}
local re = fonts_menu:choose(0, height)
local re = fonts_menu:choose(0, G_height)
if re then
Font.cfont = Font.fonts[re]
Font:update()
@ -195,14 +195,10 @@ function FileSearcher:addAllCommands()
file_entry = self.result[self.perpage*(self.page-1)+self.current]
file_full_path = file_entry.dir .. "/" .. file_entry.name
-- rotation mode might be changed while reading, so
-- record height_percent here
local height_percent = height/fb.bb:getHeight()
openFile(file_full_path)
--reset height and item index if screen has been rotated
local item_no = self.perpage * (self.page - 1) + self.current
self.perpage = math.floor(height / self.spacing) - 2
self.perpage = math.floor(G_height / self.spacing) - 2
self.current = item_no % self.perpage
self.page = math.floor(item_no / self.perpage) + 1
@ -218,6 +214,7 @@ function FileSearcher:addAllCommands()
end
function FileSearcher:choose(keywords)
local width, height = G_width, G_height
self.perpage = math.floor(height / self.spacing) - 2
self.pagedirty = true
self.markerdirty = false

@ -30,7 +30,7 @@ HelpPage.hface, HelpPage.hfhash = Font:getFaceAndHash(HelpPage.hfsize, "sans")
HelpPage.ffsize = 15
HelpPage.fface, HelpPage.ffhash = Font:getFaceAndHash(HelpPage.ffsize, "sans")
function HelpPage:show(ypos, height,commands)
function HelpPage:show(ypos, height, commands)
self.commands = {}
self.items = 0
local keys = {}

@ -13,7 +13,7 @@ function PDFReader:open(filename)
return false, self.doc -- will contain error message
end
if self.doc:needsPassword() then
local password = InputBox:input(height-100, 100, "Pass:")
local password = InputBox:input(G_height-100, 100, "Pass:")
if not password or not self.doc:authenticatePassword(password) then
self.doc:close()
self.doc = nil

@ -121,7 +121,7 @@ if optarg["G"] ~= nil then
end
fb = einkfb.open("/dev/fb0")
width, height = fb:getSize()
G_width, G_height = fb:getSize()
-- read current rotation mode
Screen:updateRotationMode()
Screen.native_rotation_mode = Screen.cur_rotation_mode
@ -146,7 +146,7 @@ if ARGV[optind] and lfs.attributes(ARGV[optind], "mode") == "directory" then
local running = true
FileChooser:setPath(ARGV[optind])
while running do
local file, callback = FileChooser:choose(0,height)
local file, callback = FileChooser:choose(0, G_height)
if callback then
callback()
else

@ -3,7 +3,7 @@ require "rendertext"
require "graphics"
fb = einkfb.open("/dev/fb0")
width, height = fb:getSize()
G_width, G_height = fb:getSize()
print("open")

@ -77,6 +77,8 @@ function Screen:updateRotationMode()
end
function Screen:saveCurrentBB()
local width, height = G_width, G_height
if not self.saved_bb then
self.saved_bb = Blitbuffer.new(width, height)
end
@ -92,7 +94,7 @@ function Screen:resotreFromSavedBB()
end
function Screen:getCurrentScreenBB()
local bb = Blitbuffer.new(width, height)
local bb = Blitbuffer.new(G_width, G_height)
bb:blitFullFrom(fb.bb)
return bb
end

@ -250,6 +250,7 @@ function UniReader:drawOrCache(no, preCache)
-- ideally, this should be factored out and only be called when needed (TODO)
local ok, page = pcall(self.doc.openPage, self.doc, no)
local width, height = G_width, G_height
if not ok then
-- TODO: error handling
return nil
@ -362,6 +363,7 @@ end
function UniReader:setzoom(page, preCache)
local dc = DrawContext.new()
local pwidth, pheight = page:getSize(self.nulldc)
local width, height = G_width, G_height
print("# page::getSize "..pwidth.."*"..pheight);
local x0, y0, x1, y1 = page:getUsedBBox()
if x0 == 0.01 and y0 == 0.01 and x1 == -0.01 and y1 == -0.01 then
@ -517,6 +519,8 @@ end
-- render and blit a page
function UniReader:show(no)
local pagehash, offset_x, offset_y = self:drawOrCache(no)
local width, height = G_width, G_height
if not pagehash then
return
end
@ -662,7 +666,8 @@ function UniReader:nextView()
pageno = pageno + 1
else
-- goto next view of current page
self.offset_y = self.offset_y - height + self.pan_overlap_vertical
self.offset_y = self.offset_y - G_height
+ self.pan_overlap_vertical
end
else
-- not in fit to content width pan mode, just do a page turn
@ -688,7 +693,8 @@ function UniReader:prevView()
pageno = pageno - 1
else
-- goto previous view of current page
self.offset_y = self.offset_y + height - self.pan_overlap_vertical
self.offset_y = self.offset_y + G_height
- self.pan_overlap_vertical
end
else
-- not in fit to content width pan mode, just do a page turn
@ -735,7 +741,8 @@ end
-- @ orien: 1 for clockwise rotate, -1 for anti-clockwise
function UniReader:screenRotate(orien)
Screen:screenRotate(orien)
width, height = fb:getSize()
-- update global width and height variable
G_width, G_height = fb:getSize()
self:clearCache()
self:redrawCurrentPage()
end
@ -849,7 +856,7 @@ end
-- used in UniReader:showMenu()
function UniReader:_drawReadingInfo()
local ypos = height - 50
local width, height = G_width, G_height
local load_percent = (self.pageno / self.doc:getPages())
local face, fhash = Font:getFaceAndHash(22)
@ -1060,7 +1067,7 @@ function UniReader:addAllCommands()
self.commands:add(KEY_G,nil,"G",
"goto page",
function(unireader)
local page = InputBox:input(height-100, 100, "Page:")
local page = InputBox:input(G_height-100, 100, "Page:")
-- convert string to number
if not pcall(function () page = page + 0 end) then
page = unireader.pageno
@ -1074,7 +1081,7 @@ function UniReader:addAllCommands()
self.commands:add(KEY_H,nil,"H",
"show help page",
function(unireader)
HelpPage:show(0,height,unireader.commands)
HelpPage:show(0, G_height, unireader.commands)
unireader:redrawCurrentPage()
end)
self.commands:add(KEY_T,nil,"T",
@ -1130,8 +1137,8 @@ function UniReader:addAllCommands()
local bbox = {}
bbox["x0"] = - unireader.offset_x / unireader.globalzoom
bbox["y0"] = - unireader.offset_y / unireader.globalzoom
bbox["x1"] = bbox["x0"] + width / unireader.globalzoom
bbox["y1"] = bbox["y0"] + height / unireader.globalzoom
bbox["x1"] = bbox["x0"] + G_width / unireader.globalzoom
bbox["y1"] = bbox["y0"] + G_height / unireader.globalzoom
bbox.pan_x = unireader.pan_x
bbox.pan_y = unireader.pan_y
unireader.bbox[unireader.pageno] = bbox
@ -1176,8 +1183,8 @@ function UniReader:addAllCommands()
x = unireader.shift_x / 5
y = unireader.shift_y / 5
elseif unireader.pan_by_page then
x = width;
y = height - unireader.pan_overlap_vertical; -- overlap for lines which didn't fit
x = G_width;
y = G_height - unireader.pan_overlap_vertical; -- overlap for lines which didn't fit
else
x = unireader.shift_x
y = unireader.shift_y

Loading…
Cancel
Save