From d829a221db57159b5511eceded550ecf0387bbdc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 14 Oct 2020 07:21:15 +0530 Subject: [PATCH] Fix reading of icon dir entries --- src/calibre/utils/open_with/windows.py | 7 ++++--- src/calibre/utils/windows/winutil.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/calibre/utils/open_with/windows.py b/src/calibre/utils/open_with/windows.py index 8dfa503017..6f88e85d4b 100644 --- a/src/calibre/utils/open_with/windows.py +++ b/src/calibre/utils/open_with/windows.py @@ -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) diff --git a/src/calibre/utils/windows/winutil.cpp b/src/calibre/utils/windows/winutil.cpp index 3d3cf48c00..d8b9981a32 100644 --- a/src/calibre/utils/windows/winutil.cpp +++ b/src/calibre/utils/windows/winutil.cpp @@ -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)); }