4242
4343FT_Library _ft2Library;
4444
45- FT2Image::FT2Image () :
46- _isDirty(true ),
47- _buffer(NULL ),
48- _width(0 ), _height(0 ),
49- _rgbCopy(NULL ),
50- _rgbaCopy(NULL ) {
51- _VERBOSE (" FT2Image::FT2Image" );
52- }
45+ // FT2Image::FT2Image() :
46+ // _isDirty(true),
47+ // _buffer(NULL),
48+ // _width(0), _height(0),
49+ // _rgbCopy(NULL),
50+ // _rgbaCopy(NULL) {
51+ // _VERBOSE("FT2Image::FT2Image");
52+ // }
5353
5454FT2Image::FT2Image (unsigned long width, unsigned long height) :
5555 _isDirty(true ),
@@ -65,75 +65,28 @@ FT2Image::~FT2Image() {
6565 _VERBOSE (" FT2Image::~FT2Image" );
6666 delete [] _buffer;
6767 _buffer=NULL ;
68+ delete _rgbCopy;
69+ delete _rgbaCopy;
6870}
6971
7072void FT2Image::resize (unsigned long width, unsigned long height) {
7173 size_t numBytes = width*height;
7274
73- if (_width != width || _height != height) {
75+ if (width != _width || height != _height) {
76+ if (numBytes > _width*_height) {
77+ delete [] _buffer;
78+ _buffer = new unsigned char [numBytes];
79+ }
80+
7481 _width = width;
7582 _height = height;
76-
77- delete [] _buffer;
78- _buffer = new unsigned char [numBytes];
7983 }
8084
81- for (size_t n=0 ; n<numBytes; n++)
82- _buffer[n] = 0 ;
85+ memset (_buffer, 0 , numBytes);
8386
8487 _isDirty = true ;
8588}
8689
87- char FT2Image::resize__doc__[] =
88- " resize(width, height)\n "
89- " \n "
90- " Resize the dimensions of the image (it is cleared in the process).\n "
91- ;
92- Py::Object
93- FT2Image::py_resize (const Py::Tuple & args) {
94- _VERBOSE (" FT2Image::resize" );
95-
96- args.verify_length (2 );
97-
98- long x0 = Py::Int (args[0 ]);
99- long y0 = Py::Int (args[1 ]);
100-
101- resize (x0, y0);
102-
103- return Py::Object ();
104- }
105-
106- void FT2Image::clear () {
107- _VERBOSE (" FT2Image::clear" );
108-
109- _width = 0 ;
110- _height = 0 ;
111- _isDirty = true ;
112- delete [] _buffer;
113- _buffer = NULL ;
114- if (_rgbCopy) {
115- delete _rgbCopy;
116- _rgbCopy = NULL ;
117- }
118- if (_rgbaCopy) {
119- delete _rgbaCopy;
120- _rgbaCopy = NULL ;
121- }
122- }
123- char FT2Image::clear__doc__[] =
124- " clear()\n "
125- " \n "
126- " Clear the contents of the image.\n "
127- ;
128- Py::Object
129- FT2Image::py_clear (const Py::Tuple & args) {
130- args.verify_length (0 );
131-
132- clear ();
133-
134- return Py::Object ();
135- }
136-
13790void
13891FT2Image::draw_bitmap ( FT_Bitmap* bitmap,
13992 FT_Int x,
@@ -345,9 +298,7 @@ void FT2Image::makeRgbaCopy() {
345298 unsigned char *dst = _rgbaCopy->_buffer ;
346299
347300 while (src != src_end) {
348- *dst++ = 0 ;
349- *dst++ = 0 ;
350- *dst++ = 0 ;
301+ dst += 3 ;
351302 *dst++ = *src++;
352303 }
353304}
@@ -824,8 +775,7 @@ FT2Font::clear(const Py::Tuple & args) {
824775 _VERBOSE (" FT2Font::clear" );
825776 args.verify_length (0 );
826777
827- if (image)
828- image->clear ();
778+ delete image;
829779
830780 angle = 0.0 ;
831781
@@ -1194,11 +1144,9 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) {
11941144 size_t width = (string_bbox.xMax -string_bbox.xMin ) / 64 + 2 ;
11951145 size_t height = (string_bbox.yMax -string_bbox.yMin ) / 64 + 2 ;
11961146
1197- if (!image) {
1198- image = new FT2Image (width, height);
1199- } else {
1200- image->resize (width, height);
1201- }
1147+ Py_XDECREF (image);
1148+ image = NULL ;
1149+ image = new FT2Image (width, height);
12021150
12031151 for ( size_t n = 0 ; n < glyphs.size (); n++ )
12041152 {
@@ -1764,10 +1712,6 @@ FT2Image::init_type() {
17641712 behaviors ().name (" FT2Image" );
17651713 behaviors ().doc (" FT2Image" );
17661714
1767- add_varargs_method (" clear" , &FT2Image::py_clear,
1768- FT2Image::clear__doc__);
1769- add_varargs_method (" resize" , &FT2Image::py_resize,
1770- FT2Image::resize__doc__);
17711715 add_varargs_method (" write_bitmap" , &FT2Image::py_write_bitmap,
17721716 FT2Image::write_bitmap__doc__);
17731717 add_varargs_method (" draw_rect" , &FT2Image::py_draw_rect,
0 commit comments