From 0499b5109aa138c8083f45527d0fabb011620a7a Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Fri, 11 Aug 2023 08:38:29 +0300 Subject: [PATCH] Profiles: fix New profile with current pdf document settings (#10778) --- frontend/dispatcher.lua | 6 ++++++ plugins/profiles.koplugin/main.lua | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index 0e8330738..47133cdac 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -584,6 +584,12 @@ function Dispatcher:getNameFromItem(item, settings, dont_show_value) return title end +-- Converts copt/kopt-options values to args. +function Dispatcher:getArgFromValue(item, value) + local value_num = util.arrayContains(settingsList[item].configurable.values, value) + return settingsList[item].args[value_num] +end + -- Add the item to the end of the execution order. -- If item or the order is nil all items will be added. function Dispatcher:_addToOrder(location, settings, item) diff --git a/plugins/profiles.koplugin/main.lua b/plugins/profiles.koplugin/main.lua index e88124d5a..195715290 100644 --- a/plugins/profiles.koplugin/main.lua +++ b/plugins/profiles.koplugin/main.lua @@ -337,27 +337,29 @@ function Profiles:getProfileFromCurrentDocument(new_name) "kopt_quality", } end + local setting_needs_arg = { + ["view_mode"] = true, + ["kopt_trim_page"] = true, + ["kopt_zoom_mode_genus"] = true, + ["kopt_zoom_mode_type"] = true, + ["kopt_page_scroll"] = true, + } local profile = { settings = { name = new_name, order = document_settings } } for _, v in ipairs(document_settings) do - profile[v] = self.document.configurable[self.ui.rolling and v or v:sub(6)] + -- document configurable settings do not have prefixes + local value = self.document.configurable[v:gsub("^kopt_", "")] + if setting_needs_arg[v] then + value = Dispatcher:getArgFromValue(v, value) + end + profile[v] = value end if self.ui.rolling then profile["set_font"] = self.ui.font.font_face profile["sync_t_b_page_margins"] = self.ui.typeset.sync_t_b_page_margins - profile["view_mode"] = self.view.view_mode profile["embedded_css"] = self.ui.typeset.embedded_css profile["embedded_fonts"] = self.ui.typeset.embedded_fonts profile["smooth_scaling"] = self.ui.typeset.smooth_scaling - else - local trim_page_to_mode = { _("manual"), _("auto"), _("semi-auto"), _("none") } - local zoom_genus_to_mode = { _("manual"), _("rows"), _("columns"), _("content"), _("page") } - local zoom_type_to_mode = { _("height"), _("width"), _("full") } - profile["rotation_mode"] = self.document.configurable.rotation_mode - profile["kopt_trim_page"] = trim_page_to_mode[profile["kopt_trim_page"]+1] - profile["kopt_zoom_mode_genus"] = zoom_genus_to_mode[profile["kopt_zoom_mode_genus"]+1] - profile["kopt_zoom_mode_type"] = zoom_type_to_mode[profile["kopt_zoom_mode_type"]+1] - profile["kopt_page_scroll"] = self.view.page_scroll end return profile end