Linux: Add support for .ttc files
This commit is contained in:
parent
85e05a447d
commit
882a4f2ab3
@ -15,7 +15,7 @@ def escape_family_name(name):
|
||||
|
||||
|
||||
Font = namedtuple(
|
||||
'Font', 'face hinting hintstyle bold italic scalable outline weight slant'
|
||||
'Font', 'face hinting hintstyle bold italic scalable outline weight slant index'
|
||||
)
|
||||
|
||||
|
||||
@ -51,19 +51,19 @@ def get_font(
|
||||
query += ':slant=100'
|
||||
raw = subprocess.check_output([
|
||||
'fc-match', query, '-f',
|
||||
'%{file}\x1e%{hinting}\x1e%{hintstyle}\x1e%{scalable}\x1e%{outline}\x1e%{weight}\x1e%{slant}'
|
||||
'%{file}\x1e%{hinting}\x1e%{hintstyle}\x1e%{scalable}\x1e%{outline}\x1e%{weight}\x1e%{slant}\x1e%{index}'
|
||||
]).decode('utf-8')
|
||||
parts = raw.split('\x1e')
|
||||
try:
|
||||
path, hinting, hintstyle, scalable, outline, weight, slant = parts
|
||||
path, hinting, hintstyle, scalable, outline, weight, slant, index = parts
|
||||
except ValueError:
|
||||
path = parts[0]
|
||||
hintstyle, hinting, scalable, outline, weight, slant = 1, 'True', 'True', 'True', 100, 0
|
||||
hintstyle, hinting, scalable, outline, weight, slant, index = 1, 'True', 'True', 'True', 100, 0, 0
|
||||
return Font(
|
||||
path,
|
||||
to_bool(hinting),
|
||||
int(hintstyle), bold, italic,
|
||||
to_bool(scalable), to_bool(outline), int(weight), int(slant)
|
||||
to_bool(scalable), to_bool(outline), int(weight), int(slant), int(index)
|
||||
)
|
||||
|
||||
|
||||
@ -117,7 +117,7 @@ def get_font_files(opts):
|
||||
return ans
|
||||
|
||||
n = get_font_information(get_family())
|
||||
ans['regular'] = n._replace(face=Face(n.face))
|
||||
ans['regular'] = n._replace(face=Face(n.face, n.index))
|
||||
|
||||
def do(key):
|
||||
b = get_font_information(
|
||||
@ -126,7 +126,7 @@ def get_font_files(opts):
|
||||
italic=key in ('italic', 'bi')
|
||||
)
|
||||
if b.face != n.face:
|
||||
ans[key] = b._replace(face=Face(b.face))
|
||||
ans[key] = b._replace(face=Face(b.face, b.index))
|
||||
|
||||
do('bold'), do('italic'), do('bi')
|
||||
return ans
|
||||
|
||||
@ -132,7 +132,7 @@ def render_char(text, bold=False, italic=False, width=1):
|
||||
)
|
||||
face = alt_face_cache.get(font)
|
||||
if face is None:
|
||||
face = alt_face_cache[font] = Face(font.face)
|
||||
face = alt_face_cache[font] = Face(font.face, font.index)
|
||||
if face.is_scalable:
|
||||
set_char_size(face, **cff_size)
|
||||
bitmap = render_to_bitmap(font, face, text)
|
||||
|
||||
@ -57,13 +57,14 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
||||
Face *self;
|
||||
char *path;
|
||||
int error;
|
||||
long index;
|
||||
/* unsigned int columns=80, lines=24, scrollback=0; */
|
||||
if (!PyArg_ParseTuple(args, "s", &path)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "sl", &path, &index)) return NULL;
|
||||
|
||||
self = (Face *)type->tp_alloc(type, 0);
|
||||
if (self != NULL) {
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
error = FT_New_Face(library, path, 0, &(self->face));
|
||||
error = FT_New_Face(library, path, index, &(self->face));
|
||||
Py_END_ALLOW_THREADS;
|
||||
if(error) { set_freetype_error("Failed to load face, with error:", error); Py_CLEAR(self); return NULL; }
|
||||
#define CPY(n) self->n = self->face->n;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user