From 49d7efd423f844fc229c52221786f9ead4824618 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 29 Jun 2022 10:09:16 +0200 Subject: [PATCH] Rename/change signature of PyGlyph_new. Unlike all other ExtensionType_new functions, PyGlyph_new is not a tp_new (https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_new) but simply a plain C function used to construct a struct from the fields of a FT2Font. Rename it to avoid confusion, and make it take a single FT2Font as argument, too (with some additional fixes for const-correctness). --- src/ft2font.h | 10 +++++----- src/ft2font_wrapper.cpp | 17 ++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/ft2font.h b/src/ft2font.h index 0863f3450b36..692be02f7ec1 100644 --- a/src/ft2font.h +++ b/src/ft2font.h @@ -93,7 +93,7 @@ class FT2Font long get_name_index(char *name); PyObject* get_path(); - FT_Face &get_face() + FT_Face const &get_face() const { return face; } @@ -101,19 +101,19 @@ class FT2Font { return image; } - FT_Glyph &get_last_glyph() + FT_Glyph const &get_last_glyph() const { return glyphs.back(); } - size_t get_last_glyph_index() + size_t get_last_glyph_index() const { return glyphs.size() - 1; } - size_t get_num_glyphs() + size_t get_num_glyphs() const { return glyphs.size(); } - long get_hinting_factor() + long get_hinting_factor() const { return hinting_factor; } diff --git a/src/ft2font_wrapper.cpp b/src/ft2font_wrapper.cpp index b265f92febf9..a35d302a75d7 100644 --- a/src/ft2font_wrapper.cpp +++ b/src/ft2font_wrapper.cpp @@ -179,8 +179,13 @@ typedef struct static PyTypeObject PyGlyphType; static PyObject * -PyGlyph_new(const FT_Face &face, const FT_Glyph &glyph, size_t ind, long hinting_factor) +PyGlyph_from_FT2Font(const FT2Font *font) { + const FT_Face &face = font->get_face(); + const FT_Glyph &glyph = font->get_last_glyph(); + size_t ind = font->get_last_glyph_index(); + long hinting_factor = font->get_hinting_factor(); + PyGlyph *self; self = (PyGlyph *)PyGlyphType.tp_alloc(&PyGlyphType, 0); @@ -625,10 +630,7 @@ static PyObject *PyFT2Font_load_char(PyFT2Font *self, PyObject *args, PyObject * CALL_CPP("load_char", (self->x->load_char(charcode, flags))); - return PyGlyph_new(self->x->get_face(), - self->x->get_last_glyph(), - self->x->get_last_glyph_index(), - self->x->get_hinting_factor()); + return PyGlyph_from_FT2Font(self->x); } const char *PyFT2Font_load_glyph__doc__ = @@ -664,10 +666,7 @@ static PyObject *PyFT2Font_load_glyph(PyFT2Font *self, PyObject *args, PyObject CALL_CPP("load_glyph", (self->x->load_glyph(glyph_index, flags))); - return PyGlyph_new(self->x->get_face(), - self->x->get_last_glyph(), - self->x->get_last_glyph_index(), - self->x->get_hinting_factor()); + return PyGlyph_from_FT2Font(self->x); } const char *PyFT2Font_get_width_height__doc__ =