diff --git a/frontend/apps/reader/modules/readerfont.lua b/frontend/apps/reader/modules/readerfont.lua index 42f92b54e..896393b92 100644 --- a/frontend/apps/reader/modules/readerfont.lua +++ b/frontend/apps/reader/modules/readerfont.lua @@ -19,6 +19,8 @@ local ReaderFont = InputContainer:new{ face_table = nil, -- default gamma from crengine's lvfntman.cpp gamma_index = nil, + steps = {0,1,1,1,1,1,2,2,2,3,3,3,4,4,5}, + gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE, } function ReaderFont:init() @@ -78,7 +80,7 @@ function ReaderFont:setupTouchZones() screen_zone = { ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1, }, - handler = function() return self:onSpread() end + handler = function(ges) return self:onAdjustSpread(ges) end }, { id = "id_pinch", @@ -86,7 +88,7 @@ function ReaderFont:setupTouchZones() screen_zone = { ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1, }, - handler = function() return self:onPinch() end + handler = function(ges) return self:onAdjustPinch(ges) end }, }) end @@ -160,9 +162,13 @@ end --[[ UpdatePos event is used to tell ReaderRolling to update pos. --]] -function ReaderFont:onChangeSize(direction) +function ReaderFont:onChangeSize(direction, font_delta) local delta = direction == "decrease" and -1 or 1 - self.font_size = self.font_size + delta + if font_delta then + self.font_size = self.font_size + font_delta * delta + else + self.font_size = self.font_size + delta + end self.ui:handleEvent(Event:new("SetFontSize", self.font_size)) return true end @@ -258,20 +264,24 @@ function ReaderFont:addToMainMenu(menu_items) } end -function ReaderFont:onPinch() - local info = Notification:new{text = _("Decreasing font size…")} +function ReaderFont:onAdjustSpread(ges) + local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale) + local delta_int = self.steps[step] or self.steps[#self.steps] + local info = Notification:new{text = _("Increasing font size…")} UIManager:show(info) UIManager:forceRePaint() - self:onChangeSize("decrease") + self:onChangeSize("increase", delta_int) UIManager:close(info) return true end -function ReaderFont:onSpread() - local info = Notification:new{text = _("Increasing font size…")} +function ReaderFont:onAdjustPinch(ges) + local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale) + local delta_int = self.steps[step] or self.steps[#self.steps] + local info = Notification:new{text = _("Decreasing font size…")} UIManager:show(info) UIManager:forceRePaint() - self:onChangeSize("increase") + self:onChangeSize("decrease", delta_int) UIManager:close(info) return true end