1 /*
2 get_name -- get ISO Latin 1 name string from name table
3 Copyright (C) 1998, 1999 Dieter Baron
4
5 This file is part of ttftot42, to use TrueType fonts in PostScript.
6 The author can be contacted at <dillo@giga.or.at>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <freetype.h>
28
29 /*
30 apple unicode 0
31
32 mac 1
33 roman 0
34 english 0
35 french 1
36 german 2
37 italian 3
38 dutch 4
39 swedish 5
40 spanish 6
41 danish 7
42 portugese 8
43 norwegian 9
44
45 iso 2
46
47 win 3
48 unicode 1
49 */
50
51 char *
get_name(TT_Face f,int nnames,int name)52 get_name(TT_Face f, int nnames, int name)
53 {
54 int i;
55 TT_UShort pid, eid, lid, nid, len;
56 char *p, *s, *t;
57
58 /* XXX: if (nnames == 0) set nnames */
59
60 for (i=0; i<nnames; i++) {
61 TT_Get_Name_ID(f, i, &pid, &eid, &lid, &nid);
62
63 if (nid == name) {
64 if (((pid == TT_PLATFORM_MACINTOSH && eid == TT_MAC_ID_ROMAN)
65 || (pid == TT_PLATFORM_MICROSOFT
66 && eid == TT_MS_ID_UNICODE_CS))) {
67 TT_Get_Name_String(f, i, &p, &len);
68 if (pid == TT_PLATFORM_MACINTOSH) {
69 if ((s=(char *)malloc(len+1)) == NULL)
70 return NULL;
71 strncpy(s, p, len);
72 s[len] = '\0';
73 return s;
74 }
75 else {
76 if ((s=(char *)malloc((len/2)+1)) == NULL)
77 return NULL;
78 for (t=s; len; p+=2,len-=2) {
79 if (*p == 0)
80 *(t++) = p[1];
81 }
82 *t = '\0';
83 return s;
84 }
85 }
86 }
87 }
88
89 return NULL;
90 }
91