mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix reading of icon dir entries
This commit is contained in:
parent
603991b2c0
commit
d829a221db
@ -13,7 +13,7 @@ from calibre.gui2 import must_use_qt
|
||||
from calibre.utils.winreg.default_programs import split_commandline
|
||||
from polyglot.builtins import filter
|
||||
|
||||
ICON_SIZE = 64
|
||||
ICON_SIZE = 256
|
||||
winutil = plugins['winutil'][0]
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ def load_icon_resource_as_pixmap(icon_resource, size=ICON_SIZE):
|
||||
q = size * size
|
||||
for pmap in pixmaps:
|
||||
if area(pmap) >= q:
|
||||
if area(pmap) == size:
|
||||
if area(pmap) == q:
|
||||
return pmap
|
||||
return pmap.scaled(size, size, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)
|
||||
return pixmaps[-1].scaled(size, size, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)
|
||||
@ -97,9 +97,10 @@ def display_image(png_data):
|
||||
m = 1 if data else 0
|
||||
cmd['m'] = m
|
||||
sys.stdout.buffer.write(serialize_gr_command(cmd, chunk))
|
||||
sys.stdout.flush()
|
||||
sys.stdout.buffer.flush()
|
||||
cmd.clear()
|
||||
|
||||
sys.stdout.flush()
|
||||
write_chunked({'a': 'T', 'f': 100}, png_data)
|
||||
|
||||
|
||||
|
@ -781,10 +781,13 @@ load_library(PyObject *self, PyObject *args) {
|
||||
return (PyObject*)Handle_create(h, ModuleHandle, PyTuple_GET_ITEM(args, 0));
|
||||
}
|
||||
|
||||
#pragma pack( push )
|
||||
#pragma pack( 2 )
|
||||
typedef struct {
|
||||
int count;
|
||||
const wchar_t *resource_id;
|
||||
} ResourceData;
|
||||
#pragma pack( pop )
|
||||
|
||||
|
||||
BOOL CALLBACK
|
||||
@ -802,6 +805,8 @@ get_resource_id_for_index(HMODULE handle, const int index, LPCWSTR type = RT_GRO
|
||||
return data.resource_id;
|
||||
}
|
||||
|
||||
#pragma pack( push )
|
||||
#pragma pack( 2 )
|
||||
struct GRPICONDIRENTRY {
|
||||
BYTE bWidth;
|
||||
BYTE bHeight;
|
||||
@ -812,6 +817,7 @@ struct GRPICONDIRENTRY {
|
||||
DWORD dwBytesInRes;
|
||||
WORD nID;
|
||||
};
|
||||
#pragma pack( pop )
|
||||
|
||||
static PyObject*
|
||||
load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
|
||||
@ -827,7 +833,7 @@ load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
|
||||
if (!data) return NULL;
|
||||
DWORD sz = SizeofResource(handle, res);
|
||||
if (!sz) return NULL;
|
||||
HICON icon = CreateIconFromResourceEx(data, sz, TRUE, 0x00030000, entry->bWidth, entry->bHeight, LR_DEFAULTCOLOR);
|
||||
HICON icon = CreateIconFromResourceEx(data, sz, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR);
|
||||
return Py_BuildValue("y#N", data, sz, Handle_create(icon, IconHandle));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user