summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvipdfm-x/agl.c
blob: dc9f674fc48184d25daf7e634c29140afa4f5f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
/* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.

    Copyright (C) 2007-2016 by Jin-Hwan Cho and Shunsaku Hirata,
    the dvipdfmx project team.

    Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/

/*
 * References:
 *
 *  Unicode and Glyph Names, ver. 2.3., Adobe Solution Network
 *  http://partners.adobe.com/asn/tech/type/unicodegn.jsp
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <ctype.h>

#include "system.h"
#include "mem.h"
#include "error.h"

#include "mfileio.h"
#include "pdfparse.h"

/* Hash */
#include "dpxutil.h"

#include "dpxfile.h"

#include "unicode.h"

#include "agl.h"

static int agl_load_listfile (const char *filename, int format);

static int verbose = 0;

void
agl_set_verbose (void)
{
  verbose++;
}

static agl_name *
agl_new_name (void)
{
  agl_name *agln;

  agln = NEW(1, agl_name);
  agln->name   = NULL;
  agln->suffix = NULL;
  agln->n_components = 0;
  agln->alternate = NULL;
  agln->is_predef = 0;

  return agln;
}

static void
agl_release_name (agl_name *agln)
{
  agl_name *next;

  while (agln) {
    next = agln->alternate;
    if (agln->name)
      RELEASE(agln->name);
    if (agln->suffix)
      RELEASE(agln->suffix);
    agln->name = NULL;
    RELEASE(agln);
    agln = next;
  }
}

char *
agl_chop_suffix (const char *glyphname, char **suffix)
{
  char  *name, *p;
  int    len;

  ASSERT(glyphname && suffix);

  p = strchr(glyphname, '.');
  if (p) {
    len = strlen(glyphname) - strlen(p);
    if (len < 1) {
      name = NULL;
      *suffix = NEW(strlen(glyphname), char);
      strcpy(*suffix, glyphname+1);
    } else {
      p++;
      name = NEW(len + 1, char);
      strncpy(name, glyphname, len);
      name[len] = '\0';
      if (p[0] == '\0') {
	*suffix = NULL;
      } else {
	*suffix = NEW(strlen(p) + 1, char);
	strcpy(*suffix, p);
      }
    }
  } else {
    name = NEW(strlen(glyphname) + 1, char);
    strcpy(name, glyphname);
    *suffix = NULL;
  }

  return name;
}

static const char * const modifiers[] = {
  "acute", "breve", "caron", "cedilla", "circumflex",
  "dieresis", "dotaccent", "grave", "hungarumlaut",
  "macron", "ogonek", "ring", "tilde", "commaaccent", 
  "slash",

  /* The following entries are not accent nor something
   * but PS font may have those "small" version...
   */
  "ampersand", "exclam", "exclamdown",
  "question","questiondown",
  NULL
};

static int
skip_capital (const char **p, const char *endptr)
{
  int slen = 0, len;

  len = (int) (endptr - (*p));

  if (len >= 2 &&
      ((**p == 'A' && *(*p+1) == 'E') ||
       (**p == 'O' && *(*p+1) == 'E'))) {
    *p  += 2;
    slen = 2;
  } else if (len >= 3 &&
	     **p     == 'E' &&
	     *(*p+1) == 't' &&
	     *(*p+2) == 'h') {
    *p  += 3;
    slen = 3;
  } else if (len >= 5 &&
	     **p     == 'T' &&
	     *(*p+1) == 'h' &&
	     *(*p+2) == 'o' &&
	     *(*p+3) == 'r' &&
	     *(*p+4) == 'n') {
    *p  += 5;
    slen = 5;
  } else if (len >= 1 &&
	     **p >= 'A' && **p <= 'Z') {
    *p  += 1;
    slen = 1;
  }

  return slen;
}

static int
skip_modifier (const char **p, const char *endptr)
{
  int  slen = 0, len;
  int  i;

  len = (int) (endptr - (*p));

  for (i = 0; modifiers[i] != NULL; i++) {
    if ((len >= strlen(modifiers[i]) &&
	 !memcmp(*p, modifiers[i], len))) {
      slen = strlen(modifiers[i]);
      *p  += slen;
      break;
    }
  }

  return slen;
}

static int
is_smallcap (const char *glyphname)
{
  int  len, slen;
  const char *p, *endptr;

  if (!glyphname)
    return 0;

  p   = glyphname;
  len = strlen(glyphname);
  if (len < 6 ||
      strcmp(p + len - 5, "small"))
    return 0;

  endptr = p + len - 5;

  len -= 5;
  slen = skip_modifier(&p, endptr);
  if (slen == len)
    return 1;  /* Acutesmall, Gravesmall, etc */
  else if (slen > 0) { /* ??? */
    return 0;
  }

  len -= skip_capital(&p, endptr);
  if (len == 0) {
    return 1;  /* Asmall, AEsmall, etc */
  }

  while (len > 0) { /* allow multiple accent */
    slen = skip_modifier(&p, endptr);
    if (slen == 0)
      return 0;
    len -= slen;
  }

  return 1;
}

#define SUFFIX_LIST_MAX  16
#define AGL_VAR_SMCP_IDX 0
static struct {
  const char   *key;
  const char   *otl_tag;
  const char   *suffixes[SUFFIX_LIST_MAX];
} var_list[] = {
  {"small"       , "smcp", {"sc", NULL}},
  {"swash"       , "swsh", {NULL}},
  {"superior"    , "sups", {NULL}},
  {"inferior"    , "sinf", {NULL}},
  {"numerator"   , "numr", {NULL}},
  {"denominator" , "dnom", {NULL}},
  {"oldstyle"    , "onum", {NULL}},

  /* The following only used by TeX, there are no
   * corresponding OTL feat. tag.
   */
  {"display" , NULL, {NULL}},
  {"text"    , NULL, {NULL}},
  {"big"     , NULL, {NULL}},
  {"bigg"    , NULL, {NULL}},
  {"Big"     , NULL, {NULL}},
  {"Bigg"    , NULL, {NULL}},
  {NULL, NULL, {NULL}}
};

const char *
agl_suffix_to_otltag (const char *suffix)
{
  int i, j;
  
  for (i = 0; var_list[i].key; i++) {
    for (j = 0; var_list[i].suffixes[j]; j++) {
      if (!strcmp(suffix, var_list[i].suffixes[j]))
        return var_list[i].otl_tag; 
    }
    if (!strcmp(suffix, var_list[i].key))
      return var_list[i].otl_tag;
    if (var_list[i].otl_tag &&
	!strcmp(suffix, var_list[i].otl_tag))
      return var_list[i].otl_tag;
  }
  
  return NULL;
}

static int
agl_guess_name (const char *glyphname)
{
  int i, len;

  if (is_smallcap(glyphname))
    return AGL_VAR_SMCP_IDX;

  len = strlen(glyphname);
  for (i = 1; var_list[i].key != NULL; i++) {
    if (len > strlen(var_list[i].key) &&
	!strcmp(glyphname+len-strlen(var_list[i].key), var_list[i].key)
	) {
      return i;
    }
  }

  return -1;
}

static agl_name *
agl_normalized_name (char *glyphname)
{
  agl_name *agln;
  char     *suffix;
  int       i, n;

  if (!glyphname)
    return NULL;

  agln   = agl_new_name();
  suffix = strchr(glyphname, '.');
  if (suffix) {
    n = strlen(glyphname) - strlen(suffix);
    if (suffix[1] != '\0') {
      agln->suffix = NEW(strlen(suffix), char);
      strcpy(agln->suffix, suffix+1);
    }
    agln->name    = NEW(n+1, char);
    memcpy(agln->name, glyphname, n);
    agln->name[n] = '\0';
  } else if (is_smallcap(glyphname)) {
    n = strlen(glyphname) - 5;
    agln->suffix = NEW(3, char);
    strcpy(agln->suffix, "sc");
    agln->name   = NEW(n+1, char);
    for (i = 0; i < n; i++) {
      agln->name[i] = isupper((unsigned char)glyphname[i]) ?
	(glyphname[i] + 32) : glyphname[i];
    }
    agln->name[n] = '\0';
  } else {
    int var_idx;

#define SET_STRING(p,s) do {\
  (p) = NEW(strlen((s))+1, char);\
  strcpy((p),(s));\
} while (0)
    var_idx = agl_guess_name(glyphname);
    if (var_idx < 0 ||
        !var_list[var_idx].key) {
        n = strlen(glyphname);
    } else {
        n = strlen(glyphname) - strlen(var_list[var_idx].key);
        if (var_list[var_idx].suffixes[0])
            SET_STRING(agln->suffix, var_list[var_idx].suffixes[0]);
        else {
            SET_STRING(agln->suffix, var_list[var_idx].key);
        }
    }
    agln->name    = NEW(n+1, char);
    memcpy(agln->name, glyphname, n);
    agln->name[n] = '\0';
  }
  
  return agln;
}

static struct ht_table aglmap;

static inline void
hval_free (void *hval)
{
  agl_release_name((struct agl_name *) hval);
}

void
agl_init_map (void)
{
  ht_init_table(&aglmap, hval_free);
  agl_load_listfile(AGL_EXTRA_LISTFILE, 0);
  if (agl_load_listfile(AGL_PREDEF_LISTFILE, 1) < 0) {
    WARN("Failed to load AGL file \"%s\"...", AGL_PREDEF_LISTFILE);
  }
  if (agl_load_listfile(AGL_DEFAULT_LISTFILE, 0) < 0) {
    WARN("Failed to load AGL file \"%s\"...", AGL_DEFAULT_LISTFILE);
  }
}

void
agl_close_map (void)
{
  ht_clear_table(&aglmap);
}

#define WBUF_SIZE 1024

static int
agl_load_listfile (const char *filename, int is_predef)
{
  int   count = 0;
  const char *p, *endptr;
  char *nextptr;
  char  wbuf[WBUF_SIZE];
  FILE *fp;

  if (!filename)
    return  -1;

  fp = DPXFOPEN(filename, DPX_RES_TYPE_AGL);
  if (!fp) {
    return -1;
  }

  if (verbose)
    MESG("<AGL:%s", filename);

  while ((p = mfgets(wbuf, WBUF_SIZE, fp)) != NULL) {
    agl_name *agln, *duplicate;
    char     *name;
    int       n_unicodes, i;
    int32_t   unicodes[AGL_MAX_UNICODES];

    endptr = p + strlen(p);
    skip_white(&p, endptr);

    /* Need table version check. */
    if (!p || p[0] == '#' || p >= endptr)
      continue;
    nextptr = strchr(p, ';');
    if (!nextptr || nextptr == p)
      continue;

    name = parse_ident(&p, nextptr);

    skip_white(&p, endptr);
    if (!name || p[0] != ';') {
      WARN("Invalid AGL entry: %s", wbuf);
      if (name)
        RELEASE(name);
      continue;
    }

    p++;
    skip_white(&p, endptr);

    n_unicodes = 0;
    while (p < endptr &&
           ((p[0]  >= '0' && p[0] <= '9') ||
            (p[0]  >= 'A' && p[0] <= 'F'))
          ) {

      if (n_unicodes >= AGL_MAX_UNICODES) {
        WARN("Too many Unicode values");
        break;
      }
      unicodes[n_unicodes++] = strtol(p, &nextptr, 16);

      p = nextptr;
      skip_white(&p, endptr);
    }

    if (n_unicodes == 0) {
      WARN("AGL entry ignored (no mapping): %s", wbuf);
      RELEASE(name);
      continue;
    }

    agln = agl_normalized_name(name);
    agln->is_predef = is_predef;
    agln->n_components = n_unicodes;
    for (i = 0; i < n_unicodes; i++) {
      agln->unicodes[i] = unicodes[i];
    }

    duplicate = ht_lookup_table(&aglmap, name, strlen(name));
    if (!duplicate)
      ht_append_table(&aglmap, name, strlen(name), agln);
    else {
      while (duplicate->alternate)
        duplicate = duplicate->alternate;
      duplicate->alternate = agln;
    }

    if (verbose > 3) {
      if (agln->suffix)
        MESG("agl: %s [%s.%s] -->", name, agln->name, agln->suffix);
      else
        MESG("agl: %s [%s] -->", name, agln->name);
      for (i = 0; i < agln->n_components; i++) {
        if (agln->unicodes[i] > 0xffff) {
          MESG(" U+%06X", agln->unicodes[i]);
        } else {
          MESG(" U+%04X", agln->unicodes[i]);
        }
      }
      MESG("\n");
    }

    RELEASE(name);
    count++;
  }
  DPXFCLOSE(fp);

  if (verbose)
    MESG(">");

  return count;
}

agl_name *
agl_lookup_list (const char *glyphname)
{
  agl_name *agln;

  if (!glyphname)
    return NULL;

  agln = ht_lookup_table(&aglmap, glyphname, strlen(glyphname));

  return agln;
}

int
agl_name_is_unicode (const char *glyphname)
{
  char c, *suffix;
  int  i, len;

  if (!glyphname)
    return 0;

  suffix = strchr(glyphname, '.');
  len    = (int) (suffix ? suffix - glyphname : strlen(glyphname));
  /*
   * uni02ac is invalid glyph name and mapped to th empty string.
   */
  if (len >= 7 && (len - 3) % 4 == 0 &&
      !strncmp(glyphname, "uni", 3)) {
    c = glyphname[3];
    /*
     * Check if the 4th character is uppercase hexadecimal digit.
     * "union" should not be treated as Unicode glyph name.
     */
    if (isdigit((unsigned char)c) || (c >= 'A' && c <= 'F'))
      return 1;
    else
      return 0;
  } else if (len <= 7 && len >= 5 &&
	     glyphname[0] == 'u') {
    for (i = 1; i < len - 1; i++) {
      c = glyphname[i];
      if (!isdigit((unsigned char)c) && (c < 'A' || c > 'F'))
	return 0;
    }
    return 1;
  }

  return 0;
}

int32_t
agl_name_convert_unicode (const char *glyphname)
{
  int32_t ucv = -1;
  const char *p;

  if (!agl_name_is_unicode(glyphname))
    return -1;

  if (strlen(glyphname) > 7 && *(glyphname+7) != '.') {
    WARN("Mapping to multiple Unicode characters not supported.");
    return -1;
  }

  if (glyphname[1] == 'n')
    p = glyphname + 3;
  else
    p = glyphname + 1;
  ucv = 0;
  while (*p != '\0' && *p != '.') {
    if (!isdigit((unsigned char)*p) && (*p < 'A' || *p > 'F')) {
      WARN("Invalid char %c in Unicode glyph name %s.", *p, glyphname);
      return -1;
    }
    ucv <<= 4;
    ucv += isdigit((unsigned char)*p) ? *p - '0' : *p - 'A' + 10;
    p++;
  }

  if (!UC_is_valid(ucv)) {
    if (ucv < 0x10000) {
      WARN("Invalid Unicode code value U+%04X.", ucv);
    } else {
      WARN("Invalid Unicode code value U+%06X.", ucv);
    }
    ucv = -1;
  }

  return ucv;
}



static int
xtol (const char *start, int len)
{
  int v = 0;

  while (len-- > 0) {
    v <<= 4;
    if (isdigit((unsigned char)*start)) {
      v += *start - '0';
    } else if (*start >= 'A' && *start <= 'F') {
      v += *start - 'A' + 10;
    } else {
      return -1;
    }
    start++;
  }

  return v;
}

#define IS_PUA(u) (((u) >= 0x00E000L && (u) <= 0x00F8FFL) || \
  ((u) >= 0x0F0000L && (u) <= 0x0FFFFDL) || \
  ((u) >= 0x100000L && (u) <= 0x10FFFDL) \
)

static int32_t
put_unicode_glyph (const char *name,
		   unsigned char **dstpp, unsigned char *limptr)
{
  const char *p;
  int32_t len = 0, ucv;

  p   = name;
  ucv = 0;

  if (p[1] != 'n') {
    p   += 1;
    ucv  = xtol(p, strlen(p));
    len += UC_UTF16BE_encode_char(ucv, dstpp, limptr);
  } else {
    p += 3;
    while (*p != '\0') {
      ucv  = xtol(p, 4);
      len += UC_UTF16BE_encode_char(ucv, dstpp, limptr);
      p   += 4;
    }
  }

  return len;
}

int32_t
agl_sput_UTF16BE (const char *glyphstr,
		  unsigned char **dstpp, unsigned char *limptr,
		  int *fail_count)
{
  int32_t len   = 0;
  int   count = 0;
  const char *p, *endptr;

  ASSERT(glyphstr && dstpp);

  p      =  glyphstr;
  endptr = strchr(p, '.');
  if (!endptr)
    endptr = p + strlen(p);

  while (p < endptr) {
    char     *name;
    const char *delim;
    int32_t   sub_len;
    int       i;
    agl_name *agln0, *agln1 = NULL;

    delim = strchr(p, '_');
    if (delim == p) {
      /*
       * Glyph names starting with a underscore or two subsequent
       * underscore in glyph name not allowed?
       */
      WARN("Invalid glyph name component in \"%s\".", glyphstr);
      count++;
      if (fail_count)
	*fail_count = count;
      return len; /* Cannot continue */
    } else if (!delim || delim > endptr) {
      delim = endptr;
    }
    sub_len = (int32_t) (delim - p);

    name = NEW(sub_len+1, char);
    memcpy(name, p, sub_len);
    name[sub_len] = '\0';

    if (agl_name_is_unicode(name)) {
      sub_len = put_unicode_glyph(name, dstpp, limptr);
      if (sub_len > 0)
	len += sub_len;
      else {
	count++;
      }
    } else {
      agln1 = agl_lookup_list(name);
      if (!agln1 || (agln1->n_components == 1 &&
		     IS_PUA(agln1->unicodes[0]))) {
	agln0 = agl_normalized_name(name);
	if (agln0) {
	  if (verbose > 1 && agln0->suffix) {
	    WARN("agl: fix %s --> %s.%s",
		 name, agln0->name, agln0->suffix);
	  }
	  agln1 = agl_lookup_list(agln0->name);
	  agl_release_name(agln0);
	}
      }
      if (agln1) {
	for (i = 0; i < agln1->n_components; i++) {
	  len += UC_UTF16BE_encode_char(agln1->unicodes[i], dstpp, limptr);
	}
      } else {
	if (verbose) {
	  WARN("No Unicode mapping for glyph name \"%s\" found.", name);
	}
	count++;
      }
    }
    RELEASE(name);
    p = delim + 1;
  }

  if (fail_count)
    *fail_count = count;
  return len;
}

int
agl_get_unicodes (const char *glyphstr,
		  int32_t *unicodes, int max_unicodes)
{
  int   count = 0;
  const char *p, *endptr;

  p      = glyphstr;
  endptr = strchr(p, '.');
  if (!endptr)
    endptr = p + strlen(p);

  while (p < endptr) {
    char     *name;
    const char *delim;
    int32_t   sub_len;
    int       i;
    agl_name *agln0, *agln1 = NULL;

    delim = strchr(p, '_');
    if (delim == p) {
      /*
       * Glyph names starting with a underscore or two subsequent
       * underscore in glyph name not allowed?
       */
      WARN("Invalid glyph name component in \"%s\".", glyphstr);
      return -1; /* Cannot continue */
    } else if (!delim || delim > endptr) {
      delim = endptr;
    }
    sub_len = (int32_t) (delim - p);

    name = NEW(sub_len+1, char);
    memcpy(name, p, sub_len);
    name[sub_len] = '\0';

    if (agl_name_is_unicode(name)) {
      p  = name;
      if (p[1] != 'n') { /* uXXXXXXXX */
	if (count >= max_unicodes) {
	  RELEASE(name);
	  return -1;
	}
	p++;
	unicodes[count++] = xtol(p, strlen(p));
      } else {
	p += 3;
	while (*p != '\0') {
	  if (count >= max_unicodes) {
	    RELEASE(name);
	    return -1;
	  }
	  unicodes[count++] = xtol(p, 4);
	  p += 4;
	}
      }
    } else {
      agln1 = agl_lookup_list(name);
      if (!agln1 || (agln1->n_components == 1 &&
		     IS_PUA(agln1->unicodes[0]))) {
	agln0 = agl_normalized_name(name);
	if (agln0) {
	  if (verbose > 1 && agln0->suffix) {
	    WARN("agl: fix %s --> %s.%s",
		 name, agln0->name, agln0->suffix);
	  }
	  agln1 = agl_lookup_list(agln0->name);
	  agl_release_name(agln0);
	}
      }
      if (agln1) {
	if (count + agln1->n_components > max_unicodes) {
	  RELEASE(name);
	  return -1;
	}
	for (i = 0; i < agln1->n_components; i++) {
	  unicodes[count++] = agln1->unicodes[i];
	}
      } else {
	if (verbose > 1)
	  WARN("No Unicode mapping for glyph name \"%s\" found.", name);
	RELEASE(name);
	return -1;
      }
    }
    RELEASE(name);
    p = delim + 1;
  }

  return count;
}