Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45fcd96

Browse files
committed
Remove deprecated ft2font API
1 parent 60ff012 commit 45fcd96

File tree

5 files changed

+4
-112
lines changed

5 files changed

+4
-112
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``ft2font.FT2Image.draw_rect`` and ``ft2font.FT2Font.get_xys``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... have been removed as they are unused.

lib/matplotlib/ft2font.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ class FT2Font:
224224
@overload
225225
def get_sfnt_table(self, name: Literal["pclt"]) -> _SfntPcltDict | None: ...
226226
def get_width_height(self) -> tuple[int, int]: ...
227-
def get_xys(self, antialiased: bool = ...) -> NDArray[np.float64]: ...
228227
def load_char(self, charcode: int, flags: int = ...) -> Glyph: ...
229228
def load_glyph(self, glyphindex: int, flags: int = ...) -> Glyph: ...
230229
def select_charmap(self, i: int) -> None: ...
@@ -237,7 +236,6 @@ class FT2Font:
237236
@final
238237
class FT2Image: # TODO: When updating mypy>=1.4, subclass from Buffer.
239238
def __init__(self, width: float, height: float) -> None: ...
240-
def draw_rect(self, x0: float, y0: float, x1: float, y1: float) -> None: ...
241239
def draw_rect_filled(self, x0: float, y0: float, x1: float, y1: float) -> None: ...
242240

243241
@final

src/ft2font.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,6 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
145145
m_dirty = true;
146146
}
147147

148-
void FT2Image::draw_rect(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1)
149-
{
150-
if (x0 > m_width || x1 > m_width || y0 > m_height || y1 > m_height) {
151-
throw std::runtime_error("Rect coords outside image bounds");
152-
}
153-
154-
size_t top = y0 * m_width;
155-
size_t bottom = y1 * m_width;
156-
for (size_t i = x0; i < x1 + 1; ++i) {
157-
m_buffer[i + top] = 255;
158-
m_buffer[i + bottom] = 255;
159-
}
160-
161-
for (size_t j = y0 + 1; j < y1; ++j) {
162-
m_buffer[x0 + j * m_width] = 255;
163-
m_buffer[x1 + j * m_width] = 255;
164-
}
165-
166-
m_dirty = true;
167-
}
168-
169148
void
170149
FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1)
171150
{
@@ -716,29 +695,6 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
716695
}
717696
}
718697

719-
void FT2Font::get_xys(bool antialiased, std::vector<double> &xys)
720-
{
721-
for (size_t n = 0; n < glyphs.size(); n++) {
722-
723-
FT_Error error = FT_Glyph_To_Bitmap(
724-
&glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
725-
if (error) {
726-
throw_ft_error("Could not convert glyph to bitmap", error);
727-
}
728-
729-
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
730-
731-
// bitmap left and top in pixel, string bbox in subpixel
732-
FT_Int x = (FT_Int)(bitmap->left - bbox.xMin * (1. / 64.));
733-
FT_Int y = (FT_Int)(bbox.yMax * (1. / 64.) - bitmap->top + 1);
734-
// make sure the index is non-neg
735-
x = x < 0 ? 0 : x;
736-
y = y < 0 ? 0 : y;
737-
xys.push_back(x);
738-
xys.push_back(y);
739-
}
740-
}
741-
742698
void FT2Font::draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd, bool antialiased)
743699
{
744700
FT_Vector sub_offset;

src/ft2font.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class FT2Image
4141

4242
void resize(long width, long height);
4343
void draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y);
44-
void draw_rect(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1);
4544
void draw_rect_filled(unsigned long x0, unsigned long y0, unsigned long x1, unsigned long y1);
4645

4746
unsigned char *get_buffer()
@@ -104,9 +103,6 @@ class FT2Font
104103
void get_width_height(long *width, long *height);
105104
void get_bitmap_offset(long *x, long *y);
106105
long get_descent();
107-
// TODO: Since we know the size of the array upfront, we probably don't
108-
// need to dynamically allocate like this
109-
void get_xys(bool antialiased, std::vector<double> &xys);
110106
void draw_glyphs_to_bitmap(bool antialiased);
111107
void draw_glyph_to_bitmap(FT2Image &im, int x, int y, size_t glyphInd, bool antialiased);
112108
void get_glyph_name(unsigned int glyph_number, std::string &buffer, bool fallback);

src/ft2font_wrapper.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,6 @@ static void PyFT2Image_dealloc(PyFT2Image *self)
6363
Py_TYPE(self)->tp_free((PyObject *)self);
6464
}
6565

66-
const char *PyFT2Image_draw_rect__doc__ =
67-
"draw_rect(self, x0, y0, x1, y1)\n"
68-
"--\n\n"
69-
"Draw an empty rectangle to the image.\n"
70-
"\n"
71-
".. deprecated:: 3.8\n";
72-
;
73-
74-
static PyObject *PyFT2Image_draw_rect(PyFT2Image *self, PyObject *args)
75-
{
76-
char const* msg =
77-
"FT2Image.draw_rect is deprecated since Matplotlib 3.8 and will be removed "
78-
"in Matplotlib 3.10 as it is not used in the library. If you rely on it, "
79-
"please let us know.";
80-
if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1)) {
81-
return NULL;
82-
}
83-
84-
double x0, y0, x1, y1;
85-
86-
if (!PyArg_ParseTuple(args, "dddd:draw_rect", &x0, &y0, &x1, &y1)) {
87-
return NULL;
88-
}
89-
90-
CALL_CPP("draw_rect", (self->x->draw_rect(x0, y0, x1, y1)));
91-
92-
Py_RETURN_NONE;
93-
}
94-
9566
const char *PyFT2Image_draw_rect_filled__doc__ =
9667
"draw_rect_filled(self, x0, y0, x1, y1)\n"
9768
"--\n\n"
@@ -137,7 +108,6 @@ static int PyFT2Image_get_buffer(PyFT2Image *self, Py_buffer *buf, int flags)
137108
static PyTypeObject* PyFT2Image_init_type()
138109
{
139110
static PyMethodDef methods[] = {
140-
{"draw_rect", (PyCFunction)PyFT2Image_draw_rect, METH_VARARGS, PyFT2Image_draw_rect__doc__},
141111
{"draw_rect_filled", (PyCFunction)PyFT2Image_draw_rect_filled, METH_VARARGS, PyFT2Image_draw_rect_filled__doc__},
142112
{NULL}
143113
};
@@ -856,37 +826,6 @@ static PyObject *PyFT2Font_draw_glyphs_to_bitmap(PyFT2Font *self, PyObject *args
856826
Py_RETURN_NONE;
857827
}
858828

859-
const char *PyFT2Font_get_xys__doc__ =
860-
"get_xys(self, antialiased=True)\n"
861-
"--\n\n"
862-
"Get the xy locations of the current glyphs.\n"
863-
"\n"
864-
".. deprecated:: 3.8\n";
865-
866-
static PyObject *PyFT2Font_get_xys(PyFT2Font *self, PyObject *args, PyObject *kwds)
867-
{
868-
char const* msg =
869-
"FT2Font.get_xys is deprecated since Matplotlib 3.8 and will be removed in "
870-
"Matplotlib 3.10 as it is not used in the library. If you rely on it, "
871-
"please let us know.";
872-
if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1)) {
873-
return NULL;
874-
}
875-
876-
bool antialiased = true;
877-
std::vector<double> xys;
878-
const char *names[] = { "antialiased", NULL };
879-
880-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&:get_xys",
881-
(char **)names, &convert_bool, &antialiased)) {
882-
return NULL;
883-
}
884-
885-
CALL_CPP("get_xys", (self->x->get_xys(antialiased, xys)));
886-
887-
return convert_xys_to_array(xys);
888-
}
889-
890829
const char *PyFT2Font_draw_glyph_to_bitmap__doc__ =
891830
"draw_glyph_to_bitmap(self, image, x, y, glyph, antialiased=True)\n"
892831
"--\n\n"
@@ -1517,7 +1456,6 @@ static PyTypeObject *PyFT2Font_init_type()
15171456
{"get_bitmap_offset", (PyCFunction)PyFT2Font_get_bitmap_offset, METH_NOARGS, PyFT2Font_get_bitmap_offset__doc__},
15181457
{"get_descent", (PyCFunction)PyFT2Font_get_descent, METH_NOARGS, PyFT2Font_get_descent__doc__},
15191458
{"draw_glyphs_to_bitmap", (PyCFunction)PyFT2Font_draw_glyphs_to_bitmap, METH_VARARGS|METH_KEYWORDS, PyFT2Font_draw_glyphs_to_bitmap__doc__},
1520-
{"get_xys", (PyCFunction)PyFT2Font_get_xys, METH_VARARGS|METH_KEYWORDS, PyFT2Font_get_xys__doc__},
15211459
{"draw_glyph_to_bitmap", (PyCFunction)PyFT2Font_draw_glyph_to_bitmap, METH_VARARGS|METH_KEYWORDS, PyFT2Font_draw_glyph_to_bitmap__doc__},
15221460
{"get_glyph_name", (PyCFunction)PyFT2Font_get_glyph_name, METH_VARARGS, PyFT2Font_get_glyph_name__doc__},
15231461
{"get_charmap", (PyCFunction)PyFT2Font_get_charmap, METH_NOARGS, PyFT2Font_get_charmap__doc__},

0 commit comments

Comments
 (0)