diff --git a/src/pyj/read_book/flow_mode.pyj b/src/pyj/read_book/flow_mode.pyj index 4d7b827fcb..c0f7b5a0b6 100644 --- a/src/pyj/read_book/flow_mode.pyj +++ b/src/pyj/read_book/flow_mode.pyj @@ -97,5 +97,9 @@ def flow_onkeydown(evt): evt.preventDefault() def layout(is_single_page): - set_css(document.body, margin='0', border_width='0', padding='0 {}px'.format(opts.margin_side)) + ms = opts.margin_side + tw = window.innerWidth - 2 * ms + if opts.max_text_width > 100 and tw > opts.max_text_width: + ms += (tw - opts.max_text_width) // 2 + set_css(document.body, margin='0', border_width='0', padding='0 {}px'.format(ms)) diff --git a/src/pyj/read_book/settings.pyj b/src/pyj/read_book/settings.pyj index aa704f02e7..2b8730f997 100644 --- a/src/pyj/read_book/settings.pyj +++ b/src/pyj/read_book/settings.pyj @@ -6,8 +6,8 @@ opts = {} def apply_settings(settings): settings = settings or {} opts.cols_per_screen = max(1, settings.cols_per_screen or 1) - opts.max_col_width = max(0, settings.max_col_width or 0) - opts.max_col_height = max(0, settings.max_col_height or 0) + opts.max_text_width = max(0, settings.max_text_width or 0) + opts.max_text_height = max(0, settings.max_text_height or 0) opts.fit_images = False if settings.fit_images is False else True opts.margin_side = max(0, settings.margin_side or 0) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 4d1d1809c1..3233c0df8c 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -65,11 +65,17 @@ class View: def iframe(self): return document.getElementById(iframe_id) - def set_margins(self, margin_top=None, margin_bottom=None, margin_side=None): + def set_margins(self, no_margins): sd = get_session_data() - margin_side = sd.get('margin_side') if margin_side is None else margin_side - margin_top = sd.get('margin_top') if margin_top is None else margin_top - margin_bottom = sd.get('margin_bottom') if margin_bottom is None else margin_bottom + margin_side = 0 if no_margins else sd.get('margin_side') + margin_top = 0 if no_margins else sd.get('margin_top') + margin_bottom = 0 if no_margins else sd.get('margin_bottom') + max_text_height = sd.get('max_text_height') + th = window.innerWidth - margin_top - margin_bottom + if not no_margins and max_text_height > 100 and th > max_text_height: + extra = (th - max_text_height) // 2 + margin_top += extra + margin_bottom += extra t = document.getElementById('book-top-margin') t.style.height = margin_top + 'px' t.style.paddingLeft = t.style.paddingRight = margin_side + 'px' @@ -143,9 +149,11 @@ class View: settings={ 'margin_side': 0 if name is self.book.manifest.title_page_name else sd.get('margin_side'), 'read_mode': sd.get('read_mode'), + 'max_text_width':sd.get('max_text_width'), + 'max_text_height':sd.get('max_text_height'), } self.currently_showing = {'name':name, 'cfi':cfi, 'settings':settings, 'initial_scroll_fraction':initial_scroll_fraction, 'loading':True} - self.set_margins(0, 0, 0) if name is self.book.manifest.title_page_name else self.set_margins() + self.set_margins(name is self.book.manifest.title_page_name) load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item) def goto_doc_boundary(self, data): diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index f47012aa30..e3e244632c 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -21,6 +21,8 @@ defaults = { 'margin_top': 20, 'margin_bottom': 20, 'read_mode': 'paged', + 'max_text_height': 0, + 'max_text_width': 0, } def storage_available(which):