Only return a dummy PNG to Qt if the resource being loaded has a raster image extension

This commit is contained in:
Kovid Goyal 2020-05-27 19:13:24 +05:30
parent 308f163a03
commit d9f2449ddc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 14 deletions

View File

@ -28,7 +28,7 @@ from calibre.gui2.widgets import LineEditECM
from calibre.gui2.widgets2 import to_plain_text
from calibre.utils.config import tweaks
from calibre.utils.imghdr import what
from polyglot.builtins import filter, iteritems, itervalues, unicode_type, as_bytes
from polyglot.builtins import filter, iteritems, itervalues, unicode_type
# Cleanup Qt markup {{{
@ -764,12 +764,13 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
with lopen(path, 'rb') as f:
data = f.read()
except EnvironmentError:
return QByteArray(bytearray.fromhex(
'89504e470d0a1a0a0000000d49484452'
'000000010000000108060000001f15c4'
'890000000a49444154789c6300010000'
'0500010d0a2db40000000049454e44ae'
'426082'))
if path.rpartition('.')[-1].lower() in {'jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'}:
return QByteArray(bytearray.fromhex(
'89504e470d0a1a0a0000000d49484452'
'000000010000000108060000001f15c4'
'890000000a49444154789c6300010000'
'0500010d0a2db40000000049454e44ae'
'426082'))
else:
return QByteArray(data)

View File

@ -489,16 +489,18 @@ class HTMLDisplay(QTextBrowser):
with lopen(path, 'rb') as f:
data = f.read()
except EnvironmentError:
return QByteArray(bytearray.fromhex(
'89504e470d0a1a0a0000000d49484452'
'000000010000000108060000001f15c4'
'890000000a49444154789c6300010000'
'0500010d0a2db40000000049454e44ae'
'426082'))
if path.rpartition('.')[-1].lower() in {'jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'}:
return QByteArray(bytearray.fromhex(
'89504e470d0a1a0a0000000d49484452'
'000000010000000108060000001f15c4'
'890000000a49444154789c6300010000'
'0500010d0a2db40000000049454e44ae'
'426082'))
else:
return QByteArray(data)
else:
QTextBrowser.loadResource(self, rtype, qurl)
return QTextBrowser.loadResource(self, rtype, qurl)
class ScrollingTabWidget(QTabWidget):