~vono22/narau/fdroid

23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
1
#!/usr/bin/env python
23.1.99 by Yvon TANGUY
Version 0.8.1 (version code 6):
2
#    Copyright (C) 2012 Yvon TANGUY
3
#
4
#    This program is free software: you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation, either version 3 of the License, or
7
#    (at your option) any later version.
8
#
9
#    This program is distributed in the hope that it will be useful,
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
15
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
16
# ---------------------------------------------------------------------------
17
# This script generate png images from the svg files.
18
# It needs inkscape and trimage to run.
19
#
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
20
21
import os
22
import sys
23
import subprocess
24
25
DIRS=['drawable-ldpi', 'drawable-mdpi', 'drawable-hdpi', 'drawable-xhdpi']
26
RES=[36, 48, 72, 96]
23.1.99 by Yvon TANGUY
Version 0.8.1 (version code 6):
27
28
def usage():
29
	print('usage:')
30
	print(sys.argv[0] + ' [-s <dir_suffix>] [-r <res_values>] [file.svg...]')
31
	print('')
32
	print('file.svg        : list of svg files. If there is no file, it takes every svg file')
33
	print('                  in the current directory')
34
	print('-s <dir_suffix> : a suffix like v11 to create drawable-{lmhx}dpi-v11')
35
	print('-r <res_values> : exported png file size: 24,32,48,64')
36
	print('                  default values are 36,48,72,96')
37
	sys.exit(0)
38
39
args_n = 1
40
dir_suffix=''
41
42
# search for --help first
43
if " ".join(sys.argv).find('--help') > -1:
44
	usage()
45
46
if len(sys.argv) >= (args_n + 2) and sys.argv[args_n] == '-s':
47
	dir_suffix = '-' + sys.argv[args_n+1]
48
	args_n += 2
49
if len(sys.argv) >= (args_n + 2) and sys.argv[args_n] == '-r':
50
	# transform the parameter into an int array
51
	try:
52
		png_res = map(int, sys.argv[args_n+1].split(','))
53
	except ValueError as ve:
54
		print('Error: ' + str(ve))
55
		usage()
56
	if len(png_res) != 4:
57
		print('Error: Not enough resolutions')
58
		usage()
59
	args_n += 2
60
else:
61
	png_res = RES
62
63
start_files_args = args_n
64
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
65
for i in range(len(DIRS)):
23.1.99 by Yvon TANGUY
Version 0.8.1 (version code 6):
66
	d_dir = DIRS[i] + dir_suffix
67
	res = str(png_res[i])
23.1.37 by Yvon Tanguy
- Lots of minor tweaks: Mostly in the download part
68
69
	if len(sys.argv) > start_files_args:
70
		files = sys.argv[start_files_args:]
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
71
	else:
72
		files = os.listdir('.')
23.1.37 by Yvon Tanguy
- Lots of minor tweaks: Mostly in the download part
73
23.1.51 by Yvon Tanguy
Fix python scripts for python 3.2
74
	print('Gen png for ' + d_dir + ' (' + res + 'x' + res + ')...')
23.1.37 by Yvon Tanguy
- Lots of minor tweaks: Mostly in the download part
75
	subprocess.call(['/bin/mkdir', '-p', d_dir])
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
76
	for svg in files:
23.1.99 by Yvon TANGUY
Version 0.8.1 (version code 6):
77
		if len(svg) > 4 and svg[-4:] == '.svg' and os.path.isfile(svg):
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
78
			png=d_dir + '/' + svg[:-4] + '.png'
23.1.81 by Yvon Tanguy
All
79
			subprocess.call(['/usr/bin/inkscape', '-z', '-C', svg, '-e', png, '-w', res, '-h', res])
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
80
			trimage = subprocess.Popen(['/usr/bin/trimage', '-f', png])
23.1.99 by Yvon TANGUY
Version 0.8.1 (version code 6):
81
		else:
82
			print('ignoring ' + svg)
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
83
23.1.99 by Yvon TANGUY
Version 0.8.1 (version code 6):
84
if trimage:
85
	trimage.wait()
23.1.35 by Yvon Tanguy
Rework icons, to respect better the Android guide line Iconography (https://developer.android.com/design/style/iconography.html)
86