Index: measure.inx =================================================================== --- measure.inx (revision 13513) +++ measure.inx (working copy) @@ -3,7 +3,10 @@ com.njhurst.filter.measure_length measure.py inkex.py - 10 + 12 + mm + -6 + 2 path Index: measure.py =================================================================== --- measure.py (revision 13513) +++ measure.py (working copy) @@ -1,5 +1,10 @@ #!/usr/bin/env python ''' +This extension module can measure arbitrary path and object length +It adds a text to the selected path containing the length in a +given unit. + +Copyright (C) 2006 Georg Wiora Copyright (C) 2006 Nathan Hurst Copyright (C) 2005 Aaron Spike, aaron@ekips.org @@ -17,7 +22,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' -import inkex, simplestyle, simplepath,sys,cubicsuperpath, bezmisc +import inkex, simplestyle, simplepath,sys,cubicsuperpath, bezmisc, locale +# Set current system locale +locale.setlocale(locale.LC_ALL, '') def numsegs(csp): return sum([len(p)-1 for p in csp]) @@ -66,8 +73,16 @@ help="Size of node label numbers") self.OptionParser.add_option("-o", "--offset", action="store", type="string", - dest="offset", default="-4", + dest="offset", default="-6", help="The distance above the curve") + self.OptionParser.add_option("-u", "--unit", + action="store", type="string", + dest="unit", default="mm", + help="The unit of the measurement") + self.OptionParser.add_option("-p", "--precision", + action="store", type="string", + dest="precision", default="2", + help="Number of significant digits after decimal point") def effect(self): for id, node in self.selected.iteritems(): if node.tagName == 'path': @@ -84,20 +99,40 @@ p = cubicsuperpath.parsePath(node.attributes.getNamedItem('d').value) num = 1 slengths, stotal = csplength(p) - self.addTextOnPath(self.group,0, 0,str(stotal), id, self.options.offset) + ''' Wio: Umrechnung in unit ''' + if self.options.unit=="mm": + factor=0.2822219 # px->mm + elif self.options.unit=="pt": + factor=0.80 # px->pt + elif self.options.unit=="cm": + factor=0.02822219 # px->cm + elif self.options.unit=="m": + factor=0.0002822219 # px->m + elif self.options.unit=="in": + factor=0.2822219/25.4 # px->in + else : + ''' Default unit is px''' + factor=1 + self.options.unit="px" + + # Format the length as string + lenstr = locale.format("%(len)10."+str(self.options.precision)+"f",{'len':stotal*factor}).strip() + self.addTextOnPath(self.group,0, 0,lenstr+' '+self.options.unit, id, self.options.offset) def addTextOnPath(self,node,x,y,text, id,dy=0): new = self.document.createElement('svg:text') tp = self.document.createElement('svg:textPath') - s = {'font-size': self.options.fontsize, 'fill-opacity': '1.0', 'stroke': 'none', + s = {'text-align': 'center', 'vertical-align': 'bottom', + 'font-size': self.options.fontsize, + 'fill-opacity': '1.0', 'stroke': 'none', 'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'} new.setAttribute('style', simplestyle.formatStyle(s)) new.setAttribute('x', str(x)) new.setAttribute('y', str(y)) tp.setAttributeNS('http://www.w3.org/1999/xlink','xlink:href', '#'+id) tp.setAttribute('startOffset', "50%") - #tp.setAttribute('dy', dy) # dubious merit + tp.setAttribute('dy', dy) # dubious merit new.appendChild(tp) tp.appendChild(self.document.createTextNode(str(text))) node.appendChild(new)