mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Apply the same workaround for use of 100% instead of 100vh in full screen SVG images as is used in the viewer. This should give the same rendering as in the viewer, leading to less confusion.
I of course dont like implementing this kind of hackery, but...
This commit is contained in:
parent
27d3a28a1d
commit
609c8a2215
@ -4,6 +4,7 @@ from __python__ import bound_methods, hash_literals
|
||||
|
||||
from elementmaker import E
|
||||
|
||||
from fs_images import fix_fullscreen_svg_images
|
||||
from live_css import get_matched_css, get_sourceline_address
|
||||
from qt import from_python, to_python
|
||||
|
||||
@ -172,3 +173,5 @@ document.documentElement.appendChild(E.style(
|
||||
type='text/css',
|
||||
'[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
|
||||
))
|
||||
|
||||
fix_fullscreen_svg_images()
|
||||
|
33
src/pyj/fs_images.pyj
Normal file
33
src/pyj/fs_images.pyj
Normal file
@ -0,0 +1,33 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __python__ import bound_methods, hash_literals
|
||||
|
||||
|
||||
def fix_fullscreen_svg_images():
|
||||
# Full screen images using SVG no longer render correctly
|
||||
# webengine. This is because it sets the width to the
|
||||
# viewport width and simply adjusts the height accordingly
|
||||
# So we replace 100% with 100vw and 100vh to get the desired
|
||||
# rendering
|
||||
child_names = v'[]'
|
||||
for node in document.body.childNodes:
|
||||
if node.tagName:
|
||||
name = node.tagName.toLowerCase()
|
||||
if name is not 'style' and name is not 'script':
|
||||
child_names.push(name)
|
||||
if child_names.length > 1:
|
||||
break
|
||||
if child_names.length is 1 and child_names[0] is 'div':
|
||||
names = []
|
||||
svg = None
|
||||
for node in document.body.querySelectorAll('*'):
|
||||
if node.tagName:
|
||||
name = node.tagName.toLowerCase()
|
||||
if name is not 'style' and name is not 'script':
|
||||
names.push(name)
|
||||
if name is 'svg':
|
||||
svg = node
|
||||
if names == ['div', 'svg', 'image'] or names == ['svg', 'image']:
|
||||
if svg.getAttribute('width') is '100%' and svg.getAttribute('height') is '100%':
|
||||
svg.setAttribute('width', '100vw')
|
||||
svg.setAttribute('height', '100vh')
|
@ -5,6 +5,7 @@ from __python__ import bound_methods, hash_literals
|
||||
import traceback
|
||||
from gettext import gettext as _
|
||||
|
||||
from fs_images import fix_fullscreen_svg_images
|
||||
from iframe_comm import IframeClient
|
||||
from read_book.cfi import scroll_to as scroll_to_cfi
|
||||
from read_book.extract import get_elements
|
||||
@ -228,35 +229,6 @@ class IframeBoss:
|
||||
opts.color_scheme = data.color_scheme
|
||||
apply_colors()
|
||||
|
||||
def fix_fullscreen_svg_images(self):
|
||||
# Full screen images using SVG no longer render correctly
|
||||
# webengine. This is because it sets the width to the
|
||||
# viewport width and simply adjusts the height accordingly
|
||||
# So we replace 100% with 100vw and 100vh to get the desired
|
||||
# rendering
|
||||
child_names = v'[]'
|
||||
for node in document.body.childNodes:
|
||||
if node.tagName:
|
||||
name = node.tagName.toLowerCase()
|
||||
if name is not 'style' and name is not 'script':
|
||||
child_names.push(name)
|
||||
if child_names.length > 1:
|
||||
break
|
||||
if child_names.length is 1 and child_names[0] is 'div':
|
||||
names = []
|
||||
svg = None
|
||||
for node in document.body.querySelectorAll('*'):
|
||||
if node.tagName:
|
||||
name = node.tagName.toLowerCase()
|
||||
if name is not 'style' and name is not 'script':
|
||||
names.push(name)
|
||||
if name is 'svg':
|
||||
svg = node
|
||||
if names == ['div', 'svg', 'image'] or names == ['svg', 'image']:
|
||||
if svg.getAttribute('width') is '100%' and svg.getAttribute('height') is '100%':
|
||||
svg.setAttribute('width', '100vw')
|
||||
svg.setAttribute('height', '100vh')
|
||||
|
||||
def content_loaded(self):
|
||||
document.documentElement.style.overflow = 'hidden'
|
||||
if self.is_titlepage and not opts.cover_preserve_aspect_ratio:
|
||||
@ -264,7 +236,7 @@ class IframeBoss:
|
||||
document.body.classList.add(f'calibre-viewer-{layout_style()}')
|
||||
self.last_window_width, self.last_window_height = scroll_viewport.width(), scroll_viewport.height()
|
||||
apply_settings()
|
||||
self.fix_fullscreen_svg_images()
|
||||
fix_fullscreen_svg_images()
|
||||
self.do_layout(self.is_titlepage)
|
||||
if self.mathjax:
|
||||
return apply_mathjax(self.mathjax, self.book.manifest.link_uid, self.content_loaded_stage2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user