def main(): f = CurrentFont() a = aifc.open("aiff_out/aiffSlice.aiff", "wb") a.setnchannels(1) a.setsampwidth(4) a.setframerate(44100) #for i in range(80): # v = sin(i/44100.0 * 440.0 * pi) * 2**7 # print v # a.writeframes(pack("h", v)) for n in f.selection: g = f[n] print n #for c in g.contours: # print c.box # for for i in range(int(g.width)): pen = MarginPen(f, i, isHorizontal=False) g.draw(pen) l = pen.getAll() #print l, v = getAverage(l) #print v a.writeframes(pack("i", v)) a.writeframes(pack("i", v)) a.close()
def getMargins(g, y): pen = MarginPen(g.getParent(), y, True) g.draw(pen) crossings = pen.getMargins() try: margins = (round(crossings[0]), g.width - round(crossings[1])) except: margins = (None, None) return margins
def get_stems(font): ref_glyph = 'i' ref_y = font.info.xHeight / 2 g = font[ref_glyph] pen = MarginPen(g, ref_y, isHorizontal=True) g.draw(pen) left_edge, right_edge = pen.getMargins() stem = right_edge - left_edge return [ stem ]
def get_hstems(font): ref_glyph = 'H' g = font[ref_glyph] ref_x = g.width / 2.0 pen = MarginPen(g, ref_x, isHorizontal=False) g.draw(pen) # try: bottom_edge, top_edge = pen.getMargins() stem = top_edge - bottom_edge return [stem]
def get_vstems(font): ref_glyph = 'l' ref_y = font.info.xHeight / 2.0 g = font[ref_glyph] pen = MarginPen(g, ref_y, isHorizontal=True) g.draw(pen) # try: print len(g) print ref_y print pen.getMargins.__doc__ #, pen.getMargins() print pen.getMargins() left_edge, right_edge = pen.getMargins() stem = right_edge - left_edge return [stem]
def get_vstems(font, glyphs=['l', 'I']): ref_y = font.info.xHeight / 2.0 stems = [] for glyph_name in glyphs: if font.has_key(glyph_name): g = font[glyph_name] # get margins pen = MarginPen(g, ref_y, isHorizontal=True) g.draw(pen) # calculate stem from margins try: left_edge, right_edge = pen.getMargins() stem = int(right_edge - left_edge) stems.append(stem) except: pass # glyph is empty return stems
def get_hstems(font, glyphs=['H']): stems = [] for glyph_name in glyphs: if font.has_key(glyph_name): g = font[glyph_name] ref_x = g.width / 2.0 # get margins pen = MarginPen(g, ref_x, isHorizontal=False) g.draw(pen) # calculate stem from margins try: bottom_edge, top_edge = pen.getMargins() stem = int(top_edge - bottom_edge) stems.append(stem) except: pass # glyph is empty return stems
def get_vstems(font, glyphs=['l', 'I']): ref_y = font.info.xHeight / 2.0 stems = [] for glyph_name in glyphs: if glyph_name in font: g = font[glyph_name] # get margins pen = MarginPen(g, ref_y, isHorizontal=True) g.draw(pen) # calculate stem from margins try: left_edge, right_edge = pen.getMargins() stem = int(right_edge - left_edge) stems.append(stem) except: pass # glyph is empty return stems
def get_hstems(font, glyphs=['H']): stems = [] for glyph_name in glyphs: if glyph_name in font: g = font[glyph_name] ref_x = g.width / 2.0 # get margins pen = MarginPen(g, ref_x, isHorizontal=False) g.draw(pen) # calculate stem from margins try: bottom_edge, top_edge = pen.getMargins() stem = int(top_edge - bottom_edge) stems.append(stem) except: pass # glyph is empty return stems