Encoding *MakeEncoding(SplineFont *sf,EncMap *map) {
    char *name;
    int i, gid;
    Encoding *item, *temp;
    SplineChar *sc;

    if ( map->enc!=&custom )
        return(NULL);

    name = gwwv_ask_string(_("Please name this encoding"),NULL,_("Please name this encoding"));
    if ( name==NULL )
        return(NULL);
    item = gcalloc(1,sizeof(Encoding));
    item->enc_name = name;
    item->only_1byte = item->has_1byte = true;
    item->char_cnt = map->enccount;
    item->unicode = gcalloc(map->enccount,sizeof(int32));
    for ( i=0; i<map->enccount; ++i ) if ( (gid = map->map[i])!=-1 && (sc=sf->glyphs[gid])!=NULL ) {
            if ( sc->unicodeenc!=-1 )
                item->unicode[i] = sc->unicodeenc;
            else if ( strcmp(sc->name,".notdef")!=0 ) {
                if ( item->psnames==NULL )
                    item->psnames = gcalloc(map->enccount,sizeof(unichar_t *));
                item->psnames[i] = copy(sc->name);
            }
        }
    RemoveMultiples(item);

    if ( enclist == NULL )
        enclist = item;
    else {
        for ( temp=enclist; temp->next!=NULL; temp=temp->next );
        temp->next = item;
    }
    DumpPfaEditEncodings();
    return( item );
}
Example #2
0
static SplineChar *AddAnchor(AnchorDlg *a, SplineFont *sf, AnchorClass *ac,
	int ismarklike) {
    char *ret, *def;
    SplineChar *sc;
    int isliga = false, ismrk=false, maxlig=-1;
    AnchorPoint *ap;
    PST *pst;
    int i;

    def = copy(".notdef");
    for (;;) {
	ret = gwwv_ask_string(_("Provide a glyph name"),def,_("Please identify a glyph by name, and FontForge will add an anchor to that glyph."));
	free(def);
	if ( ret==NULL )
return( NULL );
	sc = SFGetChar(sf,-1,ret);
	def = ret;
	if ( sc==NULL )
	    ff_post_error(_("Non-existant glyph"), _("The glyph, %.80s, is not in the font"), ret );
	else {
	    isliga = ismrk = false;
	    for ( ap=sc->anchor ; ap!=NULL; ap=ap->next ) {
		if ( ap->type == at_baselig )
		    isliga = true;
		else if ( ap->type == at_basemark || ap->type == at_mark )
		    ismrk = true;
		if ( ap->anchor == ac ) {
		    if ( (ap->type == at_centry ||
			    (ap->type == at_mark && ac->type==act_mkmk) ||
			    ap->type == at_baselig ) && ismarklike==-1 )
			ismarklike = false;
		    else if ( (ap->type == at_cexit || (ap->type == at_basemark && ac->type==act_mkmk)) && ismarklike==-1 )
			ismarklike = true;
		    else if ( ap->type != at_baselig ||
			      ( ap->type == at_baselig && ismarklike>0 ))
			ff_post_error(_("Duplicate Anchor Class"), _("The glyph, %.80s, already contains an anchor in this class, %.80s."), ret, ac->name );
		    else if ( maxlig<ap->lig_index )
			maxlig = ap->lig_index;
	    break;
		}
	    }
	    if ( ap==NULL )
    break;
	}
    }

    ap = chunkalloc(sizeof(AnchorPoint));
    ap->anchor = ac;
    ap->me.x = ap->me.y = 0;
    ap->next = sc->anchor;
    sc->anchor = ap;
    SCCharChangedUpdate(sc,ly_none);

    if ( sc->width==0 ) ismrk = true;
    for ( pst=sc->possub; pst!=NULL; pst=pst->next ) {
	if ( pst->type == pst_ligature || pst->type == pst_lcaret ) {
	    isliga = true;
    break;
	}
    }

    if ( isliga || (ac->type==act_mklg && ismarklike==0 ) ) {
	ap->type = at_baselig;
	ap->lig_index = maxlig+1;
    } else if ( ismrk && ismarklike!=0 )
	ap->type = at_mark;
    else if ( ismarklike==0 && (ismrk || ac->type==act_mkmk) )
	ap->type = at_basemark;
    else if ( ac->type == act_curs ) {
	if ( ismarklike==true )
	    ap->type = at_centry;
	else
	    ap->type = at_cexit;
    } else if ( ismarklike==true )
	ap->type = at_mark;
    else
	ap->type = at_basechar;

    if ( a!=NULL ) {
	GTextInfo **ti = AnchorD_GlyphsInClass(a);
	GGadgetSetList(GWidgetGetControl(a->gw,CID_Glyph),ti,false);
	for ( i=0; ti[i]->text!=NULL || ti[i]->line; ++i ) {
	    if ( ti[i]->userdata == ap ) {
		GGadgetSelectOneListItem(GWidgetGetControl(a->gw,CID_Glyph),i);
	break;
	    }
	}
	AnchorD_ChangeGlyph(a,sc,ap);
    }
return( sc );
}