Example #1
0
static void ming_textpara(GVJ_t * job, pointf p, textpara_t * para)
{
    SWFMovie movie = (SWFMovie)(job->context);
    SWFTextField textfield;
    SWFDisplayItem item;
    obj_state_t *obj = job->obj;
    gvcolor_t pencolor = obj->pencolor;
    pointf offset;
    char *font_file_name;
    char *libdir;
    static SWFFont font;

/* FIXME - hardcoded to a Times-like font */
    if (font == NULL) {
    	libdir=gvconfig_libdir();
	font_file_name = malloc(strlen(libdir)+strlen(FONT)+2);
	strcpy(font_file_name, libdir);
	strcat(font_file_name, "/");
	strcat(font_file_name, FONT);
	font = newSWFFont_fromFile(font_file_name);
	free(font_file_name);
    }

    textfield = newSWFTextField();
    SWFTextField_setFont(textfield, (SWFBlock)font);
    SWFTextField_addChars(textfield, para->str);
    SWFTextField_addUTF8String(textfield, para->str);
    SWFTextField_setColor(textfield,
	 pencolor.u.rgba[0],
	 pencolor.u.rgba[1],
	 pencolor.u.rgba[2],
	 pencolor.u.rgba[3]);
    SWFTextField_setHeight(textfield, para->fontsize);

    switch (para->just) {
    case 'r':
	offset.x = 0.;
	break;
    case 'l':
	offset.x = -para->width;
	break;
    case 'n':
    default:
	offset.x = -para->width/2.;
	break;
    }
    /* offset to baseline */
    offset.y = -para->height + para->fontsize*.4;  /* empirically determined */

    item = SWFMovie_add(movie, (SWFBlock)textfield);
    SWFDisplayItem_moveTo(item, p.x + offset.x, p.y + offset.y);
}
Example #2
0
static int
glob (GVC_t* gvc, char* pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
{
    char* libdir;
    WIN32_FIND_DATA wfd;
    HANDLE h;
    char** str=0;
    int arrsize=0;
    int cnt = 0;
    
    pglob->gl_pathc = 0;
    pglob->gl_pathv = NULL;
    
    h = FindFirstFile (pattern, &wfd);
    if (h == INVALID_HANDLE_VALUE) return GLOB_NOMATCH;
    libdir = gvconfig_libdir(gvc);
    do {
      if (cnt >= arrsize-1) {
        arrsize += 512;
        if (str) str = (char**)realloc (str, arrsize*sizeof(char*));
        else str = (char**)malloc (arrsize*sizeof(char*));
        if (!str) return GLOB_NOSPACE;
      }
      str[cnt] = (char*)malloc (strlen(libdir)+1+strlen(wfd.cFileName)+1);
      if (!str[cnt]) return GLOB_NOSPACE;
      strcpy(str[cnt],libdir);
      strcat(str[cnt],DIRSEP);
      strcat(str[cnt],wfd.cFileName);
      cnt++;
    } while (FindNextFile (h, &wfd));
    str[cnt] = 0;

    pglob->gl_pathc = cnt;
    pglob->gl_pathv = (char**)realloc(str, (cnt+1)*sizeof(char*));
    
    return 0;
}
Example #3
0
/*
  gvconfig - parse a config file and install the identified plugins
 */
void gvconfig(GVC_t * gvc, boolean rescan)
{
#if 0
    gvplugin_library_t **libraryp;
#endif
#ifdef ENABLE_LTDL
    int sz, rc;
    struct stat config_st, libdir_st;
    FILE *f = NULL;
    char *config_text = NULL;
    char *libdir;
    char *config_file_name = GVPLUGIN_CONFIG_FILE;

#define MAX_SZ_CONFIG 100000
#endif
    
    /* builtins don't require LTDL */
    gvconfig_plugin_install_builtins(gvc);
   
    gvc->config_found = FALSE;
#ifdef ENABLE_LTDL
    if (gvc->common.demand_loading) {
        /* see if there are any new plugins */
        libdir = gvconfig_libdir(gvc);
        rc = stat(libdir, &libdir_st);
        if (rc == -1) {
	    gvtextlayout_select(gvc);   /* choose best available textlayout plugin immediately */
    	    /* if we fail to stat it then it probably doesn't exist so just fail silently */
	    return;
        }
    
        if (! gvc->config_path) {
            gvc->config_path = gmalloc(strlen(libdir) + 1 + strlen(config_file_name) + 1);
            strcpy(gvc->config_path, libdir);
            strcat(gvc->config_path, DIRSEP);
            strcat(gvc->config_path, config_file_name);
        }
    	
        if (rescan) {
    	    config_rescan(gvc, gvc->config_path);
    	    gvc->config_found = TRUE;
	    gvtextlayout_select(gvc);   /* choose best available textlayout plugin immediately */
    	    return;
        }
    
        /* load in the cached plugin library data */
    
        rc = stat(gvc->config_path, &config_st);
        if (rc == -1) {
	    gvtextlayout_select(gvc);   /* choose best available textlayout plugin immediately */
    	    /* silently return without setting gvc->config_found = TRUE */
    	    return;
        }
        else if (config_st.st_size > MAX_SZ_CONFIG) {
    	    agerr(AGERR,"%s is bigger than I can handle.\n", gvc->config_path);
        }
        else {
    	    f = fopen(gvc->config_path,"r");
    	    if (!f) {
    	        agerr (AGERR,"failed to open %s for read.\n", gvc->config_path);
		return;
    	    }
    	    else {
    	        config_text = gmalloc(config_st.st_size + 1);
    	        sz = fread(config_text, 1, config_st.st_size, f);
    	        if (sz == 0) {
    		    agerr(AGERR,"%s is zero sized, or other read error.\n", gvc->config_path);
    		    free(config_text);
    	        }
    	        else {
    	            gvc->config_found = TRUE;
    	            config_text[sz] = '\0';  /* make input into a null terminated string */
    	            rc = gvconfig_plugin_install_from_config(gvc, config_text);
    		    /* NB. config_text not freed because we retain char* into it */
    	        }
    	    }
    	    if (f) {
    	        fclose(f);
	    }
        }
    }
#endif
    gvtextlayout_select(gvc);   /* choose best available textlayout plugin immediately */
    textfont_dict_open(gvc);    /* initialize font dict */
}
Example #4
0
static void config_rescan(GVC_t *gvc, char *config_path)
{
    FILE *f = NULL;
    glob_t globbuf;
    char *config_glob, *config_re, *path, *libdir;
    int i, rc, re_status;
    gvplugin_library_t *library;
    regex_t re;
#ifndef WIN32
    char *plugin_glob = "libgvplugin_*";
#endif
#if defined(DARWIN_DYLIB)
    char *plugin_re_beg = "[^0-9]\\.";
    char *plugin_re_end = "\\.dylib$";
#elif defined(__MINGW32__)
	char *plugin_glob = "libgvplugin_*";
	char *plugin_re_beg = "[^0-9]-";
    char *plugin_re_end = "\\.dll$"; 
#elif defined(__CYGWIN__)
    plugin_glob = "cyggvplugin_*";
    char *plugin_re_beg = "[^0-9]-";
    char *plugin_re_end = "\\.dll$"; 
#elif defined(WIN32)
    char *plugin_glob = "gvplugin_*";
    char *plugin_re_beg = "[^0-9]";
    char *plugin_re_end = "\\.dll$"; 
#elif ((defined(__hpux__) || defined(__hpux)) && !(defined(__ia64)))
    char *plugin_re_beg = "\\.sl\\.";
    char *plugin_re_end = "$"; 
#else
    /* Everyone else */
    char *plugin_re_beg = "\\.so\\.";
    char *plugin_re_end= "$";
#endif

    if (config_path) {
	f = fopen(config_path,"w");
	if (!f) {
	    agerr(AGERR,"failed to open %s for write.\n", config_path);
	    exit(1);
	}

	fprintf(f, "# This file was generated by \"dot -c\" at time of install.\n\n");
	fprintf(f, "# You may temporarily disable a plugin by removing or commenting out\n");
	fprintf(f, "# a line in this file, or you can modify its \"quality\" value to affect\n");
	fprintf(f, "# default plugin selection.\n\n");
	fprintf(f, "# Manual edits to this file **will be lost** on upgrade.\n\n");
    }

    libdir = gvconfig_libdir(gvc);

    config_re = gmalloc(strlen(plugin_re_beg) + 20 + strlen(plugin_re_end) + 1);

#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
    sprintf(config_re,"%s%s", plugin_re_beg, plugin_re_end);
#elif defined(GVPLUGIN_VERSION)
    sprintf(config_re,"%s%d%s", plugin_re_beg, GVPLUGIN_VERSION, plugin_re_end);
#else
    sprintf(config_re,"%s[0-9]+%s", plugin_re_beg, plugin_re_end);
#endif

    if (regcomp(&re, config_re, REG_EXTENDED|REG_NOSUB) != 0) {
	agerr(AGERR,"cannot compile regular expression %s", config_re);
    }

    config_glob = gmalloc(strlen(libdir) + 1 + strlen(plugin_glob) + 1);
    strcpy(config_glob, libdir);
	strcat(config_glob, DIRSEP);
    strcat(config_glob, plugin_glob);

    /* load all libraries even if can't save config */

#if defined(WIN32)
    rc = glob(gvc, config_glob, GLOB_NOSORT, NULL, &globbuf);
#else
    rc = glob(config_glob, GLOB_NOSORT, NULL, &globbuf);
#endif
    if (rc == 0) {
	for (i = 0; i < globbuf.gl_pathc; i++) {
	    re_status = regexec(&re, globbuf.gl_pathv[i], (size_t) 0, NULL, 0);
	    if (re_status == 0) {
		library = gvplugin_library_load(gvc, globbuf.gl_pathv[i]);
		if (library) {
		    gvconfig_plugin_install_from_library(gvc, globbuf.gl_pathv[i], library);
		}
	    }
	}
	/* rescan with all libs loaded to check cross dependencies */
	for (i = 0; i < globbuf.gl_pathc; i++) {
	    re_status = regexec(&re, globbuf.gl_pathv[i], (size_t) 0, NULL, 0);
	    if (re_status == 0) {
		library = gvplugin_library_load(gvc, globbuf.gl_pathv[i]);
		if (library) {
		    path = strrchr(globbuf.gl_pathv[i],DIRSEP[0]);
		    if (path)
			path++;
		    if (f && path)
			gvconfig_write_library_config(gvc, path, library, f);
		}
	    }
	}
    }
    regfree(&re);
    globfree(&globbuf);
    free(config_glob);
    free(config_re);
    if (f)
	fclose(f);
}
Example #5
0
gvplugin_library_t *gvplugin_library_load(char *path)
{
#ifndef DISABLE_LTDL
    lt_dlhandle hndl;
    lt_ptr ptr;
    char *s, *sym;
    int len;
    static char *p;
    static int lenp;
    char *libdir;
    char *suffix = "_LTX_library";

    libdir = gvconfig_libdir();
    len = strlen(libdir) + 1 + strlen(path) + 1;
    if (len > lenp) {
	lenp = len+20;
	if (p)
	    p = grealloc(p, lenp);
	else
	    p = gmalloc(lenp);
    }
	
    if (path[0] == '/') {
	strcpy(p, path);
    } else {
	strcpy(p, libdir);
	strcat(p, "/");
	strcat(p, path);
    }

    if (lt_dlinit()) {
        agerr(AGERR, "failed to init libltdl\n");
        return NULL;
    }
    hndl = lt_dlopen (p);
    if (!hndl) {
        agerr(AGWARN, (char*)lt_dlerror());
        return NULL;
    }

    s = strrchr(p, '/');
    len = strlen(s); 
    if (len < strlen("/libgvplugin_x")) {
	agerr (AGERR,"invalid plugin path \"%s\"\n", p);
	return NULL;
    }
    sym = gmalloc(len + strlen(suffix) + 1);
    strcpy(sym, s+4);         /* strip leading "/lib" or "/cyg" */
#ifdef __CYGWIN__
    s = strchr(sym, '-');     /* strip trailing "-1.dll" */
#else 
    s = strchr(sym, '.');     /* strip trailing ".so.0" or ".dll" or ".sl" */
#endif
    strcpy(s,suffix);         /* append "_LTX_library" */

    ptr = lt_dlsym (hndl, sym);
    if (!ptr) {
        agerr (AGERR,"failed to resolve %s in %s\n", sym, p);
	free(sym);
        return NULL;
    }
    free(sym);
    return (gvplugin_library_t *)(ptr);
#else
    agerr (AGERR,"dynamic loading not available\n");
    return NULL;
#endif
}