Debian Codegraph @

src/pyj/fs_images.pyj

raw
1 # vim:fileencoding=utf-8
2 # License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
3 from __python__ import bound_methods, hash_literals
4
5
6 def is_svg_fs_markup(names, svg):
7 if svg is not None:
8 if names.length is 2 or names.length is 3:
9 if names[-1] is 'image' and names[-2] is 'svg':
10 if names.length is 2 or names[0] is 'div':
11 if svg.width is '100%' and svg.height is '100%':
12 return True
13 return False
14
15
16 def fix_fullscreen_svg_images():
17 # Full screen images using SVG no longer render correctly
18 # webengine. This is because it sets the width to the
19 # viewport width and simply adjusts the height accordingly
20 # So we replace 100% with 100vw and 100vh to get the desired
21 # rendering
22 child_names = []
23 for node in document.body.childNodes:
24 if node.tagName:
25 name = node.tagName.toLowerCase()
26 if name is not 'style' and name is not 'script':
27 child_names.push(name)
28 if child_names.length > 1:
29 break
30 if child_names.length is 1 and (child_names[0] is 'div' or child_names[0] is 'svg'):
31 names = []
32 svg = None
33 for node in document.body.querySelectorAll('*'):
34 if node.tagName:
35 name = node.tagName.toLowerCase()
36 if name is not 'style' and name is not 'script':
37 names.push(name)
38 if name is 'svg':
39 svg = node
40
41 if is_svg_fs_markup(names, svg):
42 svg.setAttribute('width', '100vw')
43 svg.setAttribute('height', '100vh')