|
3 | 3 |
|
4 | 4 | # Standard library
|
5 | 5 | import errno
|
| 6 | +from itertools import product |
6 | 7 | import math
|
7 | 8 | import os
|
8 | 9 | import os.path
|
9 | 10 |
|
10 | 11 | # Third-party
|
11 | 12 | import cairo
|
12 | 13 | import gi
|
13 |
| -gi.require_version('PangoCairo', '1.0') |
| 14 | + |
| 15 | +gi.require_version("PangoCairo", "1.0") |
14 | 16 | from gi.repository import PangoCairo as pangocairo
|
15 | 17 | from functools import reduce
|
16 | 18 |
|
|
40 | 42 | STEPS = ["00", "11", "22", "33", "66", "99", "ff"]
|
41 | 43 |
|
42 | 44 | FOREGROUNDS = [
|
43 |
| - "%s%s%s" % (r, g, b) for r in STEPS for g in STEPS for b in STEPS |
| 45 | + "%s%s%s" % (r, g, b) for r, g, b in product(STEPS, STEPS, STEPS) |
44 | 46 | ]
|
45 | 47 |
|
46 | 48 | HEX_TO_FLOAT = 1.0 / 255.0
|
@@ -145,50 +147,44 @@ def genicon(
|
145 | 147 |
|
146 | 148 | for suite, licenses in SUITES.items():
|
147 | 149 | for lic, module_chars in licenses.items():
|
148 |
| - for chars in module_chars: |
149 |
| - for dimensions in DIMENSIONS: |
150 |
| - for background in BACKGROUNDS: |
151 |
| - for foreground in FOREGROUNDS: |
152 |
| - # e.g. white on white |
153 |
| - if foreground == background: |
154 |
| - continue |
155 |
| - path = os.path.realpath( |
156 |
| - os.path.abspath( |
157 |
| - os.path.join( |
158 |
| - basedir, |
159 |
| - icon_path( |
160 |
| - suite, lic, background, foreground |
161 |
| - ), |
162 |
| - ) |
163 |
| - ) |
164 |
| - ) |
165 |
| - filepath = os.path.realpath( |
166 |
| - os.path.abspath( |
167 |
| - os.path.join( |
168 |
| - path, icon_filename(dimensions, chars) |
169 |
| - ) |
170 |
| - ) |
171 |
| - ) |
172 |
| - if os.path.exists(filepath): |
173 |
| - continue |
174 |
| - width = dimensions[0] |
175 |
| - height = dimensions[1] |
176 |
| - font_size = dimensions[2] |
177 |
| - padding = dimensions[3] |
178 |
| - ctx = genicon( |
179 |
| - suite, |
180 |
| - chars, |
181 |
| - font_size, |
182 |
| - padding, |
183 |
| - width, |
184 |
| - height, |
185 |
| - background, |
186 |
| - foreground, |
187 |
| - ) |
188 |
| - try: |
189 |
| - os.makedirs(path) |
190 |
| - except OSError as e: |
191 |
| - if e.errno != errno.EEXIST: |
192 |
| - raise |
193 |
| - # Will raise and exception on error |
194 |
| - ctx.get_target().write_to_png(filepath) |
| 150 | + for chars, dimensions, background, foreground in product( |
| 151 | + module_chars, DIMENSIONS, BACKGROUNDS, FOREGROUNDS |
| 152 | + ): |
| 153 | + # e.g. white on white |
| 154 | + if foreground == background: |
| 155 | + continue |
| 156 | + path = os.path.realpath( |
| 157 | + os.path.abspath( |
| 158 | + os.path.join( |
| 159 | + basedir, icon_path(suite, lic, background, foreground), |
| 160 | + ) |
| 161 | + ) |
| 162 | + ) |
| 163 | + filepath = os.path.realpath( |
| 164 | + os.path.abspath( |
| 165 | + os.path.join(path, icon_filename(dimensions, chars)) |
| 166 | + ) |
| 167 | + ) |
| 168 | + if os.path.exists(filepath): |
| 169 | + continue |
| 170 | + width = dimensions[0] |
| 171 | + height = dimensions[1] |
| 172 | + font_size = dimensions[2] |
| 173 | + padding = dimensions[3] |
| 174 | + ctx = genicon( |
| 175 | + suite, |
| 176 | + chars, |
| 177 | + font_size, |
| 178 | + padding, |
| 179 | + width, |
| 180 | + height, |
| 181 | + background, |
| 182 | + foreground, |
| 183 | + ) |
| 184 | + try: |
| 185 | + os.makedirs(path) |
| 186 | + except OSError as e: |
| 187 | + if e.errno != errno.EEXIST: |
| 188 | + raise |
| 189 | + # Will raise and exception on error |
| 190 | + ctx.get_target().write_to_png(filepath) |
0 commit comments