From 09f81b17eaff0a6b73c9e4def54b0b21c13e9fa1 Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 30 Jul 2020 20:23:08 +0200 Subject: [PATCH 1/3] bump crengine: reworked hanging punctuation --- base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base b/base index e89d85bca..041e30d6c 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit e89d85bcaa23ff0761296137fa50f711164e52e4 +Subproject commit 041e30d6c23d76911cb74a2a7fb2661b0bac9a12 From 56627125491582f31a687b63ff2ddca60c46bee9 Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 30 Jul 2020 21:25:29 +0200 Subject: [PATCH 2/3] move setting management from ReaderTypeset to ReaderTypography And fix initial handling of defaults being loaded as true/false but needing to be saved as 1/0. --- .../apps/reader/modules/readertypeset.lua | 51 ----------------- .../apps/reader/modules/readertypography.lua | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/frontend/apps/reader/modules/readertypeset.lua b/frontend/apps/reader/modules/readertypeset.lua index b999d15a4..7ffe6dbd3 100644 --- a/frontend/apps/reader/modules/readertypeset.lua +++ b/frontend/apps/reader/modules/readertypeset.lua @@ -96,14 +96,6 @@ function ReaderTypeset:onReadSettings(config) G_reader_settings:readSetting("copt_sync_t_b_page_margins") or 0 self.sync_t_b_page_margins = self.sync_t_b_page_margins == 1 and true or false - -- default to disable floating punctuation - -- the floating punctuation should not be boolean value for the following - -- expression otherwise a false value will never be returned but numerical - -- values will survive this expression - self.floating_punctuation = config:readSetting("floating_punctuation") or - G_reader_settings:readSetting("floating_punctuation") or 0 - self:toggleFloatingPunctuation(self.floating_punctuation) - -- default to disable TXT formatting as it does more harm than good self.txt_preformatted = config:readSetting("txt_preformatted") or G_reader_settings:readSetting("txt_preformatted") or 1 @@ -129,7 +121,6 @@ end function ReaderTypeset:onSaveSettings() self.ui.doc_settings:saveSetting("css", self.css) self.ui.doc_settings:saveSetting("embedded_css", self.embedded_css) - self.ui.doc_settings:saveSetting("floating_punctuation", self.floating_punctuation) self.ui.doc_settings:saveSetting("embedded_fonts", self.embedded_fonts) self.ui.doc_settings:saveSetting("render_dpi", self.render_dpi) self.ui.doc_settings:saveSetting("smooth_scaling", self.smooth_scaling) @@ -411,18 +402,6 @@ function ReaderTypeset:toggleNightmodeImages(toggle) self.ui:handleEvent(Event:new("UpdatePos")) end -function ReaderTypeset:toggleFloatingPunctuation(toggle) - -- for some reason the toggle value read from history files may stay boolean - -- and there seems no more elegant way to convert boolean values to numbers - if toggle == true then - toggle = 1 - elseif toggle == false then - toggle = 0 - end - self.ui.document:setFloatingPunctuation(toggle) - self.ui:handleEvent(Event:new("UpdatePos")) -end - function ReaderTypeset:toggleTxtPreFormatted(toggle) self.ui.document:setTxtPreFormatted(toggle) self.ui:handleEvent(Event:new("UpdatePos")) @@ -440,36 +419,6 @@ function ReaderTypeset:addToMainMenu(menu_items) text = self.css_menu_title, sub_item_table = self:genStyleSheetMenu(), } - menu_items.floating_punctuation = { - -- @translators See https://en.wikipedia.org/wiki/Hanging_punctuation - text = _("Hanging punctuation"), - checked_func = function() return self.floating_punctuation == 1 end, - callback = function() - self.floating_punctuation = self.floating_punctuation == 1 and 0 or 1 - self:toggleFloatingPunctuation(self.floating_punctuation) - end, - hold_callback = function() self:makeDefaultFloatingPunctuation() end, - } -end - -function ReaderTypeset:makeDefaultFloatingPunctuation() - local floating_punctuation = G_reader_settings:isTrue("floating_punctuation") - UIManager:show(MultiConfirmBox:new{ - text = floating_punctuation and _("Would you like to enable or disable hanging punctuation by default?\n\nThe current default (★) is enabled.") - or _("Would you like to enable or disable hanging punctuation by default?\n\nThe current default (★) is disabled."), - choice1_text_func = function() - return floating_punctuation and _("Disable") or _("Disable (★)") - end, - choice1_callback = function() - G_reader_settings:saveSetting("floating_punctuation", false) - end, - choice2_text_func = function() - return floating_punctuation and _("Enable (★)") or _("Enable") - end, - choice2_callback = function() - G_reader_settings:saveSetting("floating_punctuation", true) - end, - }) end function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance) diff --git a/frontend/apps/reader/modules/readertypography.lua b/frontend/apps/reader/modules/readertypography.lua index 7d1312bce..c6c23b2b4 100644 --- a/frontend/apps/reader/modules/readertypography.lua +++ b/frontend/apps/reader/modules/readertypography.lua @@ -120,6 +120,7 @@ function ReaderTypography:init() self.hyph_trust_soft_hyphens = false self.hyph_soft_hyphens_only = false self.hyph_force_algorithmic = false + self.floating_punctuation = 0 -- Migrate old readerhyphenation settings (but keep them in case one -- go back to a previous version) @@ -583,6 +584,17 @@ These settings will apply to all books with any hyphenation dictionary. sub_item_table = hyphenation_submenu, }) + table.insert(self.menu_table, { + -- @translators See https://en.wikipedia.org/wiki/Hanging_punctuation + text = _("Hanging punctuation"), + checked_func = function() return self.floating_punctuation == 1 end, + callback = function() + self.floating_punctuation = self.floating_punctuation == 1 and 0 or 1 + self:onToggleFloatingPunctuation(self.floating_punctuation) + end, + hold_callback = function() self:makeDefaultFloatingPunctuation() end, + }) + self.ui.menu:registerToMainMenu(self) end @@ -598,6 +610,39 @@ function ReaderTypography:addToMainMenu(menu_items) } end +function ReaderTypography:onToggleFloatingPunctuation(toggle) + -- for some reason the toggle value read from history files may stay boolean + -- and there seems no more elegant way to convert boolean values to numbers + if toggle == true then + toggle = 1 + elseif toggle == false then + toggle = 0 + end + self.ui.document:setFloatingPunctuation(toggle) + self.ui:handleEvent(Event:new("UpdatePos")) +end + +function ReaderTypography:makeDefaultFloatingPunctuation() + local floating_punctuation = G_reader_settings:isTrue("floating_punctuation") + UIManager:show(MultiConfirmBox:new{ + text = floating_punctuation and _("Would you like to enable or disable hanging punctuation by default?\n\nThe current default (★) is enabled.") + or _("Would you like to enable or disable hanging punctuation by default?\n\nThe current default (★) is disabled."), + choice1_text_func = function() + return floating_punctuation and _("Disable") or _("Disable (★)") + end, + choice1_callback = function() + G_reader_settings:saveSetting("floating_punctuation", false) + end, + choice2_text_func = function() + return floating_punctuation and _("Enable (★)") or _("Enable") + end, + choice2_callback = function() + G_reader_settings:saveSetting("floating_punctuation", true) + end, + }) +end + + function ReaderTypography:getCurrentDefaultHyphDictLanguage() local hyph_dict_name = self.ui.document:getTextMainLangDefaultHyphDictionary() local dict_info = HYPH_DICT_NAME_TO_LANG_NAME_TAG[hyph_dict_name] @@ -718,6 +763,15 @@ function ReaderTypography:onReadSettings(config) self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or 0) self.ui.document:setHyphRightHyphenMin(G_reader_settings:readSetting("hyph_right_hyphen_min") or 0) + -- Default to disable hanging/floating punctuation + -- (Stored as 0/1 in docsetting for historical reasons, but as true/false + -- in global settings.) + self.floating_punctuation = config:readSetting("floating_punctuation") + if self.floating_punctuation == nil then + self.floating_punctuation = G_reader_settings:isTrue("floating_punctuation") and 1 or 0 + end + self:onToggleFloatingPunctuation(self.floating_punctuation) + -- Decide and set the text main lang tag according to settings self.allow_doc_lang_tag_override = false -- Use the one manually set for this document @@ -806,6 +860,7 @@ function ReaderTypography:onSaveSettings() self.ui.doc_settings:saveSetting("hyph_trust_soft_hyphens", self.hyph_trust_soft_hyphens) self.ui.doc_settings:saveSetting("hyph_soft_hyphens_only", self.hyph_soft_hyphens_only) self.ui.doc_settings:saveSetting("hyph_force_algorithmic", self.hyph_force_algorithmic) + self.ui.doc_settings:saveSetting("floating_punctuation", self.floating_punctuation) end return ReaderTypography From cd0d248dc58e96176873833600415d023b4607bf Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 30 Jul 2020 21:37:58 +0200 Subject: [PATCH 3/3] fix luacheck --- frontend/apps/reader/modules/readertypeset.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/apps/reader/modules/readertypeset.lua b/frontend/apps/reader/modules/readertypeset.lua index 7ffe6dbd3..2acc67e4a 100644 --- a/frontend/apps/reader/modules/readertypeset.lua +++ b/frontend/apps/reader/modules/readertypeset.lua @@ -3,7 +3,6 @@ local ConfirmBox = require("ui/widget/confirmbox") local Event = require("ui/event") local InfoMessage = require("ui/widget/infomessage") local InputContainer = require("ui/widget/container/inputcontainer") -local MultiConfirmBox = require("ui/widget/multiconfirmbox") local UIManager = require("ui/uimanager") local Math = require("optmath") local lfs = require("libs/libkoreader-lfs")