Пример #1
0
def test_font_glyph():
    """Test loading glyphs"""
    # try both a vispy and system font
    for face in ('OpenSans', list_fonts()[0]):
        font_dict = dict(face=face, size=12, bold=False, italic=False)
        glyphs_dict = dict()
        chars = 'foobar^C&#'
        for char in chars:
            # Warning that Arial might not exist
            _load_glyph(font_dict, char, glyphs_dict)
        assert_equal(len(glyphs_dict), np.unique([c for c in chars]).size)
Пример #2
0
def test_font_glyph(face):
    """Test loading glyphs"""
    if face in known_bad_fonts or face.split(" ")[0] in known_bad_fonts:
        pytest.xfail()
    font_dict = dict(face=face, size=12, bold=False, italic=False)
    glyphs_dict = dict()
    chars = 'foobar^C&#'
    for char in chars:
        # Warning that Arial might not exist
        with warnings.catch_warnings(record=True):
            warnings.simplefilter('always')
            _load_glyph(font_dict, char, glyphs_dict)
    assert len(glyphs_dict) == np.unique([c for c in chars]).size
Пример #3
0
def test_font_glyph():
    """Test loading glyphs"""
    # try both a vispy and system font
    sys_fonts = set(list_fonts()) - set(_vispy_fonts)
    assert_true(len(sys_fonts) > 0)
    for face in ('OpenSans', list(sys_fonts)[0]):
        font_dict = dict(face=face, size=12, bold=False, italic=False)
        glyphs_dict = dict()
        chars = 'foobar^C&#'
        for char in chars:
            # Warning that Arial might not exist
            _load_glyph(font_dict, char, glyphs_dict)
        assert_equal(len(glyphs_dict), np.unique([c for c in chars]).size)
Пример #4
0
def test_font_glyph():
    """Test loading glyphs"""
    # try both a vispy and system font
    sys_fonts = set(list_fonts()) - set(_vispy_fonts)
    assert_true(len(sys_fonts) > 0)
    for face in ('OpenSans', list(sys_fonts)[0]):
        font_dict = dict(face=face, size=12, bold=False, italic=False)
        glyphs_dict = dict()
        chars = 'foobar^C&#'
        if face != 'OpenSans' and os.getenv('APPVEYOR', '').lower() == 'true':
            continue  # strange system font failure
        for char in chars:
            # Warning that Arial might not exist
            _load_glyph(font_dict, char, glyphs_dict)
        assert_equal(len(glyphs_dict), np.unique([c for c in chars]).size)
Пример #5
0
def test_font_glyph():
    """Test loading glyphs"""
    # try both a vispy and system font
    sys_fonts = set(list_fonts()) - set(_vispy_fonts)
    assert_true(len(sys_fonts) > 0)
    for face in ['OpenSans'] + sorted(list(sys_fonts)):
        print(face)  # useful for debugging
        font_dict = dict(face=face, size=12, bold=False, italic=False)
        glyphs_dict = dict()
        chars = 'foobar^C&#'
        for char in chars:
            # Warning that Arial might not exist
            with warnings.catch_warnings(record=True):
                warnings.simplefilter('always')
                _load_glyph(font_dict, char, glyphs_dict)
        assert_equal(len(glyphs_dict), np.unique([c for c in chars]).size)
Пример #6
0
    def _load_char(self, char):
        """Build and store a glyph corresponding to an individual character

        Parameters
        ----------
        char : str
            A single character to be represented.
        """
        assert isinstance(char, str) and len(char) == 1
        assert char not in self._glyphs
        # load new glyph data from font
        _load_glyph(self._font, char, self._glyphs)
        # put new glyph into the texture
        glyph = self._glyphs[char]
        bitmap = glyph['bitmap']

        # convert to padded array
        data = np.zeros((bitmap.shape[0] + 2 * self._spread,
                         bitmap.shape[1] + 2 * self._spread), np.uint8)
        data[self._spread:-self._spread, self._spread:-self._spread] = bitmap

        # Store, while scaling down to proper size
        height = data.shape[0] // self.ratio
        width = data.shape[1] // self.ratio
        region = self._atlas.get_free_region(width + 2, height + 2)
        if region is None:
            raise RuntimeError('Cannot store glyph')
        x, y, w, h = region
        x, y, w, h = x + 1, y + 1, w - 2, h - 2

        self._renderer.render_to_texture(data, self._atlas, (x, y), (w, h))
        u0 = x / float(self._atlas.shape[1])
        v0 = y / float(self._atlas.shape[0])
        u1 = (x + w) / float(self._atlas.shape[1])
        v1 = (y + h) / float(self._atlas.shape[0])
        texcoords = (u0, v0, u1, v1)
        glyph.update(dict(size=(w, h), texcoords=texcoords))
Пример #7
0
glyph_size = 16
tex_width = 512
glyphs_on_a_row = tex_width // glyph_size

# Define characters to pack
ranges = [
    (0, 1),
    (32, 127),
]

# Generate glyphs
glyphs = {}
for ra in ranges:
    for i in range(ra[0], ra[1]):
        c = chr(i)
        fonts._load_glyph(font, c, glyphs)
        g = glyphs[c]
        print(c, g['bitmap'].shape, g['offset'], g['advance'])

# Prepare
atlas = np.zeros((512, tex_width), 'uint8')
atlas += 100
coords = {}

# Collect all glyphs in the atlas
for i, c in enumerate(sorted(glyphs)):
    g = glyphs[c]
    # Put in 16x16 bitmap
    try:
        ox, oy = g['offset']
        h, w = g['bitmap'].shape
Пример #8
0
glyph_size = 16
tex_width = 512
glyphs_on_a_row = tex_width // glyph_size

# Define characters to pack
ranges = [(0, 1),
          (32, 127),
         ]


# Generate glyphs
glyphs = {}
for ra in ranges:
    for i in range(ra[0], ra[1]):
        c = chr(i)
        fonts._load_glyph(font, c, glyphs)
        g = glyphs[c]
        print(c, g['bitmap'].shape, g['offset'], g['advance'])

# Prepare
atlas = np.zeros((512, tex_width), 'uint8')
atlas += 100
coords = {}

# Collect all glyphs in the atlas
for i, c in enumerate(sorted(glyphs)):
    g = glyphs[c]
    # Put in 16x16 bitmap
    try:
        ox, oy = g['offset']
        h, w = g['bitmap'].shape