diff --git a/frontend/apps/reader/modules/readertypeset.lua b/frontend/apps/reader/modules/readertypeset.lua index 15c1ce173..401acd216 100644 --- a/frontend/apps/reader/modules/readertypeset.lua +++ b/frontend/apps/reader/modules/readertypeset.lua @@ -3,6 +3,7 @@ local Event = require("ui/event") local InfoMessage = require("ui/widget/infomessage") local InputContainer = require("ui/widget/container/inputcontainer") local UIManager = require("ui/uimanager") +local Math = require("optmath") local lfs = require("libs/libkoreader-lfs") local _ = require("gettext") local Screen = require("device").screen @@ -71,6 +72,9 @@ function ReaderTypeset:onReadSettings(config) DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE self.unscaled_margins = { h_margins[1], t_margin, h_margins[2], b_margin } self:onSetPageMargins(self.unscaled_margins, true) + self.sync_t_b_page_margins = config:readSetting("copt_sync_t_b_page_margins") or + 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 @@ -347,17 +351,47 @@ end function ReaderTypeset:onSetPageHorizMargins(h_margins) self.unscaled_margins = { h_margins[1], self.unscaled_margins[2], h_margins[2], self.unscaled_margins[4] } - self:onSetPageMargins(self.unscaled_margins) + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins)) end function ReaderTypeset:onSetPageTopMargin(t_margin) self.unscaled_margins = { self.unscaled_margins[1], t_margin, self.unscaled_margins[3], self.unscaled_margins[4] } - self:onSetPageMargins(self.unscaled_margins) + if self.sync_t_b_page_margins then + self.unscaled_margins[4] = t_margin + -- Let ConfigDialog know so it can update it on screen and have it saved on quit + self.ui.document.configurable.b_page_margin = t_margin + end + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins)) end function ReaderTypeset:onSetPageBottomMargin(b_margin) self.unscaled_margins = { self.unscaled_margins[1], self.unscaled_margins[2], self.unscaled_margins[3], b_margin } - self:onSetPageMargins(self.unscaled_margins) + if self.sync_t_b_page_margins then + self.unscaled_margins[2] = b_margin + -- Let ConfigDialog know so it can update it on screen and have it saved on quit + self.ui.document.configurable.t_page_margin = b_margin + end + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins)) +end + +function ReaderTypeset:onSyncPageTopBottomMargins(toggle) + self.sync_t_b_page_margins = not self.sync_t_b_page_margins + if self.sync_t_b_page_margins then + -- Adjust current top and bottom margins if needed + if self.unscaled_margins[2] ~= self.unscaled_margins[4] then + -- Taking the rounded mean can change the vertical page height, + -- and so the previous lines layout. We could have used the mean + -- for the top, and the delta from the mean for the bottom (and + -- have them possibly not equal), but as these are unscaled here, + -- and later scaled, the end result could still be different. + -- So just take the mean and make them equal. + local mean_margin = Math.round((self.unscaled_margins[2] + self.unscaled_margins[4]) / 2) + self.ui.document.configurable.t_page_margin = mean_margin + self.ui.document.configurable.b_page_margin = mean_margin + self.unscaled_margins = { self.unscaled_margins[1], mean_margin, self.unscaled_margins[3], mean_margin } + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins)) + end + end end function ReaderTypeset:onSetPageMargins(margins, silent) diff --git a/frontend/ui/data/creoptions.lua b/frontend/ui/data/creoptions.lua index 46bc7c472..dd6c16fa4 100644 --- a/frontend/ui/data/creoptions.lua +++ b/frontend/ui/data/creoptions.lua @@ -57,6 +57,123 @@ Note that this may not be ensured under some conditions: in scroll mode, when a }, } }, + { + icon = "resources/icons/appbar.crop.large.png", + options = { + { + name = "h_page_margins", + name_text = S.H_PAGE_MARGINS, + buttonprogress = true, + values = { + DCREREADER_CONFIG_H_MARGIN_SIZES_SMALL, + DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM, + DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_X_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_XX_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_HUGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE, + }, + default_pos = 2, + default_value = DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM, + event = "SetPageHorizMargins", + args = { + DCREREADER_CONFIG_H_MARGIN_SIZES_SMALL, + DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM, + DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_X_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_XX_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_HUGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE, + DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE, + }, + name_text_hold_callback = optionsutil.showValuesHMargins, + }, + { + name = "sync_t_b_page_margins", + name_text = S.SYNC_T_B_PAGE_MARGINS, + toggle = {S.OFF, S.ON}, + values = {0, 1}, + default_value = 0, + args = {false, true}, + default_arg = false, + event = "SyncPageTopBottomMargins", + name_text_hold_callback = optionsutil.showValues, + help_text = _([[Keep top and bottom margins synchronized. +- 'off' allows different top and bottom margins. +- 'on' keeps top and bottom margins locked, ensuring text is vertically centered in the page. + +In the top menu → Settings → Status bar, you can choose whether the bottom margin applies from the bottom of the screen, or from above the status bar.]]), + }, + { + name = "t_page_margin", + name_text = S.T_PAGE_MARGIN, + buttonprogress = true, + fine_tune = true, + values = { + DCREREADER_CONFIG_T_MARGIN_SIZES_SMALL, + DCREREADER_CONFIG_T_MARGIN_SIZES_MEDIUM, + DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_X_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_XX_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_XXX_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_HUGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE, + }, + default_pos = 3, + default_value = DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE, + event = "SetPageTopMargin", + args = { + DCREREADER_CONFIG_T_MARGIN_SIZES_SMALL, + DCREREADER_CONFIG_T_MARGIN_SIZES_MEDIUM, + DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_X_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_XX_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_XXX_LARGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_HUGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE, + DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE, + }, + name_text_hold_callback = optionsutil.showValues, + }, + { + name = "b_page_margin", + name_text = S.B_PAGE_MARGIN, + buttonprogress = true, + fine_tune = true, + values = { + DCREREADER_CONFIG_B_MARGIN_SIZES_SMALL, + DCREREADER_CONFIG_B_MARGIN_SIZES_MEDIUM, + DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_X_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_XX_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_XXX_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_HUGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE, + }, + default_pos = 3, + default_value = DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE, + event = "SetPageBottomMargin", + args = { + DCREREADER_CONFIG_B_MARGIN_SIZES_SMALL, + DCREREADER_CONFIG_B_MARGIN_SIZES_MEDIUM, + DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_X_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_XX_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_XXX_LARGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_HUGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE, + DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE, + }, + name_text_hold_callback = optionsutil.showValues, + help_text = _([[In the top menu → Settings → Status bar, you can choose whether the bottom margin applies from the bottom of the screen, or from above the status bar.]]), + }, + } + }, { icon = "resources/icons/appbar.column.two.large.png", options = { @@ -133,106 +250,6 @@ Note that your selected font size is not affected by this setting.]]), }, } }, - { - icon = "resources/icons/appbar.crop.large.png", - options = { - { - name = "h_page_margins", - name_text = S.H_PAGE_MARGINS, - buttonprogress = true, - values = { - DCREREADER_CONFIG_H_MARGIN_SIZES_SMALL, - DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM, - DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_X_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_XX_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_HUGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE, - }, - default_pos = 2, - default_value = DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM, - event = "SetPageHorizMargins", - args = { - DCREREADER_CONFIG_H_MARGIN_SIZES_SMALL, - DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM, - DCREREADER_CONFIG_H_MARGIN_SIZES_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_X_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_XX_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_XXX_LARGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_HUGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE, - DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE, - }, - name_text_hold_callback = optionsutil.showValuesHMargins, - }, - { - name = "t_page_margin", - name_text = S.T_PAGE_MARGIN, - buttonprogress = true, - fine_tune = true, - values = { - DCREREADER_CONFIG_T_MARGIN_SIZES_SMALL, - DCREREADER_CONFIG_T_MARGIN_SIZES_MEDIUM, - DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_X_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_XX_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_XXX_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_HUGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE, - }, - default_pos = 3, - default_value = DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE, - event = "SetPageTopMargin", - args = { - DCREREADER_CONFIG_T_MARGIN_SIZES_SMALL, - DCREREADER_CONFIG_T_MARGIN_SIZES_MEDIUM, - DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_X_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_XX_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_XXX_LARGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_HUGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE, - DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE, - }, - name_text_hold_callback = optionsutil.showValues, - }, - { - name = "b_page_margin", - name_text = S.B_PAGE_MARGIN, - buttonprogress = true, - fine_tune = true, - values = { - DCREREADER_CONFIG_B_MARGIN_SIZES_SMALL, - DCREREADER_CONFIG_B_MARGIN_SIZES_MEDIUM, - DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_X_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_XX_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_XXX_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_HUGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE, - }, - default_pos = 3, - default_value = DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE, - event = "SetPageBottomMargin", - args = { - DCREREADER_CONFIG_B_MARGIN_SIZES_SMALL, - DCREREADER_CONFIG_B_MARGIN_SIZES_MEDIUM, - DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_X_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_XX_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_XXX_LARGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_HUGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE, - DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE, - }, - name_text_hold_callback = optionsutil.showValues, - }, - } - }, { icon = "resources/icons/appbar.text.size.large.png", options = { diff --git a/frontend/ui/data/strings.lua b/frontend/ui/data/strings.lua index 0788d1831..b3cfa283e 100644 --- a/frontend/ui/data/strings.lua +++ b/frontend/ui/data/strings.lua @@ -11,6 +11,7 @@ S.ZOOM_DPI = _("Zoom (dpi)") S.H_PAGE_MARGINS = _("L/R Margins") S.T_PAGE_MARGIN = _("Top Margin") S.B_PAGE_MARGIN = _("Bottom Margin") +S.SYNC_T_B_PAGE_MARGINS = _("Sync T/B Margins") S.LINE_SPACING = _("Line Spacing") S.COLUMNS = _("Columns") S.TEXT_ALIGN = _("Text Align")