mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix dark/light variants not being used when generating cover for icon theme
This commit is contained in:
parent
357555689f
commit
ab87aac5f6
@ -212,6 +212,19 @@ def default_cover_icons(cols=5):
|
|||||||
def create_cover(report=None, icons=(), cols=5, size=120, padding=16, darkbg=False):
|
def create_cover(report=None, icons=(), cols=5, size=120, padding=16, darkbg=False):
|
||||||
icons = icons or tuple(default_cover_icons(cols))
|
icons = icons or tuple(default_cover_icons(cols))
|
||||||
rows = int(math.ceil(len(icons) / cols))
|
rows = int(math.ceil(len(icons) / cols))
|
||||||
|
|
||||||
|
def get_path_for_icon(icon: str) -> str:
|
||||||
|
if report is not None:
|
||||||
|
if icon in report.name_map:
|
||||||
|
return os.path.join(report.path, report.name_map[icon])
|
||||||
|
candidates = ('dark', 'light') if darkbg else ('light', 'dark')
|
||||||
|
for candidate in candidates:
|
||||||
|
base, ext = os.path.splitext(icon)
|
||||||
|
q = f'{base}-for-{candidate}-theme{ext}'
|
||||||
|
if q in report.name_map:
|
||||||
|
return os.path.join(report.path, report.name_map[q])
|
||||||
|
return I(icon, allow_user_override=False)
|
||||||
|
|
||||||
with Canvas(cols * (size + padding), rows * (size + padding), bgcolor='#444' if darkbg else '#eee') as canvas:
|
with Canvas(cols * (size + padding), rows * (size + padding), bgcolor='#444' if darkbg else '#eee') as canvas:
|
||||||
y = -size - padding // 2
|
y = -size - padding // 2
|
||||||
x = 0
|
x = 0
|
||||||
@ -221,10 +234,7 @@ def create_cover(report=None, icons=(), cols=5, size=120, padding=16, darkbg=Fal
|
|||||||
x = padding // 2
|
x = padding // 2
|
||||||
else:
|
else:
|
||||||
x += size + padding
|
x += size + padding
|
||||||
if report and icon in report.name_map:
|
ipath = get_path_for_icon(icon)
|
||||||
ipath = os.path.join(report.path, report.name_map[icon])
|
|
||||||
else:
|
|
||||||
ipath = I(icon, allow_user_override=False)
|
|
||||||
with open(ipath, 'rb') as f:
|
with open(ipath, 'rb') as f:
|
||||||
img = image_from_data(f.read())
|
img = image_from_data(f.read())
|
||||||
scaled, nwidth, nheight = fit_image(img.width(), img.height(), size, size)
|
scaled, nwidth, nheight = fit_image(img.width(), img.height(), size, size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user