[cairo-commit] cairo/src cairo.h,1.22,1.23 cairo_ft_font.c,1.5,1.6

Carl Worth commit at pdx.freedesktop.org
Thu Oct 30 12:39:51 PST 2003


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory pdx:/tmp/cvs-serv13559/src

Modified Files:
	cairo.h cairo_ft_font.c 
Log Message:
* src/cairo_ft_font.c: A set of changes to eliminate the static
FT_Library field, (which could introduce nasty problems with
respect to threading). With the new code, each font created with
the toy API will own its own FT_Library. Meanwhile,
cairo_ft_font_create now accepts an FT_Library parameter.

Bumped version number to 0.1.9

Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** cairo.h	28 Oct 2003 20:15:03 -0000	1.22
--- cairo.h	30 Oct 2003 20:39:49 -0000	1.23
***************
*** 434,438 ****
  
  extern cairo_font_t * __external_linkage
! cairo_ft_font_create (FcPattern *pattern);
  
  extern cairo_font_t * __external_linkage
--- 434,438 ----
  
  extern cairo_font_t * __external_linkage
! cairo_ft_font_create (FT_Library ft_library, FcPattern *pattern);
  
  extern cairo_font_t * __external_linkage

Index: cairo_ft_font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_ft_font.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** cairo_ft_font.c	30 Oct 2003 18:55:04 -0000	1.5
--- cairo_ft_font.c	30 Oct 2003 20:39:49 -0000	1.6
***************
*** 29,35 ****
  
  typedef struct {
!     cairo_font_t base;  
      FT_Face face;
!     int owner_of_face_p;
      FcPattern *pattern;
  } cairo_ft_font_t;
--- 29,40 ----
  
  typedef struct {
!     cairo_font_t base;
! 
!     FT_Library ft_library;
!     int owns_ft_library;
! 
      FT_Face face;
!     int owns_face;
! 
      FcPattern *pattern;
  } cairo_ft_font_t;
***************
*** 43,75 ****
  			      + ((double)((t) & 0xFFFF) / 65535.0))
  
- static FT_Library _cairo_ft_lib = NULL;
- static int
- _init_cairo_ft_lib (void)
- {
-     if (_cairo_ft_lib != NULL)
-         return 1;
-     
-     if (FT_Init_FreeType (&_cairo_ft_lib) == 0
-         && _cairo_ft_lib != NULL)
-         return 1;
-     
-     return 0;  
- }
- 
  /* implement the platform-specific interface */
  
  cairo_font_t *
! cairo_ft_font_create (FcPattern *pattern)
  {
      cairo_ft_font_t *f = NULL;
      char *filename = NULL;
      FT_Face face = NULL;
!     int own_face = 0;
      FcPattern *resolved = NULL;
      FcResult result = FcResultMatch;
      
-     if (!_init_cairo_ft_lib ())
-         return NULL;
-     
      FcConfigSubstitute (0, pattern, FcMatchPattern);
      FcDefaultSubstitute (pattern);
--- 48,63 ----
  			      + ((double)((t) & 0xFFFF) / 65535.0))
  
  /* implement the platform-specific interface */
  
  cairo_font_t *
! cairo_ft_font_create (FT_Library ft_library, FcPattern *pattern)
  {
      cairo_ft_font_t *f = NULL;
      char *filename = NULL;
      FT_Face face = NULL;
!     int owns_face = 0;
      FcPattern *resolved = NULL;
      FcResult result = FcResultMatch;
      
      FcConfigSubstitute (0, pattern, FcMatchPattern);
      FcDefaultSubstitute (pattern);
***************
*** 90,98 ****
          /* otherwise it had better have a filename */
          int open_res = 0;
!         own_face = 1;
          result = FcPatternGetString (resolved, FC_FILE, 0, (FcChar8 **)(&filename));
        
          if (result == FcResultMatch)
!             open_res = FT_New_Face (_cairo_ft_lib, filename, 0, &face);
        
          if (face == NULL)
--- 78,86 ----
          /* otherwise it had better have a filename */
          int open_res = 0;
!         owns_face = 1;
          result = FcPatternGetString (resolved, FC_FILE, 0, (FcChar8 **)(&filename));
        
          if (result == FcResultMatch)
!             open_res = FT_New_Face (ft_library, filename, 0, &face);
        
          if (face == NULL)
***************
*** 104,108 ****
          f->pattern = FcPatternDuplicate (resolved);
  
!     f->owner_of_face_p = own_face;
  
      FcPatternDestroy (resolved);
--- 92,99 ----
          f->pattern = FcPatternDuplicate (resolved);
  
!     f->ft_library = ft_library;
!     f->owns_ft_library = 0;
! 
!     f->owns_face = owns_face;
  
      FcPatternDestroy (resolved);
***************
*** 142,145 ****
--- 133,138 ----
      int fcslant;
      int fcweight;
+     FT_Library ft_library;
+     FT_Error error;
  
      pat = FcPatternCreate ();
***************
*** 176,182 ****
      FcPatternAddInteger (pat, FC_WEIGHT, fcweight);
  
!     font = cairo_ft_font_create (pat);
      ft_font = (cairo_ft_font_t *) font;
  
      FT_Set_Char_Size (ft_font->face,
                        DOUBLE_TO_26_6 (1.0),
--- 169,183 ----
      FcPatternAddInteger (pat, FC_WEIGHT, fcweight);
  
!     error = FT_Init_FreeType (&ft_library);
!     if (error) {
! 	FcPatternDestroy (pat);
! 	return NULL;
!     }
! 
!     font = cairo_ft_font_create (ft_library, pat);
      ft_font = (cairo_ft_font_t *) font;
  
+     ft_font->owns_ft_library = 1;
+ 
      FT_Set_Char_Size (ft_font->face,
                        DOUBLE_TO_26_6 (1.0),
***************
*** 217,221 ****
      ft_font = (cairo_ft_font_t *)font;
    
!     if (ft_font->face != NULL && ft_font->owner_of_face_p)
          FT_Done_Face (ft_font->face);
    
--- 218,222 ----
      ft_font = (cairo_ft_font_t *)font;
    
!     if (ft_font->face != NULL && ft_font->owns_face)
          FT_Done_Face (ft_font->face);
    
***************
*** 223,226 ****
--- 224,230 ----
          FcPatternDestroy (ft_font->pattern);
  
+     if (ft_font->ft_library && ft_font->owns_ft_library)
+ 	FT_Done_FreeType (ft_font->ft_library);
+ 
      free (ft_font);
  }
***************
*** 585,590 ****
  		      &cairo_ft_font_backend);
      
      f->face = face;
!     f->owner_of_face_p = 0;
      return (cairo_font_t *) f;
  }
--- 589,598 ----
  		      &cairo_ft_font_backend);
      
+     f->ft_library = NULL;
+     f->owns_ft_library = 0;
+ 
      f->face = face;
!     f->owns_face = 0;
! 
      return (cairo_font_t *) f;
  }





More information about the cairo-commit mailing list