2 Copyright (c) 1997 by Mark Leisher
3 Copyright (c) 1998-2002 by Juliusz Chroboczek
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include <X11/fonts/fontmisc.h>
31 #include <X11/fonts/font.h>
33 #include FT_FREETYPE_H
34 #include FT_SFNT_NAMES_H
35 #include FT_TRUETYPE_IDS_H
43 #define LOBYTE(s,byte) ((byte)==LSBFirst?*(char*)(s):*((char*)(s)+1))
44 #define HIBYTE(s,byte) ((byte)==LSBFirst?*((char*)(s)+1):*(char*)(s))
46 int FTtoXReturnCode(int rc)
50 /* Anything else stops the font matching mechanism */
51 else return BadFontName;
55 /* Convert slen bytes from UCS-2 to ISO 8859-1. Byte specifies the
56 endianness of the string, max the maximum number of bytes written into
59 FTu2a(int slen, FT_Byte *from, char *to, int byte, int max)
64 for (i = 0; i < slen; i += 2) {
67 if(HIBYTE(from+i, byte)!=0)
70 *to++ = LOBYTE(from+i,byte);
78 FTGetName(FT_Face face, int nid, int pid, int eid, FT_SfntName *name_return)
83 n = FT_Get_Sfnt_Name_Count(face);
87 for(i = 0; i < n; i++) {
88 if(FT_Get_Sfnt_Name(face, i, &name))
90 if(name.name_id == nid &&
91 name.platform_id == pid &&
92 (eid < 0 || name.encoding_id == eid)) {
93 switch(name.platform_id) {
94 case TT_PLATFORM_APPLE_UNICODE:
95 case TT_PLATFORM_MACINTOSH:
96 if(name.language_id != TT_MAC_LANGID_ENGLISH)
99 case TT_PLATFORM_MICROSOFT:
100 if(name.language_id != TT_MS_LANGID_ENGLISH_UNITED_STATES &&
101 name.language_id != TT_MS_LANGID_ENGLISH_UNITED_KINGDOM)
116 FTGetEnglishName(FT_Face face, int nid, char *name_return, int name_len)
121 if(FTGetName(face, nid,
122 TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, &name) ||
124 TT_PLATFORM_APPLE_UNICODE, -1, &name))
125 return FTu2a(name.string_len, name.string, name_return,
128 /* Pretend that Apple Roman is ISO 8859-1. */
129 if(FTGetName(face, nid, TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, &name)) {
130 len = name.string_len;
131 if(len > name_len - 1)
133 memcpy(name_return, name.string, len);
134 name_return[len] = '\0'; /* ensure nul terminaison */
138 /* Must be some font that can only be named in Polish or something. */