diff --git a/frontend/apps/reader/modules/readerfont.lua b/frontend/apps/reader/modules/readerfont.lua index a4a9e330d..6073b27f7 100644 --- a/frontend/apps/reader/modules/readerfont.lua +++ b/frontend/apps/reader/modules/readerfont.lua @@ -1,7 +1,8 @@ local InputContainer = require("ui/widget/container/inputcontainer") local CenterContainer = require("ui/widget/container/centercontainer") -local Menu = require("ui/widget/menu") local Notification = require("ui/widget/notification") +local ConfirmBox = require("ui/widget/confirmbox") +local Menu = require("ui/widget/menu") local Device = require("ui/device") local Screen = require("ui/screen") local Input = require("ui/input") @@ -52,7 +53,10 @@ function ReaderFont:init() text = v, callback = function() self:setFont(v) - end + end, + hold_callback = function() + self:makeDefault(v) + end, }) face_list[k] = {text = v} end @@ -213,6 +217,17 @@ function ReaderFont:setFont(face) end end +function ReaderFont:makeDefault(face) + if face then + UIManager:show(ConfirmBox:new{ + text = _("Set default font \"")..face.."\"?", + ok_callback = function() + G_reader_settings:saveSetting("cre_font", face) + end, + }) + end +end + function ReaderFont:addToMainMenu(tab_item_table) -- insert table to main reader menu table.insert(tab_item_table.typeset, { diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 4673fed08..9d45c0605 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -116,6 +116,7 @@ function ReaderHighlight:onTap(arg, ges) self.ui.document:clearSelection() end self.hold_pos = nil + self.selected_text = nil UIManager:setDirty(self.dialog, "partial") return true end @@ -231,6 +232,13 @@ function ReaderHighlight:onHoldPan(arg, ges) DEBUG("no previous hold position") return true end + local page_area = self.view:getScreenPageArea(self.hold_pos.page) + DEBUG("current page area", page_area) + if ges.pos:notIntersectWith(page_area) then + DEBUG("not inside page area") + return true + end + self.holdpan_pos = self.view:screenToPageTransform(ges.pos) DEBUG("holdpan position in page", self.holdpan_pos) self.selected_text = self.ui.document:getTextFromPositions(self.hold_pos, self.holdpan_pos) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index e6c806295..244eae509 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -177,6 +177,36 @@ function ReaderView:pageToScreenTransform(page, rect) end end +--[[ +Get page area on screen for a given page number +--]] +function ReaderView:getScreenPageArea(page) + if self.ui.document.info.has_pages then + local area = Geom:new{x = 0, y = 0} + if self.page_scroll then + for _, state in ipairs(self.page_states) do + if page ~= state.page then + area.y = area.y + state.visible_area.h + state.offset.y + area.y = area.y + self.page_gap.height + else + area.x = state.offset.x + area.w = state.visible_area.w + area.h = state.visible_area.h + return area + end + end + else + area.x = self.state.offset.x + area.y = self.state.offset.y + area.w = self.visible_area.w + area.h = self.visible_area.h + return area + end + else + return self.dimen:copy() + end +end + function ReaderView:drawPageBackground(bb, x, y) bb:paintRect(x, y, self.dimen.w, self.dimen.h, self.page_bgcolor) end diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index ce5a4e8ad..46053ee3c 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -60,8 +60,7 @@ function CreDocument:engineInit() -- we need to initialize the CRE font list local fonts = Font:getFontList() for _k, _v in ipairs(fonts) do - if _v ~= "Dingbats.cff" and _v ~= "StandardSymL.cff" - and _v:sub(1, 6) ~= "Nimbus" then + if _v:sub(1, 4) ~= "urw/" then local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v) if not ok then DEBUG(err) diff --git a/frontend/ui/widget/confirmbox.lua b/frontend/ui/widget/confirmbox.lua index 7b470a29c..2423317d1 100644 --- a/frontend/ui/widget/confirmbox.lua +++ b/frontend/ui/widget/confirmbox.lua @@ -1,16 +1,19 @@ +local InputContainer = require("ui/widget/container/inputcontainer") local CenterContainer = require("ui/widget/container/centercontainer") -local FrameContainer = require("ui/widget/container/centercontainer") -local FocusManager = require("ui/widget/focusmanager") -local Button = require("ui/widget/button") +local FrameContainer = require("ui/widget/container/framecontainer") +local HorizontalGroup = require("ui/widget/horizontalgroup") local VerticalGroup = require("ui/widget/verticalgroup") local ImageWidget = require("ui/widget/imagewidget") local TextBoxWidget = require("ui/widget/textboxwidget") -local Font = require("ui/font") +local HorizontalSpan = require("ui/widget/horizontalspan") +local ButtonTable = require("ui/widget/buttontable") +local GestureRange = require("ui/gesturerange") local UIManager = require("ui/uimanager") +local Device = require("ui/device") +local Geom = require("ui/geometry") +local Input = require("ui/input") local Screen = require("ui/screen") -local HorizontalGroup = require("ui/widget/horizontalgroup") -local VerticalSpan = require("ui/widget/verticalspan") -local HorizontalSpan = require("ui/widget/horizontalspan") +local Font = require("ui/font") local DEBUG = require("dbg") local _ = require("gettext") @@ -19,73 +22,70 @@ local _ = require("gettext") --[[ Widget that shows a message and OK/Cancel buttons ]] -local ConfirmBox = FocusManager:new{ +local ConfirmBox = InputContainer:new{ text = _("no text"), - width = nil, + face = Font:getFace("infofont", 25), ok_text = _("OK"), cancel_text = _("Cancel"), ok_callback = function() end, cancel_callback = function() end, + margin = 5, + padding = 5, } function ConfirmBox:init() - -- calculate box width on the fly if not given - if not self.width then - self.width = Screen:getWidth() - 200 - end - -- build bottons - self.key_events.Close = { {{"Home","Back"}}, doc = "cancel" } - self.key_events.Select = { {{"Enter","Press"}}, doc = "chose selected option" } - - local ok_button = Button:new{ - text = self.ok_text, - callback = function() - self.ok_callback() - UIManager:close(self) - end, - show_parent = self, + local content = HorizontalGroup:new{ + align = "center", + ImageWidget:new{ + file = "resources/info-i.png" + }, + HorizontalSpan:new{ width = 10 }, + TextBoxWidget:new{ + text = self.text, + face = self.face, + width = Screen:getWidth()*2/3, + } } - local cancel_button = Button:new{ - text = self.cancel_text, - preselect = true, - callback = function() - self.cancel_callback() - UIManager:close(self) - end, + local button_table = ButtonTable:new{ + width = content:getSize().w, + button_font_face = "cfont", + button_font_size = 20, + buttons = { + { + { + text = self.cancel_text, + callback = function() + self.cancel_callback() + UIManager:close(self) + end, + }, + { + text = self.ok_text, + callback = function() + self.ok_callback() + UIManager:close(self) + end, + }, + }, + }, + zero_sep = true, show_parent = self, } - self.layout = { { ok_button, cancel_button } } - self.selected.x = 2 -- Cancel is default - self[1] = CenterContainer:new{ dimen = Screen:getSize(), FrameContainer:new{ - margin = 2, background = 0, - padding = 10, - HorizontalGroup:new{ - ImageWidget:new{ - file = "resources/info-i.png" - }, - HorizontalSpan:new{ width = 10 }, - VerticalGroup:new{ - align = "left", - TextBoxWidget:new{ - text = self.text, - face = Font:getFace("cfont", 30), - width = self.width, - }, - VerticalSpan:new{ width = 10 }, - HorizontalGroup:new{ - ok_button, - HorizontalSpan:new{ width = 10 }, - cancel_button, - } - } + margin = self.margin, + padding = self.padding, + VerticalGroup:new{ + align = "left", + content, + button_table, } } } + end function ConfirmBox:onClose() diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 4e1e97b1d..fa109e956 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -41,6 +41,13 @@ function TouchMenuItem:init() }, doc = "Select Menu Item", }, + HoldSelect = { + GestureRange:new{ + ges = "hold", + range = self.dimen, + }, + doc = "Hold Menu Item", + }, } local item_enabled = self.item.enabled @@ -96,6 +103,21 @@ function TouchMenuItem:onTapSelect(arg, ges) self.menu:onMenuSelect(self.item) end +function TouchMenuItem:onHoldSelect(arg, ges) + local enabled = self.item.enabled + if self.item.enabled_func then + enabled = self.item.enabled_func() + end + if enabled == false then return end + + self.item_frame.invert = true + UIManager:setDirty(self.show_parent, "partial") + UIManager:scheduleIn(0.5, function() + self.item_frame.invert = false + UIManager:setDirty(self.show_parent, "partial") + end) + self.menu:onMenuHold(self.item) +end --[[ TouchMenuBar widget @@ -464,11 +486,6 @@ function TouchMenu:onSwipe(arg, ges_ev) end function TouchMenu:onMenuSelect(item) - local enabled = item.enabled - if item.enabled_func then - enabled = item.enabled_func() - end - if enabled == false then return end local sub_item_table = item.sub_item_table if item.sub_item_table_func then sub_item_table = item.sub_item_table_func() @@ -494,6 +511,20 @@ function TouchMenu:onMenuSelect(item) return true end +function TouchMenu:onMenuHold(item) + local callback = item.hold_callback + if item.hold_callback_func then + callback = item.hold_callback_func() + end + if callback then + UIManager:scheduleIn(0.1, function() + self:closeMenu() + callback() + end) + end + return true +end + function TouchMenu:onTapCloseAllMenus(arg, ges_ev) if ges_ev.pos:notIntersectWith(self.dimen) then self:closeMenu()