Fix Yomichan image height calculation error

For images that have greater height than width values, the image
proportions for Yomichan were being calculated incorrectly. This can
be observed for example in the SMK8 entry for くの字点 and the
DAIJIRIN2 entry for 定積分.
This commit is contained in:
stephenmk 2023-07-16 18:53:28 -05:00
parent 4d6c3c3cf5
commit dbf0cf0eb8
No known key found for this signature in database
GPG key ID: B6DA730DB06235F1
3 changed files with 16 additions and 16 deletions

View file

@ -111,8 +111,8 @@ def __convert_gaiji(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,
@ -150,8 +150,8 @@ def __convert_logos(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,
@ -174,8 +174,8 @@ def __convert_kanjion_logos(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,
@ -198,8 +198,8 @@ def __convert_daigoginum(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,
@ -222,8 +222,8 @@ def __convert_jundaigoginum(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,

View file

@ -118,8 +118,8 @@ class JitenonKokugoGlossary(JitenonGlossary):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,

View file

@ -92,8 +92,8 @@ def __convert_gaiji(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,
@ -124,8 +124,8 @@ def __convert_rectangles(soup, image_dir):
ratio = Icons.calculate_ratio(path) ratio = Icons.calculate_ratio(path)
img = BeautifulSoup("<img/>", "xml").img img = BeautifulSoup("<img/>", "xml").img
img.attrs = { img.attrs = {
"height": 1.0 if ratio > 1.0 else ratio, "height": 1.0,
"width": ratio if ratio > 1.0 else 1.0, "width": ratio,
"sizeUnits": "em", "sizeUnits": "em",
"collapsible": False, "collapsible": False,
"collapsed": False, "collapsed": False,