mule-ja
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mule-ja:22] extending composition-function-table rules to support VS15&


From: YAMAMOTO Mitsuharu
Subject: [mule-ja:22] extending composition-function-table rules to support VS15&16
Date: Sat, 05 Jan 2013 16:04:20 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

Mac OS X 10.7 以降でカラー絵文字が表示できる Mac port(*) で、Unicode
6.1 の Variation Selector 15 (U+FE0E, text-style) と Variation
Selector 16 (U+FE0F, emoji-style)をサポートすることを考えています。その
ために、composition-function-table の rule に対して以下のような拡張をし
てはどうかと思うのですが、いかがでしょうか。

 *: http://lists.gnu.org/archive/html/emacs-devel/2012-12/msg00431.html

現状では rule は [PATTERN PREV-CHARS FUNC] の形式になっています。これに
加えて、[PATTERN PREV-CHARS FUNC FONT-POS] の形式も許すようにします。前
者は基本的に現在と同じ動きをします(少し非互換な部分があるのですがそれは
後述します)。後者は FUNC に渡す gstring で用いる font object を取得する
文字の位置を、追加した要素 FONT-POS で指定します。この値は、rule のキー
になっている文字 C の位置を基準とする相対位置を表す整数です(よって、
PATTERN にマッチした文字列でいうと、PREV-CHARS + FONT-POS 番目の文字の
font object を取得することになります)。

Mac port での Variation Selector 15&16 のサポートで、上記の追加機能をど
のように用いるのかを、U+0030 U+FE0E(または U+FE0E) U+20E3 ('0' +
VS15(または VS16) + COMBINING ENCLOSING KEYCAP) を例にとって説明します。
もし composition を行わなければ、それぞれの文字は以下のようなフォントで
表示されます。

  VS15(text-style)のとき:
    文字      フォント             キー C の位置からの相対位置
    U+0030    (ASCII用のフォント)  -1
    U+FE0E    (not found)          0
    U+20E3    Lucida Grande        1

  VS16(emoji-style)のとき:
    文字      フォント             キー C の位置からの相対位置
    U+0030    (ASCII用のフォント)  -1
    U+FE0F    Apple Color Emoji    0
    U+20E3    Lucida Grande        1

VS15(text-style)のときは U+20E3 のフォント Lucida Grande を用いるために、
FONT-POS に 1 を指定します。同様に、VS16(emoji-style)のときは U+FE0F の
フォント Apple Color Emoji を用いるために、FONT-POS に 0 を指定します。
いずれの場合も、取得した font object を用いて U+0030 U+20E3 に対して
font-shape-gstring を呼び出せば、VS15 については角の丸い四角に入った
「0」のグリフ(Lucida Grande)、VS16 については「0」ボタンアイコンのグリ
フ(Apple Color Emoji)が得られます。

先に、FONT-POS の無い形式について従来とは非互換な部分があると述べました。
これは、上の例のように Variation Selector についてもどのフォントを用い
るかの情報を取得できるようにするために、font_range (font.c) における
Variation Selector を飛ばす処理を削除するというものです。このため、
language/japanese.el で登録している
compose-gstring-for-variation-glyph については、FONT-POS を -1 にしたも
のを rule として指定することになります。

プラットフォーム非依存部分についてパッチを試作しましたので添付します。
また、Mac port における使用例は以下のようになります。御意見等いただけれ
ば幸いです。

                                        山本 光晴
                                address@hidden

(defvar mac-emoji-variation-characters-alist
  '((keycap . "#0123456789")
    (non-keycap . "\u203C\u2049\u2139\u2194\u2195\u2196\u2197\u2198\
\u2199\u21A9\u21AA\u231A\u231B\u24C2\u25AA\u25AB\
\u25B6\u25C0\u25FB\u25FC\u25FD\u25FE\u2600\u2601\
\u260E\u2611\u2614\u2615\u261D\u263A\u2648\u2649\
\u264A\u264B\u264C\u264D\u264E\u264F\u2650\u2651\
\u2652\u2653\u2660\u2663\u2665\u2666\u2668\u267B\
\u267F\u2693\u26A0\u26A1\u26AA\u26AB\u26BD\u26BE\
\u26C4\u26C5\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\
\u26FD\u2702\u2708\u2709\u270C\u270F\u2712\u2714\
\u2716\u2733\u2734\u2744\u2747\u2757\u2764\u27A1\
\u2934\u2935\u2B05\u2B06\u2B07\u2B1B\u2B1C\u2B50\
\u2B55\u303D\u3297\u3299\U0001F004\U0001F17F\U0001F21A\U0001F22F")
    (mac-specific . "\u00a9\u00ae\u2122\U0001F170\U0001F171\U0001F17E"))
  "Groups of characters that are sensitive to variation selectors 15 and 16.
It is an alist of label symbols vs sequences of characters.")

(defun mac-compose-gstring-for-keycap-variation (gstring)
  "Compose keycap glyph-string GSTRING for graphic display.
GSTRING must have three glyphs; the first is a character that is
part of a keycap symbol, the second is a glyph for the variation
selector 15 (U+FE0E, text-style) or 16 (U+FE0F, emoji-style), and
the third is the combining enclosing keycap character (U+20E3)."
  (let ((saved-header (lgstring-header gstring))
        (g2 (lgstring-glyph gstring 2))
        (i 0)
        glyph from to)
    (lgstring-set-header gstring (vector (lgstring-font gstring)
                                         (lgstring-char gstring 0)
                                         (lgstring-char gstring 2)))
    (lglyph-set-from-to g2 (1- (lglyph-from g2)) (1- (lglyph-to g2)))
    (lgstring-set-glyph gstring 1 g2)
    (lgstring-set-glyph gstring 2 nil)
    (setq gstring (font-shape-gstring gstring))
    (when gstring
      (lgstring-set-header gstring saved-header)
      (lgstring-set-id gstring nil)
      (while (and (< i (lgstring-glyph-len gstring))
                  (setq glyph (lgstring-glyph gstring i)))
        (setq from (lglyph-from glyph)
              to (lglyph-to glyph))
        (if (>= from 1) (setq from (1+ from)))
        (if (>= to 1) (setq to (1+ to)))
        (lglyph-set-from-to glyph from to)
        (setq i (1+ i)))))
  gstring)

(defun mac-compose-gstring-for-text-style-variation (gstring)
  "Compose glyph-string GSTRING in text style for graphic display.
GSTRING must have two glyphs; the first is a character that is
sensitive to the text/emoji-style variation selector, and the
second is a glyph for the variation selector 15 (U+FE0E)."
  (let ((g0 (lgstring-glyph gstring 0))
        (g1 (lgstring-glyph gstring 1)))
    (lglyph-set-from-to g0 (lglyph-from g0) (lglyph-to g1))
    (lglyph-set-char g0 0)
    (lgstring-set-glyph gstring 1 nil))
  gstring)

(defun mac-compose-gstring-for-emoji-style-variation (gstring)
  "Compose glyph-string GSTRING in emoji style for graphic display.
GSTRING must have two glyphs; the first is a character that is
sensitive to the text/emoji-style variation selector, and the
second is a glyph for the variation selector 16 (U+FE0F)."
  (let ((saved-header (lgstring-header gstring))
        glyph)
    (lgstring-set-header gstring (vector (lgstring-font gstring)
                                         (lgstring-char gstring 0)))
    (lgstring-set-glyph gstring 1 nil)
    (setq gstring (font-shape-gstring gstring))
    (when gstring
      (lgstring-set-header gstring saved-header)
      (lgstring-set-id gstring nil)
      (setq glyph (lgstring-glyph gstring 0))
      (lglyph-set-from-to glyph (lglyph-from glyph) (1+ (lglyph-to glyph)))
      (lglyph-set-char glyph 0)))
  gstring)

(let ((regexp-keycap
       (concat "[" (cdr (assq 'keycap mac-emoji-variation-characters-alist))
               "].\u20E3"))
      (regexp-all
       (concat "["
               (mapconcat 'cdr mac-emoji-variation-characters-alist "")
               "].")))
  (set-char-table-range
   composition-function-table ?\uFE0E
   `([,regexp-keycap 1 mac-compose-gstring-for-keycap-variation 1]
     [,regexp-all 1 mac-compose-gstring-for-text-style-variation -1]))
  (set-char-table-range
   composition-function-table ?\uFE0F
   `([,regexp-keycap 1 mac-compose-gstring-for-keycap-variation 0]
     [,regexp-all 1 mac-compose-gstring-for-emoji-style-variation 0])))

;;; test
;; (insert (mapconcat
;;       (lambda (c) (format "#x%04x:\t%c\uFE0E\u20E3 %c\uFE0F\u20E3" c c c))
;;       (cdr (assq 'keycap mac-emoji-variation-characters-alist)) "\n")
;;      ?\n
;;      (mapconcat
;;       (lambda (c) (format "#x%04x:\t%c\uFE0E %c\uFE0F" c c c))
;;       (mapconcat 'cdr mac-emoji-variation-characters-alist "") "\n"))

Attachment: composition.patch.gz
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]