Esempio n. 1
0
    def build_path(self, string, index, ctp):
        ctp_x, ctp_y = ctp
        
        path = VG.Path()
        vertical = False
        with VG.push([1,0,0,0,1,0,0,0,1]):
            #TODO: vertical and bidi text.
            last_glyph = None
            for char in string:
                ctp_x, ctp_y = self._transform(ctp_x, ctp_y, index)
                glyph = self.font.get_glyph(char)
                subpath = self.font.get_path_for_glyph(glyph)
                #Flip it.
                with VG.push([1,0,0,0,-1,0,0,0,1]):
                    subpath = subpath.transform()
                
                VG.translate(ctp_x, ctp_y)
                if self.font.face.has_kerning and last_glyph is not None:
                    kerning = self.font.face.get_kerning(last_glyph.index,
                                                         glyph.index,
                                                         FT_KERNING_UNSCALED)
                    VG.translate(self.font.scale*kerning[0],
                                 self.font.scale*kerning[1])
                    ctp_x += self.font.scale*kerning[0]
                    ctp_y += self.font.scale*kerning[1]
                
                if index < len(self.trot)-1:
                    VG.translate(ctp_x, ctp_y)
                    VG.rotate(self.rotate[index])
                    VG.translate(-ctp_x, -ctp_y)

                last_glyph = glyph
                
                subpath.transform(path)
                ctp_x += self.font.scale*glyph.advance[0]
                ctp_y += self.font.scale*glyph.advance[1]*vertical
                VG.load_matrix([1,0,0,0,1,0,0,0,1])

        return path, ctp