示例#1
0
    def append(self,
               text,
               family='Sans',
               size=16,
               bold=False,
               italic=False,
               color=(0.0, 0.0, 0.0, 1.0),
               lineheight=1.25,
               translate=(0, 0),
               scale=1.0,
               rotate=0.0,
               tight_bbox=True,
               anchor_x='left',
               anchor_y='baseline',
               filename='./Vera.ttf'):

        font = self.font_manager.get(filename, size)
        n = len(text)
        V = self.bake(text,
                      font,
                      anchor_x,
                      anchor_y,
                      lineheight,
                      tight_bbox=True)
        I = np.resize(np.array([0, 1, 2, 0, 2, 3], dtype=np.uint32),
                      n * (2 * 3))
        I += np.repeat(4 * np.arange(n), 6)
        U = np.zeros(1, self.utype)
        U['color'] = color
        U['translate'] = translate
        U['scale'] = scale
        U['rotate'] = rotate
        Collection.append(self, V, I, U)
示例#2
0
    def append( self, vertices, closed=False, color = (0,0,0,1),
                linewidth = 1.0, antialias = 1.0, linejoin = 'round', miter_limit = 4.0,
                translate = (0,0), scale = 1.0, rotate = 0.0, linecaps = ('round','round'),
                dash_pattern='solid', dash_phase = 0.0, dash_caps = ('round','round') ):
        V,I,length = self.bake( vertices, closed=closed )
        U = np.zeros(1, self.utype)

        if closed:
            U['closed']  = 1.0
        U['linewidth']   = linewidth
        U['antialias']   = antialias
        U['color']       = color
        U['translate']   = translate
        U['scale']       = scale
        U['rotate']      = rotate
        U['linejoin']    = self.join.get(linejoin, 'round')
        U['linecaps']    = ( self.caps.get(linecaps[0], 'round'),
                             self.caps.get(linecaps[1], 'round') )
        U['miter_limit'] = miter_limit
        U['length']      = length
        if self.dash_atlas:
            dash_index, dash_period = self.dash_atlas[dash_pattern]
            U['dash_phase']  = dash_phase
            U['dash_index']  = dash_index
            U['dash_period'] = dash_period
            U['dash_caps']   = ( self.caps.get(dash_caps[0], 'round'),
                                 self.caps.get(dash_caps[1], 'round') )
        Collection.append(self,V,I,U)
示例#3
0
 def __init__(self, dash_atlas = None):
     self.vtype = np.dtype( [('a_position', 'f4', 2),
                             ('a_segment',  'f4', 2),
                             ('a_angles',   'f4', 2),
                             ('a_tangents', 'f4', 4),
                             ('a_texcoord', 'f4', 2) ])
     self.utype = np.dtype( [('color',      'f4', 4),
                             ('translate',  'f4', 2),
                             ('scale',      'f4', 1),
                             ('rotate',     'f4', 1),
                             ('linewidth',  'f4', 1),
                             ('antialias',  'f4', 1),
                             ('linecaps',   'f4', 2),
                             ('linejoin',   'f4', 1),
                             ('miter_limit','f4', 1),
                             ('length',     'f4', 1),
                             ('dash_phase', 'f4', 1),
                             ('dash_period','f4', 1),
                             ('dash_index', 'f4', 1),
                             ('dash_caps',  'f4', 2),
                             ('closed',     'f4', 1)] )
     Collection.__init__(self, self.vtype, self.utype)
     shaders = os.path.join(os.path.dirname(__file__),'shaders')
     vertex_shader= os.path.join( shaders, 'path.vert')
     fragment_shader= os.path.join( shaders, 'path.frag')
     if dash_atlas is None:
         self.dash_atlas = DashAtlas()
     else:
         self.dash_atlas = dash_atlas
     self.shader = Shader( open(vertex_shader).read(),
                           open(fragment_shader).read() )
示例#4
0
 def append(self,
            vertices,
            color=(0, 0, 0, 1),
            linewidth=1.0,
            antialias=1.0,
            translate=(0, 0),
            scale=1.0,
            rotate=0.0,
            linecaps=('round', 'round'),
            dash_pattern='solid',
            dash_phase=0.0,
            dash_caps=('round', 'round')):
     V, I = self.bake(vertices)
     U = np.zeros(1, self.utype)
     U['linewidth'] = linewidth
     U['antialias'] = antialias
     U['color'] = color
     U['translate'] = translate
     U['scale'] = scale
     U['rotate'] = rotate
     U['linecaps'] = (self.caps.get(linecaps[0], 'round'),
                      self.caps.get(linecaps[1], 'round'))
     if self.dash_atlas:
         dash_index, dash_period = self.dash_atlas[dash_pattern]
         U['dash_phase'] = dash_phase
         U['dash_index'] = dash_index
         U['dash_period'] = dash_period
         U['dash_caps'] = (self.caps.get(dash_caps[0], 'round'),
                           self.caps.get(dash_caps[1], 'round'))
     Collection.append(self, V, I, U)
示例#5
0
    def __init__(self, font_manager=None):

        self.vtype = np.dtype([('a_position', 'f4', 2),
                               ('a_texcoord', 'f4', 2),
                               ('a_glyphtex', 'f4', 4)])
        self.utype = np.dtype([('color', 'f4', 4), ('translate', 'f4', 2),
                               ('scale', 'f4', 1), ('rotate', 'f4', 1)])
        self.font_manager = font_manager
        Collection.__init__(self, self.vtype, self.utype)

        # code = self.font_manager.filter_code
        shaders = os.path.join(os.path.dirname(__file__), '../shaders')
        vertex_shader = os.path.join(shaders, 'sdf_text.vert')
        fragment_shader = os.path.join(shaders, 'sdf_text.frag')
        self.shader = Shader(
            open(vertex_shader).read(),
            open(fragment_shader).read())
示例#6
0
    def append( self, text,
                family='Sans', size=16, bold=False, italic=False,
                color=(0.0, 0.0, 0.0, 1.0), lineheight = 1.25,
                translate=(0,0), scale = 1.0, rotate = 0.0, tight_bbox=True,
                anchor_x='left', anchor_y='baseline', filename='./Vera.ttf'):

        font = self.font_manager.get(filename, size)
        n = len(text)
        V = self.bake(text, font, anchor_x, anchor_y, lineheight, tight_bbox=True)
        I = np.resize( np.array([0,1,2,0,2,3], dtype=np.uint32), n*(2*3))
        I += np.repeat( 4*np.arange(n), 6)
        U = np.zeros(1, self.utype)
        U['color']       = color
        U['translate']   = translate
        U['scale']       = scale
        U['rotate']      = rotate
        Collection.append(self,V,I,U)
示例#7
0
    def __init__(self, font_manager=None):

        self.vtype = np.dtype([('a_position', 'f4', 2),
                               ('a_texcoord', 'f4', 2), ('a_shift', 'f4', 1),
                               ('a_gamma', 'f4', 1)])
        self.utype = np.dtype([('color', 'f4', 4), ('translate', 'f4', 2),
                               ('scale', 'f4', 1), ('rotate', 'f4', 1)])
        if font_manager:
            self.font_manager = font_manager
        else:
            self.font_manager = FontManager(1024, 1024, 3)
        Collection.__init__(self, self.vtype, self.utype)
        shaders = os.path.join(os.path.dirname(__file__), 'shaders')
        vertex_shader = os.path.join(shaders, 'text.vert')
        fragment_shader = os.path.join(shaders, 'text.frag')
        self.shader = Shader(
            open(vertex_shader).read(),
            open(fragment_shader).read())
示例#8
0
    def __init__(self, font_manager=None):
        
        self.vtype = np.dtype( [('a_position', 'f4', 2),
                                ('a_texcoord', 'f4', 2),
                                ('a_glyphtex', 'f4', 4)] )
        self.utype = np.dtype( [('color',      'f4', 4),
                                ('translate',  'f4', 2),
                                ('scale',      'f4', 1),
                                ('rotate',     'f4', 1)] )
        self.font_manager = font_manager
        Collection.__init__(self, self.vtype, self.utype)

        # code = self.font_manager.filter_code
        shaders = os.path.join(os.path.dirname(__file__),'../shaders')
        vertex_shader= os.path.join( shaders, 'sdf_text.vert')
        fragment_shader= os.path.join( shaders, 'sdf_text.frag')
        self.shader = Shader( open(vertex_shader).read(),
                              open(fragment_shader).read() )
示例#9
0
 def __init__(self, font_manager=None):
     
     self.vtype = np.dtype( [('a_position', 'f4', 2),
                             ('a_texcoord', 'f4', 2),
                             ('a_shift',    'f4', 1),
                             ('a_gamma',    'f4', 1)] )
     self.utype = np.dtype( [('color',      'f4', 4),
                             ('translate',  'f4', 2),
                             ('scale',      'f4', 1),
                             ('rotate',     'f4', 1)] )
     if font_manager:
         self.font_manager = font_manager
     else:
         self.font_manager = FontManager(1024,1024,3)
     Collection.__init__(self, self.vtype, self.utype)
     shaders = os.path.join(os.path.dirname(__file__),'shaders')
     vertex_shader= os.path.join( shaders, 'text.vert')
     fragment_shader= os.path.join( shaders, 'text.frag')
     self.shader = Shader( open(vertex_shader).read(),
                           open(fragment_shader).read() )
示例#10
0
 def __init__(self, dash_atlas=None):
     self.vtype = np.dtype([('a_p0', 'f4', 2), ('a_p1', 'f4', 2),
                            ('a_texcoord', 'f4', 2)])
     self.utype = np.dtype([('color', 'f4', 4), ('translate', 'f4', 2),
                            ('scale', 'f4', 1), ('rotate', 'f4', 1),
                            ('linewidth', 'f4', 1), ('antialias', 'f4', 1),
                            ('linecaps', 'f4', 2), ('dash_phase', 'f4', 1),
                            ('dash_period', 'f4', 1),
                            ('dash_index', 'f4', 1),
                            ('dash_caps', 'f4', 2)])
     Collection.__init__(self, self.vtype, self.utype)
     shaders = os.path.join(os.path.dirname(__file__), 'shaders')
     vertex_shader = os.path.join(shaders, 'line.vert')
     fragment_shader = os.path.join(shaders, 'line.frag')
     if dash_atlas is None:
         self.dash_atlas = DashAtlas()
     else:
         self.dash_atlas = dash_atlas
     self.shader = Shader(
         open(vertex_shader).read(),
         open(fragment_shader).read())
示例#11
0
    def append(self,
               vertices,
               closed=False,
               color=(0, 0, 0, 1),
               linewidth=1.0,
               antialias=1.0,
               linejoin='round',
               miter_limit=4.0,
               translate=(0, 0),
               scale=1.0,
               rotate=0.0,
               linecaps=('round', 'round'),
               dash_pattern='solid',
               dash_phase=0.0,
               dash_caps=('round', 'round')):
        V, I, length = self.bake(vertices, closed=closed)
        U = np.zeros(1, self.utype)

        if closed:
            U['closed'] = 1.0
        U['linewidth'] = linewidth
        U['antialias'] = antialias
        U['color'] = color
        U['translate'] = translate
        U['scale'] = scale
        U['rotate'] = rotate
        U['linejoin'] = self.join.get(linejoin, 'round')
        U['linecaps'] = (self.caps.get(linecaps[0], 'round'),
                         self.caps.get(linecaps[1], 'round'))
        U['miter_limit'] = miter_limit
        U['length'] = length
        if self.dash_atlas:
            dash_index, dash_period = self.dash_atlas[dash_pattern]
            U['dash_phase'] = dash_phase
            U['dash_index'] = dash_index
            U['dash_period'] = dash_period
            U['dash_caps'] = (self.caps.get(dash_caps[0], 'round'),
                              self.caps.get(dash_caps[1], 'round'))
        Collection.append(self, V, I, U)
示例#12
0
 def append( self, vertices, color = (0,0,0,1),
             linewidth = 1.0, antialias = 1.0,
             translate = (0,0), scale = 1.0, rotate = 0.0, linecaps = ('round','round'),
             dash_pattern='solid', dash_phase = 0.0, dash_caps = ('round','round') ):
     V,I = self.bake( vertices )
     U = np.zeros(1, self.utype)
     U['linewidth']   = linewidth
     U['antialias']   = antialias
     U['color']       = color
     U['translate']   = translate
     U['scale']       = scale
     U['rotate']      = rotate
     U['linecaps']    = ( self.caps.get(linecaps[0], 'round'),
                          self.caps.get(linecaps[1], 'round') )
     if self.dash_atlas:
         dash_index, dash_period = self.dash_atlas[dash_pattern]
         U['dash_phase']  = dash_phase
         U['dash_index']  = dash_index
         U['dash_period'] = dash_period
         U['dash_caps']   = ( self.caps.get(dash_caps[0], 'round'),
                              self.caps.get(dash_caps[1], 'round') )
     Collection.append(self,V,I,U)