From 30ca2bdcde0675a2d52a9decf9dce73e57fdcee1 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 6 Jan 2007 17:32:34 +0000 Subject: Overhaul of glyph-name handling in the paper backends. Before, we had a separate dense array of glyph names for each font, and referenced glyphs by indicies into that array, which meant that the array had to be set up before we could generate any indices. Now we have an overall array of glyph names, and use the same glyph indicies for all fonts. Some arrays have had to turn into tree234s as a result. [originally from svn r7061] --- in_afm.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'in_afm.c') diff --git a/in_afm.c b/in_afm.c index a4dd0f6..d3d5ecb 100644 --- a/in_afm.c +++ b/in_afm.c @@ -55,9 +55,7 @@ void read_afm_file(input *in) { fi = snew(font_info); fi->name = NULL; - fi->nglyphs = 0; - fi->glyphs = NULL; - fi->widths = NULL; + fi->widths = newtree234(width_cmp); fi->fp = NULL; fi->kerns = newtree234(kern_cmp); fi->ligs = newtree234(lig_cmp); @@ -153,19 +151,17 @@ void read_afm_file(input *in) { } fi->italicangle = atof(val); } else if (strcmp(key, "StartCharMetrics") == 0) { - char const **glyphs; - int *widths; - int i; + int nglyphs, i; if (!(val = strtok(NULL, " \t"))) { error(err_afmval, &in->pos, key, 1); goto giveup; } - fi->nglyphs = atoi(val); + nglyphs = atoi(val); sfree(line); - glyphs = snewn(fi->nglyphs, char const *); - widths = snewn(fi->nglyphs, int); - for (i = 0; i < fi->nglyphs; i++) { - glyphs[i] = NULL; + for (i = 0; i < nglyphs; i++) { + int width = 0; + glyph g = NOGLYPH; + line = afm_read_line(in); if (line == NULL) goto giveup; @@ -177,14 +173,14 @@ void read_afm_file(input *in) { error(err_afmval, &in->pos, key, 1); goto giveup; } - widths[i] = atoi(val); + width = atoi(val); } else if (strcmp(key, "N") == 0) { if (!(val = strtok(NULL, " \t")) || !strcmp(val, ";")) { error(err_afmval, &in->pos, key, 1); goto giveup; } - glyphs[i] = dupstr(val); + g = glyph_intern(val); } do { key = strtok(NULL, " \t"); @@ -192,21 +188,22 @@ void read_afm_file(input *in) { key = strtok(NULL, " \t"); } sfree(line); + if (width != 0 && g != NOGLYPH) { + wchar_t ucs; + glyph_width *w = snew(glyph_width); + w->glyph = g; + w->width = width; + add234(fi->widths, w); + ucs = ps_glyph_to_unicode(glyph_extern(g)); + if (ucs < 0xFFFF) + fi->bmp[ucs] = g; + } } line = afm_read_line(in); if (!line || !afm_require_key(line, "EndCharMetrics", in)) goto giveup; sfree(line); - fi->glyphs = glyphs; - fi->widths = widths; - for (i = 0; i < fi->nglyphs; i++) { - wchar_t ucs; - ucs = ps_glyph_to_unicode(fi->glyphs[i]); - if (ucs < 0xFFFF) - fi->bmp[ucs] = i; - } - font_index_glyphs(fi); } else if (strcmp(key, "StartKernPairs") == 0 || strcmp(key, "StartKernPairs0") == 0) { int nkerns, i; @@ -234,8 +231,8 @@ void read_afm_file(input *in) { error(err_afmval, &in->pos, key, 3); goto giveup; } - l = find_glyph(fi, nl); - r = find_glyph(fi, nr); + l = glyph_intern(nl); + r = glyph_intern(nr); if (l == -1 || r == -1) continue; kp = snew(kern_pair); kp->left = l; -- cgit v1.1