Ejemplo n.º 1
0
SplineChar *SCBuildDummy(SplineChar *dummy,SplineFont *sf,EncMap *map,int i) {
    static char namebuf[100];
    static Layer layers[2];

    memset(dummy,'\0',sizeof(*dummy));
    dummy->color = COLOR_DEFAULT;
    dummy->layer_cnt = 2;
    dummy->layers = layers;
    if ( sf->cidmaster!=NULL ) {
	/* CID fonts don't have encodings, instead we must look up the cid */
	if ( sf->cidmaster->loading_cid_map )
	    dummy->unicodeenc = -1;
	else
	    dummy->unicodeenc = CID2NameUni(FindCidMap(sf->cidmaster->cidregistry,sf->cidmaster->ordering,sf->cidmaster->supplement,sf->cidmaster),
		    i,namebuf,sizeof(namebuf));
    } else
	dummy->unicodeenc = UniFromEnc(i,map->enc);

    if ( sf->cidmaster!=NULL )
	dummy->name = namebuf;
    else if ( map->enc->psnames!=NULL && i<map->enc->char_cnt &&
	    map->enc->psnames[i]!=NULL )
	dummy->name = map->enc->psnames[i];
    else if ( dummy->unicodeenc==-1 )
	dummy->name = NULL;
    else
	dummy->name = (char *) StdGlyphName(namebuf,dummy->unicodeenc,sf->uni_interp,sf->for_new_glyphs);
    if ( dummy->name==NULL ) {
	/*if ( dummy->unicodeenc!=-1 || i<256 )
	    dummy->name = ".notdef";
	else*/ {
	    int j;
	    sprintf( namebuf, "NameMe.%d", i);
	    j=0;
	    while ( SFFindExistingSlot(sf,-1,namebuf)!=-1 )
		sprintf( namebuf, "NameMe.%d.%d", i, ++j);
	    dummy->name = namebuf;
	}
    }
    dummy->width = dummy->vwidth = sf->ascent+sf->descent;
    if ( dummy->unicodeenc>0 && dummy->unicodeenc<0x10000 &&
	    iscombining(dummy->unicodeenc)) {
	/* Mark characters should be 0 width */
	dummy->width = 0;
	/* Except in monospaced fonts on windows, where they should be the */
	/*  same width as everything else */
    }
    /* Actually, in a monospace font, all glyphs should be the same width */
    /*  whether mark or not */
    if ( sf->pfminfo.panose_set && sf->pfminfo.panose[3]==9 &&
	    sf->glyphcnt>0 ) {
	for ( i=sf->glyphcnt-1; i>=0; --i )
	    if ( SCWorthOutputting(sf->glyphs[i])) {
		dummy->width = sf->glyphs[i]->width;
	break;
	    }
    }
    dummy->parent = sf;
    dummy->orig_pos = 0xffff;
return( dummy );
}
struct cidmap *AskUserForCIDMap(void) {
    struct block block;
    struct cidmap *map = NULL;
    char buffer[200];
    char **choices;
    int i,ret;
    char *filename=NULL;
    char *reg, *ord, *pt;
    int supplement;

    memset(&block,'\0',sizeof(block));
    for ( map = cidmaps; map!=NULL; map = map->next ) {
        sprintf(buffer,"%s-%s-%d", map->registry, map->ordering, map->supplement);
        AddToBlock(&block,buffer,NULL);
    }
    FindMapsInDir(&block,".");
    FindMapsInDir(&block,GResourceProgramDir);
    FindMapsInNoLibsDir(&block,GResourceProgramDir);
    FindMapsInDir(&block,getFontForgeShareDir());
    FindMapsInDir(&block,"/usr/share/fontforge");

    choices = gcalloc(block.cur+2,sizeof(unichar_t *));
    choices[0] = copy(_("Browse..."));
    for ( i=0; i<block.cur; ++i )
        choices[i+1] = copy(block.maps[i]);
    ret = gwwv_choose(_("Find a cidmap file..."),(const char **) choices,i+1,0,_("Please select a CID ordering"));
    for ( i=0; i<=block.cur; ++i )
        free( choices[i] );
    free(choices);
    if ( ret==0 ) {
        filename = gwwv_open_filename(_("Find a cidmap file..."),NULL,
                                      "?*-?*-[0-9]*.cidmap",NULL);
        if ( filename==NULL )
            ret = -1;
    }
    if ( ret!=-1 ) {
        if ( filename!=NULL )
            /* Do nothing for now */;
        else if ( block.dirs[ret-1]!=NULL ) {
            filename = galloc(strlen(block.dirs[ret-1])+strlen(block.maps[ret-1])+3+8);
            strcpy(filename,block.dirs[ret-1]);
            strcat(filename,"/");
            strcat(filename,block.maps[ret-1]);
            strcat(filename,".cidmap");
        }
        if ( ret!=0 )
            reg = block.maps[ret-1];
        else {
            reg = strrchr(filename,'/');
            if ( reg==NULL ) reg = filename;
            else ++reg;
            reg = copy(reg);
        }
        pt = strchr(reg,'-');
        if ( pt==NULL )
            ret = -1;
        else {
            *pt = '\0';
            ord = pt+1;
            pt = strchr(ord,'-');
            if ( pt==NULL )
                ret = -1;
            else {
                *pt = '\0';
                supplement = strtol(pt+1,NULL,10);
            }
        }
        if ( ret == -1 )
            /* No map */;
        else if ( filename==NULL )
            map = FindCidMap(reg,ord,supplement,NULL);
        else {
            map = LoadMapFromFile(filename,reg,ord,supplement);
            free(filename);
        }
        if ( ret!=0 && reg!=block.maps[ret-1] )
            free(reg);
        /*free(filename);*/	/* Freed by loadmap */
    }
    for ( i=0; i<block.cur; ++i )
        free( block.maps[i]);
    free(block.maps);
    free(block.dirs);
    return( map );
}