Skip to content

Commit 3878f85

Browse files
Further (incomplete) progress
1 parent 4715685 commit 3878f85

File tree

4 files changed

+34
-36
lines changed

4 files changed

+34
-36
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def draw_markers(self, *kl, **kw):
8282

8383
def draw_path_collection(self, *kl, **kw):
8484
return self._renderer.draw_path_collection(*kl, **kw)
85-
85+
8686
def _update_methods(self):
8787
#self.draw_path = self._renderer.draw_path # see below
8888
#self.draw_markers = self._renderer.draw_markers
@@ -153,7 +153,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
153153
font.draw_glyphs_to_bitmap()
154154

155155
#print x, y, int(x), int(y), s
156-
156+
print "HELLO"
157+
print font.get_image().get_width()
158+
print "GOODBYE"
157159
self._renderer.draw_text_image(font.get_image(), int(x), int(y) + 1, angle, gc)
158160

159161
def get_text_width_height_descent(self, s, prop, ismath):

src/_backend_agg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ RendererAgg::draw_text_image(const Py::Tuple& args)
918918
}
919919
else
920920
{
921-
FT2Image *image = static_cast<FT2Image*>(image_obj.ptr());
921+
FT2Image *image = dynamic_cast<FT2Image*>(Py::getPythonExtensionBase(image_obj.ptr()));
922922
if (!image->get_buffer())
923923
{
924924
throw Py::ValueError(

src/ft2font.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ FT2Image::FT2Image(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwd
7272
resize(width, height);
7373
}
7474

75-
FT2Image* FT2Image::factory(int width, int height)
75+
Py::PythonClassObject<FT2Image> FT2Image::factory(int width, int height)
7676
{
7777
Py::Callable class_type(type());
7878
Py::Tuple args(2);
@@ -81,18 +81,18 @@ FT2Image* FT2Image::factory(int width, int height)
8181
Py::PythonClassObject<FT2Image> o = Py::PythonClassObject<FT2Image>(
8282
class_type.apply(args, Py::Dict()));
8383
Py_INCREF(o.ptr());
84-
return o.getCxxObject();
84+
return o;
8585
}
8686

8787

88-
FT2Image::~FT2Image()
89-
{
90-
_VERBOSE("FT2Image::~FT2Image");
91-
delete [] _buffer;
92-
_buffer = NULL;
93-
delete _rgbCopy;
94-
delete _rgbaCopy;
95-
}
88+
// FT2Image::~FT2Image()
89+
// {
90+
// _VERBOSE("FT2Image::~FT2Image");
91+
// delete [] _buffer;
92+
// _buffer = NULL;
93+
// delete _rgbCopy;
94+
// delete _rgbaCopy;
95+
// }
9696

9797
void
9898
FT2Image::resize(long width, long height)
@@ -348,17 +348,17 @@ FT2Image::makeRgbCopy()
348348
return;
349349
}
350350

351-
if (!_rgbCopy)
351+
if (!_rgbCopy.ptr())
352352
{
353353
_rgbCopy = factory(_width * 3, _height);
354354
}
355355
else
356356
{
357-
_rgbCopy->resize(_width * 3, _height);
357+
_rgbCopy.getCxxObject()->resize(_width * 3, _height);
358358
}
359359
unsigned char *src = _buffer;
360360
unsigned char *src_end = src + (_width * _height);
361-
unsigned char *dst = _rgbCopy->_buffer;
361+
unsigned char *dst = _rgbCopy.getCxxObject()->_buffer;
362362

363363
unsigned char tmp;
364364
while (src != src_end)
@@ -384,7 +384,7 @@ FT2Image::py_as_rgb_str(const Py::Tuple & args)
384384

385385
makeRgbCopy();
386386

387-
return _rgbCopy->py_as_str(args);
387+
return _rgbCopy.getCxxObject()->py_as_str(args);
388388
}
389389
PYCXX_VARARGS_METHOD_DECL(FT2Image, py_as_rgb_str)
390390

@@ -395,17 +395,17 @@ void FT2Image::makeRgbaCopy()
395395
return;
396396
}
397397

398-
if (!_rgbaCopy)
398+
if (_rgbaCopy.ptr())
399399
{
400400
_rgbaCopy = factory(_width * 4, _height);
401401
}
402402
else
403403
{
404-
_rgbaCopy->resize(_width * 4, _height);
404+
_rgbaCopy.getCxxObject()->resize(_width * 4, _height);
405405
}
406406
unsigned char *src = _buffer;
407407
unsigned char *src_end = src + (_width * _height);
408-
unsigned char *dst = _rgbaCopy->_buffer;
408+
unsigned char *dst = _rgbaCopy.getCxxObject()->_buffer;
409409

410410
while (src != src_end)
411411
{
@@ -430,7 +430,7 @@ FT2Image::py_as_rgba_str(const Py::Tuple & args)
430430

431431
makeRgbaCopy();
432432

433-
return _rgbaCopy->py_as_str(args);
433+
return _rgbaCopy.getCxxObject()->py_as_str(args);
434434
}
435435
PYCXX_VARARGS_METHOD_DECL(FT2Image, py_as_rgba_str)
436436

@@ -890,7 +890,6 @@ FT2Font::~FT2Font()
890890
{
891891
_VERBOSE("FT2Font::~FT2Font");
892892

893-
Py_XDECREF(image);
894893
FT_Done_Face(face);
895894

896895
for (size_t i = 0; i < glyphs.size(); i++)
@@ -927,9 +926,6 @@ FT2Font::clear(const Py::Tuple & args)
927926
_VERBOSE("FT2Font::clear");
928927
args.verify_length(0);
929928

930-
Py_XDECREF(image);
931-
image = NULL;
932-
933929
angle = 0.0;
934930

935931
pen.x = 0;
@@ -1400,8 +1396,6 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args)
14001396
size_t width = (string_bbox.xMax - string_bbox.xMin) / 64 + 2;
14011397
size_t height = (string_bbox.yMax - string_bbox.yMin) / 64 + 2;
14021398
1403-
Py_XDECREF(image);
1404-
image = NULL;
14051399
image = FT2Image::factory(width, height);
14061400
14071401
for (size_t n = 0; n < glyphs.size(); n++)
@@ -1426,7 +1420,7 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args)
14261420
FT_Int x = (FT_Int)(bitmap->left - (string_bbox.xMin / 64.));
14271421
FT_Int y = (FT_Int)((string_bbox.yMax / 64.) - bitmap->top + 1);
14281422
1429-
image->draw_bitmap(&bitmap->bitmap, x, y);
1423+
image.getCxxObject()->draw_bitmap(&bitmap->bitmap, x, y);
14301424
}
14311425
14321426
return Py::Object();
@@ -1979,10 +1973,9 @@ Py::Object
19791973
FT2Font::get_image(const Py::Tuple &args)
19801974
{
19811975
args.verify_length(0);
1982-
if (image)
1976+
if (image.ptr())
19831977
{
1984-
Py_XINCREF(image);
1985-
return Py::asObject(image);
1978+
return image;
19861979
}
19871980
throw Py::RuntimeError("You must call .set_text() before .get_image()");
19881981
}

src/ft2font.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ class FT2Image : public Py::PythonClass<FT2Image>
2727
public:
2828
// FT2Image();
2929
FT2Image(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds);
30-
virtual ~FT2Image();
31-
static FT2Image* factory(int width, int height);
30+
virtual ~FT2Image() {
31+
delete [] _buffer;
32+
_buffer = NULL;
33+
}
34+
static Py::PythonClassObject<FT2Image> factory(int width, int height);
3235

3336
static void init_type();
3437

@@ -75,8 +78,8 @@ class FT2Image : public Py::PythonClass<FT2Image>
7578
unsigned char *_buffer;
7679
unsigned long _width;
7780
unsigned long _height;
78-
FT2Image* _rgbCopy;
79-
FT2Image* _rgbaCopy;
81+
Py::PythonClassObject<FT2Image> _rgbCopy;
82+
Py::PythonClassObject<FT2Image> _rgbaCopy;
8083

8184
void makeRgbCopy();
8285
void makeRgbaCopy();
@@ -135,7 +138,7 @@ class FT2Font : public Py::PythonClass<FT2Font>
135138
Py::Object attach_file(const Py::Tuple & args);
136139
int setattro(const Py::String &name, const Py::Object &value);
137140
Py::Object getattro(const Py::String &name);
138-
FT2Image* image;
141+
Py::PythonClassObject<FT2Image> image;
139142

140143
private:
141144
Py::Dict __dict__;

0 commit comments

Comments
 (0)