macenc.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (c) 2003 Ben Harris
  3. * All rights reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person
  6. * obtaining a copy of this software and associated documentation
  7. * files (the "Software"), to deal in the Software without
  8. * restriction, including without limitation the rights to use,
  9. * copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following
  12. * conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  21. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  22. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. */
  26. /*
  27. * macenc.c -- Convert a Mac OS script/region/font combination to our
  28. * internal charset code.
  29. */
  30. #include <string.h>
  31. #include "charset.h"
  32. #include "internal.h"
  33. /*
  34. * These are defined by Mac OS's <Script.h>, but we'd like to be
  35. * independent of that.
  36. */
  37. #define smRoman 0
  38. #define smJapanese 1
  39. #define smTradChinese 2
  40. #define smKorean 3
  41. #define smArabic 4
  42. #define smHebrew 5
  43. #define smCyrillic 7
  44. #define smDevenagari 9
  45. #define smGurmukhi 10
  46. #define smGujurati 11
  47. #define smThai 21
  48. #define smSimpChinese 25
  49. #define smTibetan 26
  50. #define smEthiopic 28
  51. #define smCentralEuroRoman 29
  52. #define verGreece 20
  53. #define verIceland 21
  54. #define verTurkey 24
  55. #define verYugoCroatian 25
  56. #define verRomania 39
  57. #define verFaroeIsl 47
  58. #define verIran 48
  59. #define verRussia 49
  60. #define verSlovenian 66
  61. #define verCroatia 68
  62. #define verBulgaria 72
  63. #define verScottishGaelic 75
  64. #define verManxGaelic 76
  65. #define verBreton 77
  66. #define verNunavut 78
  67. #define verWelsh 79
  68. #define verIrishGaelicScript 81
  69. static const struct {
  70. int script;
  71. int region;
  72. int sysvermin;
  73. char const *fontname;
  74. int charset;
  75. } macencs[] = {
  76. { smRoman, -1, 0x850, "VT100", CS_MAC_VT100 },
  77. { smRoman, -1, 0, "VT100", CS_MAC_VT100_OLD },
  78. /*
  79. * From here on, this table is largely derived from
  80. * <http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/README.TXT>,
  81. * with _OLD version added based on the comments in individual
  82. * mapping files.
  83. */
  84. { smRoman, -1, 0, "Symbol", CS_MAC_SYMBOL },
  85. { smRoman, -1, 0, "Zapf Dingbats", CS_MAC_DINGBATS },
  86. { smRoman, verTurkey, 0, NULL, CS_MAC_TURKISH },
  87. { smRoman, verYugoCroatian, 0x850, NULL, CS_MAC_CROATIAN },
  88. { smRoman, verYugoCroatian, 0, NULL, CS_MAC_CROATIAN_OLD },
  89. { smRoman, verSlovenian, 0x850, NULL, CS_MAC_CROATIAN },
  90. { smRoman, verSlovenian, 0, NULL, CS_MAC_CROATIAN_OLD },
  91. { smRoman, verCroatia, 0x850, NULL, CS_MAC_CROATIAN },
  92. { smRoman, verCroatia, 0, NULL, CS_MAC_CROATIAN_OLD },
  93. { smRoman, verIceland, 0x850, NULL, CS_MAC_ICELAND },
  94. { smRoman, verIceland, 0, NULL, CS_MAC_ICELAND_OLD },
  95. { smRoman, verFaroeIsl, 0x850, NULL, CS_MAC_ICELAND },
  96. { smRoman, verFaroeIsl, 0, NULL, CS_MAC_ICELAND_OLD },
  97. { smRoman, verRomania, 0x850, NULL, CS_MAC_ROMANIAN },
  98. { smRoman, verRomania, 0, NULL, CS_MAC_ROMANIAN_OLD },
  99. #if 0 /* No mapping table on ftp.unicode.org */
  100. { smRoman, verIreland, 0x850, NULL, CS_MAC_CELTIC },
  101. { smRoman, verIreland, 0, NULL, CS_MAC_CELTIC_OLD },
  102. { smRoman, verScottishGaelic, 0x850, NULL, CS_MAC_CELTIC },
  103. { smRoman, verScottishGaelic, 0, NULL, CS_MAC_CELTIC_OLD },
  104. { smRoman, verManxGaelic, 0x850, NULL, CS_MAC_CELTIC },
  105. { smRoman, verManxGaelic, 0, NULL, CS_MAC_CELTIC_OLD },
  106. { smRoman, verBreton, 0x850, NULL, CS_MAC_CELTIC },
  107. { smRoman, verBreton, 0, NULL, CS_MAC_CELTIC_OLD },
  108. { smRoman, verWelsh, 0x850, NULL, CS_MAC_CELTIC },
  109. { smRoman, verWelsh, 0, NULL, CS_MAC_CELTIC_OLD },
  110. { smRoman, verIrishGaelicScript, 0x850, NULL, CS_MAC_GAELIC },
  111. { smRoman, verIrishGaelicScript, 0, NULL, CS_MAC_GAELIC_OLD },
  112. #endif
  113. { smRoman, verGreece, 0x922, NULL, CS_MAC_GREEK },
  114. { smRoman, verGreece, 0, NULL, CS_MAC_GREEK_OLD },
  115. { smRoman, -1, 0x850, NULL, CS_MAC_ROMAN },
  116. { smRoman, -1, 0, NULL, CS_MAC_ROMAN_OLD },
  117. #if 0 /* Multi-byte encodings, not yet supported */
  118. { smJapanese, -1, 0, NULL, CS_MAC_JAPANESE },
  119. { smTradChinese, -1, 0, NULL, CS_MAC_CHINTRAD },
  120. { smKorean, -1, 0, NULL, CS_MAC_KOREAN },
  121. #endif
  122. #if 0 /* Bidirectional encodings, not yet supported */
  123. { smArabic, verIran, 0, NULL, CS_MAC_FARSI },
  124. { smArabic, -1, 0, NULL, CS_MAC_ARABIC },
  125. { smHebrew, -1, 0, NULL, CS_MAC_HEBREW },
  126. #endif
  127. { smCyrillic, -1, 0x900, NULL, CS_MAC_CYRILLIC },
  128. { smCyrillic, verRussia, 0, NULL, CS_MAC_CYRILLIC_OLD },
  129. { smCyrillic, verBulgaria, 0, NULL, CS_MAC_CYRILLIC_OLD },
  130. { smCyrillic, -1, 0, NULL, CS_MAC_UKRAINE },
  131. #if 0 /* Complex Indic scripts, not yet supported */
  132. { smDevanagari, -1, 0, NULL, CS_MAC_DEVENAGA },
  133. { smGurmukhi, -1, 0, NULL, CS_MAC_GURMUKHI },
  134. { smGujurati, -1, 0, NULL, CS_MAC_GUJURATI },
  135. #endif
  136. { smThai, -1, 0, NULL, CS_MAC_THAI },
  137. #if 0 /* Multi-byte encoding, not yet supported */
  138. { smSimpChinese, -1, 0, NULL, CS_MAC_CHINSIMP },
  139. #endif
  140. #if 0 /* No mapping table on ftp.unicode.org */
  141. { smTibetan, -1, 0, NULL, CS_MAC_TIBETAN },
  142. { smEthiopic, -1, 0, NULL, CS_MAC_ETHIOPIC },
  143. { smEthiopic, verNanavut, 0, NULL, CS_MAC_INUIT },
  144. #endif
  145. { smCentralEuroRoman, -1, 0, NULL, CS_MAC_CENTEURO },
  146. };
  147. int charset_from_macenc(int script, int region, int sysvers,
  148. char const *fontname)
  149. {
  150. int i;
  151. for (i = 0; i < (int)lenof(macencs); i++)
  152. if ((macencs[i].script == script) &&
  153. (macencs[i].region < 0 || macencs[i].region == region) &&
  154. (macencs[i].sysvermin <= sysvers) &&
  155. (macencs[i].fontname == NULL ||
  156. (fontname != NULL && strcmp(macencs[i].fontname, fontname) == 0)))
  157. return macencs[i].charset;
  158. return CS_NONE;
  159. }