diff --git a/Makefile.am b/Makefile.am index 379d36803..3cf851c55 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,6 @@ # Copyright (C) Lumiera.org # 2007, Christian Thaeter +# 2008, Joel Holdsworth # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -44,6 +45,9 @@ include $(top_srcdir)/src/gui/Makefile.am # plugins #include $(top_srcdir)/src... +# resources +include $(top_srcdir)/icons/Makefile.am + # tests include $(top_srcdir)/tests/common/Makefile.am include $(top_srcdir)/tests/components/Makefile.am diff --git a/icons/render-icons.py b/admin/render-icon.py similarity index 53% rename from icons/render-icons.py rename to admin/render-icon.py index 4ebbd3fc4..9bf4c7dc5 100755 --- a/icons/render-icons.py +++ b/admin/render-icon.py @@ -19,12 +19,16 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +import sys +import getopt from xml.dom import minidom import os import shutil +import cairo +import rsvg -svgDir = "svg" -prerenderedDir = "prerendered" +#svgDir = "svg" +#prerenderedDir = "prerendered" inkscapePath = "/usr/bin/inkscape" artworkLayerPrefix = "artwork:" @@ -63,7 +67,6 @@ def parsePlateLayer( layer ): height = float(node.getAttribute("height")) rectangles.append([x, y, width, height]) return rectangles - def parseSVG( file_path ): print "Rendering " + file_path @@ -82,46 +85,91 @@ def parseSVG( file_path ): return artwork_name, size, parsePlateLayer( plate ) return None -def renderSVGIcons(): - listing = os.listdir(svgDir) - for file_path in listing: - [root, extension] = os.path.splitext(file_path) - if extension.lower() == ".svg": - file_path = os.path.join(svgDir, file_path) - artwork_name, doc_size, rectangles = parseSVG(file_path) - for rectangle in rectangles: - x1 = rectangle[0] - y1 = doc_size[1] - rectangle[1] - rectangle[3] - x2 = x1 + rectangle[2] - y2 = y1 + rectangle[3] - os.spawnlp(os.P_WAIT, inkscapePath, inkscapePath, - file_path, - "-z", - "-a %g:%g:%g:%g" % (x1, y1, x2, y2), - "-w %g" % (rectangle[2]), "-h %g" % (rectangle[3]), - "--export-png=%gx%g/%s.png" % (rectangle[2], rectangle[3], artwork_name)) +def renderSvgInkscape(file_path, out_dir, artwork_name, rectangle, doc_size): -def copyPrerenderedIcons(): - listing = os.listdir(prerenderedDir) - for list_item in listing: - src_dir = os.path.join(prerenderedDir, list_item) - copyMergeDirectory(src_dir, list_item) + # Calculate the rendering rectangle + x1 = rectangle[0] + y1 = doc_size[1] - rectangle[1] - rectangle[3] + x2 = x1 + rectangle[2] + y2 = y1 + rectangle[3] + + # Call Inkscape to do the render + os.spawnlp(os.P_WAIT, inkscapePath, inkscapePath, + file_path, + "-z", + "-a %g:%g:%g:%g" % (x1, y1, x2, y2), + "-w %g" % (rectangle[2]), "-h %g" % (rectangle[3]), + "--export-png=" + os.path.join(out_dir, "%gx%g/%s.png" % (rectangle[2], rectangle[3], artwork_name))) + +def renderSvgRsvg(file_path, out_dir, artwork_name, rectangle, doc_size): + # Prepare a Cairo context + width = int(rectangle[2]) + height = int(rectangle[3]) + + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + context = cairo.Context(surface) + context.translate(-rectangle[0], -rectangle[1]) -def main(): + # Load an render the SVG + svg = rsvg.Handle(file=file_path) + svg.render_cairo(context) + + # Output a PNG file + surface.write_to_png(os.path.join(out_dir, + "%ix%i/%s.png" % (width, height, artwork_name))) + +def renderSvgIcon(file_path, out_dir): + artwork_name, doc_size, rectangles = parseSVG(file_path) + for rectangle in rectangles: + renderSvgRsvg(file_path, out_dir, artwork_name, rectangle, doc_size) + +#def renderSvgIcons(): +# listing = os.listdir(svgDir) +# for file_path in listing: +# [root, extension] = os.path.splitext(file_path) +# if extension.lower() == ".svg": +# renderSvgIcon(os.path.join(svgDir, file_path)) + +#def copyPrerenderedIcons(): +# listing = os.listdir(prerenderedDir) +# for list_item in listing: +# src_dir = os.path.join(prerenderedDir, list_item) +# copyMergeDirectory(src_dir, list_item) + +def printHelp(): + print "render-icon.py - An icon rendering utility script for lumiera" + +def parseArguments(argv): + optlist, args = getopt.getopt(argv, "") + + if len(args) == 2: + return args[0], args[1] + + printHelp() + return None, None + +def main(argv): + in_path, out_dir = parseArguments(argv) + + if in_path == None or out_dir == None: + return + + if os.path.exists(out_dir) == False: + print "Directory not found: " + out_dir + return # Create the icons folders - createDirectory("48x48") - createDirectory("32x32") - createDirectory("24x24") - createDirectory("22x22") - createDirectory("16x16") - - # Render the SVG icons - renderSVGIcons() + createDirectory(os.path.join(out_dir, "48x48")) + createDirectory(os.path.join(out_dir, "32x32")) + createDirectory(os.path.join(out_dir, "24x24")) + createDirectory(os.path.join(out_dir, "22x22")) + createDirectory(os.path.join(out_dir, "16x16")) + renderSvgIcon(in_path, out_dir) + # Copy in prerendered icons - copyPrerenderedIcons() + #copyPrerenderedIcons() if __name__=="__main__": - main() + main(sys.argv[1:]) diff --git a/icons/Makefile.am b/icons/Makefile.am new file mode 100644 index 000000000..d3adca1fa --- /dev/null +++ b/icons/Makefile.am @@ -0,0 +1,53 @@ +# Copyright (C) Lumiera.org +# 2008, Joel Holdsworth +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +svgdir = $(top_srcdir)/icons/svg +prerendereddir = $(top_srcdir)/icons/prerendered +icondir = $(top_builddir) +iconcommand = python $(top_srcdir)/admin/render-icon.py + +16x16 = $(icondir)/16x16 +22x22 = $(icondir)/22x22 +24x24 = $(icondir)/24x24 +32x32 = $(icondir)/32x32 +48x48 = $(icondir)/48x48 + +16x16pre = $(prerendereddir)/16x16 +22x22pre = $(prerendereddir)/22x22 +24x24pre = $(prerendereddir)/24x24 +32x32pre = $(prerendereddir)/32x32 +48x48pre = $(prerendereddir)/48x48 + +lumigui_DEPENDENCIES += \ + $(16x16)/arrow.png $(22x22)/arrow.png $(24x24)/arrow.png $(32x32)/arrow.png $(48x48)/arrow.png \ + $(16x16)/i-beam.png $(22x22)/i-beam.png $(24x24)/i-beam.png $(32x32)/i-beam.png $(48x48)/i-beam.png \ + $(16x16)/assets-panel.png \ + $(16x16)/timeline-panel.png \ + $(16x16)/viewer-panel.png + +$(16x16)/arrow.png $(22x22)/arrow.png $(24x24)/arrow.png $(32x32)/arrow.png $(48x48)/arrow.png : $(svgdir)/arrow.svg + $(iconcommand) $< $(icondir) +$(16x16)/i-beam.png $(22x22)/i-beam.png $(24x24)/i-beam.png $(32x32)/i-beam.png $(48x48)/i-beam.png : $(svgdir)/i-beam.svg + $(iconcommand) $< $(icondir) + +$(16x16)/assets-panel.png: + cp $(16x16pre)/assets-panel.png $(16x16) +$(16x16)/timeline-panel.png: + cp $(16x16pre)/timeline-panel.png $(16x16) +$(16x16)/viewer-panel.png: + cp $(16x16pre)/viewer-panel.png $(16x16) + diff --git a/icons/svg/i-beam.svg b/icons/svg/i-beam.svg index 2f4e82f27..250f087c0 100644 --- a/icons/svg/i-beam.svg +++ b/icons/svg/i-beam.svg @@ -554,9 +554,9 @@ objecttolerance="10" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="5.6568543" - inkscape:cx="79.400744" - inkscape:cy="54.133354" + inkscape:zoom="32" + inkscape:cx="135.70823" + inkscape:cy="18.300078" inkscape:document-units="px" inkscape:current-layer="layer4" showgrid="true" @@ -565,9 +565,9 @@ inkscape:snap-global="true" showguides="true" inkscape:guide-bbox="true" - inkscape:window-width="1679" - inkscape:window-height="977" - inkscape:window-x="1281" + inkscape:window-width="1670" + inkscape:window-height="973" + inkscape:window-x="1285" inkscape:window-y="48">