OSDN Git Service

support vertical origin (requires luaotfload 2019-07-24 or later)
[luatex-ja/luatexja.git] / test / test19-ivs.tex
index 38e4d89..3f28997 100644 (file)
 %#!lualatex
 \documentclass{ltjsarticle}
-\usepackage{luatexja-fontspec,booktabs,array}
+\usepackage{luatexja-fontspec,luatexja-otf, luacode, booktabs,array,xcolor}
+\usepackage[scale=0.80]{geometry}
+\usepackage{listings}
+\setsansjfont{KozGoPr6N-Regular}
+
+% \IVS[?] 用
+\begin{luacode}
+   local identifiers = fonts.hashes.identifiers
+   local fallback_color = 'red'  -- IVS がないときは,この色で既定文字を出力
+   local list_color = 'blue!50!black'     -- リスト表示の色
+
+   local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
+   local ubyte = unicode.utf8.byte
+   local uchar = unicode.utf8.char
+   local sort = table.sort
+   function list_ivs(s)
+      local c = ubyte(s)
+      local pt = identifiers[tex.getattribute(attr_curjfnt)].resources
+      pt = pt and pt.variants
+      if pt then
+         local t = {}
+         for i,v in pairs(pt) do
+           if v[c] then t[#t+1]={i,v[c]} end
+         end
+         sort(t, function(a,b) return a[1]<b[1] end)
+         tex.sprint('\\textcolor{' .. list_color .. '}{')
+         for _,i in ipairs(t) do
+            if i[1]>=0xE0100 then -- only IVS
+               tex.sprint('\\oalign{' .. s .. uchar(i[1])
+                          .. '\\crcr\\hss\\tiny' .. tostring(i[1]-0xE0100) .. '\\hss\\crcr}')
+            end
+         end
+         tex.sprint('}')
+      else
+         tex.sprint('\\textcolor{' .. fallback_color .. '}{' .. s .. '}')
+      end
+   end
+\end{luacode}
+
+\makeatletter
+
+%%%%%    \IVS[<selector number>]{<character>}
+%%%%% or \IVS<selector number>{<character>}
+%%%%% (<selector number>: 0--239, or `?')
+\def\ltj@ivs@out#1#2{#2\char\numexpr "E0100+#1\relax} % IVS"
+\def\ltj@ivs@list?#1{\directlua{list_ivs('#1')}}
+\def\ltj@ivs@grab@num{\expandafter\expandafter\expandafter\ltj@ivs@out\ltj@grab@num}
+\def\ltj@ivs@nobracket{\@ifnextchar?{\ltj@ivs@list}{\ltj@ivs@grab@num}}
+\def\ltj@ivs@bracket[#1]{\ltj@ivs@nobracket#1}
+\def\IVS{\@ifnextchar[{\ltj@ivs@bracket}{\ltj@ivs@nobracket}}
+
+\let\MJI=\IVS
 
-\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 明朝
+\jfontspec{ipamjm} % IPAmj明朝
 
 例文はZRさんのブログ記事「ipamjmパッケージでアレしてみた」\footnote{%
 \verb+http://d.hatena.ne.jp/zrbabbler/20131214/1387029624+}より引用.
 
-\paragraph{標準状態では……}
 \begin{quote}
 \LARGE
-渡邉󠄏さんとか   % { } の中は U+9089 U+E010F
+渡邉󠄏さんとか%    { } の中は 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]{邉}
+\MJI15{邉}\MJI25{邉}\MJI27{邉}\MJI26{邉}\MJI26{邉}\MJI16{邊}
+\MJI18{邊}\textcolor{blue}{\MJI2{𫟪}}\MJI17{邊}〓\\
+\MJI28{邉}\MJI29{邉}\MJI23{邉}\MJI15{邊}\MJI8{邊}\MJI20{邉}
+\MJI24{邉}\MJI19{邉}\MJI18{邉}\MJI16{邉}\\
+\MJI14{邊}\MJI10{邊}\MJI12{邊}\MJI11{邊}\MJI13{邊}\MJI9{邊}
+\textcolor{blue}{\MJI0{𫟪}}\textcolor{blue}{\MJI1{𫟪}}〓\MJI21{邉}
 \end{quote}
-「〓」はMJ番号を直接指定していたところなので,とりあえず無視している
-なぜか𫟪(U+2B7EA)のIVSが機能していないようだが,フォント側にその記述がない,ということ?
+MJ番号を直接指定していたところは,このソース中では無視して下駄「〓」にした
+青色は「𫟪」(U+2B7EA)のIVS.
 
 \begin{quote}
 \LARGE
-渡邉󠄏さんとか   % { } の中は U+9089 U+E010F
+渡邉󠄏さんとか%    { } の中は 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
+
+\def\TEST{%
+  奈良県葛󠄀城市と東京都葛󠄁飾区.%
+  江戸川区葛西はどっち?
+}
+
+\paragraph{IVSとopentype featureの干渉テスト}
+
+\begin{quote}
+ \Large
+ {\jfontspec{KozMinPr6N-Regular}\TEST}\\
+ {\jfontspec[CJKShape=JIS1978]{KozMinPr6N-Regular}\TEST}\\
+ {\jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}\TEST}
+\end{quote}
+
+\newpage
+\def\TABLE#1#2{%
+   \begin{center}
+   #1\par\medskip
+   \jfontspec{#2}
+   \Large
+   \begin{tabular}{c>{\tt}ll}
+      \toprule
+      文字&Unicode&異体字\\
+      \midrule
+      今&U+4ECA&\IVS?{今}\\
+      邉&U+9089&\IVS?{邉}\\
+      邊&U+908A&\IVS?{邊}\\
+      𫟪&U+2B7EA&\IVS?{𫟪}\\
+      葛&U+845B&\IVS?{葛}\\
+      \bottomrule
+   \end{tabular}
+   \end{center}
+}
+
+\TABLE{IPAmj明朝}{ipamjm}
+\TABLE{小塚明朝 Pr6N R}{kozminpr6n-regular}
+\TABLE{Source Han Serif Regular}{Source\space Han\space Serif\space Regular}
+
+\begin{lstlisting}[basicstyle=\tt, columns=fixed, basewidth=.5em]
+奈良県葛󠄀城市と東京都葛󠄁飾区.%
+江戸川区葛西はどっち?
+\end{lstlisting}
+
+\end{document}