<commit_before>local InputContainer = require("ui/widget/container/inputcontainer")
local Device = require("ui/device")
local Input = require("ui/input")
local Screen = require("ui/screen")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local Event = require("ui/event")
local DEBUG = require("dbg")
local _ = require("gettext")

local ReaderZooming = InputContainer:new{
	zoom = 1.0,
	-- default to nil so we can trigger ZoomModeUpdate events on start up
	zoom_mode = nil,
	DEFAULT_ZOOM_MODE = "page",
	current_page = 1,
	rotation = 0
}

function ReaderZooming:init()
	if Device:hasKeyboard() then
		self.key_events = {
			ZoomIn = {
				{ "Shift", Input.group.PgFwd },
				doc = _("zoom in"),
				event = "Zoom", args = "in"
			},
			ZoomOut = {
				{ "Shift", Input.group.PgBack },
				doc = _("zoom out"),
				event = "Zoom", args = "out"
			},
			ZoomToFitPage = {
				{ "A" },
				doc = _("zoom to fit page"),
				event = "SetZoomMode", args = "page"
			},
			ZoomToFitContent = {
				{ "Shift", "A" },
				doc = _("zoom to fit content"),
				event = "SetZoomMode", args = "content"
			},
			ZoomToFitPageWidth = {
				{ "S" },
				doc = _("zoom to fit page width"),
				event = "SetZoomMode", args = "pagewidth"
			},
			ZoomToFitContentWidth = {
				{ "Shift", "S" },
				doc = _("zoom to fit content width"),
				event = "SetZoomMode", args = "contentwidth"
			},
			ZoomToFitPageHeight = {
				{ "D" },
				doc = _("zoom to fit page height"),
				event = "SetZoomMode", args = "pageheight"
			},
			ZoomToFitContentHeight = {
				{ "Shift", "D" },
				doc = _("zoom to fit content height"),
				event = "SetZoomMode", args = "contentheight"
			},
		}
	end
	if Device:isTouchDevice() then
		self.ges_events = {
			Spread = {
				GestureRange:new{
					ges = "spread",
					range = Geom:new{
						x = 0, y = 0,
						w = Screen:getWidth(),
						h = Screen:getHeight(),
					}
				}
			},
			Pinch = {
				GestureRange:new{
					ges = "pinch",
					range = Geom:new{
						x = 0, y = 0,
						w = Screen:getWidth(),
						h = Screen:getHeight(),
					}
				}
			},
			ToggleFreeZoom = {
				GestureRange:new{
					ges = "double_tap",
					range = Geom:new{
						x = 0, y = 0,
						w = Screen:getWidth(),
						h = Screen:getHeight(),
					}
				}
			},
		}
	end
	self.ui.menu:registerToMainMenu(self)
end

function ReaderZooming:onReadSettings(config)
	-- @TODO config file from old code base uses globalzoom_mode
	-- instead of zoom_mode, we need to handle this imcompatibility
	-- 04.12 2012 (houqp)
	local zoom_mode = config:readSetting("zoom_mode")
	if not zoom_mode then
		zoom_mode = self.DEFAULT_ZOOM_MODE
	end
	self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode))
end

function ReaderZooming:onSaveSettings()
	self.ui.doc_settings:saveSetting("zoom_mode", self.zoom_mode)
end

function ReaderZooming:onSpread(arg, ges)
	if ges.direction == "horizontal" then
		self:genSetZoomModeCallBack("contentwidth")()
	elseif ges.direction == "vertical" then
		self:genSetZoomModeCallBack("contentheight")()
	elseif ges.direction == "diagonal" then
		self:genSetZoomModeCallBack("content")()
	end
	return true<commit_msg>fix page states not updated in scroll mode<commit_after>local InputContainer = require("ui/widget/container/inputcontainer")
local Device = require("ui/device")
local Input = require("ui/input")
local Screen = require("ui/screen")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local Event = require("ui/event")
local DEBUG = require("dbg")
local _ = require("gettext")

local ReaderZooming = InputContainer:new{
	zoom = 1.0,
	-- default to nil so we can trigger ZoomModeUpdate events on start up
	zoom_mode = nil,
	DEFAULT_ZOOM_MODE = "page",
	current_page = 1,
	rotation = 0
}

function ReaderZooming:init()
	if Device:hasKeyboard() then
		self.key_events = {
			ZoomIn = {
				{ "Shift", Input.group.PgFwd },
				doc = _("zoom in"),
				event = "Zoom", args = "in"
			},
			ZoomOut = {
				{ "Shift", Input.group.PgBack },
				doc = _("zoom out"),
				event = "Zoom", args = "out"
			},
			ZoomToFitPage = {
				{ "A" },
				doc = _("zoom to fit page"),
				event = "SetZoomMode", args = "page"
			},
			ZoomToFitContent = {
				{ "Shift", "A" },
				doc = _("zoom to fit content"),
				event = "SetZoomMode", args = "content"
			},
			ZoomToFitPageWidth = {
				{ "S" },
				doc = _("zoom to fit page width"),
				event = "SetZoomMode", args = "pagewidth"
			},
			ZoomToFitContentWidth = {
				{ "Shift", "S" },
				doc = _("zoom to fit content width"),
				event = "SetZoomMode", args = "contentwidth"
			},
			ZoomToFitPageHeight = {
				{ "D" },
				doc = _("zoom to fit page height"),
				event = "SetZoomMode", args = "pageheight"
			},
			ZoomToFitContentHeight = {
				{ "Shift", "D" },
				doc = _("zoom to fit content height"),
				event = "SetZoomMode", args = "contentheight"
			},
		}
	end
	if Device:isTouchDevice() then
		self.ges_events = {
			Spread = {
				GestureRange:new{
					ges = "spread",
					range = Geom:new{
						x = 0, y = 0,
						w = Screen:getWidth(),
						h = Screen:getHeight(),
					}
				}
			},
			Pinch = {
				GestureRange:new{
					ges = "pinch",
					range = Geom:new{
						x = 0, y = 0,
						w = Screen:getWidth(),
						h = Screen:getHeight(),
					}
				}
			},
			ToggleFreeZoom = {
				GestureRange:new{
					ges = "double_tap",
					range = Geom:new{
						x = 0, y = 0,
						w = Screen:getWidth(),
						h = Screen:getHeight(),
					}
				}
			},
		}
	end
	self.ui.menu:registerToMainMenu(self)
end

function ReaderZooming:onReadSettings(config)
	-- @TODO config file from old code base uses globalzoom_mode
	-- instead of zoom_mode, we need to handle this imcompatibility
	-- 04.12 2012 (houqp)
	local zoom_mode = config:readSetting("zoom_mode")
	if not zoom_mode then
		zoom_mode = self.DEFAULT_ZOOM_MODE
	end
	self:setZoomMode(zoom_mode)
end

function ReaderZooming:onSaveSettings()
	self.ui.doc_settings:saveSetting("zoom_mode", self.zoom_mode)
end

function ReaderZooming:onSpread(arg, ges)
	if ges.direction == "horizontal" then
		self:genSetZoomModeCallBack("contentwidth")()
	elseif ges.direction == "vertical" then
		self:genSetZoomModeCallBack("contentheight")()
	elseif ges.direction == "diagonal" then
		self:genSetZoomModeCallBack("content")()
	end
	return true
{'fraction_non_alphanumeric': 0.14373619438308616, 'fraction_numerical': 0.005680025244556642, 'mean_word_length': 3.1813984168865437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1992408', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2170, 'n_words': 529}