Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Add round Version.
Browse files Browse the repository at this point in the history
My take on generating different forms.
Some xml ids in base.ink.svg are now human-readable.
Added also the clip object.
  • Loading branch information
fes0j committed Jun 7, 2018
1 parent f32e6d0 commit ef9d78b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 43 deletions.
78 changes: 46 additions & 32 deletions make.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
33 changes: 22 additions & 11 deletions src/base.ink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ef9d78b

Please sign in to comment.