libXfont-1.1.0-noftinternals.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. diff -urbN libXfont-1.1.0/src/FreeType/ftfuncs.c libXfont-1.1.0.new/src/FreeType/ftfuncs.c
  2. --- xc/lib/font/FreeType/ftfuncs.c 2005-10-24 02:32:05.000000000 +0800
  3. +++ xc/lib/font/FreeType/ftfuncs.c 2006-06-25 10:56:24.221147322 +0800
  4. @@ -54,10 +54,7 @@
  5. #include FT_TYPE1_TABLES_H
  6. #include FT_XFREE86_H
  7. #include FT_BBOX_H
  8. -#include FT_INTERNAL_TRUETYPE_TYPES_H
  9. #include FT_TRUETYPE_TAGS_H
  10. -#include FT_INTERNAL_SFNT_H
  11. -#include FT_INTERNAL_STREAM_H
  12. /*
  13. * If you want to use FT_Outline_Get_CBox instead of
  14. * FT_Outline_Get_BBox, define here.
  15. @@ -123,6 +120,25 @@
  16. };
  17. +/* read 2-byte value from a SFNT table */
  18. +static FT_UShort
  19. +sfnt_get_ushort( FT_Face face,
  20. + FT_ULong table_tag,
  21. + FT_ULong table_offset )
  22. +{
  23. + FT_Byte buff[2];
  24. + FT_ULong len = sizeof(buff);
  25. + FT_UShort result = 0;
  26. +
  27. + if ( !FT_Load_Sfnt_Table( face, table_tag, table_offset, buff, &len ) );
  28. + result = (FT_UShort)( (buff[0] << 8) | buff[1] );
  29. +
  30. + return result;
  31. +}
  32. +
  33. +#define sfnt_get_short(f,t,o) ((FT_Short)sfnt_get_ushort((f),(t),(o)))
  34. +
  35. +
  36. static int ftypeInitP = 0; /* is the engine initialised? */
  37. FT_Library ftypeLibrary;
  38. @@ -211,6 +227,10 @@
  39. if(maxp && maxp->maxContours == 0)
  40. face->bitmap = 1;
  41. }
  42. +
  43. + face->num_hmetrics = (FT_UInt) sfnt_get_ushort( face->face,
  44. + TTAG_hhea, 34 );
  45. +
  46. /* Insert face in hashtable and return it */
  47. face->next = faceTable[bucket];
  48. faceTable[bucket] = face;
  49. @@ -462,6 +482,34 @@
  50. }
  51. if( FT_IS_SFNT( face->face ) ) {
  52. +#if 1
  53. + FT_F26Dot6 tt_char_width, tt_char_height, tt_dim_x, tt_dim_y;
  54. + FT_UInt nn;
  55. +
  56. + instance->strike_index=0xFFFFU;
  57. +
  58. + tt_char_width = (FT_F26Dot6)(trans->scale*(1<<6) + 0.5);
  59. + tt_char_height = (FT_F26Dot6)(trans->scale*(1<<6) + 0.5);
  60. +
  61. + tt_dim_x = FLOOR64( ( tt_char_width * trans->xres + 36 ) / 72 + 32 );
  62. + tt_dim_y = FLOOR64( ( tt_char_height * trans->yres + 36 ) / 72 + 32 );
  63. +
  64. + if ( tt_dim_x && !tt_dim_y )
  65. + tt_dim_y = tt_dim_x;
  66. + else if ( !tt_dim_x && tt_dim_y )
  67. + tt_dim_x = tt_dim_y;
  68. +
  69. + for ( nn = 0; nn < face->face->num_fixed_sizes; nn++ )
  70. + {
  71. + FT_Bitmap_Size* sz = &face->face->available_sizes[nn];
  72. +
  73. + if ( tt_dim_x == FLOOR64(sz->x_ppem + 32) && tt_dim_y == FLOOR64(sz->y_ppem + 32) )
  74. + {
  75. + instance->strike_index = nn;
  76. + break;
  77. + }
  78. + }
  79. +#else
  80. /* See Set_Char_Sizes() in ttdriver.c */
  81. FT_Error err;
  82. TT_Face tt_face;
  83. @@ -486,6 +534,7 @@
  84. sfnt = (SFNT_Service)tt_face->sfnt;
  85. err = sfnt->set_sbit_strike(tt_face,tt_x_ppem,tt_y_ppem,&instance->strike_index);
  86. if ( err ) instance->strike_index=0xFFFFU;
  87. +#endif
  88. }
  89. /* maintain a linked list of instances */
  90. @@ -803,31 +852,61 @@
  91. * parse the htmx field in TrueType font.
  92. */
  93. -/* from src/truetype/ttgload.c */
  94. static void
  95. -tt_get_metrics( TT_HoriHeader* header,
  96. +tt_get_metrics( FT_Face face,
  97. FT_UInt idx,
  98. + FT_UInt num_hmetrics,
  99. FT_Short* bearing,
  100. FT_UShort* advance )
  101. -/* Copyright 1996-2001, 2002 by */
  102. -/* David Turner, Robert Wilhelm, and Werner Lemberg. */
  103. {
  104. - TT_LongMetrics longs_m;
  105. - FT_UShort k = header->number_Of_HMetrics;
  106. + /* read the metrics directly from the horizontal header, we
  107. + * parse the SFNT table directly through the standard FreeType API.
  108. + * this works with any version of the library and doesn't need to
  109. + * peek at its internals. Maybe a bit less
  110. + */
  111. + FT_UInt count = num_hmetrics;
  112. + FT_ULong length = 0;
  113. + FT_ULong offset = 0;
  114. + FT_Error error;
  115. - if ( k == 0 ) {
  116. - *bearing = *advance = 0;
  117. - return;
  118. - }
  119. + error = FT_Load_Sfnt_Table( face, TTAG_hmtx, 0, NULL, &length );
  120. - if ( idx < (FT_UInt)k ) {
  121. - longs_m = (TT_LongMetrics )header->long_metrics + idx;
  122. - *bearing = longs_m->bearing;
  123. - *advance = longs_m->advance;
  124. + if ( count == 0 || error )
  125. + {
  126. + *advance = 0;
  127. + *bearing = 0;
  128. + }
  129. + else if ( idx < count )
  130. + {
  131. + offset = idx * 4L;
  132. + if ( offset + 4 > length )
  133. + {
  134. + *advance = 0;
  135. + *bearing = 0;
  136. + }
  137. + else
  138. + {
  139. + *advance = sfnt_get_ushort( face, TTAG_hmtx, offset );
  140. + *bearing = sfnt_get_short ( face, TTAG_hmtx, offset+2 );
  141. + }
  142. + }
  143. + else
  144. + {
  145. + offset = 4L * (count - 1);
  146. + if ( offset + 4 > length )
  147. + {
  148. + *advance = 0;
  149. + *bearing = 0;
  150. + }
  151. + else
  152. + {
  153. + *advance = sfnt_get_ushort ( face, TTAG_hmtx, offset );
  154. + offset += 4 + 2 * ( idx - count );
  155. + if ( offset + 2 > length)
  156. + *bearing = 0;
  157. + else
  158. + *bearing = sfnt_get_short ( face, TTAG_hmtx, offset );
  159. }
  160. - else {
  161. - *bearing = ((TT_ShortMetrics*)header->short_metrics)[idx - k];
  162. - *advance = ((TT_LongMetrics )header->long_metrics)[k - 1].advance;
  163. }
  164. }
  165. @@ -835,6 +914,7 @@
  166. ft_get_very_lazy_bbox( FT_UInt index,
  167. FT_Face face,
  168. FT_Size size,
  169. + FT_UInt num_hmetrics,
  170. double slant,
  171. FT_Matrix *matrix,
  172. FT_BBox *bbox,
  173. @@ -842,15 +922,14 @@
  174. FT_Long *vertAdvance)
  175. {
  176. if ( FT_IS_SFNT( face ) ) {
  177. - TT_Face ttface = (TT_Face)face;
  178. FT_Size_Metrics *smetrics = &size->metrics;
  179. FT_Short leftBearing = 0;
  180. FT_UShort advance = 0;
  181. FT_Vector p0, p1, p2, p3;
  182. /* horizontal */
  183. - tt_get_metrics(&ttface->horizontal, index,
  184. - &leftBearing, &advance);
  185. + tt_get_metrics( face, index, num_hmetrics,
  186. + &leftBearing, &advance );
  187. #if 0
  188. fprintf(stderr,"x_scale=%f y_scale=%f\n",
  189. @@ -910,7 +989,27 @@
  190. FT_UShort glyph_index, FT_Glyph_Metrics *metrics_return,
  191. int *sbitchk_incomplete_but_exist )
  192. {
  193. -#if (FREETYPE_VERSION >= 2001008)
  194. +#if 1
  195. + if ( strike_index != 0xFFFFU && ft_face->available_sizes != NULL )
  196. + {
  197. + FT_Error error;
  198. + FT_Bitmap_Size* sz = &ft_face->available_sizes[strike_index];
  199. +
  200. + error = FT_Set_Pixel_Sizes( ft_face, sz->x_ppem/64, sz->y_ppem/64 );
  201. + if ( !error )
  202. + {
  203. + error = FT_Load_Glyph( ft_face, glyph_index, FT_LOAD_SBITS_ONLY );
  204. + if ( !error )
  205. + {
  206. + if ( metrics_return != NULL )
  207. + *metrics_return = ft_face->glyph->metrics;
  208. +
  209. + return 0;
  210. + }
  211. + }
  212. + }
  213. + return -1;
  214. +#elif (FREETYPE_VERSION >= 2001008)
  215. SFNT_Service sfnt;
  216. TT_Face face;
  217. FT_Error error;
  218. @@ -1043,6 +1142,7 @@
  219. if( bitmap_metrics == NULL ) {
  220. if ( sbitchk_incomplete_but_exist==0 && (instance->ttcap.flags & TTCAP_IS_VERY_LAZY) ) {
  221. if( ft_get_very_lazy_bbox( idx, face->face, instance->size,
  222. + face->num_hmetrics,
  223. instance->ttcap.vl_slant,
  224. &instance->transformation.matrix,
  225. &bbox, &outline_hori_advance,
  226. @@ -1207,10 +1307,27 @@
  227. }
  228. if( face->face->glyph->format != FT_GLYPH_FORMAT_BITMAP ) {
  229. +#ifdef USE_GET_CBOX
  230. + FT_Outline_Get_CBox(&face->face->glyph->outline, &bbox);
  231. + ftrc = 0;
  232. +#else
  233. + ftrc = FT_Outline_Get_BBox(&face->face->glyph->outline, &bbox);
  234. +#endif
  235. + if( ftrc != 0 ) return FTtoXReturnCode(ftrc);
  236. + bbox.yMin = FLOOR64( bbox.yMin );
  237. + bbox.yMax = CEIL64 ( bbox.yMax );
  238. + ht_actual = ( bbox.yMax - bbox.yMin ) >> 6;
  239. + /* FreeType think a glyph with 0 height control box is invalid.
  240. + * So just let X to create a empty bitmap instead. */
  241. + if ( ht_actual == 0 )
  242. + is_outline = -1;
  243. + else
  244. + {
  245. ftrc = FT_Render_Glyph(face->face->glyph,FT_RENDER_MODE_MONO);
  246. if( ftrc != 0 ) return FTtoXReturnCode(ftrc);
  247. is_outline = 1;
  248. }
  249. + }
  250. else{
  251. is_outline=0;
  252. }
  253. @@ -1221,6 +1338,7 @@
  254. if( is_outline == 1 ){
  255. if( correct ){
  256. if( ft_get_very_lazy_bbox( idx, face->face, instance->size,
  257. + face->num_hmetrics,
  258. instance->ttcap.vl_slant,
  259. &instance->transformation.matrix,
  260. &bbox, &outline_hori_advance,
  261. diff -urbN libXfont-1.1.0/src/FreeType/ftfuncs.h libXfont-1.1.0.new/src/FreeType/ftfuncs.h
  262. --- xc/lib/font/FreeType/ftfuncs.h 2005-07-07 22:59:47.000000000 +0800
  263. +++ xc/lib/font/FreeType/ftfuncs.h 2006-06-21 21:05:28.533849804 +0800
  264. @@ -47,6 +47,7 @@
  265. char *filename;
  266. FT_Face face;
  267. int bitmap;
  268. + FT_UInt num_hmetrics;
  269. struct _FTInstance *instances;
  270. struct _FTInstance *active_instance;
  271. struct _FTFace *next; /* link to next face in bucket */
  272. diff -urbN libXfont-1.1.0/src/FreeType/ftsystem.c libXfont-1.1.0.new/src/FreeType/ftsystem.c
  273. --- xc/lib/font/FreeType/ftsystem.c 2005-07-09 14:36:10.000000000 +0800
  274. +++ xc/lib/font/FreeType/ftsystem.c 2006-06-21 21:05:28.534849622 +0800
  275. @@ -35,7 +35,6 @@
  276. #endif
  277. #include <ft2build.h>
  278. #include FT_CONFIG_CONFIG_H
  279. -#include FT_INTERNAL_DEBUG_H
  280. #include FT_SYSTEM_H
  281. #include FT_ERRORS_H
  282. #include FT_TYPES_H