Exemple #1
0
static INT ComputeSurfaceGridStats (MULTIGRID *theMG, COVISE_HEADER *covise)
{
  NODE *theNode;
  INT l, n_vertices, n_elem, n_conn;

  /* surface grid up to current level */
  n_vertices = n_elem = n_conn = 0;
  for (l=covise->min_level; l<=covise->max_level; l++)
  {
    ELEMENT *theElement;
    GRID *theGrid = GRID_ON_LEVEL(theMG,l);

    /* reset USED flags in all vertices to be counted */
    for (theNode=FIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
    {
      SETUSED(MYVERTEX(theNode),0);
    }

    /* count geometric objects */
    for (theElement=FIRSTELEMENT(theGrid);
         theElement!=NULL; theElement=SUCCE(theElement))
    {
      if ((EstimateHere(theElement)) || (l==covise->max_level))
      {
        int i, coe = CORNERS_OF_ELEM(theElement);
        n_elem++;

        for (i=0; i<coe; i++)
        {
          theNode = CORNER(theElement,i);

          n_conn++;

          if (USED(MYVERTEX(theNode))) continue;
          SETUSED(MYVERTEX(theNode),1);

          if ((SONNODE(theNode)==NULL) || (l==covise->max_level))
          {
                                                #ifdef ModelP
            if (PRIO(theNode) == PrioMaster)
                                                #endif
            n_vertices++;
          }
        }
      }
    }
  }
        #ifdef ModelP
  n_vertices = UG_GlobalSumINT(n_vertices);
  n_elem     = UG_GlobalSumINT(n_elem);
  n_conn     = UG_GlobalSumINT(n_conn);
        #endif
  covise->n_vertices = n_vertices;
  covise->n_elems    = n_elem;
  covise->n_conns    = n_conn;

  return(0);
}
static int
doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
{
    char *dirname, *fontscale_name, *filename, *encdir;
    FILE *fontscale, *encfile;
    DIR *dirp;
    struct dirent *entry;
    FT_Error ftrc;
    FT_Face face;
    ListPtr encoding, xlfd, lp;
    HashTablePtr entries;
    HashBucketPtr *array;
    int i, n, found, rc;
    int isBitmap=0,xl=0;

    if (exclusionSuffix)
        xl = strlen (exclusionSuffix);

    i = strlen(dirname_given);
    if(i == 0)
        dirname = dsprintf("./");
    else if(dirname_given[i - 1] != '/')
        dirname = dsprintf("%s/", dirname_given);
    else
        dirname = dsprintf("%s", dirname_given);

    if(dirname == NULL) {
        perror("dirname");
        exit(1);
    }

    if (onlyEncodings)
	goto encodings;

    entries = makeHashTable();
    if(doBitmaps && !doScalable) {
        readFontScale(entries, dirname);
    }

    if(strcmp(outfilename, "-") == 0)
        fontscale_name = NULL;
    else {
        if(outfilename[0] == '/')
            fontscale_name = dsprintf("%s", outfilename);
        else
            fontscale_name = dsprintf("%s%s", dirname, outfilename);
        if(fontscale_name == NULL) {
            perror("fontscale_name");
            exit(1);
        }
    }

    dirp = opendir(dirname);
    if(dirp == NULL) {
        fprintf(stderr, "%s: ", dirname);
        perror("opendir");
        return 0;
    }

    if(fontscale_name == NULL)
        fontscale = stdout;
    else
        fontscale = fopen(fontscale_name, "wb");

    if(fontscale == NULL) {
        fprintf(stderr, "%s: ", fontscale_name);
        perror("fopen(w)");
        return 0;
    }

    while((entry = readdir(dirp)) != NULL) {
        int have_face = 0;
        char *xlfd_name = NULL;
	struct stat f_stat;
	int tprio = 1;

        xlfd = NULL;

	if (xl) {
	    int dl = strlen (entry->d_name);
	    if (strcmp (entry->d_name + dl - xl, exclusionSuffix) == 0)
		continue;
	}

        filename = dsprintf("%s%s", dirname, entry->d_name);

#define PRIO(x) ((x << 1) + tprio)
#ifdef DT_LNK
	if (entry->d_type != DT_UNKNOWN) {
	    if (entry->d_type == DT_LNK)
		tprio = 0;
	} else
#endif
#ifdef S_ISLNK
	{
#ifndef WIN32
	    if (lstat(filename, &f_stat))
		goto done;
	    if (S_ISLNK(f_stat.st_mode))
		tprio = 0;
#endif
	}
#else
	;
#endif
        if(doBitmaps)
            rc = bitmapIdentify(filename, &xlfd_name);
        else
            rc = 0;

        if(rc < 0)
            goto done;

        if(rc == 0) {
            ftrc = FT_New_Face(ft_library, filename, 0, &face);
            if(ftrc)
                goto done;
            have_face = 1;

            isBitmap = ((face->face_flags & FT_FACE_FLAG_SCALABLE) == 0);

            if(!isBitmap) {
                /* Workaround for bitmap-only SFNT fonts */
                if(FT_IS_SFNT(face) && face->num_fixed_sizes > 0 &&
                   strcmp(FT_Get_X11_Font_Format(face), "TrueType") == 0) {
                    TT_MaxProfile *maxp;
                    maxp = FT_Get_Sfnt_Table(face, ft_sfnt_maxp);
                    if(maxp != NULL && maxp->maxContours == 0)
                        isBitmap = 1;
                }
            }

            if(isBitmap) {
                if(!doBitmaps)
                    goto done;
            } else {
                if(!doScalable)
                    goto done;
            }

            if(isBitmap) {
                BDF_PropertyRec prop;
                rc = FT_Get_BDF_Property(face, "FONT", &prop);
                if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
                    xlfd_name = strdup(prop.u.atom);
                    if(xlfd_name == NULL)
                        goto done;
                }
            }
        }

        if(xlfd_name) {
            /* We know it's a bitmap font, and we know its XLFD */
            int n = strlen(xlfd_name);
            if(reencodeLegacy &&
               n >= 12 && strcasecmp(xlfd_name + n - 11, "-iso10646-1") == 0) {
                char *s;

                s = malloc(n - 10);
                memcpy(s, xlfd_name, n - 11);
                s[n - 11] = '\0';
                xlfd = listCons(s, xlfd);
            } else {
                /* Not a reencodable font -- skip all the rest of the loop body */
                putHash(entries, xlfd_name, entry->d_name, PRIO(filePrio(entry->d_name)));
                goto done;
            }
        }

        if(!have_face) {
            ftrc = FT_New_Face(ft_library, filename, 0, &face);
            if(ftrc)
                goto done;
            have_face = 1;
            isBitmap = ((face->face_flags & FT_FACE_FLAG_SCALABLE) == 0);

            if(!isBitmap) {
                if(face->num_fixed_sizes > 0) {
                    TT_MaxProfile *maxp;
                    maxp = FT_Get_Sfnt_Table(face, ft_sfnt_maxp);
                    if(maxp != NULL && maxp->maxContours == 0)
                        isBitmap = 1;
                }
            }
        }

        if(xlfd == NULL)
            xlfd = makeXLFD(entry->d_name, face, isBitmap);

        found = 0;

        for(lp = xlfd; lp; lp = lp->next) {
            char buf[MAXFONTNAMELEN];
            for(encoding = encodings; encoding; encoding = encoding->next) {
                if(checkEncoding(face, encoding->value)) {
                    found = 1;
                    snprintf(buf, MAXFONTNAMELEN, "%s-%s",
                            lp->value, encoding->value);
                    putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name)));
                }
            }
            for(encoding = extra_encodings; encoding;
                encoding = encoding->next) {
                if(checkExtraEncoding(face, encoding->value, found)) {
                    /* Do not set found! */
                    snprintf(buf, MAXFONTNAMELEN, "%s-%s",
                            lp->value, encoding->value);
                    putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name)));
                }
            }
        }
    done:
        if(have_face)
            FT_Done_Face(face);
        deepDestroyList(xlfd);
        xlfd = NULL;
        free(filename);
#undef PRIO
    }

    closedir(dirp);
    n = hashElements(entries);
    fprintf(fontscale, "%d\n", n);
    array = hashArray(entries, 1);
    for(i = 0; i < n; i++)
        fprintf(fontscale, "%s %s\n", array[i]->value, array[i]->key);
    destroyHashArray(array);
    entries = NULL;
    if(fontscale_name) {
        fclose(fontscale);
        free(fontscale_name);
    }

 encodings:
    encdir = dsprintf("%s%s", dirname, "encodings.dir");

    if(encdir == NULL) {
	perror("encodings");
	exit(1);
    }
    unlink(encdir);

    if (numEncodings) {
	encfile = fopen(encdir, "w");
	if(encfile == NULL) {
	    perror("open(encodings.dir)");
	    exit(1);
	}
        fprintf(encfile, "%d\n", numEncodings);
        encodingsToDo = sortList(encodingsToDo);
        for(lp = encodingsToDo; lp; lp = lp->next) {
            fprintf(encfile, "%s\n", lp->value);
        }
	fclose (encfile);
    }

    free(dirname);
    return 1;
}