mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Viewer: Add option under Page layout to control if the aspect ratio of the cover is preserved or not
This commit is contained in:
parent
ae7a86e73b
commit
7661bb00d1
@ -258,12 +258,14 @@ class Container(ContainerBase):
|
||||
<head><style>
|
||||
html, body, img { height: 100vh; display: block; margin: 0; padding: 0; border-width: 0; }
|
||||
img {
|
||||
width: auto; height: auto;
|
||||
width: 100%%; height: 100%%;
|
||||
object-fit: contain;
|
||||
margin-left: auto; margin-right: auto;
|
||||
max-width: 100vw; max-height: 100vh;
|
||||
top: 50vh; transform: translateY(-50%%);
|
||||
position: relative;
|
||||
}
|
||||
body.cover-fill img { object-fit: fill; }
|
||||
</style></head><body><img src="%s"/></body></html>
|
||||
'''
|
||||
|
||||
|
@ -140,6 +140,7 @@ class IframeBoss:
|
||||
self.content_ready = False
|
||||
self.replace_history_on_next_cfi_update = True
|
||||
self.book = current_book.book = data.book
|
||||
self.is_titlepage = data.is_titlepage
|
||||
spine = self.book.manifest.spine
|
||||
index = spine.indexOf(data.name)
|
||||
reset_paged_mode_globals()
|
||||
@ -243,6 +244,8 @@ class IframeBoss:
|
||||
|
||||
def content_loaded(self):
|
||||
document.documentElement.style.overflow = 'hidden'
|
||||
if self.is_titlepage and not opts.cover_preserve_aspect_ratio:
|
||||
document.body.classList.add('cover-fill')
|
||||
self.last_window_width, self.last_window_height = scroll_viewport.width(), scroll_viewport.height()
|
||||
apply_settings()
|
||||
self.fix_fullscreen_svg_images()
|
||||
|
@ -61,6 +61,10 @@ def create_layout_panel(container):
|
||||
E.tr(E.td(_('Max. height:')), E.td(E.input(type='number', name='height', min='0', step='10', value=str(sd.get('max_text_height'))))),
|
||||
))
|
||||
|
||||
sec(_('Control how the cover is displayed'))
|
||||
container.appendChild(E.div(style='margin: 1ex 2rem; display: flex;',
|
||||
E.label(E.input(type='checkbox', name='cover_preserve_aspect_ratio', checked=sd.get('cover_preserve_aspect_ratio')), _('Preserve cover aspect ratio'))))
|
||||
|
||||
|
||||
develop = create_layout_panel
|
||||
|
||||
@ -103,5 +107,10 @@ def commit_layout(onchange, container):
|
||||
was_changed = True
|
||||
sd.set('max_text_' + which, val)
|
||||
|
||||
cover_preserve_aspect_ratio = element(CONTAINER, 'input[name=cover_preserve_aspect_ratio]').checked
|
||||
if cover_preserve_aspect_ratio is not sd.get('cover_preserve_aspect_ratio'):
|
||||
was_changed = True
|
||||
sd.set('cover_preserve_aspect_ratio', cover_preserve_aspect_ratio)
|
||||
|
||||
if was_changed:
|
||||
onchange()
|
||||
|
@ -15,7 +15,8 @@ def update_settings(settings):
|
||||
opts.color_scheme = settings.color_scheme
|
||||
opts.base_font_size = max(8, min(settings.base_font_size or 16, 64))
|
||||
opts.user_stylesheet = settings.user_stylesheet or ''
|
||||
opts.hide_tooltips = settings.hide_tooltips or False
|
||||
opts.hide_tooltips = settings.hide_tooltips
|
||||
opts.cover_preserve_aspect_ratio = settings.cover_preserve_aspect_ratio
|
||||
|
||||
update_settings()
|
||||
|
||||
|
@ -532,6 +532,7 @@ class View:
|
||||
'user_stylesheet': sd.get('user_stylesheet'),
|
||||
'keyboard_shortcuts': sd.get('keyboard_shortcuts'),
|
||||
'hide_tooltips': sd.get('hide_tooltips'),
|
||||
'cover_preserve_aspect_ratio': sd.get('cover_preserve_aspect_ratio'),
|
||||
}
|
||||
|
||||
def show_name(self, name, initial_position=None):
|
||||
@ -744,6 +745,7 @@ class View:
|
||||
resource_data=resource_data, book=self.book, name=self.currently_showing.name,
|
||||
initial_position=self.currently_showing.initial_position,
|
||||
settings=self.currently_showing.settings,
|
||||
is_titlepage=self.currently_showing.name is self.book.manifest.title_page_name,
|
||||
)
|
||||
|
||||
def on_content_loaded(self, data):
|
||||
|
@ -29,6 +29,7 @@ defaults = {
|
||||
'margin_top': 20,
|
||||
'margin_bottom': 20,
|
||||
'read_mode': 'paged',
|
||||
'cover_preserve_aspect_ratio': True,
|
||||
'max_text_height': 0,
|
||||
'max_text_width': 0,
|
||||
'columns_per_screen': {'portrait':0, 'landscape':0},
|
||||
|
Loading…
x
Reference in New Issue
Block a user