mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Script to render icons
This commit is contained in:
parent
4f4ab5af27
commit
8b55311323
@ -4,14 +4,14 @@
|
|||||||
|
|
||||||
from __future__ import (unicode_literals, division, absolute_import,
|
from __future__ import (unicode_literals, division, absolute_import,
|
||||||
print_function)
|
print_function)
|
||||||
import os
|
import os, glob, subprocess, argparse
|
||||||
|
|
||||||
duplicates = {
|
duplicates = {
|
||||||
'character-set': ['languages'],
|
'character-set': ['languages'],
|
||||||
'calibre': ['library', 'lt'],
|
'calibre': ['library', 'lt'],
|
||||||
'format-text-color': 'lookfeel',
|
'format-text-color': ['lookfeel'],
|
||||||
'books_in_series': ['series'],
|
'books_in_series': ['series'],
|
||||||
'plugins.svg': ['plugins/plugin_upgrade_ok.svg'],
|
'plugins.svg': ['plugins/plugin_upgrade_ok'],
|
||||||
}
|
}
|
||||||
|
|
||||||
sizes = {
|
sizes = {
|
||||||
@ -23,13 +23,45 @@ sizes = {
|
|||||||
|
|
||||||
skip = {'calibre'}
|
skip = {'calibre'}
|
||||||
|
|
||||||
|
j = os.path.join
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
output_base = j(os.path.dirname(base), 'resources', 'images')
|
||||||
|
|
||||||
for src in os.listdir(base):
|
|
||||||
if src.endswith('.svg'):
|
def iterfiles(only=()):
|
||||||
name = src.rpartition('.')[0]
|
for src in glob.glob(j(base, '*.svg')) + glob.glob(j(base, 'plugins/*.svg')):
|
||||||
names = [name] + duplicates.get(name, [])
|
name = os.path.relpath(src, base).rpartition('.')[0]
|
||||||
for oname in names:
|
if only and name not in only:
|
||||||
if oname in skip:
|
continue
|
||||||
continue
|
output_names = [n for n in [name] + duplicates.get(name, []) if n not in skip]
|
||||||
src = os.path.join(base, name + '.svg')
|
output_files = [j(output_base, n) + '.png' for n in output_names]
|
||||||
|
if output_files:
|
||||||
|
yield src, output_files
|
||||||
|
|
||||||
|
|
||||||
|
def rsvg(src, size, dest):
|
||||||
|
cmd = ['rsvg-convert', '-d', '96', '-p', '96']
|
||||||
|
if size != 'original':
|
||||||
|
cmd += ['--width', size, '--height', size]
|
||||||
|
subprocess.check_call(cmd + ['-o', dest, src])
|
||||||
|
subprocess.check_call(['optipng', '-o7', '-quiet', '-strip', 'all', dest])
|
||||||
|
|
||||||
|
|
||||||
|
def render(src, output_files):
|
||||||
|
for dest in output_files:
|
||||||
|
oname = os.path.basename(dest).rpartition('.')[0]
|
||||||
|
size = sizes.get(oname, '128')
|
||||||
|
print('Rendering', oname, 'at size:', size)
|
||||||
|
rsvg(src, size, dest)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
p = argparse.ArgumentParser()
|
||||||
|
p.add_argument('only', nargs='*', default=[], help='Only render the specified icons')
|
||||||
|
args = p.parse_args()
|
||||||
|
for src, ofiles in iterfiles(args.only):
|
||||||
|
render(src, ofiles)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
@ -74,19 +74,11 @@ def get_path(path, data=False, allow_user_override=True):
|
|||||||
return f.read()
|
return f.read()
|
||||||
return fpath
|
return fpath
|
||||||
|
|
||||||
if os.environ.get('CALIBRE_TEST_ICONS') == '1' and os.path.exists('/home/kovid/work/calibre/imgsrc/new'):
|
|
||||||
def get_image_path(path, data=False, allow_user_override=True):
|
def get_image_path(path, data=False, allow_user_override=True):
|
||||||
if not path:
|
if not path:
|
||||||
return get_path('images', allow_user_override=allow_user_override)
|
return get_path('images', allow_user_override=allow_user_override)
|
||||||
q = '/home/kovid/work/calibre/imgsrc/new/' + path[:-4] + '.svg'
|
return get_path('images/'+path, data=data, allow_user_override=allow_user_override)
|
||||||
if os.path.exists(q):
|
|
||||||
return q
|
|
||||||
return get_path('images/'+path, data=data, allow_user_override=allow_user_override)
|
|
||||||
else:
|
|
||||||
def get_image_path(path, data=False, allow_user_override=True):
|
|
||||||
if not path:
|
|
||||||
return get_path('images', allow_user_override=allow_user_override)
|
|
||||||
return get_path('images/'+path, data=data, allow_user_override=allow_user_override)
|
|
||||||
|
|
||||||
|
|
||||||
def js_name_to_path(name, ext='.coffee'):
|
def js_name_to_path(name, ext='.coffee'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user