Advertisement
Guest User

Untitled

a guest
Dec 11th, 2012
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. diff -ur /tmp/orig/_imagingft.c ./_imagingft.c
  2. --- /tmp/orig/_imagingft.c 2009-10-31 22:44:12.000000000 -0200
  3. +++ ./_imagingft.c 2012-12-12 02:30:31.000000000 -0200
  4. @@ -35,6 +35,9 @@
  5. #include <freetype/freetype.h>
  6. #endif
  7.  
  8. +#include FT_GLYPH_H
  9. +
  10. +
  11. #if PY_VERSION_HEX < 0x01060000
  12. #define PyObject_New PyObject_NEW
  13. #define PyObject_Del PyMem_DEL
  14. @@ -160,7 +163,7 @@
  15.  
  16. return (PyObject*) self;
  17. }
  18. -
  19. +
  20. static int
  21. font_getchar(PyObject* string, int index, FT_ULong* char_out)
  22. {
  23. @@ -188,7 +191,7 @@
  24. static PyObject*
  25. font_getsize(FontObject* self, PyObject* args)
  26. {
  27. - int i, x;
  28. + int i, x, y_max, y_min;
  29. FT_ULong ch;
  30. FT_Face face;
  31. int xoffset;
  32. @@ -212,6 +215,7 @@
  33.  
  34. face = NULL;
  35. xoffset = 0;
  36. + y_max = y_min = 0;
  37.  
  38. for (x = i = 0; font_getchar(string, i, &ch); i++) {
  39. int index, error;
  40. @@ -229,6 +233,16 @@
  41. if (i == 0)
  42. xoffset = face->glyph->metrics.horiBearingX;
  43. x += face->glyph->metrics.horiAdvance;
  44. +
  45. + FT_BBox bbox;
  46. + FT_Glyph glyph;
  47. + FT_Get_Glyph(face->glyph, &glyph);
  48. + FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_SUBPIXELS, &bbox);
  49. + if (bbox.yMax > y_max)
  50. + y_max = bbox.yMax;
  51. + if (bbox.yMin < y_min)
  52. + y_min = bbox.yMin;
  53. +
  54. last_index = index;
  55. }
  56.  
  57. @@ -249,7 +263,7 @@
  58.  
  59. return Py_BuildValue(
  60. "(ii)(ii)",
  61. - PIXEL(x), PIXEL(self->face->size->metrics.height),
  62. + PIXEL(x), PIXEL(y_max - y_min),
  63. PIXEL(xoffset), 0
  64. );
  65. }
  66. @@ -330,6 +344,19 @@
  67. if (mask)
  68. load_flags |= FT_LOAD_TARGET_MONO;
  69.  
  70. + int temp;
  71. + ascender = 0;
  72. + for (i = 0; font_getchar(string, i, &ch); i++) {
  73. + index = FT_Get_Char_Index(self->face, ch);
  74. + error = FT_Load_Glyph(self->face, index, load_flags);
  75. + if (error)
  76. + return geterror(error);
  77. + glyph = self->face->glyph;
  78. + temp = (glyph->bitmap.rows - glyph->bitmap_top);
  79. + if (temp > ascender)
  80. + ascender = temp;
  81. + }
  82. +
  83. for (x = i = 0; font_getchar(string, i, &ch); i++) {
  84. if (i == 0 && self->face->glyph->metrics.horiBearingX < 0)
  85. x = -PIXEL(self->face->glyph->metrics.horiBearingX);
  86. @@ -348,7 +375,6 @@
  87. /* use monochrome mask (on palette images, etc) */
  88. int xx, x0, x1;
  89. source = (unsigned char*) glyph->bitmap.buffer;
  90. - ascender = PIXEL(self->face->size->metrics.ascender);
  91. xx = x + glyph->bitmap_left;
  92. x0 = 0;
  93. x1 = glyph->bitmap.width;
  94. @@ -357,7 +383,7 @@
  95. if (xx + x1 > im->xsize)
  96. x1 = im->xsize - xx;
  97. for (y = 0; y < glyph->bitmap.rows; y++) {
  98. - int yy = y + ascender - glyph->bitmap_top;
  99. + int yy = y + im->ysize - (PIXEL(glyph->metrics.horiBearingY) + ascender);
  100. if (yy >= 0 && yy < im->ysize) {
  101. /* blend this glyph into the buffer */
  102. unsigned char *target = im->image8[yy] + xx;
  103. @@ -377,7 +403,6 @@
  104. /* use antialiased rendering */
  105. int xx, x0, x1;
  106. source = (unsigned char*) glyph->bitmap.buffer;
  107. - ascender = PIXEL(self->face->size->metrics.ascender);
  108. xx = x + glyph->bitmap_left;
  109. x0 = 0;
  110. x1 = glyph->bitmap.width;
  111. @@ -386,7 +411,7 @@
  112. if (xx + x1 > im->xsize)
  113. x1 = im->xsize - xx;
  114. for (y = 0; y < glyph->bitmap.rows; y++) {
  115. - int yy = y + ascender - glyph->bitmap_top;
  116. + int yy = y + im->ysize - (PIXEL(glyph->metrics.horiBearingY) + ascender);
  117. if (yy >= 0 && yy < im->ysize) {
  118. /* blend this glyph into the buffer */
  119. int i;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement