OSDN Git Service

test19-ivs.tex, ivs.lua: test of variation selectors
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 17 Dec 2013 10:18:42 +0000 (19:18 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 17 Dec 2013 10:18:42 +0000 (19:18 +0900)
 * Test with IPA MJ Mincho (ipamjm.ttf, version 002.02).
   It seems that IVS for U+2B7EA does not work. Why?
 * Perhaps ivs.lua works fine even if LuaTeX-ja is not loaded.

test/ivs.lua [new file with mode: 0644]
test/test19-ivs.pdf [new file with mode: 0644]
test/test19-ivs.tex [new file with mode: 0644]

diff --git a/test/ivs.lua b/test/ivs.lua
new file mode 100644 (file)
index 0000000..7f3ac4e
--- /dev/null
@@ -0,0 +1,77 @@
+require('unicode')
+
+local id_glyph = node.id('glyph')
+local has_attr = node.has_attribute
+local identifiers = fonts.hashes.identifiers
+local node_next = node.next
+local node_remove = node.remove
+
+local get_node_font, get_current_font
+if luatexja then -- test if LuaTeX-ja is loaded
+   luatexja.load_module('charrange'); local ltjc = luatexja.charrange
+   local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
+   local ltjc_is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char
+   get_node_font = function(p)
+      return (ltjc_is_ucs_in_japanese_char(p) and (has_attr(p, attr_curjfnt) or 0) or p.font)
+   end
+   get_current_font = function() return tex.attribute[attr_curjfnt] or 0 end
+else
+   get_node_font = function(p) return p.font end
+   get_current_font = font.current
+end
+
+local function do_ivs_repr(head)
+  local p = head
+  while p do
+     local pid = p.id
+     if pid==id_glyph then
+        local pf = get_node_font(p)
+        local pt = identifiers[pf]
+        pt = pt and pt.resources; pt = pt and pt.variants
+        if pt then
+           local q = node_next(p) -- the next node of p
+           if q and q.id==id_glyph then
+              local qc = q.char
+              if qc>=0xE0100 and qc<0xE01F0 then -- q is an IVS selector
+                 pt = pt[qc];  pt = pt and  pt[p.char]
+                 if pt then
+                    p.char = pt or p.char
+                 end
+                 head = node_remove(head,q)
+              end
+           end
+        end
+     end
+     p = node_next(p)
+  end
+  return head
+end
+-- callback
+luatexbase.add_to_callback('hpack_filter', 
+   function (head) return do_ivs_repr(head) end,'do_ivs', 1)
+luatexbase.add_to_callback('pre_linebreak_filter', 
+   function (head) return do_ivs_repr(head) end, 'do_ivs', 1)
+
+ivs = {}
+
+do
+   local ubyte = unicode.utf8.byte
+   local uchar = unicode.utf8.char
+   local sort = table.sort
+   function ivs.list_ivs(s)
+      local c = ubyte(s)
+      local pt = identifiers[get_current_font()]
+      pt = pt and pt.resources; pt = pt and pt.variants
+      if pt then
+         local t = {}
+         for i,v in pairs(pt) do
+            if v[c] then t[1+#t]=i end
+         end
+         sort(t)
+         for _,v in ipairs(t) do 
+            tex.sprint('\\oalign{' .. s .. uchar(v) 
+                          .. '\\crcr\\hss\\tiny' .. tostring(v-0xE0100) .. '\\hss\\crcr}') 
+         end
+      end
+   end
+end
diff --git a/test/test19-ivs.pdf b/test/test19-ivs.pdf
new file mode 100644 (file)
index 0000000..ab0ab73
Binary files /dev/null and b/test/test19-ivs.pdf differ
diff --git a/test/test19-ivs.tex b/test/test19-ivs.tex
new file mode 100644 (file)
index 0000000..38e4d89
--- /dev/null
@@ -0,0 +1,53 @@
+%#!lualatex
+\documentclass{ltjsarticle}
+\usepackage{luatexja-fontspec,booktabs,array}
+
+\def\MJI[#1]#2{#2\char\numexpr "E0100+#1\relax}%"
+\def\IVSL#1{\directlua{ivs.list_ivs('#1')}}
+\begin{document}
+\jfontspec{ipamjm.ttf} % IPA MJ 明朝
+
+例文はZRさんのブログ記事「ipamjmパッケージでアレしてみた」\footnote{%
+\verb+http://d.hatena.ne.jp/zrbabbler/20131214/1387029624+}より引用.
+
+\paragraph{標準状態では……}
+\begin{quote}
+\LARGE
+渡邉󠄏さんとか   % { } の中は U+9089 U+E010F
+渡𫟪󠄂さんとか。% { } の中は U+2B7EA U+E0102
+\end{quote}
+
+\paragraph{IVS処理コードをここで読み込んだ.}\ 
+\directlua{dofile('ivs.lua')}
+
+\begin{quote}
+\LARGE
+\MJI[15]{邉}\MJI[25]{邉}\MJI[27]{邉}\MJI[26]{邉}\MJI[26]{邉}\MJI[16]{邊}
+\MJI[18]{邊}\MJI[2]{𫟪}\MJI[17]{邊}〓\\
+\MJI[28]{邉}\MJI[29]{邉}\MJI[23]{邉}\MJI[15]{邊}\MJI[8]{邊}\MJI[20]{邉}
+\MJI[24]{邉}\MJI[19]{邉}\MJI[18]{邉}\MJI[16]{邉}\\
+\MJI[14]{邊}\MJI[10]{邊}\MJI[12]{邊}\MJI[11]{邊}\MJI[13]{邊}\MJI[9]{邊}
+\MJI[0]{𫟪}\MJI[1]{𫟪}〓\MJI[21]{邉}
+\end{quote}
+「〓」はMJ番号を直接指定していたところなので,とりあえず無視している.
+なぜか𫟪(U+2B7EA)のIVSが機能していないようだが,フォント側にその記述がない,ということ?
+
+\begin{quote}
+\LARGE
+渡邉󠄏さんとか   % { } の中は U+9089 U+E010F
+渡𫟪󠄂さんとか。% { } の中は U+2B7EA U+E0102
+\end{quote}
+
+\begin{center}
+\Large
+\begin{tabular}{c>{\tt}ll}
+\toprule
+文字&Unicode&IVS\\
+\midrule
+邉&U+9089&\IVSL{邉}\\
+邊&U+908A&\IVSL{邊}\\
+𫟪&U+2B7EA&\IVSL{𫟪}\\
+\bottomrule
+\end{tabular}
+\end{center}
+\end{document}
\ No newline at end of file