From: André W. <wo...@us...> - 2011-06-16 19:59:26
|
Dear Bastian, the symbols in the graph style show one possibility to draw paths. You can make a function that returns a path at a certain position (not tested): from pyx import * def symbol(x, y, size): return path.path(path.moveto(x, y), path.lineto(x+size, y+size)) c = canvas.canvas() c.stroke(symbol(0, 0, 1)) c.writePDFfile() There are other solutions as well (like returning a canvas). It just depends on what needs to be drawn (whether it can be returned as a path or not for example). But that way you'll always need to rebuilt the symbols using PyX paths. However, when you discuss music symbols, you might want to check existing fonts. MusixTeX for example provides a set of fonts. You will most probably have it on your machine already, as it is contained in many LaTeX distributions. Just check whether you can find a font like musix11.pfb on your system (of find it online somewhere). You can than use this font by the following code (just update the position of the pdf file): from pyx import * from pyx import bbox, font from pyx.font import t1file, metric n = '/usr/local/texlive/2008/texmf-dist/fonts/type1/public/musixtex/musix11.pfb' class noMetric(metric.metric): def __init__(self, t1font): self.t1font = t1font self.t1font._data2decode() self.glyphinfocache = {} def getglyphinfo(self, glyphname): if glyphname not in self.glyphinfocache: self.glyphinfocache[glyphname] = self.t1font.getglyphinfo(glyphname) return self.glyphinfocache[glyphname] def width_ds(self, glyphnames): return sum(self.getglyphinfo(glyphname)[0] for glyphname in glyphnames) def width_pt(self, glyphnames, size_pt): return sum(self.getglyphinfo(glyphname)[4] for glyphname in glyphnames)*size_pt/1000.0 def height_pt(self, glyphnames, size_pt): return sum(self.getglyphinfo(glyphname)[5] for glyphname in glyphnames)*size_pt/1000.0 def depth_pt(self, glyphnames, size_pt): return sum(self.getglyphinfo(glyphname)[3] for glyphname in glyphnames)*size_pt/1000.0 def writePDFfontinfo(self, file): self.t1font.writePDFfontinfo(file) c = canvas.canvas() t1 = t1file.from_PFB_filename(n) f = font.T1font(t1, noMetric(t1)) for x in range(16): for y in range(16): i = x+16*y c.stroke(path.rect_pt(-25+50*x, -25-50*y, 50, 50)) c.text_pt(50*x, 15-50*y, str(i), [text.halign.center]) c.insert(f.text_pt(x*50, -y*50, 'a', 10, decoding={'a': t1.glyphlist[i]})) c.writePDFfile() Unfortunately there is no AFM file available for this font, but I quickly created a "noMetric" replacement to grab the information from the pdf file itself. I'll probably fix this in PyX itself by some other workaround, but for the moment this should be fine to show you what you could do instead by reusing some existing font. Best, André Am 16.06.2011 um 11:04 schrieb R. Bastian: > Bonjour, > > I try to include music symbols in PyX. > The symbols were writtent originally by Daniel Taupin and later > transformed by Matti Koskinen (bitmap -> PS) and Bill Schottstaedt (-> Lisp). > > In 'style.py' are the functions _squaresymbol & others written as pseudo-PostScript, > with 'change...' functions. > In 'path.py' are the functions rlineto, rcurveto, ... which are usefull to > translate the PostScript code to Python ("et retour" :-). > > The model of my PS code is always: > x y scale symbol > % symbol = bemol | diese | becarre | viertel | halbe | kopf | wkopf ... > > Is there a convenient way to use this symbols in PyX ? > > > -- > René Bastian > www.pythoneon.org > www.musiques-rb.org > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > PyX-user mailing list > PyX...@li... > https://lists.sourceforge.net/lists/listinfo/pyx-user -- by _ _ _ Dr. André Wobst, Amselweg 22, 85716 Unterschleißheim / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ |