| 128 | static bool lookupFamilyName(FT_Face ftface, QString& familyName) |
| 129 | { |
| 130 | FT_UInt nNameCount; |
| 131 | FT_UInt i; |
| 132 | FT_SfntName sfntName; |
| 133 | FT_UInt found, best; |
| 134 | |
| 135 | nNameCount = FT_Get_Sfnt_Name_Count(ftface); |
| 136 | |
| 137 | if (nNameCount == 0) |
| 138 | return false; |
| 139 | |
| 140 | #ifndef QT_NO_TEXTCODEC |
| 141 | QTextCodec *codec = QTextCodec::codecForName("UTF-16BE"); |
| 142 | |
| 143 | // find a unicode name at first |
| 144 | if (codec) { |
| 145 | found = (FT_UInt)-1; |
| 146 | best = (FT_UInt)-1; |
| 147 | |
| 148 | // try to find the unicode name matching to the locale |
| 149 | for (i = 0; found == (FT_UInt)-1 && i < nNameCount; i++) { |
| 150 | FT_Get_Sfnt_Name(ftface, i, &sfntName); |
| 151 | |
| 152 | if (sfntName.name_id == TT_NAME_ID_FONT_FAMILY && |
| 153 | sfntName.platform_id == TT_PLATFORM_MICROSOFT && |
| 154 | sfntName.encoding_id == TT_MS_ID_UNICODE_CS) { |
| 155 | if (best == (FT_UInt)-1 || sfntName.language_id == TT_MS_LANGID_ENGLISH_UNITED_STATES) |
| 156 | best = i; |
| 157 | |
| 158 | switch (sfntName.language_id) { |
| 159 | case TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA : |
| 160 | if (QLocale::system().language() == QLocale::Korean) |
| 161 | found = i; |
| 162 | break; |
| 163 | |
| 164 | case TT_MS_LANGID_JAPANESE_JAPAN : |
| 165 | if (QLocale::system().language() == QLocale::Japanese) |
| 166 | found = i; |
| 167 | break; |
| 168 | |
| 169 | case TT_MS_LANGID_CHINESE_PRC : |
| 170 | if (QLocale::system().country() == QLocale::China && |
| 171 | QLocale::system().language() == QLocale::Chinese) |
| 172 | found = i; |
| 173 | break; |
| 174 | |
| 175 | case TT_MS_LANGID_CHINESE_TAIWAN : |
| 176 | if (QLocale::system().country() == QLocale::Taiwan && |
| 177 | QLocale::system().language() == QLocale::Chinese) |
| 178 | found = i; |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (found == (FT_UInt)-1) |
| 185 | found = best; |
| 186 | |
| 187 | if (found != (FT_UInt)-1) { |
| 188 | FT_Get_Sfnt_Name(ftface, found, &sfntName); |
| 189 | |
| 190 | familyName = codec->toUnicode((const char *)sfntName.string, sfntName.string_len); |
| 191 | |
| 192 | return true; |
| 193 | } |
| 194 | } |
| 195 | #endif |
| 196 | |
| 197 | found = (FT_UInt)-1; |
| 198 | best = (FT_UInt)-1; |
| 199 | |
| 200 | // unicode name is not available, try the NLS encoded name |
| 201 | for (i = 0; found == (FT_UInt)-1 && i < nNameCount; i++) { |
| 202 | FT_Get_Sfnt_Name(ftface, i, &sfntName); |
| 203 | |
| 204 | if (sfntName.name_id == TT_NAME_ID_FONT_FAMILY && |
| 205 | sfntName.platform_id == TT_PLATFORM_MICROSOFT) { |
| 206 | if (best == (FT_UInt)-1) |
| 207 | best = i; |
| 208 | |
| 209 | switch (sfntName.encoding_id) { |
| 210 | case TT_MS_ID_WANSUNG : |
| 211 | if (QLocale::system().language() == QLocale::Korean) |
| 212 | found = i; |
| 213 | break; |
| 214 | |
| 215 | case TT_MS_ID_SJIS : |
| 216 | if (QLocale::system().language() == QLocale::Japanese) |
| 217 | found = i; |
| 218 | break; |
| 219 | |
| 220 | case TT_MS_ID_BIG_5 : |
| 221 | if (QLocale::system().country() == QLocale::Taiwan && |
| 222 | QLocale::system().language() == QLocale::Chinese) |
| 223 | found = i; |
| 224 | break; |
| 225 | |
| 226 | case TT_MS_ID_GB2312 : |
| 227 | if (QLocale::system().country() == QLocale::China && |
| 228 | QLocale::system().language() == QLocale::Chinese) |
| 229 | found = i; |
| 230 | break; |
| 231 | |
| 232 | case TT_MS_ID_SYMBOL_CS : |
| 233 | found = i; |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if (found == (FT_UInt)-1) |
| 240 | found = best; |
| 241 | |
| 242 | if (found != (FT_UInt)-1) |
| 243 | { |
| 244 | char *name; |
| 245 | FT_UInt name_len = 0; |
| 246 | |
| 247 | FT_Get_Sfnt_Name(ftface, found, &sfntName); |
| 248 | |
| 249 | name = (char *)alloca(sfntName.string_len); |
| 250 | |
| 251 | for (FT_UInt j = 0; j < sfntName.string_len; j++) |
| 252 | if (sfntName.string[j]) |
| 253 | name[name_len++] = sfntName.string[j]; |
| 254 | |
| 255 | #ifndef QT_NO_TEXTCODEC |
| 256 | switch (sfntName.encoding_id) { |
| 257 | case TT_MS_ID_WANSUNG : |
| 258 | codec = QTextCodec::codecForName("cp949"); |
| 259 | break; |
| 260 | |
| 261 | case TT_MS_ID_SJIS : |
| 262 | codec = QTextCodec::codecForName("SJIS"); |
| 263 | break; |
| 264 | |
| 265 | case TT_MS_ID_BIG_5 : |
| 266 | codec = QTextCodec::codecForName("Big5"); |
| 267 | break; |
| 268 | |
| 269 | case TT_MS_ID_GB2312 : |
| 270 | codec = QTextCodec::codecForName("GB2312"); |
| 271 | break; |
| 272 | |
| 273 | case TT_MS_ID_SYMBOL_CS : |
| 274 | default : |
| 275 | codec = NULL; |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | if (codec) |
| 280 | familyName = codec->toUnicode(name, name_len); |
| 281 | else |
| 282 | #endif |
| 283 | familyName = QString::fromLocal8Bit(name, name_len); |
| 284 | |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | return false; |
| 289 | } |
| 290 | |