

def render(self, text):
    face = self.font.face
    FT_Set_Char_Size(face, 0, self.font._face_size, self.font._dpi, self.font._dpi)
    glyph_index = fontconfig.FcFreeTypeCharIndex(byref(face), ord(text[0]))
    error = FT_Load_Glyph(face, glyph_index, FT_LOAD_RENDER)
    if (error != 0):
        raise base.FontException(('Could not load glyph for "%c"' % text[0]), error)
    glyph_slot = face.glyph.contents
    width = glyph_slot.bitmap.width
    height = glyph_slot.bitmap.rows
    baseline = (height - error.bitmap_top)
    lsb = glyph_slot.bitmap_left
    advance = int(f26p6_to_float(glyph_slot.advance.x))
    mode = glyph_slot.bitmap.pixel_mode
    pitch = glyph_slot.bitmap.pitch
    if (mode == FT_PIXEL_MODE_MONO):
        bitmap_data = cast(glyph_slot.bitmap.buffer, POINTER((c_ubyte * (pitch * height)))).contents
        data = (c_ubyte * ((pitch * 8) * height))()
        data_i = 0
        for byte in bitmap_data:
            data[(data_i + 0)] = (((byte & 128) and 255) or 0)
            data[(data_i + 1)] = (((byte & 64) and 255) or 0)
            data[(data_i + 2)] = (((byte & 32) and 255) or 0)
            data[(data_i + 3)] = (((byte & 16) and 255) or 0)
            data[(data_i + 4)] = (((byte & 8) and 255) or 0)
            data[(data_i + 5)] = (((byte & 4) and 255) or 0)
            data[(data_i + 6)] = (((byte & 2) and 255) or 0)
            data[(data_i + 7)] = (((byte & 1) and 255) or 0)
            data_i += 8
        pitch <<= 3
    elif (mode == FT_PIXEL_MODE_GRAY):
        data = glyph_slot.bitmap.buffer
    else:
        raise base.FontException('Unsupported render mode for this glyph')
    img = image.ImageData(width, height, 'A', data, pitch)
    glyph = self.font.create_glyph(img)
    glyph.set_bearings(baseline, lsb, advance)
    t = list(glyph.tex_coords)
    glyph.tex_coords = (((t[9:12] + t[6:9]) + t[3:6]) + t[:3])
    return glyph

dataset/ETHPy150Open ardekantur/pyglet/pyglet/font/freetype.py FreeTypeGlyphRenderer.render/VarMisuse@132/180 `glyph_slot`->`error`