Merge pull request #1820 from koreader/houqp-master

fix keyvaluepage to truncate long text
pull/1822/head
Frans de Jonge 8 years ago
commit d6b5af7d40

@ -6,6 +6,9 @@ globals = {
}
read_globals = {
"ANDROID_FONT_DIR",
"KOBO_TOUCH_MIRRORED",
"KOBO_SYNC_BRIGHTNESS_WITH_NICKEL",
"DRCOUNTMAX",
"DHINTCOUNT",
"DFULL_SCREEN",

@ -71,7 +71,7 @@ script:
- make all
- travis_retry make testfront
- luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out
- test $(grep Total ./luacheck.out | awk '{print $2}') -le 196
- test $(grep Total ./luacheck.out | awk '{print $2}') -le 65
after_success:
- make coverage

@ -1 +1 @@
Subproject commit 8a305a81a7a04e2f6df5cb336ad79cb17432fb4d
Subproject commit 047968a9b85af0b065d0adc0eecd5cdce997d2cb

@ -8,5 +8,5 @@ use_markdown_titles = true
readme = '../README.md'
package = ''
format = 'markdown'
sort_modules=true
sort_modules = true
file = '../frontend'

@ -22,7 +22,8 @@ local Font = require("ui/font")
local DEBUG = require("dbg")
local _ = require("gettext")
function getDefaultDir()
local function getDefaultDir()
if Device:isKindle() then
return "/mnt/us/documents"
elseif Device:isKobo() then
@ -34,7 +35,7 @@ function getDefaultDir()
end
end
function restoreScreenMode()
local function restoreScreenMode()
local screen_mode = G_reader_settings:readSetting("fm_screen_mode")
if Screen:getScreenMode() ~= screen_mode then
Screen:setScreenMode(screen_mode or "portrait")
@ -273,7 +274,7 @@ function FileManager:deleteFile(file)
local is_doc = DocumentRegistry:getProvider(file_abs_path)
ok, err = os.remove(file_abs_path)
if err == nil then
if ok and err == nil then
if is_doc ~= nil then
-- also delete history/settings for documents
local sidecar_dir = docsettings:getSidecarDir(file_abs_path)
@ -281,7 +282,8 @@ function FileManager:deleteFile(file)
util.purgeDir(sidecar_dir)
end
local legacy_history_file = docsettings:getHistoryPath(file)
ok, err = os.remove(legacy_history_file)
-- @todo: check return from os.remove
os.remove(legacy_history_file)
end
UIManager:show(InfoMessage:new{
text = util.template(_("Successfully deleted %1"), file),

@ -85,7 +85,6 @@ function FileManagerMenu:setUpdateItemTable()
checked_func = function() return self.ui.file_chooser.show_hidden end,
callback = function() self.ui:toggleHiddenFiles() end
})
local FileManager = require("apps/filemanager/filemanager")
table.insert(self.tab_item_table.setting, self.ui:getSortingMenuTable())
table.insert(self.tab_item_table.setting, {
text = _("Reverse sorting"),
@ -125,10 +124,10 @@ function FileManagerMenu:setUpdateItemTable()
table.insert(self.tab_item_table.tools, {
text = _("OPDS catalog"),
callback = function()
local FileManager = require("apps/filemanager/filemanager")
local OPDSCatalog = require("apps/opdscatalog/opdscatalog")
function OPDSCatalog:onExit()
DEBUG("refresh filemanager")
filemanager:onRefresh()
FileManager:onRefresh()
end
OPDSCatalog:showCatalog()
end,

@ -1,21 +1,10 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local FileManagerMenu = require("apps/filemanager/filemanagermenu")
local DocumentRegistry = require("document/documentregistry")
local VerticalGroup = require("ui/widget/verticalgroup")
local ButtonDialog = require("ui/widget/buttondialog")
local VerticalSpan = require("ui/widget/verticalspan")
local OPDSBrowser = require("ui/widget/opdsbrowser")
local TextWidget = require("ui/widget/textwidget")
local lfs = require("libs/libkoreader-lfs")
local UIManager = require("ui/uimanager")
local Font = require("ui/font")
local Screen = require("device").screen
local Geom = require("ui/geometry")
local Event = require("ui/event")
local DEBUG = require("dbg")
local _ = require("gettext")
local util = require("ffi/util")
local Blitbuffer = require("ffi/blitbuffer")
local OPDSCatalog = InputContainer:extend{

@ -92,7 +92,7 @@ function ReaderBookmark:importSavedHighlight(config)
if not config:readSetting("highlights_imported") then
for page, marks in pairs(textmarks) do
for _, mark in ipairs(marks) do
local page = self.ui.document.info.has_pages and page or mark.pos0
page = self.ui.document.info.has_pages and page or mark.pos0
-- highlights saved by some old versions don't have pos0 field
-- we just ignore those highlights
if page then
@ -125,7 +125,7 @@ function ReaderBookmark:onSaveSettings()
end
function ReaderBookmark:onToggleBookmark()
local pn_or_xp = nil
local pn_or_xp
if self.ui.document.info.has_pages then
pn_or_xp = self.view.state.page
else
@ -295,16 +295,16 @@ end
-- binary search of sorted bookmarks
function ReaderBookmark:isBookmarkAdded(item)
local _start, _middle, _end, direction = 1, 1, #self.bookmarks, 0
local _start, _middle, _end = 1, 1, #self.bookmarks
while _start <= _end do
_middle = math.floor((_start + _end)/2)
if self:isBookmarkSame(item, self.bookmarks[_middle]) then
return true
end
if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then
_end, direction = _middle - 1, 0
_end = _middle - 1
else
_start, direction = _middle + 1, 1
_start = _middle + 1
end
end
return false

@ -1,9 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local Screen = require("device").screen
local Geom = require("ui/geometry")
local Device = require("device")
local Event = require("ui/event")
local GestureRange = require("ui/gesturerange")
local _ = require("gettext")
local ReaderRotation = InputContainer:new{
@ -26,7 +23,7 @@ function ReaderRotation:init()
end
end
-- TODO: reset rotation on new document, maybe on new page?
-- @TODO: reset rotation on new document, maybe on new page?
function ReaderRotation:onRotate(rotate_by)
self.current_rotation = (self.current_rotation + rotate_by) % 360

@ -1,8 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local ButtonDialog = require("ui/widget/buttondialog")
local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local DEBUG = require("dbg")
local _ = require("gettext")
@ -69,7 +67,7 @@ function ReaderSearch:onShowSearchDialog(text)
self.ui.highlight:clear()
end,
}
local res = do_search(self.searchFromCurrent, text, 0)()
do_search(self.searchFromCurrent, text, 0)()
UIManager:show(self.search_dialog)
-- TODO: regional
UIManager:setDirty(self.dialog, "partial")

@ -1,5 +1,5 @@
local Generic = require("device/generic/device")
local isAndroid, android = pcall(require, "android")
local _, android = pcall(require, "android")
local ffi = require("ffi")
local DEBUG = require("dbg")

@ -40,7 +40,7 @@ local Device = {
}
function Device:new(o)
local o = o or {}
o = o or {}
setmetatable(o, self)
self.__index = self
return o

@ -10,7 +10,7 @@ local BasePowerD = {
}
function BasePowerD:new(o)
local o = o or {}
o = o or {}
setmetatable(o, self)
self.__index = self
if o.init then o:init() end

@ -73,7 +73,7 @@ local GestureDetector = {
}
function GestureDetector:new(o)
local o = o or {}
o = o or {}
setmetatable(o, self)
self.__index = self
if o.init then o:init() end

@ -6,6 +6,8 @@ local _ = require("gettext")
local Key = require("device/key")
local GestureDetector = require("device/gesturedetector")
-- luacheck: push
-- luacheck: ignore
-- constants from <linux/input.h>
local EV_SYN = 0
local EV_KEY = 1
@ -36,6 +38,7 @@ local ABS_MT_POSITION_X = 53
local ABS_MT_POSITION_Y = 54
local ABS_MT_TRACKING_ID = 57
local ABS_MT_PRESSURE = 58
-- luacheck: pop
--[[
an interface to get input events
@ -105,7 +108,7 @@ local Input = {
}
function Input:new(o)
local o = o or {}
o = o or {}
setmetatable(o, self)
self.__index = self
if o.init then o:init() end

@ -147,8 +147,11 @@ function Kindle4:init()
Kindle.init(self)
end
-- luacheck: push
-- luacheck: ignore
local ABS_MT_POSITION_X = 53
local ABS_MT_POSITION_Y = 54
-- luacheck: pop
function KindleTouch:init()
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG}
self.powerd = require("device/kindle/powerd"):new{

@ -1,6 +1,8 @@
local Generic = require("device/generic/device") -- <= look at this file!
local DEBUG = require("dbg")
-- luacheck: push
-- luacheck: ignore
local EVT_INIT = 21
local EVT_EXIT = 22
local EVT_SHOW = 23
@ -32,6 +34,7 @@ local KEY_PREV2 = 0x1c
local KEY_NEXT2 = 0x1d
local KEY_COVEROPEN = 0x02
local KEY_COVERCLOSE = 0x03
-- luacheck: pop
local function yes() return true end
@ -49,12 +52,12 @@ function PocketBook:init()
ev.value = ev.type == EVT_KEYDOWN and 1 or 0
ev.type = 1 -- EV_KEY
elseif ev.type == EVT_BACKGROUND then
isInBackGround = true
self.isInBackGround = true
self:onPowerEvent("Power")
elseif isInBackGround and ev.type == EVT_FOREGROUND then
isInBackGround = false
elseif self.isInBackGround and ev.type == EVT_FOREGROUND then
self.isInBackGround = false
self:onPowerEvent("Power")
elseif not isInBackGround and ev.type == EVT_FOREGROUND then
elseif not self.isInBackGround and ev.type == EVT_FOREGROUND then
self.screen:refreshPartial()
end
end)

@ -594,7 +594,7 @@ function KoptInterface:getReflewOCRWord(doc, pageno, rect)
local cached = Cache:check(kctx_hash)
if cached then
local kc = self:waitForContext(cached.kctx)
local ok, word = pcall(
local _, word = pcall(
kc.getTOCRWord, kc, "dst",
rect.x, rect.y, rect.w, rect.h,
self.tessocr_data, self.ocr_lang, self.ocr_type, 0, 1)
@ -628,7 +628,7 @@ function KoptInterface:getNativeOCRWord(doc, pageno, rect)
--kc:exportSrcPNGFile({rect}, nil, "ocr-word.png")
local word_w, word_h = kc:getPageDim()
--DEBUG(word_w, word_h)
local ok, word = pcall(
local _, word = pcall(
kc.getTOCRWord, kc, "src",
0, 0, word_w, word_h,
self.tessocr_data, self.ocr_lang, self.ocr_type, 0, 1)
@ -655,7 +655,7 @@ end
function KoptInterface:getClipPageContext(doc, pos0, pos1, pboxes, drawer)
assert(pos0.page == pos1.page)
assert(pos0.zoom == pos1.zoom)
local rect = nil
local rect
if pboxes and #pboxes > 0 then
local box = pboxes[1]
rect = Geom:new{
@ -1060,7 +1060,7 @@ function KoptInterface:nativeToPageRectTransform(doc, pageno, rect)
y = rect.y + rect.h - 5
}
local boxes = self:getPageBoxesFromPositions(doc, pageno, pos0, pos1)
res_rect = nil
local res_rect = nil
if #boxes > 0 then
res_rect = boxes[1]
for _, box in pairs(boxes) do

@ -9,8 +9,8 @@ local DownloadMgr = {
onConfirm = function() end,
}
function DownloadMgr:new(o)
local o = o or {}
function DownloadMgr:new(from_o)
local o = from_o or {}
setmetatable(o, self)
self.__index = self
return o

@ -1,3 +1,7 @@
--[[--
Font module.
]]
local lfs = require("libs/libkoreader-lfs")
local Freetype = require("ffi/freetype")
local Screen = require("device").screen
@ -35,6 +39,18 @@ local Font = {
-- font for info messages
infofont = "noto/NotoSans-Regular.ttf",
},
sizemap = {
cfont = 24,
tfont = 26,
ffont = 20,
pgfont = 20,
scfont = 20,
rifont = 16,
hpkfont = 20,
hfont = 24,
infont = 22,
infofont = 24,
},
fallbacks = {
[1] = "noto/NotoSansCJK-Regular.ttf",
[2] = "noto/NotoSans-Regular.ttf",
@ -51,9 +67,10 @@ function Font:getFace(font, size)
-- default to content font
if not font then font = self.cfont end
if not size then size = self.sizemap[font] end
-- original size before scaling by screen DPI
local orig_size = size
local size = Screen:scaleBySize(size)
size = Screen:scaleBySize(size)
local hash = font..size
local face_obj = self.faces[hash]
@ -64,11 +81,17 @@ function Font:getFace(font, size)
realname = font
end
realname = self.fontdir.."/"..realname
ok, face = pcall(Freetype.newFace, realname, size)
local ok, face = pcall(Freetype.newFace, realname, size)
if not ok then
DEBUG("#! Font "..font.." ("..realname..") not supported: "..face)
return nil
end
--- Freetype font face wrapper object
-- @table FontFaceObj
-- @field size size of the font face (after scaled by screen size)
-- @field orig_size raw size of the font face (before scale)
-- @field ftface font face object from freetype
-- @field hash hash key for this font face
face_obj = {
size = size,
orig_size = orig_size,
@ -76,7 +99,6 @@ function Font:getFace(font, size)
hash = hash
}
self.faces[hash] = face_obj
-- DEBUG("getFace, found: "..realname.." size:"..size)
end
return face_obj
end

@ -20,7 +20,7 @@ local Geom = {
}
function Geom:new(o)
local o = o or {}
if not o then o = {} end
setmetatable(o, self)
self.__index = self
return o

@ -1,7 +1,7 @@
local ffi = require("ffi")
local DEBUG = require("dbg")
local MessageQueue = require("ui/message/messagequeue")
local dummy = require("ffi/zeromq_h")
local _ = require("ffi/zeromq_h")
local czmq = ffi.load("libs/libczmq.so.1")
local filemq = ffi.load("libs/libfmq.so.1")

@ -1,11 +1,9 @@
local ffi = require("ffi")
local util = require("ffi/util")
local Event = require("ui/event")
local DEBUG = require("dbg")
local dummy = require("ffi/zeromq_h")
local _ = require("ffi/zeromq_h")
local czmq = ffi.load("libs/libczmq.so.1")
local zyre = ffi.load("libs/libzyre.so.1")
local MessageQueue = {}
@ -39,7 +37,6 @@ function MessageQueue:handleZMsgs(messages)
end
local function pop_string()
local str_p = czmq.zmsg_popstr(messages[1])
local message_size = czmq.zmsg_size(messages[1])
local res = ffi.string(str_p)
czmq.zstr_free(ffi.new('char *[1]', str_p))
drop_message()
@ -64,7 +61,6 @@ function MessageQueue:handleZMsgs(messages)
return header
end
if #messages == 0 then return end
local message_size = czmq.zmsg_size(messages[1])
local command = pop_string()
DEBUG("ØMQ message", command)
if command == "ENTER" then

@ -1,6 +1,5 @@
local ffi = require("ffi")
local DEBUG = require("dbg")
local Event = require("ui/event")
local MessageQueue = require("ui/message/messagequeue")
local _ = require("ffi/zeromq_h")
@ -24,7 +23,8 @@ function StreamMessageQueue:start()
end
local id_size = ffi.new("size_t[1]", 256)
local buffer = ffi.new("uint8_t[?]", id_size[0])
rc = zmq.zmq_getsockopt(self.socket, ffi.C.ZMQ_IDENTITY, buffer, id_size)
-- @todo: check return of zmq_getsockopt
zmq.zmq_getsockopt(self.socket, ffi.C.ZMQ_IDENTITY, buffer, id_size)
self.id = ffi.string(buffer, id_size[0])
DEBUG("id", #self.id, self.id)
end
@ -65,7 +65,7 @@ function StreamMessageQueue:waitEvent()
while czmq.zpoller_wait(self.poller, 0) ~= nil and wait_packages > 0 do
local id_frame = czmq.zframe_recv(self.socket)
if id_frame ~= nil then
local id = self:handleZframe(id_frame)
self:handleZframe(id_frame)
end
local frame = czmq.zframe_recv(self.socket)
if frame ~= nil then

@ -1,10 +1,8 @@
local ffi = require("ffi")
local DEBUG = require("dbg")
local util = require("ffi/util")
local Event = require("ui/event")
local MessageQueue = require("ui/message/messagequeue")
local dummy = require("ffi/zeromq_h")
local _ = require("ffi/zeromq_h")
local czmq = ffi.load("libs/libczmq.so.1")
local zyre = ffi.load("libs/libzyre.so.1")

@ -2,7 +2,6 @@ local InfoMessage = require("ui/widget/infomessage")
local ConfirmBox = require("ui/widget/confirmbox")
local UIManager = require("ui/uimanager")
local Device = require("device")
local DEBUG = require("dbg")
local T = require("ffi/util").template
local _ = require("gettext")
local NetworkMgr = {}

@ -5,7 +5,6 @@
--]]
local util = require("ffi/util")
local luxl = require("luxl")
local DEBUG = require("dbg")
local ffi = require("ffi")
local OPDSParser = {}
@ -18,7 +17,7 @@ local unescape_map = {
["apos"] = "'"
}
local gsub, char = string.gsub, string.char
local gsub = string.gsub
local function unescape(str)
return gsub(str, '(&(#?)([%d%a]+);)', function(orig, n, s)
return unescape_map[s] or n=="#" and util.unichar(tonumber(s)) or orig

@ -75,7 +75,7 @@ function OTAManager:checkUpdate()
local local_zsync_file = ota_dir .. zsync_file
-- download zsync file from OTA server
DEBUG("downloading zsync file", ota_zsync_file)
local r, c, h = http.request{
local _, c, _ = http.request{
url = ota_zsync_file,
sink = ltn12.sink.file(io.open(local_zsync_file, "w"))}
if c ~= 200 then

@ -1,3 +1,7 @@
--[[--
Text rendering module.
]]
local Font = require("ui/font")
local Cache = require("cache")
local CacheItem = require("cacheitem")
@ -5,7 +9,7 @@ local BlitBuffer = require("ffi/blitbuffer")
local DEBUG = require("dbg")
--[[
TODO: all these functions should probably be methods on Face objects
@TODO: all these functions should probably be methods on Face objects
]]--
local RenderText = {}
@ -95,9 +99,18 @@ function RenderText:getGlyph(face, charcode, bold)
return rendered_glyph
end
--- Return a substring of a given text that meets the maximum width (in pixels)
-- restriction.
--
-- @string text text to truncate
-- @tparam ui.font.FontFaceObj face font face for the text
-- @int width maximum width in pixels
-- @bool[opt=false] kerning whether the text should be measured with kerning
-- @bool[opt=false] bold whether the text should be measured as bold
-- @treturn string
function RenderText:getSubTextByWidth(text, face, width, kerning, bold)
local pen_x = 0
local prevcharcode = 0
local prevcharcode
local char_list = {}
for _, charcode, uchar in utf8Chars(text) do
if pen_x < width then
@ -118,6 +131,18 @@ function RenderText:getSubTextByWidth(text, face, width, kerning, bold)
return table.concat(char_list)
end
--- Measure rendered size for a given text.
--
-- Note this function does not render the text into a bitmap. Use it if you
-- only care about the size for the rendered result.
--
-- @int x start position for a given text (within maximum width)
-- @int width maximum rendering width in pixels (think of it as size of the bitmap)
-- @tparam ui.font.FontFaceObj face font face that will be used for rendering
-- @string text text to measure
-- @bool[opt=false] kerning whether the text should be measured with kerning
-- @bool[opt=false] bold whether the text should be measured as bold
-- @treturn RenderTextSize
function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold)
if not text then
DEBUG("sizeUtf8Text called without text");
@ -139,11 +164,16 @@ function RenderText:sizeUtf8Text(x, width, face, text, kerning, bold)
pen_x = pen_x + glyph.ax
pen_y_top = math.max(pen_y_top, glyph.t)
pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - glyph.t)
--DEBUG("ax:"..glyph.ax.." t:"..glyph.t.." r:"..glyph.r.." h:"..glyph.bb:getHeight().." w:"..glyph.bb:getWidth().." yt:"..pen_y_top.." yb:"..pen_y_bottom)
prevcharcode = charcode
end -- if pen_x < (width - x)
end
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom}
--- RenderText size information
-- @table RenderTextSize
-- @field x length of the text on x coordinates
-- @field y_top top offset for the text (relative to center of the text)
-- @field y_bottom bottom offset for the text (relative to center of the text)
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom }
end
function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bold, fgcolor, width)

@ -5,8 +5,8 @@ local TimeVal = {
usec = 0,
}
function TimeVal:new(o)
local o = o or {}
function TimeVal:new(from_o)
local o = from_o or {}
if o.sec == nil then
o.sec = 0
end

@ -55,7 +55,8 @@ function Translator:loadPage(target_lang, source_lang, text)
DEBUG("request", request)
http.TIMEOUT, https.TIMEOUT = 10, 10
local httpRequest = parsed.scheme == 'http' and http.request or https.request
local code, headers, status = socket.skip(1, httpRequest(request))
-- first argument returned by skip is code
local _, headers, status = socket.skip(1, httpRequest(request))
-- raise error message when network is unavailable
if headers == nil then

@ -422,7 +422,7 @@ function UIManager:_refresh(mode, region)
-- combine both refreshes' regions
local combined = region:combine(self._refresh_stack[i].region)
-- update the mode, if needed
local mode = update_mode(mode, self._refresh_stack[i].mode)
mode = update_mode(mode, self._refresh_stack[i].mode)
-- remove colliding update
table.remove(self._refresh_stack, i)
-- and try again with combined data

@ -3,7 +3,8 @@ Button widget that shows an "×" and handles closing window when tapped
Example:
local parent_widget = HorizontalGroup:new{}
local CloseButton = require("ui/widget/closebutton")
local parent_widget = OverlapGroup:new{}
table.insert(parent_widget, CloseButton:new{
window = parent_widget,
})

@ -9,7 +9,6 @@ local HorizontalGroup = require("ui/widget/horizontalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local VerticalGroup = require("ui/widget/verticalgroup")
local FixedTextWidget = require("ui/widget/fixedtextwidget")
local ProgressWidget = require("ui/widget/progresswidget")
local ToggleSwitch = require("ui/widget/toggleswitch")
local ConfirmBox = require("ui/widget/confirmbox")
local ImageWidget = require("ui/widget/imagewidget")
@ -176,9 +175,6 @@ function ConfigOption:init()
local item_font_size = self.options[c].item_font_size and self.options[c].item_font_size or default_item_font_size
local option_height = Screen:scaleBySize(self.options[c].height and self.options[c].height or default_option_height)
local item_spacing_with = self.options[c].spacing and self.options[c].spacing or default_items_spacing
local items_spacing = HorizontalSpan:new{
width = Screen:scaleBySize(item_spacing_with)
}
local enabled = true
if self.options[c].enabled_func then
enabled = self.options[c].enabled_func(self.config.configurable)
@ -224,16 +220,15 @@ function ConfigOption:init()
-- check if current value is stored in configurable or calculated in runtime
local val = self.options[c].current_func and self.options[c].current_func()
or self.config.configurable[self.options[c].name]
local min_diff = nil
local min_diff
if type(val) == "table" then
min_diff = value_diff(val[1], self.options[c].values[1][1])
else
min_diff = value_diff(val, self.options[c].values[1])
end
local diff = nil
local diff
for index, val_ in pairs(self.options[c].values) do
local diff = nil
if type(val) == "table" then
diff = value_diff(val[1], val_[1])
else
@ -277,7 +272,7 @@ function ConfigOption:init()
width = math.min(max_item_spacing, Screen:scaleBySize(item_spacing_with))
}
for d = 1, #self.options[c].item_text do
local option_item = nil
local option_item
if option_items_fixed then
option_item = OptionTextItem:new{
FixedTextWidget:new{
@ -584,7 +579,7 @@ function ConfigDialog:onMakeDefault(name, name_text, values, labels, position)
labels[position]
),
ok_callback = function()
local name = self.config_options.prefix.."_"..name
name = self.config_options.prefix.."_"..name
G_reader_settings:saveSetting(name, values[position])
end,
})

@ -99,9 +99,9 @@ function FileChooser:genItemTableFromPath(path)
local item_table = {}
for i, dir in ipairs(dirs) do
local path = self.path.."/"..dir.name
local subdir_path = self.path.."/"..dir.name
local items = 0
local ok, iter, dir_obj = pcall(lfs.dir, path)
ok, iter, dir_obj = pcall(lfs.dir, subdir_path)
if ok then
for f in iter, dir_obj do
items = items + 1
@ -116,13 +116,13 @@ function FileChooser:genItemTableFromPath(path)
table.insert(item_table, {
text = dir.name.."/",
mandatory = istr,
path = path
path = subdir_path
})
end
for _, file in ipairs(files) do
local full_path = self.path.."/"..file.name
local file_size = lfs.attributes(full_path, "size") or 0
local sstr = ""
local sstr
if file_size > 1024*1024 then
sstr = string.format("%4.1f MB", file_size/1024/1024)
elseif file_size > 1024 then

@ -32,25 +32,56 @@ local CloseButton = require("ui/widget/closebutton")
local UIManager = require("ui/uimanager")
local TextWidget = require("ui/widget/textwidget")
local GestureRange = require("ui/gesturerange")
local RenderText = require("ui/rendertext")
local Geom = require("ui/geometry")
local Font = require("ui/font")
local Device = require("device")
local Screen = Device.screen
local ellipsis, space = "...", " "
local ellipsis_width, space_width
local function truncateTextByWidth(text, face, max_width, prepend_space)
if not ellipsis_width then
ellipsis_width = RenderText:sizeUtf8Text(0, max_width, face, ellipsis).x
end
if not space_width then
space_width = RenderText:sizeUtf8Text(0, max_width, face, space).x
end
local new_txt_width = max_width - ellipsis_width - space_width
local sub_txt = RenderText:getSubTextByWidth(text, face, new_txt_width)
if prepend_space then
return space.. sub_txt .. ellipsis
else
return sub_txt .. ellipsis .. space
end
end
local KeyValueTitle = VerticalGroup:new{
kv_page = nil,
title = "",
tface = Font:getFace("tfont"),
align = "left",
}
function KeyValueTitle:init()
self.close_button = CloseButton:new{ window = self }
local btn_width = self.close_button:getSize().w
local title_txt_width = RenderText:sizeUtf8Text(
0, self.width, self.tface, self.title).x
local show_title_txt
if self.width < (title_txt_width + btn_width) then
show_title_txt = truncateTextByWidth(
self.title, self.tface, self.width-btn_width)
else
show_title_txt = self.title
end
table.insert(self, OverlapGroup:new{
dimen = { w = self.width },
TextWidget:new{
text = self.title,
face = Font:getFace("tfont", 26),
text = show_title_txt,
face = self.tface,
},
self.close_button,
})
@ -100,7 +131,7 @@ end
local KeyValueItem = InputContainer:new{
key = nil,
value = nil,
cface = Font:getFace("cfont", 24),
cface = Font:getFace("cfont"),
width = nil,
height = nil,
}
@ -117,20 +148,40 @@ function KeyValueItem:init()
}
end
self[1] = OverlapGroup:new{
dimen = self.dimen:copy(),
LeftContainer:new{
dimen = self.dimen:copy(),
TextWidget:new{
text = self.key,
face = self.cface,
}
},
RightContainer:new{
local key_w = RenderText:sizeUtf8Text(0, self.width, self.cface, self.key).x
local value_w = RenderText:sizeUtf8Text(0, self.width, self.cface, self.value).x
if key_w + value_w > self.width then
-- truncate key or value so they fits in one row
if key_w >= value_w then
self.show_key = truncateTextByWidth(self.key, self.cface, self.width-value_w)
self.show_value = self.value
else
self.show_value = truncateTextByWidth(self.value, self.cface, self.width-key_w, true)
self.show_key = self.key
end
else
self.show_key = self.key
self.show_value = self.value
end
self[1] = FrameContainer:new{
padding = 0,
bordersize = 0,
OverlapGroup:new{
dimen = self.dimen:copy(),
TextWidget:new{
text = self.value,
face = self.cface,
LeftContainer:new{
dimen = self.dimen:copy(),
TextWidget:new{
text = self.show_key,
face = self.cface,
}
},
RightContainer:new{
dimen = self.dimen:copy(),
TextWidget:new{
text = self.show_value,
face = self.cface,
}
}
}
}
@ -176,8 +227,8 @@ function KeyValuePage:init()
kv_page = self,
}
-- setup main content
self.item_padding = self.item_height / 4
local line_height = self.item_height + 2 * self.item_padding
self.item_margin = self.item_height / 4
local line_height = self.item_height + 2 * self.item_margin
local content_height = self.dimen.h - self.title_bar:getSize().h
self.items_per_page = math.floor(content_height / line_height)
self.pages = math.ceil(#self.kv_pairs / self.items_per_page)
@ -212,7 +263,7 @@ function KeyValuePage:prevPage()
end
end
-- make sure self.item_padding and self.item_height are set before calling this
-- make sure self.item_margin and self.item_height are set before calling this
function KeyValuePage:_populateItems()
self.main_content:clear()
local idx_offset = (self.show_page - 1) * self.items_per_page
@ -221,7 +272,7 @@ function KeyValuePage:_populateItems()
if entry == nil then break end
table.insert(self.main_content,
VerticalSpan:new{ width = self.item_padding })
VerticalSpan:new{ width = self.item_margin })
if type(entry) == "table" then
table.insert(
self.main_content,
@ -247,7 +298,7 @@ function KeyValuePage:_populateItems()
end
end
table.insert(self.main_content,
VerticalSpan:new{ width = self.item_padding })
VerticalSpan:new{ width = self.item_margin })
end
self.title_bar:setPageCount(self.show_page, self.pages)
UIManager:setDirty(self, function()

@ -149,13 +149,13 @@ function TouchMenuBar:init()
local icon_sep_width = Screen:scaleBySize(2)
local icons_sep_width = icon_sep_width * (#self.icons + 1)
-- we assume all icons are of the same width
local ib = IconButton:new{icon_file = self.icons[1]}
local content_width = ib:getSize().w * #self.icons + icons_sep_width
local tmp_ib = IconButton:new{icon_file = self.icons[1]}
local content_width = tmp_ib:getSize().w * #self.icons + icons_sep_width
local spacing_width = (self.width - content_width)/(#self.icons*2)
local spacing = HorizontalSpan:new{
width = math.min(spacing_width, Screen:scaleBySize(20))
}
self.height = ib:getSize().h + Screen:scaleBySize(10)
self.height = tmp_ib:getSize().h + Screen:scaleBySize(10)
self.show_parent = self.show_parent or self
self.bar_icon_group = HorizontalGroup:new{}
-- build up image widget for menu icon bar
@ -225,7 +225,6 @@ function TouchMenuBar:init()
table.insert(self.bar_icon_group, self.icon_widgets[k])
table.insert(self.bar_icon_group, icon_sep)
start_seg = _start_seg
end_seg = _end_seg
end
@ -451,7 +450,7 @@ function TouchMenu:updateItems()
--VerticalSpan:new{
--width = self.item_height
--})
--break
break
end -- if i <= self.items
end -- for c=1, self.perpage

@ -52,7 +52,8 @@ function Wikipedia:loadPage(text, lang, intro, plain)
DEBUG("request", request)
http.TIMEOUT, https.TIMEOUT = 10, 10
local httpRequest = parsed.scheme == 'http' and http.request or https.request
local code, headers, status = socket.skip(1, httpRequest(request))
-- first argument returned by skip is code
local _, headers, status = socket.skip(1, httpRequest(request))
-- raise error message when network is unavailable
if headers == nil then

49
kodev

@ -2,7 +2,7 @@
CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function assert_return_zero {
function assert_ret_zero {
if [ $1 -ne 0 ]; then
if [ ! -z $2 ]; then
echo $2
@ -45,43 +45,43 @@ ${SUPPORTED_TARGETS}"
;;
kindle)
make TARGET=kindle
assert_return_zero $?
assert_ret_zero $?
;;
kobo)
make TARGET=kobo
assert_return_zero $?
assert_ret_zero $?
;;
kindle-legacy)
make TARGET=kindle-legacy
assert_return_zero $?
assert_ret_zero $?
;;
android)
if [ ! -d ${CURDIR}/base/toolchain/android-toolchain ]; then
make android-toolchain
assert_return_zero $?
assert_ret_zero $?
fi
make TARGET=android
assert_return_zero $?
assert_ret_zero $?
;;
pocketbook)
if [ ! -d ${CURDIR}/base/toolchain/pocketbook-toolchain ]; then
make pocketbook-toolchain
assert_return_zero $?
assert_ret_zero $?
fi
make TARGET=pocketbook
assert_return_zero $?
assert_ret_zero $?
;;
ubuntu-touch)
make TARGET=ubuntu-touch
assert_return_zero $?
assert_ret_zero $?
;;
win32)
make TARGET=win32
assert_return_zero $?
assert_ret_zero $?
;;
*)
make
assert_return_zero $? "Failed to build emulator!"
assert_ret_zero $? "Failed to build emulator!"
setup_env
;;
esac
@ -246,10 +246,33 @@ OPTIONS:
function kodev-test {
TEST_HELP_MSG="
usage: test [front|base] <TEST_NAME>
usage: test <OPTIONS> [front|base] <TEST_NAME>
TEST_NAME is optional. If no TEST_NAME is given, all tests will be run.
OPTIONS:
--tags=TAGS only run tests with given tags
"
while [[ $1 == '--'* ]]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
--tags)
opts="--tags=${VALUE}"
;;
-h | --help)
echo "${TEST_HELP_MSG}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "${TEST_HELP_MSG}"
exit 1
;;
esac
shift
done
if [ $# -lt 1 ]; then
echo "${TEST_HELP_MSG}"
@ -265,7 +288,7 @@ usage: test [front|base] <TEST_NAME>
if [ ! -z $2 ]; then
test_path="${test_path}/$2"
fi
busted -o verbose_print --exclude-tags=notest ${test_path}
busted ${opts} -o verbose_print --exclude-tags=notest ${test_path}
popd
}

@ -1,11 +1,16 @@
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local DocSettings = require("docsettings")
local DEBUG = require("dbg")
local purgeDir = require("ffi/util").purgeDir
describe("Readerfooter module", function()
it("should setup footer for epub without error", function()
local sample_epub = "spec/front/unit/data/juliet.epub"
purgeDir(DocSettings:getSidecarDir(sample_epub))
os.remove(DocSettings:getHistoryPath(sample_epub))
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
@ -20,6 +25,9 @@ describe("Readerfooter module", function()
it("should setup footer for pdf without error", function()
local sample_pdf = "spec/front/unit/data/2col.pdf"
purgeDir(DocSettings:getSidecarDir(sample_pdf))
os.remove(DocSettings:getHistoryPath(sample_pdf))
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_pdf),
}

@ -343,9 +343,11 @@ local TestInputText = InputText:new{
-----------------------------------------------------
local KeyValuePage = require("ui/widget/keyvaluepage")
local kvp = KeyValuePage:new{
title = 'Statistics',
title = 'Statistics This is a very very log item whose length should exceed the width of the men',
kv_pairs = {
{"1 Current period", "00:00:00"},
{"This is a very very log item whose length should exceed the width of the menu.", "value"},
{"2 Time to read", "00:00:00 00:00:00 00:00:00 00:00:00"},
{"2 Time to read", "00:00:00"},
{"3 Time to read", "00:00:00"},
{"4 Time to read", "00:00:00"},
@ -377,7 +379,7 @@ local kvp = KeyValuePage:new{
--UIManager:show(TestGrid)
UIManager:show(TestVisible)
UIManager:show(Clock:new())
--UIManager:show(M)
-- UIManager:show(M)
--UIManager:show(Quiz)
--UIManager:show(readerwindow)
--UIManager:show(touch_menu)

Loading…
Cancel
Save