📄 ps_afm.c
字号:
if(!expect(";")) { ps_error(psdoc, PS_RuntimeError, _("Expected ';' in protusion file.")); return(ps_false); } } return(ps_true);}/* }}} *//* calculatekern() {{{ * * Calculates the kerning between two consecutive glyphs. */int calculatekern(ADOBEINFO *ai, ADOBEINFO *succ) { KERN *k; if((NULL == ai) || (NULL == succ)) return(0); k = ai->kerns;// printf("get kerning for %s followed by %s\n", ai->adobename, succ->adobename); while (k && strcmp(k->succ, succ->adobename)!=0) {// printf("'%s' == '%s': kerning %d\n", k->succ, succ->adobename, k->delta); k = k->next ; } if(k) {// printf("%s == %s: kerning %d\n", k->succ, succ->adobename, k->delta); return(k->delta); } else { return(0); }}/* }}} *//* addkern() {{{ * * Adds a new kerning pair to the list. Does not check if the pair * already exists. The new pair is inserted at the beginning of the * list. */void addkern(PSDoc *psdoc, ADOBEINFO *ai, ADOBEINFO *succ, int kerning) { KERN *nk ; if((NULL == ai) || (NULL == succ)) { error("One of the glyphs is not set."); return; } nk = newkern(psdoc) ; nk->succ = newstring(psdoc, succ->adobename); nk->delta = kerning; nk->next = ai->kerns ; ai->kerns = nk ;}/* }}} *//* addligature() {{{ * * Adds a new ligature to the list. Does not check if the ligature * already exists. The new ligature is inserted at the beginning of the * list. */void addligature(PSDoc *psdoc, ADOBEINFO *ai, ADOBEINFO *succ, ADOBEINFO *sub) { LIG *nl ; if((NULL == ai) || (NULL == succ) || (NULL == sub)) { error("One of the glyphs is not set."); return; } nl = newlig(psdoc) ; nl->succ = newstring(psdoc, succ->adobename); nl->sub = newstring(psdoc, sub->adobename) ; nl->next = ai->ligs ; ai->ligs = nl ;}/* }}} *//* gfindadobe() {{{ * * Finds metric of a glyph by its name. * This function replaces findadobe(). */ADOBEINFO *gfindadobe(ght_hash_table_t *gadobechars, const char *p) { ADOBEINFO *ai ; if(p == NULL || p[0] == '\0') return(NULL); if(gadobechars == NULL) return(NULL); ai = ght_get(gadobechars, strlen(p)+1, (void *) p); return(ai) ;}/* }}} *//* handlekern() {{{ * * The following comment no longer applies; we rely on the LIGKERN * entries to kill space kerns. Also, the same applies to numbers. * * We ignore kerns before and after space characters, because (1) TeX * is using the space only for Polish ligatures, and (2) TeX's * boundarychar mechanisms are not oriented to kerns (they apply * to both spaces and punctuation) so we don't want to use them. */static void handlekern(PSDoc *psdoc, ADOBEFONTMETRIC *metric) { /* an input line beginning with KPX */ ADOBEINFO *ai ; char *p ; KERN *nk ; p = paramstring() ; ai = gfindadobe(metric->gadobechars, p) ; if (ai == NULL) error("kern char not found") ; else { nk = newkern(psdoc) ; nk->succ = paramnewstring(psdoc) ; nk->delta = paramnum(); //transform(paramnum(),0) ; nk->next = ai->kerns ; ai->kerns = nk ; }}/* }}} *//* handleconstruct() {{{ * * Reads lines for composite chars from afm file. */static int handleconstruct(PSDoc *psdoc, ADOBEFONTMETRIC *metric) { /* an input line beginning with CC */ ADOBEINFO *ai ; char *p ; PCC *np ; int n ; PCC *npp = NULL; p = paramstring() ; ai = gfindadobe(metric->gadobechars, p) ; if (ai == NULL) error("! composite character name not found") ; n = paramnum() ; if(!expect(";")) { fprintf(stderr, "; expected: ") ; error("syntax error"); return(ps_false); } while (n--) { if (strcmp(paramstring(),"PCC") != 0) return(ps_false); /* maybe I should expect("PCC") instead, but I'm playing it safe */ np = newpcc(psdoc) ; np->partname = paramnewstring(psdoc) ; if (gfindadobe(metric->gadobechars, np->partname)==NULL) return(ps_false); np->xoffset = paramnum() ; np->yoffset = paramnum() ;// np->xoffset = transform(np->xoffset, np->yoffset) ; if (npp) npp->next = np ; else ai->pccs = np ; npp = np ; if(!expect(";")) { fprintf(stderr, "; expected: ") ; error("syntax error"); return(ps_false); } } return(ps_true);}/* }}} *//* makeaccentligs() {{{ * * Creates artificial ligatures for glyphs like adieresis or Aacute by * using the first letter (a, A, ...) and the rest of the glyph name * (dieresis, acute, ...) to form a ligature. This will also try to * make ligature for eg. one, exclam, space, which will fail because * there is no glyph 'ne', 'xclam' or 'pace'. This is somewhat a brute * force methode. *//*static void makeaccentligs(ght_hash_table_t *gadobechars) { ADOBEINFO *ai, *aci ; char *p ; LIG *nl ; ght_iterator_t iterator; for(ai = ght_first(gadobechars, &iterator, (void **) &p); ai != NULL; ai = ght_next(gadobechars, &iterator, (void **) &p)) { if (strlen(p)>2) if ((aci=gfindadobe(gadobechars, p+1)) && (aci->adobenum > 127)) { nl = newlig() ; nl->succ = mymalloc((unsigned long)2) ; *(nl->succ + 1) = 0 ; *(nl->succ) = *p ; nl->sub = ai->adobename ; nl->next = aci->ligs ; aci->ligs = nl ; } }}*//* }}} *//* readprotusion() {{{ * * Read file with information about protusion of single chars. */int readprotusion(PSDoc *psdoc, PSFont *psfont, const char *filename) { ADOBEFONTMETRIC *metrics; FILE *fp;#ifdef VMCMS int i;#endif metrics = psfont->metrics; if(NULL == (fp = ps_open_file_in_path(psdoc, filename))) { return(-1); } while (getline(fp)) { switch(interest(paramstring())) { case N: handleprotusion(psdoc, metrics) ; break ; } } fclose(fp) ; return(0);}/* }}} *//* readadobe() {{{ * * Reads an afm file and returns a adobe font metric structure. */ADOBEFONTMETRIC *readadobe(PSDoc *psdoc, const char *filename) { ADOBEINFO *ai; ADOBEFONTMETRIC *metric;#ifdef VMCMS int i;#endif if(NULL == (metric = (ADOBEFONTMETRIC *) psdoc->malloc(psdoc, sizeof(ADOBEFONTMETRIC), _("Allocate space for font metric.")))) { return(NULL); } memset(metric, 0, sizeof(ADOBEFONTMETRIC)); if(0 == (metric->afmin = ps_open_file_in_path(psdoc, filename))) { ps_error(psdoc, PS_RuntimeError, _("Couldn't open afm file: %s\n"), filename); return(NULL); } /* * Create the hash table for the chars */ metric->gadobechars = ght_create(512); ght_set_alloc(metric->gadobechars, ps_ght_malloc, ps_ght_free, psdoc); /* * Set default font encoding */// metric->fontenc = ps_build_enc_hash(psdoc, &fontencoding); metric->fontenc = NULL; /* * Read file line by line. */ while (getline(metric->afmin)) { switch(interest(paramstring())) {case FontName: metric->fontname = paramnewstring(psdoc) ;#ifdef VMCMS /* fontname comes in as ebcdic but we need it asciified for tfm file so we save it in ebfontname and change it in fontname */ metric->ebfontname = newstring(psdoc, metric->fontname) ; i=0; while(metric->fontname[i] != '\0') { metric->fontname[i]=ebcdic2ascii[metric->fontname[i]]; i++; }#endif break ;case EncodingScheme: metric->codingscheme = paramnewstring(psdoc) ;#ifdef VMCMS/* for codingscheme, we do the same as we did for fontname */ metric->ebcodingscheme = newstring(psdoc, metric->codingscheme) ; i=0; while(metric->codingscheme[i] != '\0') { metric->codingscheme[i]=ebcdic2ascii[metric->codingscheme[i]]; i++; }#endif break ;case ItalicAngle: metric->italicangle = paramfloat() ; break ;case UnderlinePosition: metric->underlineposition = paramfloat() ; break ;case UnderlineThickness: metric->underlinethickness = paramfloat() ; break ;case Ascender: metric->ascender = paramfloat() ; break ;case Descender: metric->descender = paramfloat() ; break ;case CapHeight: metric->capheight = paramfloat() ; break ;case IsFixedPitch: if (*param == 't' || *param == 'T') metric->fixedpitch = 1 ; else metric->fixedpitch = 0 ; break ;case XHeight: metric->xheight = paramnum() ; break ;case C: { ADOBEINFO *hai = handlechar(psdoc, metric) ; if(gfindadobe(metric->gadobechars, hai->adobename)) { ps_error(psdoc, PS_Warning, _("Trying to insert the glyph '%s' which already exists. Please check your afm file for duplicate glyph names."), hai->adobename); /* FIXME: Freeing the name and the ADOBEINFO structure may not be * enough. There can be kerning pairs and ligatures. */ psdoc->free(psdoc, hai->adobename); psdoc->free(psdoc, hai); } else ght_insert(metric->gadobechars, hai, strlen(hai->adobename)+1, hai->adobename); break ;}case KPX: handlekern(psdoc, metric) ; break ;case CC: handleconstruct(psdoc, metric) ; break ;default: break ; } } fclose(metric->afmin) ; metric->afmin = 0 ; if (0 != (ai = gfindadobe(metric->gadobechars, "space"))) { metric->fontspace = ai->width ; } else { metric->fontspace = 500; //transform(500, 0) ; }/* { ght_iterator_t iterator; char *p_key; ADOBEINFO *p_e; for(p_e = ght_first(metric->gadobechars, &iterator, &p_key); p_e; p_e = ght_next(metric->gadobechars, &iterator, &p_key)) { fprintf(stderr, "%s = %s\n", p_key, p_e->adobename); } }*/ return(metric);}/* }}} *//* * Re-encode the adobe font. Assumes that the header file will * also contain the appropriate instructions! *//*static char *outenname, *inenname ;static ENCODING *outencoding = NULL ;static ENCODING *inencoding = NULL ;voidhandlereencoding(ADOBEFONTMETRIC *metric) { if (inenname) { int i ; ADOBEINFO *ai ; char *p ; ignoreligkern = 1 ; inencoding = readencoding(inenname) ; for (i=0; i<256; i++) if (0 != (ai=metric->adobeptrs[i])) { ai->adobenum = -1 ; metric->adobeptrs[i] = NULL ; } for (i=0; i<256; i++) { p = inencoding->vec[i] ; if (p && *p && 0 != (ai = gfindadobe(metric->gadobechars, p))) { ai->adobenum = i ; metric->adobeptrs[i] = ai ; } } metric->codingscheme = inencoding->name ; } ignoreligkern = 0 ; if (outenname) { outencoding = readencoding(outenname) ; } else { outencoding = readencoding((char *)0) ; }}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -