Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -ur /tmp/orig/_imagingft.c ./_imagingft.c
- --- /tmp/orig/_imagingft.c 2009-10-31 22:44:12.000000000 -0200
- +++ ./_imagingft.c 2012-12-12 02:30:31.000000000 -0200
- @@ -35,6 +35,9 @@
- #include <freetype/freetype.h>
- #endif
- +#include FT_GLYPH_H
- +
- +
- #if PY_VERSION_HEX < 0x01060000
- #define PyObject_New PyObject_NEW
- #define PyObject_Del PyMem_DEL
- @@ -160,7 +163,7 @@
- return (PyObject*) self;
- }
- -
- +
- static int
- font_getchar(PyObject* string, int index, FT_ULong* char_out)
- {
- @@ -188,7 +191,7 @@
- static PyObject*
- font_getsize(FontObject* self, PyObject* args)
- {
- - int i, x;
- + int i, x, y_max, y_min;
- FT_ULong ch;
- FT_Face face;
- int xoffset;
- @@ -212,6 +215,7 @@
- face = NULL;
- xoffset = 0;
- + y_max = y_min = 0;
- for (x = i = 0; font_getchar(string, i, &ch); i++) {
- int index, error;
- @@ -229,6 +233,16 @@
- if (i == 0)
- xoffset = face->glyph->metrics.horiBearingX;
- x += face->glyph->metrics.horiAdvance;
- +
- + FT_BBox bbox;
- + FT_Glyph glyph;
- + FT_Get_Glyph(face->glyph, &glyph);
- + FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_SUBPIXELS, &bbox);
- + if (bbox.yMax > y_max)
- + y_max = bbox.yMax;
- + if (bbox.yMin < y_min)
- + y_min = bbox.yMin;
- +
- last_index = index;
- }
- @@ -249,7 +263,7 @@
- return Py_BuildValue(
- "(ii)(ii)",
- - PIXEL(x), PIXEL(self->face->size->metrics.height),
- + PIXEL(x), PIXEL(y_max - y_min),
- PIXEL(xoffset), 0
- );
- }
- @@ -330,6 +344,19 @@
- if (mask)
- load_flags |= FT_LOAD_TARGET_MONO;
- + int temp;
- + ascender = 0;
- + for (i = 0; font_getchar(string, i, &ch); i++) {
- + index = FT_Get_Char_Index(self->face, ch);
- + error = FT_Load_Glyph(self->face, index, load_flags);
- + if (error)
- + return geterror(error);
- + glyph = self->face->glyph;
- + temp = (glyph->bitmap.rows - glyph->bitmap_top);
- + if (temp > ascender)
- + ascender = temp;
- + }
- +
- for (x = i = 0; font_getchar(string, i, &ch); i++) {
- if (i == 0 && self->face->glyph->metrics.horiBearingX < 0)
- x = -PIXEL(self->face->glyph->metrics.horiBearingX);
- @@ -348,7 +375,6 @@
- /* use monochrome mask (on palette images, etc) */
- int xx, x0, x1;
- source = (unsigned char*) glyph->bitmap.buffer;
- - ascender = PIXEL(self->face->size->metrics.ascender);
- xx = x + glyph->bitmap_left;
- x0 = 0;
- x1 = glyph->bitmap.width;
- @@ -357,7 +383,7 @@
- if (xx + x1 > im->xsize)
- x1 = im->xsize - xx;
- for (y = 0; y < glyph->bitmap.rows; y++) {
- - int yy = y + ascender - glyph->bitmap_top;
- + int yy = y + im->ysize - (PIXEL(glyph->metrics.horiBearingY) + ascender);
- if (yy >= 0 && yy < im->ysize) {
- /* blend this glyph into the buffer */
- unsigned char *target = im->image8[yy] + xx;
- @@ -377,7 +403,6 @@
- /* use antialiased rendering */
- int xx, x0, x1;
- source = (unsigned char*) glyph->bitmap.buffer;
- - ascender = PIXEL(self->face->size->metrics.ascender);
- xx = x + glyph->bitmap_left;
- x0 = 0;
- x1 = glyph->bitmap.width;
- @@ -386,7 +411,7 @@
- if (xx + x1 > im->xsize)
- x1 = im->xsize - xx;
- for (y = 0; y < glyph->bitmap.rows; y++) {
- - int yy = y + ascender - glyph->bitmap_top;
- + int yy = y + im->ysize - (PIXEL(glyph->metrics.horiBearingY) + ascender);
- if (yy >= 0 && yy < im->ysize) {
- /* blend this glyph into the buffer */
- int i;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement