setup_typography_canvas.py revision 6c97635ad1185cbd08910ee5042001e243496503
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico'''
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoCopyright (C) 2011 Felipe Correa da Silva Sanches
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoThis program is free software; you can redistribute it and/or modify
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoit under the terms of the GNU General Public License as published by
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicothe Free Software Foundation; either version 2 of the License, or
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico(at your option) any later version.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoThis program is distributed in the hope that it will be useful,
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicobut WITHOUT ANY WARRANTY; without even the implied warranty of
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoGNU General Public License for more details.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoYou should have received a copy of the GNU General Public License
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoalong with this program; if not, write to the Free Software
107e00c8104649437b9520d0ba298dba659e7cd7JazzyNicoFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico'''
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoimport inkex
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoimport sys
040e298be5b23e77e33309d65449072183c82d5cacspike
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owensclass SetupTypographyCanvas(inkex.Effect):
040e298be5b23e77e33309d65449072183c82d5cacspike def __init__(self):
040e298be5b23e77e33309d65449072183c82d5cacspike inkex.Effect.__init__(self)
040e298be5b23e77e33309d65449072183c82d5cacspike self.OptionParser.add_option("-e", "--emsize",
040e298be5b23e77e33309d65449072183c82d5cacspike action="store", type="int",
040e298be5b23e77e33309d65449072183c82d5cacspike dest="emsize", default=1000,
040e298be5b23e77e33309d65449072183c82d5cacspike help="Em-size")
040e298be5b23e77e33309d65449072183c82d5cacspike self.OptionParser.add_option("-a", "--ascender",
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico action="store", type="int",
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico dest="ascender", default='750',
040e298be5b23e77e33309d65449072183c82d5cacspike help="Ascender")
040e298be5b23e77e33309d65449072183c82d5cacspike self.OptionParser.add_option("-c", "--caps",
040e298be5b23e77e33309d65449072183c82d5cacspike action="store", type="int",
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico dest="caps", default='700',
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico help="Caps Height")
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico self.OptionParser.add_option("-x", "--xheight",
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico action="store", type="int",
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico dest="xheight", default='500',
040e298be5b23e77e33309d65449072183c82d5cacspike help="x-height")
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico self.OptionParser.add_option("-d", "--descender",
040e298be5b23e77e33309d65449072183c82d5cacspike action="store", type="int",
040e298be5b23e77e33309d65449072183c82d5cacspike dest="descender", default='250',
040e298be5b23e77e33309d65449072183c82d5cacspike help="Descender")
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspike def create_horizontal_guideline(self, name, position):
040e298be5b23e77e33309d65449072183c82d5cacspike self.create_guideline(name, "0,1", 0, position)
040e298be5b23e77e33309d65449072183c82d5cacspike
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens def create_vertical_guideline(self, name, position):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico self.create_guideline(name, "1,0", position, 0)
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico def create_guideline(self, label, orientation, x,y):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico namedview = self.svg.find(inkex.addNS('namedview', 'sodipodi'))
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico guide = inkex.etree.SubElement(namedview, inkex.addNS('guide', 'sodipodi'))
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico guide.set("orientation", orientation)
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico guide.set("position", str(x)+","+str(y))
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico guide.set(inkex.addNS('label', 'inkscape'), label)
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico def effect(self):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico # Get all the options
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico emsize = self.options.emsize
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico ascender = self.options.ascender
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico caps = self.options.caps
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens xheight = self.options.xheight
040e298be5b23e77e33309d65449072183c82d5cacspike descender = self.options.descender
# Get access to main SVG document element
self.svg = self.document.getroot()
self.svg.set("width", str(emsize))
self.svg.set("height", str(emsize))
self.svg.set("showborder"(true))
self.svg.set("inkscape:showpageshadow"(false))
baseline = descender
# Create guidelines
self.create_horizontal_guideline("baseline", baseline)
self.create_horizontal_guideline("ascender", baseline+ascender)
self.create_horizontal_guideline("caps", baseline+caps)
self.create_horizontal_guideline("xheight", baseline+xheight)
self.create_horizontal_guideline("descender", baseline-descender)
if __name__ == '__main__':
e = SetupTypographyCanvas()
e.affect()