[gs-cvs] rev 7106 - trunk/gs/src

leonardo at ghostscript.com leonardo at ghostscript.com
Thu Oct 12 18:14:59 PDT 2006


Author: leonardo
Date: 2006-10-12 18:14:58 -0700 (Thu, 12 Oct 2006)
New Revision: 7106

Modified:
   trunk/gs/src/fapiufst.c
   trunk/gs/src/gxfapiu.c
   trunk/gs/src/gxfapiu.h
Log:
Fix (FAPI) : Restore the functionality and the documentation, which were broken with commitments 6998 7077 7078.

DETAILS :

1. The reentrant UFST was not tested yet.
2. We noticed a problem with -dTextAlphaBits=4, which to be fixed separately.

EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/src/fapiufst.c
===================================================================
--- trunk/gs/src/fapiufst.c	2006-10-13 00:02:34 UTC (rev 7105)
+++ trunk/gs/src/fapiufst.c	2006-10-13 01:14:58 UTC (rev 7106)
@@ -39,8 +39,6 @@
 
 typedef struct fapi_ufst_server_s fapi_ufst_server;
 
-static SW16 static_fcHandle[3] = { 0, 0, 0 };
-
 #if UFST_REENTRANT
 #define FSA_FROM_SERVER IF_STATE *pIFS = &r->IFS
 #else
@@ -49,9 +47,6 @@
 private fapi_ufst_server *static_server_ptr_for_ufst_callback = 0;
 #endif
 
-#ifndef PSI_INCLUDED
-GLOBAL const SW16 trace_sw = 0; /* UFST 4.3 wants it. */
-#endif
 GLOBAL UW16  PCLswapHdr( FSP LPUB8 p, UW16 gifct ); /* UFST header doesn't define it. */
 
 typedef struct pcleo_glyph_list_elem_s pcleo_glyph_list_elem;
@@ -88,6 +83,7 @@
     FONTCONTEXT fc;
     void *char_data;
     bool bRaster;
+    bool ufst_is_singleton;
     double tran_xx, tran_xy, tran_yx, tran_yy;
     fco_list_elem *fco_list;
     FAPI_retcode callback_error;
@@ -135,8 +131,6 @@
  * disadvantage that the dynamic parameters set in server_param are
  * not available. Thus, it is switched through this compile time option.
 */
-
-#ifdef PSI_INCLUDED
 private FAPI_retcode open_UFST(fapi_ufst_server *r, const byte *server_param, int server_param_size)
 {
     int code;
@@ -180,9 +174,10 @@
 	eprintf("Warning: UFST_SSdir is not specified, will search *.ss files in the curent directory.\n");
     }
 #endif
-
-    gx_UFST_init(ufst_root_dir);
-
+    code = gx_UFST_init((const UB8 *)ufst_root_dir);
+    if (code < 0)
+	return code;
+    r->ufst_is_singleton = (code == 1);
     if (bPlugIn) {
 	if ((code = gx_UFST_open_static_fco(sPlugIn, &fcHandle)) != 0)
 	    return code;
@@ -193,80 +188,9 @@
 	eprintf("Warning: UFST_PlugIn is not specified, some characters may be missing.\n");
 #endif
     }
-
     return 0;
 }		      
-#else
-private FAPI_retcode open_UFST(fapi_ufst_server *r, const byte *server_param, int server_param_size)
-{   IFCONFIG   config_block;
-    int code;
-    SW16 fcHandle;
-    int l;
-    char sPlugIn[sizeof(config_block.ufstPath)] = "";
-    bool bSSdir = false, bPlugIn = false;
-    const char *keySSdir = "UFST_SSdir=";
-    const int keySSdir_length = strlen(keySSdir);
-    const char *keyPlugIn = "UFST_PlugIn=";
-    const int keyPlugIn_length = strlen(keyPlugIn);
-    const char sep = gp_file_name_list_separator;
-    const byte *p = server_param, *e = server_param + server_param_size, *q;
-    FSA_FROM_SERVER;
 
-    config_block.ufstPath[0] = 0;
-    for (; p < e ; p = q + 1) {
-	for (q = p; q < e && *q != sep; q++)
-	    /* DO_NOTHING */;
-	l = q - p;
-	if (l > keySSdir_length && !memcmp(p, keySSdir, keySSdir_length)) {
-	    l = q - p - keySSdir_length;
-	    if (l > sizeof(config_block.ufstPath) - 1)
-		l = sizeof(config_block.ufstPath) - 1;
-	    memcpy(config_block.ufstPath, p + keySSdir_length, l);
-	    config_block.ufstPath[l] = 0;
-	    bSSdir = true;
-	} else if (l > keyPlugIn_length && !memcmp(p, keyPlugIn, keyPlugIn_length)) {
-	    l = q - p - keyPlugIn_length;
-	    if (l > sizeof(sPlugIn) - 1)
-		l = sizeof(sPlugIn) - 1;
-	    memcpy(sPlugIn, p + keyPlugIn_length, l);
-	    sPlugIn[l] = 0;
-	    bPlugIn = true;
-	} else
-	    eprintf("Warning: Unknown UFST parameter ignored.\n");
-    }
-#if !NO_SYMSET_MAPPING
-    if (!bSSdir) {
-	strcpy(config_block.ufstPath, ".");
-	eprintf("Warning: UFST_SSdir is not specified, will search *.ss files in the curent directory.\n");
-    }
-#endif
-    config_block.bit_map_width = 1;
-    config_block.num_files = 10;
-    config_block.typePath[0] = 0;
-    if ((code = CGIFinit(FSA0)) != 0)
-	return code;
-    config_block.num_files = 10;
-    config_block.bit_map_width = 1;
-    UFST_debug_on(FSA0);
-    if ((code = CGIFconfig(FSA &config_block)) != 0)
-	return code;
-    if ((code = CGIFenter(FSA0)) != 0)
-	return code;
-    if (bPlugIn) {
-	if ((code = CGIFfco_Open(FSA (byte *)sPlugIn, &fcHandle)) != 0)
-	    return code;
-	if ((code = CGIFfco_Plugin(FSA fcHandle)) != 0)
-	    return code;
-    } else {
-#ifdef FCO_RDR
-	eprintf("Warning: UFST_PlugIn is not specified, some characters may be missing.\n");
-#endif
-    }
-
-    return 0;
-}		      
-#endif
-
 private LPUB8 impl_PCLchId2ptr(FSP UW16 chId);
 
 private FAPI_retcode ensure_open(FAPI_server *server, const byte *server_param, int server_param_size)
@@ -640,8 +564,12 @@
 
 private FAPI_retcode fco_open(fapi_ufst_server *r, const char *font_file_path, fco_list_elem **result)
 {   int code;
-    fco_list_elem *e;
-
+    fco_list_elem *e = gx_UFST_find_static_fco(font_file_path);
+    
+    if (e != NULL) {   
+	*result = e;   
+	return 0;   
+    } 
     for (e = r->fco_list; e != 0; e = e->next) {
         if (!strcmp(e->file_path, font_file_path))
             break;
@@ -650,21 +578,18 @@
         SW16 fcHandle;
 	FSA_FROM_SERVER;
 
-	fco_list_elem *estatic = gx_UFST_find_static_fco(font_file_path);
-	if (estatic != 0)
-	    fcHandle = estatic->fcHandle;
-	else if ((code = gx_UFST_open_static_fco(font_file_path, &fcHandle)) != 0)
+	if ((code = CGIFfco_Open(FSA (UB8 *)font_file_path, &fcHandle)) != 0)
 	    return code;
         e = (fco_list_elem *)r->client_mem.alloc(&r->client_mem, sizeof(*e), "fco_list_elem");
         if (e == 0) {
-            gx_UFST_close_static_fco(FSA fcHandle);
+            CGIFfco_Close(FSA fcHandle);
             return e_VMerror;
         }
         e->open_count = 0;
         e->fcHandle = fcHandle;
         e->file_path = my_strdup(r, font_file_path, "fco_file_path");
         if (e->file_path == 0) {
-            gx_UFST_close_static_fco(FSA fcHandle);
+            CGIFfco_Close(FSA fcHandle);
             r->client_mem.free(&r->client_mem, e, "fco_list_elem");
             return e_VMerror;
         }
@@ -713,6 +638,13 @@
     d->glyphs = 0;
     d->is_disk_font = (ff->font_file_path != NULL);
     if (d->is_disk_font) {
+	 fco_list_elem *e = gx_UFST_find_static_fco(font_file_path);   
+
+	 if (e != NULL) {   
+	     memcpy(d + 1, font_file_path, strlen(font_file_path) + 1);   
+	     d->font_id = (e->fcHandle << 16) | ff->subfont;   
+	     d->font_type = FC_FCO_TYPE;   
+	 } else { 
 	    stream *f = sfopen(font_file_path, "rb", (gs_memory_t *)(r->client_mem.client_data));
 	    if (f == NULL) {
 		eprintf1("fapiufst: Can't open %s\n", font_file_path);
@@ -727,6 +659,7 @@
 		    return code;
 		d->font_id = (e->fcHandle << 16) | ff->subfont;
 	    }
+	}
     } else {
         d->font_type = (ff->is_type1 ? FC_PST1_TYPE : FC_TT_TYPE);
 	d->font_id = ff->get_long(ff, FAPI_FONT_FEATURE_UniqueID, 0);
@@ -1301,7 +1234,7 @@
 	    FSA_FROM_SERVER;
 
             *e = ee->next;
-            gx_UFST_close_static_fco(FSA ee->fcHandle);
+            CGIFfco_Close(FSA ee->fcHandle);
             r->client_mem.free(&r->client_mem, ee->file_path, "fco_file_path");
             r->client_mem.free(&r->client_mem, ee, "fco_list_elem");
         } else
@@ -1382,9 +1315,12 @@
 
     if (r->If.ig.d != &ufst_descriptor)
         return; /* safety */
+#if 0 /* Disabled against a reentrancy problem 
+	 in a single language build for host-based applications. */
+    gx_set_UFST_Callbacks(NULL, NULL, NULL);
+#endif
     release_char_data_inline(r);
-    if (r->bInitialized) {
-	    CGIFexit(FSA0);
-    }
+    if (r->bInitialized && !r->ufst_is_singleton)
+	gx_UFST_fini();
     mem->free(mem, r, "fapi_ufst_server");
 }

Modified: trunk/gs/src/gxfapiu.c
===================================================================
--- trunk/gs/src/gxfapiu.c	2006-10-13 00:02:34 UTC (rev 7105)
+++ trunk/gs/src/gxfapiu.c	2006-10-13 01:14:58 UTC (rev 7106)
@@ -62,9 +62,12 @@
 static LPUB8 (*m_PCLEO_charptr)(FSP LPUB8 pfont_hdr, UW16  sym_code) = stub_PCLEO_charptr;
 static LPUB8 (*m_PCLchId2ptr)(FSP UW16 chId) = stub_PCLchId2ptr;
 static LPUB8 (*m_PCLglyphID2Ptr)(FSP UW16 glyphID) = stub_PCLglyphID2Ptr;
+#if !UFST_REENTRANT
 static fco_list_elem static_fco_list[MAX_STATIC_FCO_COUNT] = {0, 0, 0, 0};
 static char static_fco_paths[MAX_STATIC_FCO_COUNT][gp_file_name_sizeof];
 static int static_fco_count = 0;
+static bool ufst_initialized = false;
+#endif
 
 LPUB8 PCLEO_charptr(FSP LPUB8 pfont_hdr, UW16  sym_code)
 {   return m_PCLEO_charptr(FSA pfont_hdr, sym_code);
@@ -81,7 +84,13 @@
 /* Set UFST callbacks. Each PDL will want it's own character build function and must set the callbacks
  * upon language entry/initialization.
  */
-
+/* Warning : this function may cause a reentrancy problem   
+     due to a modification of static variables.   
+     Nevertheless this problem isn't important in a   
+     single interpreter build, because the values   
+     really change on the first demand only.   
+     See also a comment in gs_fapiufst_finit.   
+   */ 
 void gx_set_UFST_Callbacks(LPUB8 (*p_PCLEO_charptr)(FSP LPUB8 pfont_hdr, UW16  sym_code),
                            LPUB8 (*p_PCLchId2ptr)(FSP UW16 chId),
                            LPUB8 (*p_PCLglyphID2Ptr)(FSP UW16 glyphID))
@@ -95,50 +104,54 @@
 
 
 /* returns negative on error, 
- * 1 on I just initialized for the first time and you might want to as well.
- * 0 I've already initialized but its ok to call me.
- * NB: since this is using a static library UFST the initialization is static as well 
- * ie no multi-threading through here, once per process please.  
+ * 1 = "I just initialized for the first time and you might want to as well."
+ * 0 = "I've already initialized but its ok to call me."
+ * <0 = error.
  */
 int
-gx_UFST_init(UB8 ufst_root_dir[])
+gx_UFST_init(const UB8 *ufst_root_dir)
 {
     IFCONFIG            config_block;
     int status;
-    static bool ufst_initialized = false;
 
-    if (!ufst_initialized) {
-	strcpy(config_block.ufstPath, ufst_root_dir);
-	strcpy(config_block.typePath, ufst_root_dir);
-	config_block.num_files = MAX_OPEN_LIBRARIES;  /* max open library files */
-	config_block.bit_map_width = BITMAP_WIDTH;    /* bitmap width 1, 2 or 4 */
+#if !UFST_REENTRANT
+    if (ufst_initialized)
+	return 0;
+#endif
+    strcpy(config_block.ufstPath, ufst_root_dir);
+    strcpy(config_block.typePath, ufst_root_dir);
+    config_block.num_files = MAX_OPEN_LIBRARIES;  /* max open library files */
+    config_block.bit_map_width = BITMAP_WIDTH;    /* bitmap width 1, 2 or 4 */
 
-	/* These parameters were set in open_UFST() (fapiufst.c) but were left
-	   uninitialized in pl_load_built_in_fonts() (plulfont.c). */
-	config_block.typePath[0] = 0;
+    /* These parameters were set in open_UFST() (fapiufst.c) but were left
+       uninitialized in pl_load_built_in_fonts() (plulfont.c). */
+    config_block.typePath[0] = 0;
 
-	if ((status = CGIFinit(FSA0)) != 0) {
-	    dprintf1("CGIFinit() error: %d\n", status);
-	    return status;
-	}
-	if ((status = CGIFconfig(FSA &config_block)) != 0) {
-	    dprintf1("CGIFconfig() error: %d\n", status);
-	    return status;
-	}
-	if ((status = CGIFenter(FSA0)) != 0) {
-	    dprintf1("CGIFenter() error: %u\n",status);
-	    return status;
-	}
-	ufst_initialized = TRUE;
-	return 1; /* first time, caller may have more initialization to do */
+    if ((status = CGIFinit(FSA0)) != 0) {
+	dprintf1("CGIFinit() error: %d\n", status);
+	return status;
     }
-    return 0;  /* been here before, caller has no more initialization do do */
+    if ((status = CGIFconfig(FSA &config_block)) != 0) {
+	dprintf1("CGIFconfig() error: %d\n", status);
+	return status;
+    }
+    if ((status = CGIFenter(FSA0)) != 0) {
+	dprintf1("CGIFenter() error: %u\n",status);
+	return status;
+    }
+#if !UFST_REENTRANT
+    ufst_initialized = TRUE;
+#endif
+    return 1; /* first time, caller may have more initialization to do */
 }
 
 int
 gx_UFST_fini(void)
 {
     CGIFexit(FSA0);
+#if !UFST_REENTRANT
+    ufst_initialized = false;
+#endif
     return 0;
 }
 
@@ -146,37 +159,42 @@
 
 fco_list_elem *gx_UFST_find_static_fco(const char *font_file_path)
 {   
+#if !UFST_REENTRANT
     int i;
 
     for (i = 0; i < static_fco_count; i++)
 	if (!strcmp(static_fco_list[i].file_path, font_file_path))
 	    return &static_fco_list[i];
-
+#endif
     return NULL;
 }
 
 fco_list_elem *gx_UFST_find_static_fco_handle(SW16 fcHandle)
 {   
+#if !UFST_REENTRANT
     int i;
 
     for (i = 0; i < static_fco_count; i++)
 	if (static_fco_list[i].fcHandle == fcHandle)
 	    return &static_fco_list[i];
-
+#endif
     return NULL;
 }
 
 SW16 gx_UFST_find_fco_handle_by_name(const char *font_file_path)
 {   
+#if !UFST_REENTRANT
     fco_list_elem *fco = gx_UFST_find_static_fco(font_file_path);
 
     if (fco)
 	return fco->fcHandle;
-    return 0; /* or is it -1? */ 
+    return 0;
+#endif
 }
 
 UW16 gx_UFST_open_static_fco(const char *font_file_path, SW16 *result_fcHandle)
 {   
+#if !UFST_REENTRANT
     SW16 fcHandle;
     UW16 code;
     fco_list_elem *e;
@@ -195,10 +213,15 @@
     static_fco_count++;
     *result_fcHandle = fcHandle;
     return 0;
+#else
+    **result_fcHandle = -1;
+    return ERR_fco_NoMem;
+#endif
 }
 
 UW16 gx_UFST_close_static_fco(SW16 fcHandle)
 {   
+#if !UFST_REENTRANT
     int i;
 
     for (i = 0; i < static_fco_count; i++)
@@ -212,12 +235,14 @@
 	strcpy(static_fco_paths[i - 1], static_fco_paths[i]);
     }
     static_fco_count--;
-
+#endif
     return 0;
 }
 
 void gx_UFST_close_static_fcos()
 {
+#if !UFST_REENTRANT
     for(; static_fco_count; )
 	gx_UFST_close_static_fco(static_fco_list[0].fcHandle);
+#endif
 }

Modified: trunk/gs/src/gxfapiu.h
===================================================================
--- trunk/gs/src/gxfapiu.h	2006-10-13 00:02:34 UTC (rev 7105)
+++ trunk/gs/src/gxfapiu.h	2006-10-13 01:14:58 UTC (rev 7106)
@@ -59,7 +59,7 @@
 fco_list_elem *gx_UFST_find_static_fco(const char *font_file_path);
 fco_list_elem *gx_UFST_find_static_fco_handle(SW16 fcHandle);
 
-int gx_UFST_init(UB8 ufst_root_dir[]);
+int gx_UFST_init(const UB8 *ufst_root_dir);
 
 int gx_UFST_fini(void);
 



More information about the gs-cvs mailing list