Implement CTFace.__repr__
This commit is contained in:
parent
ef4010b575
commit
f4a6c42b48
@ -187,6 +187,18 @@ end:
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
repr(Face *self) {
|
||||
char buf[400] = {0};
|
||||
snprintf(buf, sizeof(buf)/sizeof(buf[0]), "ascent=%.1f, descent=%.1f, leading=%.1f, point_sz=%.1f, scaled_point_sz=%.1f, underline_position=%.1f underline_thickness=%.1f",
|
||||
(self->ascent), (self->descent), (self->leading), (self->point_sz), (self->scaled_point_sz), (self->underline_position), (self->underline_thickness));
|
||||
return PyUnicode_FromFormat(
|
||||
"Face(family=%U, full_name=%U, postscript_name=%U, units_per_em=%u, %s)",
|
||||
self->family_name, self->full_name, self->postscript_name, self->units_per_em, buf
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Boilerplate {{{
|
||||
|
||||
static PyMemberDef members[] = {
|
||||
@ -224,6 +236,7 @@ PyTypeObject Face_Type = {
|
||||
.tp_methods = methods,
|
||||
.tp_members = members,
|
||||
.tp_new = new,
|
||||
.tp_repr = (reprfunc)repr,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -76,10 +76,7 @@ def develop(family='monospace', sz=288):
|
||||
pass
|
||||
set_font_family(family, sz, ignore_dpi_failure=True)
|
||||
for (bold, italic), face in main_font.items():
|
||||
print('bold: {} italic: {} family:{} full name: {} postscript_name: {}'.format(bold, italic, face.family_name, face.full_name, face.postscript_name))
|
||||
f = main_font[(False, False)]
|
||||
for attr in 'units_per_em ascent descent leading underline_position underline_thickness scaled_point_sz'.split():
|
||||
print(attr, getattr(f, attr))
|
||||
print('bold: {} italic: {} {}'.format(bold, italic, face))
|
||||
print('cell_width: {}, cell_height: {}, baseline: {}'.format(cell_width, cell_height, baseline))
|
||||
buf, w, h = render_string()
|
||||
open('/tmp/cell.data', 'wb').write(pickle.dumps((bytearray(buf), w, h)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user