model_server/driver_aset/src/dis_setfont.cxx
// returns:  0 if the font inf.font_nm exists with the font path added infront to existing path
//             reset the font path back to existing if font is not found
0 if the font inf.font_nm exists with the font path added infront to existing path
reset the font path back to existing if font is not found
0 if the font inf . font_nm exists with the font path added infront to existing path reset the font path back to existing if font is not found
static int check_fontpath (Display *dpy, args_INFO& inf, const char *p)
{
    int ret = -1;
    if (!p || !p[0]) return ret;
    if (p[0] == '/' && stat_dir(p)) {
	msg("Directory $1 does not exist.", warning_sev) << p << eom;
	ret = -1;
	return ret;
    }
    int npaths = 0;
    char **orig_fp = XGetFontPath(dpy, &npaths);
    if (font_err) return ret;
    int i = 0; int len = strlen(p);
    for(i = 0; i < npaths; i++) {
	if ( strncmp(p, orig_fp[i], len) == 0 )
	    break;
    }
    if (!npaths || i >= npaths) {
	msg("Append font path with $1", normal_sev) << p << eom;
	char **new_font_path = (char **)mymalloc((npaths+1)*sizeof(char *));
	if (npaths) {
	    for (i = 0; i < npaths; i++) {
		new_font_path[i] = (char *)mymalloc(strlen(orig_fp[i]) + 1);
		strcpy(new_font_path[i], orig_fp[i]);
	    }
	}
	new_font_path[npaths] = (char *)mymalloc(len + 13);
	strcpy(new_font_path[npaths], p);
	XSetFontPath (dpy, new_font_path, npaths+1);
	if (font_err) {
	    msg("Failed to set new font path.", error_sev) << eom;
	    if (orig_fp) XFreeFontPath (orig_fp);
	    return ret;
	}
	for (i = 0; i <= npaths; i++)
	    myfree (new_font_path[i]);
	myfree(new_font_path);
    } else {
	msg("Rehashing font path that already contains path $1", normal_sev) << p << eoarg << eom;
	npaths = 0;
	orig_fp = XGetFontPath(dpy, &npaths);
	if (npaths) XSetFontPath (dpy, orig_fp, npaths);
    }
    ret = load_font_check (dpy, inf);
    if (ret) {
	msg("Removing $1 from X server font path.", warning_sev) << p << eom;
	int good = 0;
	char **new_font_path = 0;
	if ( npaths > 1) {
	    new_font_path = (char **)mymalloc((npaths)*sizeof(char *));
	    for (i = 0; i < npaths; i++) {
		if (strncmp(p, orig_fp[i], len) != 0) {
		    new_font_path[i] = (char *)mymalloc(strlen(orig_fp[i]) + 1);
		    strcpy(new_font_path[i], orig_fp[i]);
		    good ++;
		}
	    }
	}
	XSetFontPath (dpy, new_font_path, good);
	for (i = 0; i < good; i++)
	    myfree (new_font_path[i]);
	myfree(new_font_path);
    }
    if (orig_fp) XFreeFontPath (orig_fp);
    return ret;
}
static int check_fontpath ( Display * dpy , args_INFO & inf , const char * p ) { int ret = -1 ; if ( ! p || ! p [ 0 ] ) return ret ; if ( p [ 0 ] == ' ' && stat_dir ( p ) ) { msg ( " " , warning_sev ) << p << eom ; ret = -1 ; return ret ; } int npaths = 0 ; char * * orig_fp = XGetFontPath ( dpy , & npaths ) ; if ( font_err ) return ret ; int i = 0 ; int len = strlen ( p ) ; for ( i = 0 ; i < npaths ; i ++ ) { if ( strncmp ( p , orig_fp [ i ] , len ) == 0 ) break ; } if ( ! npaths || i >= npaths ) { msg ( " " , normal_sev ) << p << eom ; char * * new_font_path = ( char * * ) mymalloc ( ( npaths + 1 ) * sizeof ( char * ) ) ; if ( npaths ) { for ( i = 0 ; i < npaths ; i ++ ) { new_font_path [ i ] = ( char * ) mymalloc ( strlen ( orig_fp [ i ] ) + 1 ) ; strcpy ( new_font_path [ i ] , orig_fp [ i ] ) ; } } new_font_path [ npaths ] = ( char * ) mymalloc ( len + 13 ) ; strcpy ( new_font_path [ npaths ] , p ) ; XSetFontPath ( dpy , new_font_path , npaths + 1 ) ; if ( font_err ) { msg ( " " , error_sev ) << eom ; if ( orig_fp ) XFreeFontPath ( orig_fp ) ; return ret ; } for ( i = 0 ; i <= npaths ; i ++ ) myfree ( new_font_path [ i ] ) ; myfree ( new_font_path ) ; } else { msg ( " " , normal_sev ) << p << eoarg << eom ; npaths = 0 ; orig_fp = XGetFontPath ( dpy , & npaths ) ; if ( npaths ) XSetFontPath ( dpy , orig_fp , npaths ) ; } ret = load_font_check ( dpy , inf ) ; if ( ret ) { msg ( " " , warning_sev ) << p << eom ; int good = 0 ; char * * new_font_path = 0 ; if ( npaths > 1 ) { new_font_path = ( char * * ) mymalloc ( ( npaths ) * sizeof ( char * ) ) ; for ( i = 0 ; i < npaths ; i ++ ) { if ( strncmp ( p , orig_fp [ i ] , len ) != 0 ) { new_font_path [ i ] = ( char * ) mymalloc ( strlen ( orig_fp [ i ] ) + 1 ) ; strcpy ( new_font_path [ i ] , orig_fp [ i ] ) ; good ++ ; } } } XSetFontPath ( dpy , new_font_path , good ) ; for ( i = 0 ; i < good ; i ++ ) myfree ( new_font_path [ i ] ) ; myfree ( new_font_path ) ; } if ( orig_fp ) XFreeFontPath ( orig_fp ) ; return ret ; }
returns:  0 if the font inf.font_nm exists with the font path added infront to existing path
reset the font path back to existing if font is not found
returns : 0 if the font inf . font_nm exists with the font path added infront to existing path reset the font path back to existing if font is not found
// prepend our path to font path //rehash font path