Store hinting flags on the Face object
This commit is contained in:
parent
25c6735a5f
commit
5b0e2311e9
@ -102,7 +102,7 @@ def get_font_files(opts):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
n = get_font_information(get_family())
|
n = get_font_information(get_family())
|
||||||
ans['regular'] = n._replace(face=Face(n.face, n.index))
|
ans['regular'] = n._replace(face=Face(n.face, n.index, n.hinting, n.hintstyle))
|
||||||
|
|
||||||
def do(key):
|
def do(key):
|
||||||
b = get_font_information(
|
b = get_font_information(
|
||||||
@ -111,7 +111,7 @@ def get_font_files(opts):
|
|||||||
italic=key in ('italic', 'bi')
|
italic=key in ('italic', 'bi')
|
||||||
)
|
)
|
||||||
if b.face != n.face:
|
if b.face != n.face:
|
||||||
ans[key] = b._replace(face=Face(b.face, b.index))
|
ans[key] = b._replace(face=Face(b.face, b.index, b.hinting, b.hintstyle))
|
||||||
|
|
||||||
do('bold'), do('italic'), do('bi')
|
do('bold'), do('italic'), do('bi')
|
||||||
return ans
|
return ans
|
||||||
@ -119,4 +119,4 @@ def get_font_files(opts):
|
|||||||
|
|
||||||
def font_for_family(family):
|
def font_for_family(family):
|
||||||
ans = get_font_information(family)
|
ans = get_font_information(family)
|
||||||
return ans._replace(face=Face(ans.face, ans.index))
|
return ans._replace(face=Face(ans.face, ans.index, ans.hinting, ans.hintstyle))
|
||||||
|
|||||||
@ -27,7 +27,7 @@ def set_char_size(face, width=0, height=0, hres=0, vres=0):
|
|||||||
|
|
||||||
|
|
||||||
def load_char(font, face, text):
|
def load_char(font, face, text):
|
||||||
face.load_char(text, font.hinting, font.hintstyle)
|
face.load_char(ord(text[0]))
|
||||||
|
|
||||||
|
|
||||||
def calc_cell_width(font, face):
|
def calc_cell_width(font, face):
|
||||||
@ -178,7 +178,7 @@ def face_for_text(text, bold=False, italic=False):
|
|||||||
)
|
)
|
||||||
face = alt_face_cache.get(font)
|
face = alt_face_cache.get(font)
|
||||||
if face is None:
|
if face is None:
|
||||||
face = alt_face_cache[font] = Face(font.face, font.index)
|
face = alt_face_cache[font] = Face(font.face, font.index, font.hinting, font.hintstyle)
|
||||||
if face.is_scalable:
|
if face.is_scalable:
|
||||||
set_char_size(face, **cff_size)
|
set_char_size(face, **cff_size)
|
||||||
else:
|
else:
|
||||||
@ -194,7 +194,7 @@ def render_char(text, bold=False, italic=False, width=1):
|
|||||||
def render_complex_char(text, bold=False, italic=False, width=1):
|
def render_complex_char(text, bold=False, italic=False, width=1):
|
||||||
font, face = face_for_text(text, bold, italic)
|
font, face = face_for_text(text, bold, italic)
|
||||||
import pprint
|
import pprint
|
||||||
pprint.pprint(face.shape(text, font.hinting, font.hintstyle))
|
pprint.pprint(face.shape(text))
|
||||||
|
|
||||||
|
|
||||||
def place_char_in_cell(bitmap_char):
|
def place_char_in_cell(bitmap_char):
|
||||||
|
|||||||
@ -25,6 +25,7 @@ typedef struct {
|
|||||||
FT_Face face;
|
FT_Face face;
|
||||||
unsigned int units_per_EM;
|
unsigned int units_per_EM;
|
||||||
int ascender, descender, height, max_advance_width, max_advance_height, underline_position, underline_thickness;
|
int ascender, descender, height, max_advance_width, max_advance_height, underline_position, underline_thickness;
|
||||||
|
int hinting, hintstyle;
|
||||||
bool is_scalable;
|
bool is_scalable;
|
||||||
PyObject *path;
|
PyObject *path;
|
||||||
hb_buffer_t *harfbuzz_buffer;
|
hb_buffer_t *harfbuzz_buffer;
|
||||||
@ -70,10 +71,10 @@ static PyObject*
|
|||||||
new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
||||||
Face *self;
|
Face *self;
|
||||||
char *path;
|
char *path;
|
||||||
int error;
|
int error, hinting, hintstyle;
|
||||||
long index;
|
long index;
|
||||||
/* unsigned int columns=80, lines=24, scrollback=0; */
|
/* unsigned int columns=80, lines=24, scrollback=0; */
|
||||||
if (!PyArg_ParseTuple(args, "sl", &path, &index)) return NULL;
|
if (!PyArg_ParseTuple(args, "slii", &path, &index, &hinting, &hintstyle)) return NULL;
|
||||||
|
|
||||||
self = (Face *)type->tp_alloc(type, 0);
|
self = (Face *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL) {
|
if (self != NULL) {
|
||||||
@ -86,6 +87,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||||||
#undef CPY
|
#undef CPY
|
||||||
self->is_scalable = FT_IS_SCALABLE(self->face);
|
self->is_scalable = FT_IS_SCALABLE(self->face);
|
||||||
self->harfbuzz_buffer = hb_buffer_create();
|
self->harfbuzz_buffer = hb_buffer_create();
|
||||||
|
self->hinting = hinting; self->hintstyle = hintstyle;
|
||||||
if (self->harfbuzz_buffer == NULL || !hb_buffer_allocation_successful(self->harfbuzz_buffer) || !hb_buffer_pre_allocate(self->harfbuzz_buffer, 20)) { Py_CLEAR(self); return PyErr_NoMemory(); }
|
if (self->harfbuzz_buffer == NULL || !hb_buffer_allocation_successful(self->harfbuzz_buffer) || !hb_buffer_pre_allocate(self->harfbuzz_buffer, 20)) { Py_CLEAR(self); return PyErr_NoMemory(); }
|
||||||
self->harfbuzz_font = hb_ft_font_create(self->face, NULL);
|
self->harfbuzz_font = hb_ft_font_create(self->face, NULL);
|
||||||
if (self->harfbuzz_font == NULL) { Py_CLEAR(self); return PyErr_NoMemory(); }
|
if (self->harfbuzz_font == NULL) { Py_CLEAR(self); return PyErr_NoMemory(); }
|
||||||
@ -138,13 +140,12 @@ get_load_flags(int hinting, int hintstyle, int base) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
load_char(Face *self, PyObject *args) {
|
load_char(Face *self, PyObject *ch) {
|
||||||
#define load_char_doc "load_char(char, hinting, hintstyle)"
|
#define load_char_doc "load_char(char)"
|
||||||
int char_code, hinting, hintstyle, error;
|
int char_code = (int)PyLong_AsLong(ch);
|
||||||
if (!PyArg_ParseTuple(args, "Cpp", &char_code, &hinting, &hintstyle)) return NULL;
|
int flags = get_load_flags(self->hinting, self->hintstyle, FT_LOAD_RENDER);
|
||||||
int flags = get_load_flags(hinting, hintstyle, FT_LOAD_RENDER);
|
|
||||||
int glyph_index = FT_Get_Char_Index(self->face, char_code);
|
int glyph_index = FT_Get_Char_Index(self->face, char_code);
|
||||||
error = FT_Load_Glyph(self->face, glyph_index, flags);
|
int error = FT_Load_Glyph(self->face, glyph_index, flags);
|
||||||
if (error) { set_freetype_error("Failed to load glyph, with error:", error); Py_CLEAR(self); return NULL; }
|
if (error) { set_freetype_error("Failed to load glyph, with error:", error); Py_CLEAR(self); return NULL; }
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -256,10 +257,10 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
_shape(Face *self, const char *string, int len, int UNUSED hinting, int UNUSED hintstyle, ShapeData *ans) {
|
_shape(Face *self, const char *string, int len, ShapeData *ans) {
|
||||||
hb_buffer_clear_contents(self->harfbuzz_buffer);
|
hb_buffer_clear_contents(self->harfbuzz_buffer);
|
||||||
#ifdef HARBUZZ_HAS_LOAD_FLAGS
|
#ifdef HARBUZZ_HAS_LOAD_FLAGS
|
||||||
hb_ft_font_set_load_flags(self->harfbuzz_font, get_load_flags(hinting, hintstyle, FT_LOAD_DEFAULT));
|
hb_ft_font_set_load_flags(self->harfbuzz_font, get_load_flags(self->hinting, self->hintstyle, FT_LOAD_DEFAULT));
|
||||||
#endif
|
#endif
|
||||||
hb_buffer_add_utf8(self->harfbuzz_buffer, string, len, 0, len);
|
hb_buffer_add_utf8(self->harfbuzz_buffer, string, len, 0, len);
|
||||||
hb_buffer_guess_segment_properties(self->harfbuzz_buffer);
|
hb_buffer_guess_segment_properties(self->harfbuzz_buffer);
|
||||||
@ -274,13 +275,13 @@ _shape(Face *self, const char *string, int len, int UNUSED hinting, int UNUSED h
|
|||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
shape(Face *self, PyObject *args) {
|
shape(Face *self, PyObject *args) {
|
||||||
#define shape_doc "shape(text, hinting, hintstyle)"
|
#define shape_doc "shape(text)"
|
||||||
const char *string;
|
const char *string;
|
||||||
int hinting, hintstyle, len;
|
int len;
|
||||||
if (!PyArg_ParseTuple(args, "s#ii", &string, &len, &hinting, &hintstyle)) return NULL;
|
if (!PyArg_ParseTuple(args, "s#", &string, &len)) return NULL;
|
||||||
|
|
||||||
ShapeData sd;
|
ShapeData sd;
|
||||||
_shape(self, string, len, hinting, hintstyle, &sd);
|
_shape(self, string, len, &sd);
|
||||||
PyObject *ans = PyTuple_New(sd.length);
|
PyObject *ans = PyTuple_New(sd.length);
|
||||||
if (ans == NULL) return NULL;
|
if (ans == NULL) return NULL;
|
||||||
for (unsigned int i = 0; i < sd.length; i++) {
|
for (unsigned int i = 0; i < sd.length; i++) {
|
||||||
@ -351,7 +352,7 @@ static PyMemberDef members[] = {
|
|||||||
|
|
||||||
static PyMethodDef methods[] = {
|
static PyMethodDef methods[] = {
|
||||||
METHOD(set_char_size, METH_VARARGS)
|
METHOD(set_char_size, METH_VARARGS)
|
||||||
METHOD(load_char, METH_VARARGS)
|
METHOD(load_char, METH_O)
|
||||||
METHOD(shape, METH_VARARGS)
|
METHOD(shape, METH_VARARGS)
|
||||||
METHOD(get_char_index, METH_VARARGS)
|
METHOD(get_char_index, METH_VARARGS)
|
||||||
METHOD(glyph_metrics, METH_NOARGS)
|
METHOD(glyph_metrics, METH_NOARGS)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user