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

leonardo at ghostscript.com leonardo at ghostscript.com
Thu Jul 20 11:50:29 PDT 2006


Author: leonardo
Date: 2006-07-20 11:50:28 -0700 (Thu, 20 Jul 2006)
New Revision: 6923

Modified:
   trunk/gs/src/fapiufst.c
   trunk/gs/src/gxfapiu.c
   trunk/gs/src/gxfapiu.h
   trunk/gs/src/lib.mak
Log:
UFST bridge : Upgrading to UFST 5.0, part 27.

DETAILS :

Provide a static list of FCO handles,
which are useful for a multilanguage embedded systems.

We define a storage for 2 handles because currently we need only 2 ones -
one for Windings and another for all other fonts.
FCO plugin does not go to this list, because it
doesn't define a font.

EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/src/fapiufst.c
===================================================================
--- trunk/gs/src/fapiufst.c	2006-07-20 06:45:50 UTC (rev 6922)
+++ trunk/gs/src/fapiufst.c	2006-07-20 18:50:28 UTC (rev 6923)
@@ -33,11 +33,16 @@
 #define DOES_ANYONE_USE_THIS_STRUCTURE /* see TTPCLEO.H, UFST 4.2 */
 #include "ttpcleo.h"
 #undef  DOES_ANYONE_USE_THIS_STRUCTURE
-#include "gp.h"
 #include "gxfapiu.h"
 
 typedef struct fapi_ufst_server_s fapi_ufst_server;
 
+#define DEBUG_STATIC_FCO 1
+
+#if DEBUG_STATIC_FCO
+static SW16 static_fcHandle[2];
+#endif
+
 #if UFST_REENTRANT
 #define FSA_FROM_SERVER IF_STATE *pIFS = &r->IFS
 #else
@@ -57,14 +62,6 @@
     /* more data follows here depending on font type */
 };
 
-typedef struct fco_list_elem_s fco_list_elem;
-struct fco_list_elem_s {
-    int open_count;
-    SW16 fcHandle;
-    char *file_path;
-    fco_list_elem *next;
-};
-
 typedef struct {
     SL32 font_id;
     uint tt_font_body_offset;
@@ -196,6 +193,15 @@
 	eprintf("Warning: UFST_PlugIn is not specified, some characters may be missing.\n");
 #endif
     }
+
+#if DEBUG_STATIC_FCO
+    code = gx_UFST_open_static_fco("F:/AFPL/ufst/fontdata/MTFONTS/PCLPS2/MT3/pclp2_xj.fco", &static_fcHandle[0]);
+    if (code != 0)
+	return code;
+    code = gx_UFST_open_static_fco("F:/AFPL/ufst/fontdata/MTFONTS/PCL45/MT3/wd____xh.fco", &static_fcHandle[1]);
+    if (code != 0)
+	return code;
+#endif
     return 0;
 }		      
 
@@ -574,10 +580,14 @@
 }
 
 private FAPI_retcode fco_open(fapi_ufst_server *r, const char *font_file_path, fco_list_elem **result)
-{   fco_list_elem *e = r->fco_list;
-    int code;
+{   int code;
+    fco_list_elem *e = gx_UFST_find_static_fco(font_file_path);
 
-    for (; e != 0; e = e->next) {
+    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;
     }
@@ -645,20 +655,28 @@
     d->glyphs = 0;
     d->is_disk_font = (ff->font_file_path != NULL);
     if (d->is_disk_font) {
-        FILE *f = fopen(font_file_path, "rb"); /* note: gp_fopen isn't better since UFST calls fopen. */
-	if (f == NULL) {
-	    eprintf1("fapiufst: Can't open %s\n", font_file_path);
-            return e_undefinedfilename;
+	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 {
+	    FILE *f = fopen(font_file_path, "rb"); /* note: gp_fopen isn't better since UFST calls fopen. */
+	    if (f == NULL) {
+		eprintf1("fapiufst: Can't open %s\n", font_file_path);
+		return e_undefinedfilename;
+	    }
+	    memcpy(d + 1, font_file_path, strlen(font_file_path) + 1);
+	    d->font_type = get_font_type(f);
+	    fclose(f);
+	    if (d->font_type == FC_FCO_TYPE) {
+		fco_list_elem *e;
+		if ((code = fco_open(r, font_file_path, &e)) != 0)
+		    return code;
+		d->font_id = (e->fcHandle << 16) | ff->subfont;
+	    }
 	}
-        memcpy(d + 1, font_file_path, strlen(font_file_path) + 1);
-        d->font_type = get_font_type(f);
-        fclose(f);
-        if (d->font_type == FC_FCO_TYPE) {
-            fco_list_elem *e;
-            if ((code = fco_open(r, font_file_path, &e)) != 0)
-		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);
@@ -1219,9 +1237,12 @@
 }
 
 private void release_fco(fapi_ufst_server *r, SW16 fcHandle)
-{   fco_list_elem **e = &r->fco_list;
+{   
+    fco_list_elem **e;
 
-    for (; *e != 0; )
+    if(gx_UFST_find_static_fco_handle(fcHandle) != NULL)
+	return;
+    for (e = &r->fco_list; *e != 0; )
         if ((*e)->fcHandle == fcHandle && (--(*e)->open_count) == 0) {
             fco_list_elem *ee = *e;
 	    FSA_FROM_SERVER;
@@ -1308,6 +1329,10 @@
 
     if (r->If.ig.d != &ufst_descriptor)
         return; /* safety */
+#if DEBUG_STATIC_FCO
+    gx_UFST_close_static_fco(static_fcHandle[0]);
+    gx_UFST_close_static_fco(static_fcHandle[1]);
+#endif
 #if 0 /* Disabled against a reentrancy problem 
 	 in a single language build for host-based applications. */
     gx_set_UFST_Callbacks(NULL, NULL, NULL);

Modified: trunk/gs/src/gxfapiu.c
===================================================================
--- trunk/gs/src/gxfapiu.c	2006-07-20 06:45:50 UTC (rev 6922)
+++ trunk/gs/src/gxfapiu.c	2006-07-20 18:50:28 UTC (rev 6923)
@@ -28,6 +28,8 @@
 /* GS includes : */
 #include "gxfapiu.h"
 
+#define MAX_STATIC_FCO_COUNT 2
+
 /* -------------------- UFST callback dispatcher ------------- */
 
 /*  This code provides dispatching UFST callbacks to GS or PCL. */
@@ -52,11 +54,14 @@
     a general dynamic context for all interpreters.
  */
 
-private LPUB8 (*m_PCLEO_charptr)(FSP LPUB8 pfont_hdr, UW16  sym_code) = stub_PCLEO_charptr;
-private LPUB8 (*m_PCLchId2ptr)(FSP UW16 chId) = stub_PCLchId2ptr;
-private LPUB8 (*m_PCLglyphID2Ptr)(FSP UW16 glyphID) = stub_PCLglyphID2Ptr;
+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
-private bool global_UFST_lock = false;
+static bool global_UFST_lock = false;
+static fco_list_elem static_fco_list[MAX_STATIC_FCO_COUNT];
+static char static_fco_paths[MAX_STATIC_FCO_COUNT][gp_file_name_sizeof];
+static int static_fco_count = 0;
 #endif
 
 
@@ -110,3 +115,77 @@
     return global_UFST_lock;
 }
 #endif /*!UFST_REENTRANT*/
+
+/* Access to the static FCO list for the language switching project. */
+
+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;
+}
+
+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;
+
+    if (static_fco_count >= MAX_STATIC_FCO_COUNT)
+	return ERR_fco_NoMem;
+    code = CGIFfco_Open(FSA (UB8 *)font_file_path, &fcHandle);
+    if (code != 0)
+	return code;
+    e = &static_fco_list[static_fco_count];
+    strncpy(static_fco_paths[static_fco_count], font_file_path, 
+	    sizeof(static_fco_paths[static_fco_count]));
+    e->file_path = static_fco_paths[static_fco_count];
+    e->fcHandle = fcHandle;
+    e->open_count = -1; /* Unused for static FCOs. */
+    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++)
+	if (static_fco_list[i].fcHandle == fcHandle)
+	    break;
+    if (i >= static_fco_count)
+	return ERR_fco_NoMem;
+    CGIFfco_Close(FSA fcHandle);
+    for (i++; i < static_fco_count; i++) {
+	static_fco_list[i - 1] = static_fco_list[i];
+	strcpy(static_fco_paths[i - 1], static_fco_paths[i]);
+    }
+    static_fco_count--;
+#endif
+    return 0;
+}
+

Modified: trunk/gs/src/gxfapiu.h
===================================================================
--- trunk/gs/src/gxfapiu.h	2006-07-20 06:45:50 UTC (rev 6922)
+++ trunk/gs/src/gxfapiu.h	2006-07-20 18:50:28 UTC (rev 6923)
@@ -20,6 +20,8 @@
 #ifndef gxfapiu_INCLUDED
 #define gxfapiu_INCLUDED
 
+#include "gp.h"
+
 /* Set UFST callbacks. */
 /* Warning : the language switch progect doesn't guarantee
    that this function is called when switching
@@ -51,4 +53,20 @@
 bool gs_get_UFST_lock(void);
 #endif /*!UFST_REENTRANT*/
 
+typedef struct fco_list_elem_s fco_list_elem;
+struct fco_list_elem_s {
+    int open_count;
+    SW16 fcHandle;
+    char *file_path;
+    fco_list_elem *next;
+};
+
+/* Access to the static FCO list for the language switching project : */
+/* For the language switch : */
+UW16 gx_UFST_open_static_fco(const char *font_file_path, SW16 *result_fcHandle);
+UW16 gx_UFST_close_static_fco(SW16 fcHandle);
+/* For fapiufst.c : */
+fco_list_elem *gx_UFST_find_static_fco(const char *font_file_path);
+fco_list_elem *gx_UFST_find_static_fco_handle(SW16 fcHandle);
+
 #endif /* gxfapiu_INCLUDED */

Modified: trunk/gs/src/lib.mak
===================================================================
--- trunk/gs/src/lib.mak	2006-07-20 06:45:50 UTC (rev 6922)
+++ trunk/gs/src/lib.mak	2006-07-20 18:50:28 UTC (rev 6923)
@@ -2673,7 +2673,7 @@
 UFST_INC_1=$(I_)$(UFST_ROOT)$(D)sys$(D)inc$(_I) $(I_)$(UFST_ROOT)$(D)rts$(D)inc$(_I)  $(I_)$(UFST_ROOT)$(D)rts$(D)tt$(_I)   
 UFST_INC_=$(UFST_INC_1) $(I_)$(UFST_ROOT)$(D)rts$(D)fco$(_I) $(I_)$(UFST_ROOT)$(D)rts$(D)gray$(_I)   
     
-gxfapiu_h=$(GLSRC)gxfapiu.h   
+gxfapiu_h=$(GLSRC)gxfapiu.h $(GLSRC)gp.h
     
 $(GLD)gxfapiu1.dev : $(LIB_MAK) $(ECHOGS_XE) $(GLOBJ)gxfapiu.$(OBJ)   
 	$(SETMOD) $(GLD)gxfapiu1 $(GLOBJ)gxfapiu.$(OBJ)   



More information about the gs-cvs mailing list