def __init__(self, FPath='./',FName='Arial.ttf', String=None, Height=10, Track=0): self.FTFont = FontUtils.initFreeType(FPath, FName) self.String = String self.Height = Height # FC units self.Tracking = Track # FC units self.Scale = FontUtils.getUniformScale(self.FTFont, self.Height) # attributes we may need later # self.FType = (FName.split('.')[-1])).upper() # self.Position = (0,0,0) # self.Plane = (0,0,1) # self.Shape = None if DEBUG: print "TextShape Parms" print "Font Path: ", FPath print "Font Name: ", FName print "String: ", String print "Height: ", Height print "Track: ", Track print "Scale: ", self.Scale
def toWires(self): '''toWires(self): Creates a collection of Part.Wires outlining the text string. Returns a list where each entry corresponds to 1 character. Each list entry is a list of Wires describing 1 of the character's Contours''' PenPos = 0 # offset along baseline KChar = chr(0) # kerning. missing glyph convention Chars = [] for char in self.String: # get unpacked and segmented contour outlines and positioning metrics # for this char CharCons,Adv,Kern = FontUtils.getTTFCharContours( self.FTFont, char, KChar) PenPos += Kern.x * self.Scale[0] # only horiz strings for now CharWires = self._makeCharWires(CharCons, PenPos) if CharWires: Chars.append(CharWires) PenPos += (Adv * self.Scale[0]) + self.Tracking KChar = char return(Chars)