Implement max_text_(width|height) options

This commit is contained in:
Kovid Goyal 2016-04-22 17:27:23 +05:30
parent 850a689404
commit 857d2c7cfc
4 changed files with 22 additions and 8 deletions

View File

@ -97,5 +97,9 @@ def flow_onkeydown(evt):
evt.preventDefault() evt.preventDefault()
def layout(is_single_page): 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))

View File

@ -6,8 +6,8 @@ opts = {}
def apply_settings(settings): def apply_settings(settings):
settings = settings or {} settings = settings or {}
opts.cols_per_screen = max(1, settings.cols_per_screen or 1) 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_text_width = max(0, settings.max_text_width or 0)
opts.max_col_height = max(0, settings.max_col_height 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.fit_images = False if settings.fit_images is False else True
opts.margin_side = max(0, settings.margin_side or 0) opts.margin_side = max(0, settings.margin_side or 0)

View File

@ -65,11 +65,17 @@ class View:
def iframe(self): def iframe(self):
return document.getElementById(iframe_id) 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() sd = get_session_data()
margin_side = sd.get('margin_side') if margin_side is None else margin_side margin_side = 0 if no_margins else sd.get('margin_side')
margin_top = sd.get('margin_top') if margin_top is None else margin_top margin_top = 0 if no_margins else sd.get('margin_top')
margin_bottom = sd.get('margin_bottom') if margin_bottom is None else margin_bottom 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 = document.getElementById('book-top-margin')
t.style.height = margin_top + 'px' t.style.height = margin_top + 'px'
t.style.paddingLeft = t.style.paddingRight = margin_side + 'px' t.style.paddingLeft = t.style.paddingRight = margin_side + 'px'
@ -143,9 +149,11 @@ class View:
settings={ settings={
'margin_side': 0 if name is self.book.manifest.title_page_name else sd.get('margin_side'), 'margin_side': 0 if name is self.book.manifest.title_page_name else sd.get('margin_side'),
'read_mode': sd.get('read_mode'), '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.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) load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item)
def goto_doc_boundary(self, data): def goto_doc_boundary(self, data):

View File

@ -21,6 +21,8 @@ defaults = {
'margin_top': 20, 'margin_top': 20,
'margin_bottom': 20, 'margin_bottom': 20,
'read_mode': 'paged', 'read_mode': 'paged',
'max_text_height': 0,
'max_text_width': 0,
} }
def storage_available(which): def storage_available(which):