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 calibre.utils.winreg.default_programs import split_commandline
|
||||||
from polyglot.builtins import filter
|
from polyglot.builtins import filter
|
||||||
|
|
||||||
ICON_SIZE = 64
|
ICON_SIZE = 256
|
||||||
winutil = plugins['winutil'][0]
|
winutil = plugins['winutil'][0]
|
||||||
|
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ def load_icon_resource_as_pixmap(icon_resource, size=ICON_SIZE):
|
|||||||
q = size * size
|
q = size * size
|
||||||
for pmap in pixmaps:
|
for pmap in pixmaps:
|
||||||
if area(pmap) >= q:
|
if area(pmap) >= q:
|
||||||
if area(pmap) == size:
|
if area(pmap) == q:
|
||||||
return pmap
|
return pmap
|
||||||
return pmap.scaled(size, size, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)
|
return pmap.scaled(size, size, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)
|
||||||
return pixmaps[-1].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
|
m = 1 if data else 0
|
||||||
cmd['m'] = m
|
cmd['m'] = m
|
||||||
sys.stdout.buffer.write(serialize_gr_command(cmd, chunk))
|
sys.stdout.buffer.write(serialize_gr_command(cmd, chunk))
|
||||||
sys.stdout.flush()
|
sys.stdout.buffer.flush()
|
||||||
cmd.clear()
|
cmd.clear()
|
||||||
|
|
||||||
|
sys.stdout.flush()
|
||||||
write_chunked({'a': 'T', 'f': 100}, png_data)
|
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));
|
return (PyObject*)Handle_create(h, ModuleHandle, PyTuple_GET_ITEM(args, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma pack( push )
|
||||||
|
#pragma pack( 2 )
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int count;
|
int count;
|
||||||
const wchar_t *resource_id;
|
const wchar_t *resource_id;
|
||||||
} ResourceData;
|
} ResourceData;
|
||||||
|
#pragma pack( pop )
|
||||||
|
|
||||||
|
|
||||||
BOOL CALLBACK
|
BOOL CALLBACK
|
||||||
@ -802,6 +805,8 @@ get_resource_id_for_index(HMODULE handle, const int index, LPCWSTR type = RT_GRO
|
|||||||
return data.resource_id;
|
return data.resource_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma pack( push )
|
||||||
|
#pragma pack( 2 )
|
||||||
struct GRPICONDIRENTRY {
|
struct GRPICONDIRENTRY {
|
||||||
BYTE bWidth;
|
BYTE bWidth;
|
||||||
BYTE bHeight;
|
BYTE bHeight;
|
||||||
@ -812,6 +817,7 @@ struct GRPICONDIRENTRY {
|
|||||||
DWORD dwBytesInRes;
|
DWORD dwBytesInRes;
|
||||||
WORD nID;
|
WORD nID;
|
||||||
};
|
};
|
||||||
|
#pragma pack( pop )
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
|
load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
|
||||||
@ -827,7 +833,7 @@ load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
|
|||||||
if (!data) return NULL;
|
if (!data) return NULL;
|
||||||
DWORD sz = SizeofResource(handle, res);
|
DWORD sz = SizeofResource(handle, res);
|
||||||
if (!sz) return NULL;
|
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));
|
return Py_BuildValue("y#N", data, sz, Handle_create(icon, IconHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user