Commit b9ee7370f60304da99ba3424edbfd36502e0d391

Werner Lemberg 2005-05-20T21:52:19

* docs/CHANGES: Updated. * src/base/ftbitmap.c: Don't include FT_FREETYPE_H and FT_IMAGE_H but FT_BITMAP_H. (FT_Bitmap_Copy): New function (from ftglyph.c). * include/freetype/ftbitmap.h (FT_Bitmap_Copy): New public definition. * src/base/ftglyph.c: Include FT_BITMAP_H. (ft_bitmap_copy): Move to ftbitmap.c. (ft_bitmap_glyph_init): Remove `memory' variable. Create new bitmap object if FT_GLYPH_OWN_BITMAP isn't set. (ft_bitmap_glyph_copy): Use FT_Bitmap_Copy. (ft_bitmap_glyph_done): Use FT_Bitmap_Done. (ft_outline_glyph_init): Use FT_Outline_Copy. * src/base/ftoutln.c (FT_Outline_Copy): Handle source == target. (FT_Outline_Done_Internal): Check for valid `memory' pointer. (FT_Outline_Translate, FT_Outline_Reverse, FT_Outline_Render, FT_Outline_Transform): Check for valid `outline' pointer. * src/base/ftobjs.c (FT_New_GlyphSlot): Prepend glyph slot to face->glyph, otherwise a new second glyph slot cannot be created. (FT_Done_GlyphSlot): Fix memory leak. (FT_Open_Face): Updated -- face->glyph is already managed by FT_New_GlyphSlot. * src/type42/t42objs.c (T42_GlyphSlot_Done): Updated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
diff --git a/ChangeLog b/ChangeLog
index bde26fb..5d491c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2005-05-20  Werner Lemberg  <wl@gnu.org>
+
+	* docs/CHANGES: Updated.
+
+2005-05-20  Chia I Wu  <b90201047@ntu.edu.tw>
+
+	* src/base/ftbitmap.c: Don't include FT_FREETYPE_H and FT_IMAGE_H
+	but FT_BITMAP_H.
+	(FT_Bitmap_Copy): New function (from ftglyph.c).
+
+	* include/freetype/ftbitmap.h (FT_Bitmap_Copy): New public
+	definition.
+
+	* src/base/ftglyph.c: Include FT_BITMAP_H.
+	(ft_bitmap_copy): Move to ftbitmap.c.
+	(ft_bitmap_glyph_init): Remove `memory' variable.
+	Create new bitmap object if FT_GLYPH_OWN_BITMAP isn't set.
+	(ft_bitmap_glyph_copy): Use FT_Bitmap_Copy.
+	(ft_bitmap_glyph_done): Use FT_Bitmap_Done.
+	(ft_outline_glyph_init): Use FT_Outline_Copy.
+
+	* src/base/ftoutln.c (FT_Outline_Copy): Handle source == target.
+	(FT_Outline_Done_Internal): Check for valid `memory' pointer.
+	(FT_Outline_Translate, FT_Outline_Reverse, FT_Outline_Render,
+	FT_Outline_Transform): Check for valid `outline' pointer.
+
+	* src/base/ftobjs.c (FT_New_GlyphSlot): Prepend glyph slot to
+	face->glyph, otherwise a new second glyph slot cannot be created.
+	(FT_Done_GlyphSlot): Fix memory leak.
+	(FT_Open_Face): Updated -- face->glyph is already managed by
+	FT_New_GlyphSlot.
+
+	* src/type42/t42objs.c (T42_GlyphSlot_Done): Updated.
+
 2005-05-20  Kirill Smelkov  <kirr@mns.spb.ru>
 
 	* include/freetype/ftimage.h (FT_Raster_Params),
diff --git a/docs/CHANGES b/docs/CHANGES
index 631bf39..0b5c299 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -60,9 +60,10 @@ LATEST CHANGES BETWEEN 2.1.10 and 2.1.9
       for errors in those tables while accessing them.
 
     - A new API in FT_BITMAP_H  (`FT_Bitmap_New', `FT_Bitmap_Convert',
-      `FT_Bitmap_Done')  has  been  added.   Its  use  is  to  convert
-      an FT_Bitmap structure in 1bpp, 2bpp, 4bpp, or 8bpp format  into
-      another 8bpp FT_Bitmap, probably using a different pitch.
+      `FT_Bitmap_Copy', `FT_Bitmap_Done') has been added.   Its use is
+      to convert an FT_Bitmap structure in 1bpp,  2bpp, 4bpp, or  8bpp
+      format into another 8bpp FT_Bitmap,  probably using a  different
+      pitch.
 
     - The method  how BDF and PCF  bitmap fonts  are accessed has been
       refined.   Formerly,   FT_Set_Pixel_Sizes  and  FT_Set_Char_Size
diff --git a/include/freetype/ftbitmap.h b/include/freetype/ftbitmap.h
index 8f5e23e..68218df 100644
--- a/include/freetype/ftbitmap.h
+++ b/include/freetype/ftbitmap.h
@@ -5,7 +5,7 @@
 /*    FreeType utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp */
 /*    bitmaps into 8bpp format (specification).                            */  
 /*                                                                         */
-/*  Copyright 2004 by                                                      */
+/*  Copyright 2004, 2005 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -69,6 +69,29 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
+  /*    FT_Bitmap_Copy                                                     */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Copies an bitmap into another one.                                 */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    source :: A handle to the source bitmap.                           */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    target :: A handle to the target bitmap.                           */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_EXPORT_DEF( FT_Error )
+  FT_Bitmap_Copy( FT_Library        library,
+                  const FT_Bitmap  *source,
+                  FT_Bitmap        *target);
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
   /*    FT_Bitmap_Convert                                                  */
   /*                                                                       */
   /* <Description>                                                         */
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index 9f8cbf7..6d208e6 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -5,7 +5,7 @@
 /*    FreeType utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp */
 /*    bitmaps into 8bpp format (body).                                     */
 /*                                                                         */
-/*  Copyright 2004 by                                                      */
+/*  Copyright 2004, 2005 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -18,8 +18,7 @@
 
 
 #include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_IMAGE_H
+#include FT_BITMAP_H
 #include FT_INTERNAL_OBJECTS_H
 
 
@@ -39,6 +38,65 @@
   /* documentation is in ftbitmap.h */
 
   FT_EXPORT_DEF( FT_Error )
+  FT_Bitmap_Copy( FT_Library        library,
+                  const FT_Bitmap  *source,
+                  FT_Bitmap        *target)
+  {
+    FT_Memory  memory = library->memory;
+    FT_Error   error  = FT_Err_Ok;
+    FT_Int     pitch  = source->pitch;
+    FT_ULong   size;
+
+
+    if ( source == target )
+      return FT_Err_Ok;
+
+    if ( source->buffer == NULL )
+    {
+      *target = *source;
+
+      return FT_Err_Ok;
+    }
+
+    if ( pitch < 0 )
+      pitch = -pitch;
+    size = (FT_ULong)( pitch * source->rows );
+
+    if ( target->buffer )
+    {
+      FT_Int    target_pitch = target->pitch;
+      FT_ULong  target_size;
+
+
+      if ( target_pitch < 0  )
+        target_pitch = -target_pitch;
+      target_size = (FT_ULong)( target_pitch * target->rows );
+
+      if ( target_size != size )
+        FT_QREALLOC( target->buffer, target_size, size );
+    }
+    else
+      FT_QALLOC( target->buffer, size );
+
+    if ( !error )
+    {
+      unsigned char *p;
+
+
+      p = target->buffer;
+      *target = *source;
+      target->buffer = p;
+
+      FT_MEM_COPY( target->buffer, source->buffer, size );
+    }
+
+    return error;
+  }
+
+
+  /* documentation is in ftbitmap.h */
+
+  FT_EXPORT_DEF( FT_Error )
   FT_Bitmap_Convert( FT_Library        library,
                      const FT_Bitmap  *source,
                      FT_Bitmap        *target,
diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c
index 18f5a8e..8f85510 100644
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -31,6 +31,7 @@
 #include <ft2build.h>
 #include FT_GLYPH_H
 #include FT_OUTLINE_H
+#include FT_BITMAP_H
 #include FT_INTERNAL_OBJECTS_H
 
 
@@ -114,30 +115,6 @@
   /*************************************************************************/
   /*************************************************************************/
 
-  static FT_Error
-  ft_bitmap_copy( FT_Memory   memory,
-                  FT_Bitmap*  source,
-                  FT_Bitmap*  target )
-  {
-    FT_Error  error;
-    FT_Int    pitch = source->pitch;
-    FT_ULong  size;
-
-
-    *target = *source;
-
-    if ( pitch < 0 )
-      pitch = -pitch;
-
-    size = (FT_ULong)( pitch * source->rows );
-
-    if ( !FT_ALLOC( target->buffer, size ) )
-      FT_MEM_COPY( target->buffer, source->buffer, size );
-
-    return error;
-  }
-
-
   FT_CALLBACK_DEF( FT_Error )
   ft_bitmap_glyph_init( FT_Glyph      bitmap_glyph,
                         FT_GlyphSlot  slot )
@@ -145,7 +122,6 @@
     FT_BitmapGlyph  glyph   = (FT_BitmapGlyph)bitmap_glyph;
     FT_Error        error   = FT_Err_Ok;
     FT_Library      library = FT_GLYPH( glyph )->library;
-    FT_Memory       memory  = library->memory;
 
 
     if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
@@ -154,17 +130,19 @@
       goto Exit;
     }
 
-    /* grab the bitmap in the slot - do lazy copying whenever possible */
-    glyph->bitmap = slot->bitmap;
-    glyph->left   = slot->bitmap_left;
-    glyph->top    = slot->bitmap_top;
+    glyph->left = slot->bitmap_left;
+    glyph->top  = slot->bitmap_top;
 
+    /* do lazy copying whenever possible */
     if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+    {
+      glyph->bitmap = slot->bitmap;
       slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+    }
     else
     {
-      /* copy the bitmap into a new buffer */
-      error = ft_bitmap_copy( memory, &slot->bitmap, &glyph->bitmap );
+      FT_Bitmap_New( &glyph->bitmap );
+      error = FT_Bitmap_Copy( library, &slot->bitmap, &glyph->bitmap );
     }
 
   Exit:
@@ -176,26 +154,26 @@
   ft_bitmap_glyph_copy( FT_Glyph  bitmap_source,
                         FT_Glyph  bitmap_target )
   {
-    FT_BitmapGlyph  source = (FT_BitmapGlyph)bitmap_source;
-    FT_BitmapGlyph  target = (FT_BitmapGlyph)bitmap_target;
-    FT_Memory       memory = bitmap_source->library->memory;
+    FT_Library      library = bitmap_source->library;
+    FT_BitmapGlyph  source  = (FT_BitmapGlyph)bitmap_source;
+    FT_BitmapGlyph  target  = (FT_BitmapGlyph)bitmap_target;
 
 
     target->left = source->left;
     target->top  = source->top;
 
-    return ft_bitmap_copy( memory, &source->bitmap, &target->bitmap );
+    return FT_Bitmap_Copy( library, &source->bitmap, &target->bitmap );
   }
 
 
   FT_CALLBACK_DEF( void )
   ft_bitmap_glyph_done( FT_Glyph  bitmap_glyph )
   {
-    FT_BitmapGlyph  glyph  = (FT_BitmapGlyph)bitmap_glyph;
-    FT_Memory       memory = FT_GLYPH( glyph )->library->memory;
+    FT_BitmapGlyph  glyph   = (FT_BitmapGlyph)bitmap_glyph;
+    FT_Library      library = FT_GLYPH( glyph )->library;
 
 
-    FT_FREE( glyph->bitmap.buffer );
+    FT_Bitmap_Done( library, &glyph->bitmap );
   }
 
 
@@ -261,15 +239,7 @@
     if ( error )
       goto Exit;
 
-    /* copy it */
-    FT_ARRAY_COPY( target->points, source->points, source->n_points );
-
-    FT_ARRAY_COPY( target->tags, source->tags, source->n_points );
-
-    FT_ARRAY_COPY( target->contours, source->contours, source->n_contours );
-
-    /* copy all flags, except the `FT_OUTLINE_OWNER' one */
-    target->flags = source->flags | FT_OUTLINE_OWNER;
+    FT_Outline_Copy( source, target );
 
   Exit:
     return error;
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index f8ccce7..611818a 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -348,11 +348,9 @@
     FT_GlyphSlot      slot;
 
 
-    if ( !face || !aslot || !face->driver )
+    if ( !face || !face->driver )
       return FT_Err_Invalid_Argument;
 
-    *aslot = 0;
-
     driver = face->driver;
     clazz  = driver->clazz;
     memory = driver->root.memory;
@@ -370,8 +368,15 @@
         goto Exit;
       }
 
-      *aslot = slot;
+      slot->next  = face->glyph;
+      face->glyph = slot;
+
+      if ( aslot )
+        *aslot = slot;
     }
+    else if ( aslot )
+      *aslot = 0;
+
 
   Exit:
     FT_TRACE4(( "FT_New_GlyphSlot: Return %d\n", error ));
@@ -386,26 +391,31 @@
   {
     if ( slot )
     {
-      FT_Driver      driver = slot->face->driver;
-      FT_Memory      memory = driver->root.memory;
-      FT_GlyphSlot*  parent;
-      FT_GlyphSlot   cur;
+      FT_Driver     driver = slot->face->driver;
+      FT_Memory     memory = driver->root.memory;
+      FT_GlyphSlot  prev;
+      FT_GlyphSlot  cur;
 
 
       /* Remove slot from its parent face's list */
-      parent = &slot->face->glyph;
-      cur    = *parent;
+      prev = NULL;
+      cur  = slot->face->glyph;
 
       while ( cur )
       {
         if ( cur == slot )
         {
-          *parent = cur->next;
+          if ( !prev )
+            slot->face->glyph = cur->next;
+          else
+            prev->next = cur->next;
+
           ft_glyphslot_done( slot );
           FT_FREE( slot );
           break;
         }
-        cur = cur->next;
+        prev = cur;
+        cur  = cur->next;
       }
     }
   }
@@ -1677,18 +1687,11 @@
     FT_List_Add( &face->driver->faces_list, node );
 
     /* now allocate a glyph slot object for the face */
-    {
-      FT_GlyphSlot  slot;
-
-
-      FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
+    FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
 
-      error = FT_New_GlyphSlot( face, &slot );
-      if ( error )
-        goto Fail;
-
-      face->glyph = slot;
-    }
+    error = FT_New_GlyphSlot( face, NULL );
+    if ( error )
+      goto Fail;
 
     /* finally, allocate a size object for the face */
     {
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index b0bbe18..8eed85c 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -358,6 +358,9 @@
          source->n_contours != target->n_contours )
       return FT_Err_Invalid_Argument;
 
+    if ( source == target )
+      return FT_Err_Ok;
+
     FT_ARRAY_COPY( target->points, source->points, source->n_points );
 
     FT_ARRAY_COPY( target->tags, source->tags, source->n_points );
@@ -379,7 +382,7 @@
   FT_Outline_Done_Internal( FT_Memory    memory,
                             FT_Outline*  outline )
   {
-    if ( outline )
+    if ( memory && outline )
     {
       if ( outline->flags & FT_OUTLINE_OWNER )
       {
@@ -472,6 +475,9 @@
     FT_Vector*  vec = outline->points;
 
 
+    if ( !outline )
+      return;
+
     for ( n = 0; n < outline->n_points; n++ )
     {
       vec->x += xOffset;
@@ -490,6 +496,9 @@
     FT_Int     first, last;
 
 
+    if ( !outline )
+      return;
+
     first = 0;
 
     for ( n = 0; n < outline->n_contours; n++ )
@@ -553,7 +562,7 @@
     if ( !library )
       return FT_Err_Invalid_Library_Handle;
 
-    if ( !params )
+    if ( !outline || !params )
       return FT_Err_Invalid_Argument;
 
     renderer = library->cur_renderer;
@@ -644,9 +653,15 @@
   FT_Outline_Transform( const FT_Outline*  outline,
                         const FT_Matrix*   matrix )
   {
-    FT_Vector*  vec = outline->points;
-    FT_Vector*  limit = vec + outline->n_points;
+    FT_Vector*  vec;
+    FT_Vector*  limit;
+
+
+    if ( !outline || !matrix )
+      return;
 
+    vec   = outline->points;
+    limit = vec + outline->n_points;
 
     for ( ; vec < limit; vec++ )
       FT_Vector_Transform( vec, matrix );
diff --git a/src/type42/t42objs.c b/src/type42/t42objs.c
index 8837136..d51a91c 100644
--- a/src/type42/t42objs.c
+++ b/src/type42/t42objs.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Type 42 objects manager (body).                                      */
 /*                                                                         */
-/*  Copyright 2002, 2003, 2004 by Roberto Alameda.                         */
+/*  Copyright 2002, 2003, 2004, 2005 by Roberto Alameda.                   */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
 /*  modified, and distributed under the terms of the FreeType project      */
@@ -515,21 +515,7 @@
   FT_LOCAL_DEF( void )
   T42_GlyphSlot_Done( T42_GlyphSlot slot )
   {
-    FT_Face       face    = slot->root.face;
-    T42_Face      t42face = (T42_Face)face;
-    FT_GlyphSlot  cur     = t42face->ttf_face->glyph;
-
-
-    while ( cur )
-    {
-      if ( cur == slot->ttslot )
-      {
-        FT_Done_GlyphSlot( slot->ttslot );
-        break;
-      }
-
-      cur = cur->next;
-    }
+    FT_Done_GlyphSlot( slot->ttslot );
   }