]> git.pld-linux.org Git - packages/XFree86.git/blob - XFree86-freetype-nointernals.patch
- oops
[packages/XFree86.git] / XFree86-freetype-nointernals.patch
1 --- XFree86-4.6.0/xc/lib/font/FreeType/ftfuncs.c.orig   2005-10-14 17:16:01.000000000 +0200
2 +++ XFree86-4.6.0/xc/lib/font/FreeType/ftfuncs.c        2006-07-19 08:16:57.502772250 +0200
3 @@ -50,10 +50,7 @@
4  #include FT_TYPE1_TABLES_H
5  #include FT_XFREE86_H
6  #include FT_BBOX_H
7 -#include FT_INTERNAL_TRUETYPE_TYPES_H
8  #include FT_TRUETYPE_TAGS_H
9 -#include FT_INTERNAL_SFNT_H
10 -#include FT_INTERNAL_STREAM_H
11  /*
12   *  If you want to use FT_Outline_Get_CBox instead of 
13   *  FT_Outline_Get_BBox, define here.
14 @@ -119,6 +116,25 @@
15  };
16  
17  
18 +/* read 2-byte value from a SFNT table */
19 +static FT_UShort
20 +sfnt_get_ushort( FT_Face     face,
21 +                 FT_ULong    table_tag,
22 +                 FT_ULong    table_offset )
23 +{
24 +  FT_Byte    buff[2];
25 +  FT_ULong   len = sizeof(buff);
26 +  FT_UShort  result = 0;
27 +
28 +  if ( !FT_Load_Sfnt_Table( face, table_tag, table_offset, buff, &len ) );
29 +    result = (FT_UShort)( (buff[0] << 8) | buff[1] );
30 +
31 +  return result;
32 +}
33 +
34 +#define  sfnt_get_short(f,t,o)  ((FT_Short)sfnt_get_ushort((f),(t),(o)))
35 +
36 +
37  static int ftypeInitP = 0;      /* is the engine initialised? */
38  static FT_Library ftypeLibrary;
39  
40 @@ -207,6 +223,10 @@
41          if(maxp && maxp->maxContours == 0)
42              face->bitmap = 1;
43      }
44 +
45 +    face->num_hmetrics = (FT_UInt) sfnt_get_ushort( face->face,
46 +                                                    TTAG_hhea, 34 );
47 +
48      /* Insert face in hashtable and return it */
49      face->next = faceTable[bucket];
50      faceTable[bucket] = face;
51 @@ -458,6 +478,34 @@
52      }
53  
54      if( FT_IS_SFNT( face->face ) ) {
55 +#if 1
56 +        FT_F26Dot6  tt_char_width, tt_char_height, tt_dim_x, tt_dim_y;
57 +        FT_UInt     nn;
58 +
59 +        instance->strike_index=0xFFFFU;
60 +
61 +        tt_char_width  = (FT_F26Dot6)(trans->scale*(1<<6) + 0.5);
62 +        tt_char_height = (FT_F26Dot6)(trans->scale*(1<<6) + 0.5);
63 +
64 +        tt_dim_x = FLOOR64( ( tt_char_width  * trans->xres + 36 ) / 72 + 32 );
65 +        tt_dim_y = FLOOR64( ( tt_char_height * trans->yres + 36 ) / 72 + 32 );
66 +
67 +       if ( tt_dim_x && !tt_dim_y )
68 +           tt_dim_y = tt_dim_x;
69 +       else if ( !tt_dim_x && tt_dim_y )
70 +           tt_dim_x = tt_dim_y;
71 +
72 +        for ( nn = 0; nn < face->face->num_fixed_sizes; nn++ )
73 +        {
74 +          FT_Bitmap_Size*  sz = &face->face->available_sizes[nn];
75 +
76 +          if ( tt_dim_x == FLOOR64(sz->x_ppem + 32) && tt_dim_y == FLOOR64(sz->y_ppem + 32) )
77 +          {
78 +            instance->strike_index = nn;
79 +            break;
80 +          }
81 +        }
82 +#else
83         /* See Set_Char_Sizes() in ttdriver.c */
84         FT_Error err;
85         TT_Face tt_face;
86 @@ -482,6 +530,7 @@
87         sfnt   = (SFNT_Service)tt_face->sfnt;
88         err = sfnt->set_sbit_strike(tt_face,tt_x_ppem,tt_y_ppem,&instance->strike_index);
89         if ( err ) instance->strike_index=0xFFFFU;
90 +#endif
91      }
92  
93      /* maintain a linked list of instances */
94 @@ -799,31 +848,61 @@
95   * parse the htmx field in TrueType font.
96   */
97  
98 -/* from src/truetype/ttgload.c */
99  static void
100 -tt_get_metrics( TT_HoriHeader*  header,
101 +tt_get_metrics( FT_Face         face,
102                 FT_UInt         idx,
103 +               FT_UInt         num_hmetrics,
104                 FT_Short*       bearing,
105                 FT_UShort*      advance )
106 -/*  Copyright 1996-2001, 2002 by                      */
107 -/*  David Turner, Robert Wilhelm, and Werner Lemberg. */
108  {
109 -    TT_LongMetrics  longs_m;
110 -    FT_UShort       k = header->number_Of_HMetrics;
111 +   /* read the metrics directly from the horizontal header, we
112 +    * parse the SFNT table directly through the standard FreeType API.
113 +    * this works with any version of the library and doesn't need to
114 +    * peek at its internals. Maybe a bit less
115 +    */
116 +    FT_UInt  count  = num_hmetrics;
117 +    FT_ULong length = 0;
118 +    FT_ULong offset = 0;
119 +    FT_Error error;
120  
121 -    if ( k == 0 ) {
122 -       *bearing = *advance = 0;
123 -       return;
124 -    }
125 +    error = FT_Load_Sfnt_Table( face, TTAG_hmtx, 0, NULL, &length );
126  
127 -    if ( idx < (FT_UInt)k ) {
128 -       longs_m  = (TT_LongMetrics )header->long_metrics + idx;
129 -       *bearing = longs_m->bearing;
130 -       *advance = longs_m->advance;
131 +    if ( count == 0 || error )
132 +    {
133 +      *advance = 0;
134 +      *bearing = 0;
135 +    }
136 +    else if ( idx < count )
137 +    {
138 +       offset = idx * 4L;
139 +       if ( offset + 4 > length )
140 +       {
141 +           *advance = 0;
142 +           *bearing = 0;
143 +       }
144 +       else
145 +       {
146 +           *advance = sfnt_get_ushort( face, TTAG_hmtx, offset );
147 +           *bearing = sfnt_get_short ( face, TTAG_hmtx, offset+2 );
148 +       }
149 +    }
150 +    else
151 +    {
152 +       offset = 4L * (count - 1);
153 +       if ( offset + 4 > length )
154 +       {
155 +           *advance = 0;
156 +           *bearing = 0;
157 +       }
158 +       else
159 +       {
160 +           *advance = sfnt_get_ushort ( face, TTAG_hmtx, offset );
161 +           offset += 4 + 2 * ( idx - count );
162 +           if ( offset + 2 > length)
163 +               *bearing = 0;
164 +           else
165 +               *bearing = sfnt_get_short ( face, TTAG_hmtx, offset );
166      }
167 -    else {
168 -       *bearing = ((TT_ShortMetrics*)header->short_metrics)[idx - k];
169 -       *advance = ((TT_LongMetrics )header->long_metrics)[k - 1].advance;
170      }
171  }
172  
173 @@ -831,6 +910,7 @@
174  ft_get_very_lazy_bbox( FT_UInt index,
175                        FT_Face face,
176                        FT_Size size,
177 +                      FT_UInt num_hmetrics,
178                        double slant,
179                        FT_Matrix *matrix,
180                        FT_BBox *bbox,
181 @@ -838,15 +918,14 @@
182                        FT_Long *vertAdvance)
183  {
184      if ( FT_IS_SFNT( face ) ) {
185 -       TT_Face   ttface = (TT_Face)face;
186         FT_Size_Metrics *smetrics = &size->metrics;
187         FT_Short  leftBearing = 0;
188         FT_UShort advance = 0;
189         FT_Vector p0, p1, p2, p3;
190  
191         /* horizontal */
192 -       tt_get_metrics(&ttface->horizontal, index,
193 -                      &leftBearing, &advance);
194 +       tt_get_metrics( face, index, num_hmetrics,
195 +                      &leftBearing, &advance );
196  
197  #if 0
198         fprintf(stderr,"x_scale=%f y_scale=%f\n",
199 @@ -903,8 +982,30 @@
200  
201  static FT_Error
202  FT_Do_SBit_Metrics( FT_Face ft_face, FT_Size ft_size, FT_ULong strike_index,
203 -                   FT_UShort glyph_index, FT_Glyph_Metrics *metrics_return )
204 +                   FT_UShort glyph_index, FT_Glyph_Metrics *metrics_return,
205 +                   int *sbitchk_incomplete_but_exist )
206  {
207 +#if 1
208 +    if ( strike_index != 0xFFFFU && ft_face->available_sizes != NULL )
209 +    {
210 +      FT_Error         error;
211 +      FT_Bitmap_Size*  sz = &ft_face->available_sizes[strike_index];
212 +
213 +      error = FT_Set_Pixel_Sizes( ft_face, sz->x_ppem/64, sz->y_ppem/64 );
214 +      if ( !error )
215 +      {
216 +        error = FT_Load_Glyph( ft_face, glyph_index, FT_LOAD_SBITS_ONLY );
217 +        if ( !error )
218 +        {
219 +          if ( metrics_return != NULL )
220 +            *metrics_return = ft_face->glyph->metrics;
221 +
222 +          return 0;
223 +        }
224 +      }
225 +    }
226 +    return -1;
227 +#elif (FREETYPE_VERSION >= 2001008)
228      SFNT_Service       sfnt;
229      TT_Face            face;
230      FT_Error           error;
231 @@ -925,7 +1026,8 @@
232      face = (TT_Face)ft_face;
233      sfnt   = (SFNT_Service)face->sfnt;
234  
235 -    if ( strike_index != 0xFFFFU && sfnt->load_sbits ) {
236 +    if (strike_index != 0xFFFFU && sfnt && sfnt->find_sbit_image &&
237 +            sfnt->load_sbits) {
238          /* Check whether there is a glyph sbit for the current index */
239          error = sfnt->find_sbit_image( face, glyph_index, strike_index,
240                                         &range, &strike, &glyph_offset );
241 @@ -968,6 +1070,17 @@
242  
243    Exit:
244        return error;
245 +#else  /* if (FREETYPE_VERSION < 2001008) */
246 +    TT_Face            face;
247 +    SFNT_Service       sfnt;
248 +    if ( ! FT_IS_SFNT( ft_face ) ) return -1;
249 +    face = (TT_Face)ft_face;
250 +    sfnt = (SFNT_Service)face->sfnt;
251 +    if ( strike_index != 0xFFFFU && sfnt->load_sbits ) {
252 +        if ( sbitchk_incomplete_but_exist ) *sbitchk_incomplete_but_exist=1;
253 +    }
254 +    return -1;
255 +#endif
256  }
257  
258  int
259 @@ -986,6 +1099,7 @@
260      int dx, dy;
261      int leftSideBearing, rightSideBearing, characterWidth, rawCharacterWidth,
262          ascent, descent;
263 +    int sbitchk_incomplete_but_exist;
264      double bbox_center_raw;
265  
266      face = instance->face;
267 @@ -1014,15 +1128,17 @@
268             int new_width;
269             double ratio;
270  
271 +           sbitchk_incomplete_but_exist=0;
272             if( ! (instance->load_flags & FT_LOAD_NO_BITMAP) ) {
273                 if( FT_Do_SBit_Metrics(face->face,instance->size,instance->strike_index,
274 -                                      idx,&sbit_metrics)==0 ) {
275 +                                      idx,&sbit_metrics,&sbitchk_incomplete_but_exist)==0 ) {
276                     bitmap_metrics = &sbit_metrics;
277                 }
278             }
279             if( bitmap_metrics == NULL ) {
280 -               if ( instance->ttcap.flags & TTCAP_IS_VERY_LAZY ) {
281 +               if ( sbitchk_incomplete_but_exist==0 && (instance->ttcap.flags & TTCAP_IS_VERY_LAZY) ) {
282                     if( ft_get_very_lazy_bbox( idx, face->face, instance->size, 
283 +                                              face->num_hmetrics,
284                                                instance->ttcap.vl_slant,
285                                                &instance->transformation.matrix,
286                                                &bbox, &outline_hori_advance, 
287 @@ -1040,6 +1156,8 @@
288             }
289  
290             if( bitmap_metrics ) {
291 +               FT_Pos factor;
292 +               
293                 leftSideBearing = bitmap_metrics->horiBearingX / 64;
294                 rightSideBearing = (bitmap_metrics->width + bitmap_metrics->horiBearingX) / 64;
295                 bbox_center_raw = (2.0 * bitmap_metrics->horiBearingX + bitmap_metrics->width)/2.0/64.0;
296 @@ -1062,8 +1180,8 @@
297                 rightSideBearing += instance->ttcap.rsbShiftOfBitmapAutoItalic;
298                 leftSideBearing  += instance->ttcap.lsbShiftOfBitmapAutoItalic;
299                 /* */
300 -               rawCharacterWidth =
301 -                   (unsigned short)(short)(floor(1000 * bitmap_metrics->horiAdvance 
302 +               factor = bitmap_metrics->horiAdvance;
303 +               rawCharacterWidth = (unsigned short)(short)(floor(1000 * factor
304                                                   * instance->ttcap.scaleBBoxWidth * ratio / 64.
305                                                   / instance->pixel_size));
306             }
307 @@ -1155,14 +1273,16 @@
308      else if( flags & FT_FORCE_CONSTANT_SPACING ) correct=1;
309      else{
310         int sbit_available=0;
311 +       sbitchk_incomplete_but_exist=0;
312         if( !(instance->load_flags & FT_LOAD_NO_BITMAP) ) {
313             if( FT_Do_SBit_Metrics(face->face,instance->size,
314 -                                  instance->strike_index,idx,NULL)==0 ) {
315 +                                  instance->strike_index,idx,NULL,
316 +                                  &sbitchk_incomplete_but_exist)==0 ) {
317                 sbit_available=1;
318             }
319         }
320         if( sbit_available == 0 ) {
321 -           if ( instance->ttcap.flags & TTCAP_IS_VERY_LAZY ) {
322 +           if ( sbitchk_incomplete_but_exist==0 && (instance->ttcap.flags & TTCAP_IS_VERY_LAZY) ) {
323                 if( FT_IS_SFNT(face->face) ) correct=1;
324             }
325         }
326 @@ -1183,10 +1303,27 @@
327         }
328  
329         if( face->face->glyph->format != FT_GLYPH_FORMAT_BITMAP ) {
330 +#ifdef USE_GET_CBOX
331 +           FT_Outline_Get_CBox(&face->face->glyph->outline, &bbox);
332 +           ftrc = 0;
333 +#else
334 +           ftrc = FT_Outline_Get_BBox(&face->face->glyph->outline, &bbox);
335 +#endif
336 +           if( ftrc != 0 ) return FTtoXReturnCode(ftrc);
337 +           bbox.yMin = FLOOR64( bbox.yMin );
338 +           bbox.yMax = CEIL64 ( bbox.yMax );
339 +           ht_actual = ( bbox.yMax - bbox.yMin ) >> 6;
340 +           /* FreeType think a glyph with 0 height control box is invalid. 
341 +            * So just let X to create a empty bitmap instead. */
342 +           if ( ht_actual == 0 )
343 +               is_outline = -1;
344 +           else
345 +           {
346             ftrc = FT_Render_Glyph(face->face->glyph,FT_RENDER_MODE_MONO);
347             if( ftrc != 0 ) return FTtoXReturnCode(ftrc);
348             is_outline = 1;
349         }
350 +       }
351         else{
352             is_outline=0;
353         }
354 @@ -1197,6 +1334,7 @@
355         if( is_outline == 1 ){
356             if( correct ){
357                 if( ft_get_very_lazy_bbox( idx, face->face, instance->size, 
358 +                                          face->num_hmetrics,
359                                            instance->ttcap.vl_slant,
360                                            &instance->transformation.matrix,
361                                            &bbox, &outline_hori_advance, 
362 --- XFree86-4.6.0/xc/lib/font/FreeType/ftfuncs.h.orig   2004-04-14 17:32:43.000000000 +0200
363 +++ XFree86-4.6.0/xc/lib/font/FreeType/ftfuncs.h        2006-07-19 08:17:53.774289000 +0200
364 @@ -47,6 +47,7 @@
365      char *filename;
366      FT_Face face;
367      int bitmap;
368 +    FT_UInt num_hmetrics;
369      struct _FTInstance *instances;
370      struct _FTInstance *active_instance;
371      struct _FTFace *next;       /* link to next face in bucket */
372 --- XFree86-4.6.0/xc/programs/fonttosfnt/util.c.orig    2005-02-07 02:01:16.000000000 +0100
373 +++ XFree86-4.6.0/xc/programs/fonttosfnt/util.c 2006-07-19 17:46:00.392569500 +0200
374 @@ -34,7 +34,6 @@
375  
376  #include <ft2build.h>
377  #include FT_FREETYPE_H
378 -#include FT_INTERNAL_OBJECTS_H
379  #include FT_BDF_H
380  #include "X11/Xos.h"
381  #include "fonttosfnt.h"
This page took 0.060564 seconds and 3 git commands to generate.