@@ -60,8 +60,8 @@ FT2Image::FT2Image(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwd
6060 _isDirty(true ),
6161 _buffer(NULL ),
6262 _width(0 ), _height(0 ),
63- _rgbCopy(NULL ),
64- _rgbaCopy(NULL )
63+ _rgbCopy(),
64+ _rgbaCopy()
6565{
6666 _VERBOSE (" FT2Image::FT2Image" );
6767
@@ -72,6 +72,12 @@ FT2Image::FT2Image(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwd
7272 resize (width, height);
7373}
7474
75+ FT2Image::~FT2Image () {
76+ delete [] _buffer;
77+ _buffer = NULL ;
78+ }
79+
80+
7581Py::PythonClassObject<FT2Image> FT2Image::factory (int width, int height)
7682{
7783 Py::Callable class_type (type ());
@@ -343,6 +349,8 @@ PYCXX_VARARGS_METHOD_DECL(FT2Image, py_as_array)
343349void
344350FT2Image::makeRgbCopy()
345351{
352+ FT2Image* rgbCopy;
353+
346354 if (!_isDirty)
347355 {
348356 return ;
@@ -351,14 +359,16 @@ FT2Image::makeRgbCopy()
351359 if (!_rgbCopy.ptr ())
352360 {
353361 _rgbCopy = factory (_width * 3 , _height);
362+ rgbCopy = Py::PythonClassObject<FT2Image>(_rgbCopy).getCxxObject ();
354363 }
355364 else
356365 {
357- _rgbCopy.getCxxObject ()->resize (_width * 3 , _height);
366+ rgbCopy = Py::PythonClassObject<FT2Image>(_rgbCopy).getCxxObject ();
367+ rgbCopy->resize (_width * 3 , _height);
358368 }
359369 unsigned char *src = _buffer;
360370 unsigned char *src_end = src + (_width * _height);
361- unsigned char *dst = _rgbCopy. getCxxObject () ->_buffer ;
371+ unsigned char *dst = rgbCopy ->_buffer ;
362372
363373 unsigned char tmp;
364374 while (src != src_end)
@@ -384,12 +394,14 @@ FT2Image::py_as_rgb_str(const Py::Tuple & args)
384394
385395 makeRgbCopy ();
386396
387- return _rgbCopy.getCxxObject ()->py_as_str (args);
397+ return Py::PythonClassObject<FT2Image>( _rgbCopy) .getCxxObject ()->py_as_str (args);
388398}
389399PYCXX_VARARGS_METHOD_DECL (FT2Image, py_as_rgb_str)
390400
391401void FT2Image::makeRgbaCopy()
392402{
403+ FT2Image* rgbaCopy;
404+
393405 if (!_isDirty)
394406 {
395407 return ;
@@ -398,14 +410,16 @@ void FT2Image::makeRgbaCopy()
398410 if (_rgbaCopy.ptr ())
399411 {
400412 _rgbaCopy = factory (_width * 4 , _height);
413+ rgbaCopy = Py::PythonClassObject<FT2Image>(_rgbaCopy).getCxxObject ();
401414 }
402415 else
403416 {
404- _rgbaCopy.getCxxObject ()->resize (_width * 4 , _height);
417+ rgbaCopy = Py::PythonClassObject<FT2Image>(_rgbaCopy).getCxxObject ();
418+ rgbaCopy->resize (_width * 4 , _height);
405419 }
406420 unsigned char *src = _buffer;
407421 unsigned char *src_end = src + (_width * _height);
408- unsigned char *dst = _rgbaCopy. getCxxObject () ->_buffer ;
422+ unsigned char *dst = rgbaCopy ->_buffer ;
409423
410424 while (src != src_end)
411425 {
@@ -430,7 +444,7 @@ FT2Image::py_as_rgba_str(const Py::Tuple & args)
430444
431445 makeRgbaCopy ();
432446
433- return _rgbaCopy.getCxxObject ()->py_as_str (args);
447+ return Py::PythonClassObject<FT2Image>( _rgbaCopy) .getCxxObject ()->py_as_str (args);
434448}
435449PYCXX_VARARGS_METHOD_DECL (FT2Image, py_as_rgba_str)
436450
@@ -454,7 +468,8 @@ FT2Image::py_get_height(const Py::Tuple & args)
454468}
455469PYCXX_VARARGS_METHOD_DECL (FT2Image, py_get_height)
456470
457- Glyph* Glyph::factory(const FT_Face& face, const FT_Glyph& glyph, size_t ind)
471+ Py::PythonClassObject<Glyph> Glyph::factory(
472+ const FT_Face& face, const FT_Glyph& glyph, size_t ind)
458473{
459474 Py::Callable class_type (type ());
460475 Py::PythonClassObject<Glyph> obj = Py::PythonClassObject<Glyph>(
@@ -485,7 +500,7 @@ Glyph* Glyph::factory(const FT_Face& face, const FT_Glyph& glyph, size_t ind)
485500 o->setattro (" bbox" , abbox);
486501 o->setattro (" path" , o->get_path (face));
487502
488- return o ;
503+ return obj ;
489504}
490505
491506Glyph::~Glyph ()
@@ -769,7 +784,7 @@ Glyph::get_path(const FT_Face& face)
769784
770785FT2Font::FT2Font (Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds) :
771786 Py::PythonClass<FT2Font>::PythonClass(self, args, kwds),
772- image(NULL )
787+ image()
773788{
774789 args.verify_length (1 );
775790 std::string facefile = Py::String (args[0 ]);
@@ -1283,8 +1298,7 @@ FT2Font::load_char(const Py::Tuple & args, const Py::Dict & kwargs)
12831298
12841299 size_t num = glyphs.size(); //the index into the glyphs list
12851300 glyphs.push_back(thisGlyph);
1286- Glyph* gm = Glyph::factory(face, thisGlyph, num);
1287- return Py::asObject(gm);
1301+ return Glyph::factory(face, thisGlyph, num);
12881302}
12891303PYCXX_KEYWORDS_METHOD_DECL(FT2Font, load_char)
12901304
@@ -1334,8 +1348,7 @@ FT2Font::load_glyph(const Py::Tuple & args, const Py::Dict & kwargs)
13341348
13351349 size_t num = glyphs.size(); //the index into the glyphs list
13361350 glyphs.push_back(thisGlyph);
1337- Glyph* gm = Glyph::factory(face, thisGlyph, num);
1338- return Py::asObject(gm);
1351+ return Glyph::factory(face, thisGlyph, num);
13391352}
13401353PYCXX_KEYWORDS_METHOD_DECL(FT2Font, load_glyph)
13411354
@@ -1420,7 +1433,8 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args)
14201433 FT_Int x = (FT_Int)(bitmap->left - (string_bbox.xMin / 64.));
14211434 FT_Int y = (FT_Int)((string_bbox.yMax / 64.) - bitmap->top + 1);
14221435
1423- image.getCxxObject()->draw_bitmap(&bitmap->bitmap, x, y);
1436+ FT2Image* image_cxx = Py::PythonClassObject<FT2Image>(image).getCxxObject();
1437+ image_cxx->draw_bitmap(&bitmap->bitmap, x, y);
14241438 }
14251439
14261440 return Py::Object();
@@ -1973,7 +1987,7 @@ Py::Object
19731987FT2Font::get_image (const Py::Tuple &args)
19741988{
19751989 args.verify_length (0 );
1976- if (image.ptr ())
1990+ if (! image.isNone ())
19771991 {
19781992 return image;
19791993 }
0 commit comments