japanese.el 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. ;;; japanese.el --- support for Japanese -*- coding: iso-2022-7bit; no-byte-compile: t -*-
  2. ;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
  4. ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
  5. ;; National Institute of Advanced Industrial Science and Technology (AIST)
  6. ;; Registration Number H14PRO021
  7. ;; Copyright (C) 2003
  8. ;; National Institute of Advanced Industrial Science and Technology (AIST)
  9. ;; Registration Number H13PRO009
  10. ;; Keywords: multilingual, Japanese
  11. ;; This file is part of GNU Emacs.
  12. ;; GNU Emacs is free software: you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation, either version 3 of the License, or
  15. ;; (at your option) any later version.
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  22. ;;; Commentary:
  23. ;; For Japanese, character sets JISX0201, JISX0208, JISX0212 are
  24. ;; supported.
  25. ;;; Code:
  26. ;;; Load translation tables for CP932.
  27. (load "international/cp51932")
  28. (load "international/eucjp-ms")
  29. (define-coding-system 'iso-2022-jp
  30. "ISO 2022 based 7bit encoding for Japanese (MIME:ISO-2022-JP)."
  31. :coding-type 'iso-2022
  32. :mnemonic ?J
  33. :designation [(ascii japanese-jisx0208-1978 japanese-jisx0208
  34. latin-jisx0201)
  35. nil nil nil]
  36. :flags '(short ascii-at-eol ascii-at-cntl 7-bit designation)
  37. :charset-list '(ascii japanese-jisx0208
  38. japanese-jisx0208-1978 latin-jisx0201)
  39. :mime-charset 'iso-2022-jp
  40. :suitable-for-keyboard t)
  41. (define-coding-system-alias 'junet 'iso-2022-jp)
  42. (define-coding-system 'iso-2022-jp-2
  43. "ISO 2022 based 7bit encoding for CJK, Latin-1, Greek (MIME:ISO-2022-JP-2)."
  44. :coding-type 'iso-2022
  45. :mnemonic ?J
  46. :designation [(ascii japanese-jisx0208-1978 japanese-jisx0208
  47. latin-jisx0201 japanese-jisx0212
  48. chinese-gb2312 korean-ksc5601)
  49. nil
  50. (nil latin-iso8859-1 greek-iso8859-7)
  51. nil]
  52. :flags '(short ascii-at-eol ascii-at-cntl 7-bit designation single-shift
  53. init-at-bol)
  54. :charset-list '(ascii japanese-jisx0208 japanese-jisx0212
  55. latin-jisx0201 japanese-jisx0208-1978
  56. chinese-gb2312 korean-ksc5601
  57. latin-iso8859-1 greek-iso8859-7)
  58. :mime-charset 'iso-2022-jp-2
  59. :suitable-for-keyboard t)
  60. (let ((map ; JIS vs CP932
  61. '((#x301C . #xFF5E) ; WAVE DASH FULLWIDTH TILDE
  62. (#x2014 . #x2015) ; EM DASH HORIZONTAL BAR
  63. (#x2016 . #x2225) ; DOUBLE VERTICAL LINE PARALLEL TO
  64. (#x2212 . #xFF0D) ; MINUS SIGN FULLWIDTH HYPHEN-MINUS
  65. (#x00A2 . #xFFE0) ; CENT SIGN FULLWIDTH CENT SIGN
  66. (#x00A3 . #xFFE1) ; POUND SIGN FULLWIDTH POUND SIGN
  67. (#x00AC . #xFFE2) ; NOT SIGN FULLWIDTH NOT SIGN
  68. (#x00A6 . #xFFE4) ; BROKEN LINE FULLWIDTH BROKEN LINE
  69. )))
  70. (define-translation-table 'japanese-ucs-jis-to-cp932-map map)
  71. (mapc #'(lambda (x) (let ((tmp (car x)))
  72. (setcar x (cdr x)) (setcdr x tmp)))
  73. map)
  74. (define-translation-table 'japanese-ucs-cp932-to-jis-map map))
  75. ;; U+2014 (EM DASH) vs U+2015 (HORIZONTAL BAR)
  76. (define-translation-table 'japanese-ucs-glibc-to-jis-map '((#x2015 . #x2014)))
  77. (define-translation-table 'japanese-ucs-jis-to-glibc-map '((#x2014 . #x2015)))
  78. (define-coding-system 'japanese-shift-jis
  79. "Shift-JIS 8-bit encoding for Japanese (MIME:SHIFT_JIS)"
  80. :coding-type 'shift-jis
  81. :mnemonic ?S
  82. :charset-list '(ascii katakana-jisx0201 japanese-jisx0208)
  83. :mime-charset 'shift_jis)
  84. (define-coding-system-alias 'shift_jis 'japanese-shift-jis)
  85. (define-coding-system-alias 'sjis 'japanese-shift-jis)
  86. (define-coding-system 'japanese-cp932
  87. "CP932 (Microsoft shift-jis)"
  88. :coding-type 'charset
  89. :mnemonic ?S
  90. :charset-list '(ascii katakana-sjis cp932-2-byte))
  91. (define-coding-system-alias 'cp932 'japanese-cp932)
  92. (define-coding-system 'japanese-iso-7bit-1978-irv
  93. "ISO 2022 based 7-bit encoding for Japanese JISX0208-1978 and JISX0201-Roman."
  94. :coding-type 'iso-2022
  95. :mnemonic ?j
  96. :designation [(latin-jisx0201 japanese-jisx0208-1978 japanese-jisx0208
  97. japanese-jisx0212 katakana-jisx0201)
  98. nil nil nil]
  99. :flags '(short ascii-at-eol ascii-at-cntl 7-bit designation
  100. use-roman use-oldjis)
  101. :charset-list '(ascii latin-jisx0201 japanese-jisx0208-1978 japanese-jisx0208
  102. japanese-jisx0212))
  103. (define-coding-system-alias 'iso-2022-jp-1978-irv 'japanese-iso-7bit-1978-irv)
  104. (define-coding-system-alias 'old-jis 'japanese-iso-7bit-1978-irv)
  105. (define-coding-system 'japanese-iso-8bit
  106. "ISO 2022 based EUC encoding for Japanese (MIME:EUC-JP)."
  107. :coding-type 'iso-2022
  108. :mnemonic ?E
  109. :designation [ascii japanese-jisx0208 katakana-jisx0201 japanese-jisx0212]
  110. :flags '(short ascii-at-eol ascii-at-cntl single-shift)
  111. :charset-list '(ascii latin-jisx0201 japanese-jisx0208
  112. katakana-jisx0201 japanese-jisx0212
  113. japanese-jisx0208-1978)
  114. :mime-charset 'euc-jp)
  115. (define-coding-system-alias 'euc-japan-1990 'japanese-iso-8bit)
  116. (define-coding-system-alias 'euc-japan 'japanese-iso-8bit)
  117. (define-coding-system-alias 'euc-jp 'japanese-iso-8bit)
  118. (define-coding-system 'eucjp-ms
  119. "eucJP-ms (like EUC-JP but with CP932 extension).
  120. eucJP-ms is defined in <http://www.opengroup.or.jp/jvc/cde/appendix.html>."
  121. :coding-type 'iso-2022
  122. :mnemonic ?E
  123. :designation [ascii japanese-jisx0208 katakana-jisx0201 japanese-jisx0212]
  124. :flags '(short ascii-at-eol ascii-at-cntl single-shift)
  125. :charset-list '(ascii latin-jisx0201 japanese-jisx0208
  126. katakana-jisx0201 japanese-jisx0212)
  127. :decode-translation-table 'eucjp-ms-decode
  128. :encode-translation-table 'eucjp-ms-encode)
  129. (define-coding-system 'iso-2022-jp-2004
  130. "ISO 2022 based 7bit encoding for JIS X 0213:2004 (MIME:ISO-2022-JP-2004)."
  131. :coding-type 'iso-2022
  132. :mnemonic ?J
  133. :designation [(ascii japanese-jisx0208 japanese-jisx0213.2004-1
  134. japanese-jisx0213-1 japanese-jisx0213-2)
  135. nil nil nil]
  136. :flags '(short ascii-at-eol ascii-at-cntl 7-bit designation)
  137. ;; init-at-bol)
  138. :charset-list '(ascii japanese-jisx0208 japanese-jisx0213.2004-1
  139. japanese-jisx0213-1 japanese-jisx0213-2)
  140. :mime-charset 'iso-2022-jp-2004
  141. :suitable-for-keyboard t)
  142. (define-coding-system-alias 'iso-2022-jp-3 'iso-2022-jp-2004)
  143. (define-coding-system 'euc-jis-2004
  144. "ISO 2022 based EUC encoding for JIS X 0213 (MIME:EUC-JIS-2004)."
  145. :coding-type 'iso-2022
  146. :mnemonic ?E
  147. :designation [ascii japanese-jisx0213.2004-1 katakana-jisx0201
  148. japanese-jisx0213-2]
  149. :flags '(short ascii-at-eol ascii-at-cntl single-shift)
  150. :charset-list '(ascii latin-jisx0201 japanese-jisx0213.2004-1
  151. japanese-jisx0213-1 katakana-jisx0201
  152. japanese-jisx0213-2)
  153. :mime-charset 'euc-jis-2004)
  154. (define-coding-system-alias 'euc-jisx0213 'euc-jis-2004)
  155. (define-coding-system 'japanese-shift-jis-2004
  156. "Shift_JIS 8-bit encoding for Japanese (MIME:SHIFT_JIS-2004)"
  157. :coding-type 'shift-jis
  158. :mnemonic ?S
  159. :charset-list '(ascii katakana-jisx0201
  160. japanese-jisx0213.2004-1 japanese-jisx0213-2))
  161. (define-coding-system-alias 'shift_jis-2004 'japanese-shift-jis-2004)
  162. (set-language-info-alist
  163. "Japanese" '((setup-function . setup-japanese-environment-internal)
  164. (exit-function . use-default-char-width-table)
  165. (iso639-language . ja)
  166. (tutorial . "TUTORIAL.ja")
  167. (charset japanese-jisx0208
  168. japanese-jisx0212 latin-jisx0201 katakana-jisx0201
  169. japanese-jisx0213.2004-1 japanese-jisx0213-1
  170. japanese-jisx0213-2 japanese-jisx0208-1978)
  171. (coding-system iso-2022-jp japanese-iso-8bit
  172. japanese-shift-jis japanese-iso-7bit-1978-irv
  173. iso-2022-jp-2004 japanese-shift-jis-2004
  174. euc-jis-2004)
  175. (coding-priority iso-2022-jp japanese-iso-8bit
  176. japanese-shift-jis
  177. iso-2022-jp-2004 euc-jis-2004
  178. japanese-shift-jis-2004
  179. iso-2022-jp-2)
  180. (input-method . "japanese")
  181. (features japan-util)
  182. (sample-text . "Japanese ($BF|K\8l(B) $B$3$s$K$A$O(B, (I:]FAJ(B")
  183. (documentation . t)))
  184. (let ((map
  185. ;; JISX0213-1 vs Unicode
  186. '((#x2477 . [#x304B #x309A])
  187. (#x2478 . [#x304D #x309A])
  188. (#x2479 . [#x304F #x309A])
  189. (#x247a . [#x3051 #x309A])
  190. (#x247b . [#x3053 #x309A])
  191. (#x2577 . [#x30AB #x309A])
  192. (#x2578 . [#x30AD #x309A])
  193. (#x2579 . [#x30AF #x309A])
  194. (#x257a . [#x30B1 #x309A])
  195. (#x257b . [#x30B3 #x309A])
  196. (#x257c . [#x30BB #x309A])
  197. (#x257d . [#x30C4 #x309A])
  198. (#x257e . [#x30C8 #x309A])
  199. (#x2678 . [#x31F7 #x309A])
  200. (#x2b44 . [#x00E6 #x0300])
  201. (#x2b48 . [#x0254 #x0300])
  202. (#x2b49 . [#x0254 #x0301])
  203. (#x2b4a . [#x028C #x0300])
  204. (#x2b4b . [#x028C #x0301])
  205. (#x2b4c . [#x0259 #x0300])
  206. (#x2b4d . [#x0259 #x0301])
  207. (#x2b4e . [#x025A #x0300])
  208. (#x2b4f . [#x025A #x0301])
  209. (#x2b65 . [#x02E9 #x02E5])
  210. (#x2b66 . [#x02E5 #x02E9])))
  211. table)
  212. (dolist (elt map)
  213. (setcar elt (decode-char 'japanese-jisx0213-1 (car elt))))
  214. (setq table (make-translation-table-from-alist map))
  215. (define-translation-table 'jisx0213-to-unicode table)
  216. (define-translation-table 'unicode-to-jisx0213
  217. (char-table-extra-slot table 0)))
  218. (defun compose-gstring-for-variation-glyph (gstring)
  219. "Compose glyph-string GSTRING for graphic display.
  220. GSTRING must have two glyphs; the first is a glyph for a han character,
  221. and the second is a glyph for a variation selector."
  222. (let* ((font (lgstring-font gstring))
  223. (han (lgstring-char gstring 0))
  224. (vs (lgstring-char gstring 1))
  225. (glyphs (font-variation-glyphs font han))
  226. (g0 (lgstring-glyph gstring 0))
  227. (g1 (lgstring-glyph gstring 1)))
  228. (catch 'tag
  229. (dolist (elt glyphs)
  230. (if (= (car elt) vs)
  231. (progn
  232. (lglyph-set-code g0 (cdr elt))
  233. (lglyph-set-from-to g0 (lglyph-from g0) (lglyph-to g1))
  234. (lgstring-set-glyph gstring 1 nil)
  235. (throw 'tag gstring)))))))
  236. (let ((elt '([".." 1 compose-gstring-for-variation-glyph])))
  237. (set-char-table-range composition-function-table '(#xFE00 . #xFE0F) elt)
  238. (set-char-table-range composition-function-table '(#xE0100 . #xE01EF) elt))
  239. (provide 'japanese)
  240. ;;; japanese.el ends here