def convert_outline(outline): paths = [] trafo = Scale(0.001) for closed, sub in outline: if closed: sub.append(sub[0]) path = CreatePath() paths.append(path) for item in sub: if len(item) == 2: apply(path.AppendLine, item) else: apply(path.AppendBezier, item) if closed: path.load_close() for path in paths: path.Transform(trafo) return tuple(paths)
def GetPaths(self, text, prop): # convert glyph data into bezier polygons paths = [] fheight = self.getFontHeight(prop) voffset = 0 tab = 1 lastIndex = 0 lines = split(text, '\n') for line in lines: offset = c = 0 align_offset = self.getAlignOffset(line, prop) for c in line: if c == '\t': c = ' ' tab = 3 else: tab = 1 try: thisIndex = self.enc_vector[ord(c)] except: thisIndex = self.enc_vector[ord('?')] glyph = ft2.Glyph(self.face, thisIndex, 1) kerning = self.face.getKerning(lastIndex, thisIndex, 0) lastIndex = thisIndex offset += kerning[0] / 4.0 voffset += kerning[1] / 4.0 for contour in glyph.outline: # rotate contour so that it begins with an onpoint x, y, onpoint = contour[0] if onpoint: for j in range(1, len(contour)): x, y, onpoint = contour[j] if onpoint: contour = contour[j:] + contour[:j] break else: print "unsupported type of contour (no onpoint)" # create a sK1 path object path = CreatePath() j = 0 npoints = len(contour) x, y, onpoint = contour[0] last_point = Point(x, y) while j <= npoints: if j == npoints: x, y, onpoint = contour[0] else: x, y, onpoint = contour[j] point = Point(x, y) j = j + 1 if onpoint: path.AppendLine(point) last_point = point else: c1 = last_point + (point - last_point) * 2.0 / 3.0 x, y, onpoint = contour[j % npoints] if onpoint: j = j + 1 cont = ContAngle else: x = point.x + (x - point.x) * 0.5 y = point.y + (y - point.y) * 0.5 cont = ContSmooth last_point = Point(x, y) c2 = last_point + (point - last_point) * 2.0 / 3.0 path.AppendBezier(c1, c2, last_point, cont) path.ClosePath() path.Translate(offset, voffset) path.Transform(Scale(0.5 / 1024.0)) path.Translate(align_offset, 0) paths.append(path) if c == ' ': offset = offset + glyph.advance[ 0] * prop.chargap * prop.wordgap * tab / 1000 else: offset = offset + glyph.advance[0] * prop.chargap / 1000 voffset -= fheight return tuple(paths)