From ef9d78b6793cd6d7054b97e167b57fb72f4a4858 Mon Sep 17 00:00:00 2001 From: fes0j Date: Thu, 7 Jun 2018 20:39:14 +0200 Subject: [PATCH] Add round Version. My take on generating different forms. Some xml ids in base.ink.svg are now human-readable. Added also the clip object. --- make.py | 78 ++++++++++++++++++++++++++++-------------------- src/base.ink.svg | 33 +++++++++++++------- 2 files changed, 68 insertions(+), 43 deletions(-) mode change 100644 => 100755 make.py diff --git a/make.py b/make.py old mode 100644 new mode 100755 index cd23aac..0436da3 --- a/make.py +++ b/make.py @@ -37,45 +37,57 @@ def mkdir(path: str): if not os.path.exists(path): os.makedirs(path) -def export(colors: [str] = [DEFAULT_COLOR], size: int = DEFAULT_SIZE, svg_dir: str = DEFAULT_DIR, png: bool = True, png_dir: str = DEFAULT_DIR): +def export(colors: [str] = [DEFAULT_COLOR], form: [int] = [1], size: int = DEFAULT_SIZE, svg_dir: str = DEFAULT_DIR, png: bool = True, png_dir: str = DEFAULT_DIR): mkdir(svg_dir) mkdir(png_dir) # Open source file tree = ET.parse('src/base.ink.svg') root = tree.getroot() - - for c in colors: - if not c in ACCENT_PALETTE: - print(c, "is not an accent color. Please choose one from the accent color list") - continue - - if DEBUG: - print("Generating files for color:", c) - - c_id = 'foss-ag_' + c; - - # Change color to the selected - t = root.find(".//*[@id='path6107-4-3']") - t.set('fill','url(#' + c_id + ')' ) - t.set('stroke','url(#' + c_id + ')' ) - - tree.write(svg_dir + '/logo_' + c + '.svg') - - # Generate the .png-files, if it has been selected to do so - if png: - res = call(['inkscape', - '--export-png', - png_dir + '/logo' + str(size) + 'px_' + c + '.png', - '--export-height=' + str(size), - svg_dir + '/logo_' + c + '.svg']) - - if res != 0: - # The build failed. Abort the process - return res + for f in form: + for c in colors: + if not c in ACCENT_PALETTE: + print(c, "is not an accent color. Please choose one from the accent color list") + continue + + if DEBUG: + print("Generating files for color:", c) + + c_id = 'foss-ag_' + c; + + # Change color to the selected + + editAttribute(root, "star_left",'fill','url(#' + c_id + ')') + editAttribute(root, "star_left",'stroke','url(#' + c_id + ')') + + # Disable Clip if needed + if f == 2: + editAttribute(root, "background","clip-path","") + + # write all changes to file + tree.write(svg_dir + '/logoForm'+ str(f) + '_' + c + '.svg') + + # Generate the .png-files, if it has been selected to do so + if png: + res = call(['inkscape', + '--export-png', + png_dir + '/logoForm' + str(f) + '_' + str(size) + 'px_' + c + '.png', + '--export-height=' + str(size), + svg_dir + '/logoForm'+ str(f) + '_' + c + '.svg']) + + if res != 0: + # The build failed. Abort the process + return res # Building was successful for all files return 0 + + #only call this after tree has been build +def editAttribute(root: str, node_id: str, name: str, value: str): + t = root.find(".//*[@id='" + node_id + "']") #node needs an id to be found and changed + t.set(name,value) + + return 0 #After all changes please call tree.write def main(): # Commandline options @@ -87,6 +99,7 @@ def main(): parser.add_argument('-v', '--svg_only', action = 'store_true', help = 'Only generate the SVG files') parser.add_argument('-s', '--size', nargs = '?', type = int, default = DEFAULT_SIZE, help = 'The size the generated bitmap file(s) should have. Default is ' + str(DEFAULT_SIZE)) parser.add_argument('-c', '--colors', nargs = '*', default = [DEFAULT_COLOR], help = 'The colors the script should generate. Default is single ' + DEFAULT_COLOR + ' version. This argument will be ignored when the --all flag is set') + parser.add_argument('-r', '--form', nargs = '*', default = [1], help = 'Form-Factor: round (1), rect (2)') # Read command line input args = parser.parse_args() @@ -109,14 +122,15 @@ def main(): # Make sure all colors are built when the all option is set if args.all: args.colors = ACCENT_PALETTE + args.form = [1,2] # 1 = round, 2 = rectangle - svg_dir = DEFAULT_DIR; + svg_dir = DEFAULT_DIR if args.png_only: svg_dir = "/tmp" print('Building the following colors:', args.colors) - return export(args.colors, args.size, svg_dir, not args.svg_only, DEFAULT_DIR) + return export(args.colors, args.form, args.size, svg_dir, not args.svg_only, DEFAULT_DIR) if __name__ == "__main__": main() diff --git a/src/base.ink.svg b/src/base.ink.svg index 9bfd0ee..afa8f75 100644 --- a/src/base.ink.svg +++ b/src/base.ink.svg @@ -14,7 +14,7 @@ viewBox="0 0 512 512" version="1.1" id="svg2250" - inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" + inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="base.ink.svg" inkscape:export-filename="~/basis.png" inkscape:export-xdpi="96" @@ -100,6 +100,16 @@ id="foss-ag_darker-grey"> + + + + inkscape:label="background" + clip-path="url(#clipCircle)" /> -