OSDN Git Service

more unicode library -> utf
[luatex-ja/luatexja.git] / test / test19-ivs.tex
1 %#!lualatex
2 \documentclass{ltjsarticle}
3 \usepackage{luatexja-fontspec,luatexja-otf, luacode, booktabs,array,xcolor}
4 \usepackage[scale=0.80]{geometry}
5 \usepackage{listings}
6 \setsansjfont{KozGoPr6N-Regular}
7
8 % \IVS[?] 用
9 \begin{luacode}
10    local identifiers = fonts.hashes.identifiers
11    local fallback_color = 'red'  -- IVS がないときは,この色で既定文字を出力
12    local list_color = 'blue!50!black'     -- リスト表示の色
13
14    local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
15    local ubyte = utf.byte
16    local uchar = utf.char
17    local sort = table.sort
18    function list_ivs(s)
19       local c = ubyte(s)
20       local pt = identifiers[tex.getattribute(attr_curjfnt)].resources
21       pt = pt and pt.variants
22       if pt then
23          local t = {}
24          for i,v in pairs(pt) do
25            if v[c] then t[#t+1]={i,v[c]} end
26          end
27          sort(t, function(a,b) return a[1]<b[1] end)
28          tex.sprint('\\textcolor{' .. list_color .. '}{')
29          for _,i in ipairs(t) do
30             if i[1]>=0xE0100 then -- only IVS
31                tex.sprint('\\oalign{' .. s .. uchar(i[1])
32                           .. '\\crcr\\hss\\tiny' .. tostring(i[1]-0xE0100) .. '\\hss\\crcr}')
33             end
34          end
35          tex.sprint('}')
36       else
37          tex.sprint('\\textcolor{' .. fallback_color .. '}{' .. s .. '}')
38       end
39    end
40 \end{luacode}
41
42 \makeatletter
43
44 %%%%%    \IVS[<selector number>]{<character>}
45 %%%%% or \IVS<selector number>{<character>}
46 %%%%% (<selector number>: 0--239, or `?')
47 \def\ltj@ivs@out#1#2{#2\char\numexpr "E0100+#1\relax} % IVS"
48 \def\ltj@ivs@list?#1{\directlua{list_ivs('#1')}}
49 \def\ltj@ivs@grab@num{\expandafter\expandafter\expandafter\ltj@ivs@out\ltj@grab@num}
50 \def\ltj@ivs@nobracket{\@ifnextchar?{\ltj@ivs@list}{\ltj@ivs@grab@num}}
51 \def\ltj@ivs@bracket[#1]{\ltj@ivs@nobracket#1}
52 \def\IVS{\@ifnextchar[{\ltj@ivs@bracket}{\ltj@ivs@nobracket}}
53
54 \let\MJI=\IVS
55
56 \begin{document}
57 \jfontspec{ipamjm} % IPAmj明朝
58
59 例文はZRさんのブログ記事「ipamjmパッケージでアレしてみた」\footnote{%
60 \verb+http://d.hatena.ne.jp/zrbabbler/20131214/1387029624+}より引用.
61
62 \begin{quote}
63 \LARGE
64 渡邉󠄏さんとか%    { } の中は U+9089 U+E010F
65 渡𫟪󠄂さんとか。% { } の中は U+2B7EA U+E0102
66 \end{quote}
67
68
69 \begin{quote}
70 \LARGE
71 \MJI15{邉}\MJI25{邉}\MJI27{邉}\MJI26{邉}\MJI26{邉}\MJI16{邊}
72 \MJI18{邊}\textcolor{blue}{\MJI2{𫟪}}\MJI17{邊}〓\\
73 \MJI28{邉}\MJI29{邉}\MJI23{邉}\MJI15{邊}\MJI8{邊}\MJI20{邉}
74 \MJI24{邉}\MJI19{邉}\MJI18{邉}\MJI16{邉}\\
75 \MJI14{邊}\MJI10{邊}\MJI12{邊}\MJI11{邊}\MJI13{邊}\MJI9{邊}
76 \textcolor{blue}{\MJI0{𫟪}}\textcolor{blue}{\MJI1{𫟪}}〓\MJI21{邉}
77 \end{quote}
78 MJ番号を直接指定していたところは,このソース中では無視して下駄「〓」にした.
79 青色は「𫟪」(U+2B7EA)のIVS.
80
81 \begin{quote}
82 \LARGE
83 渡邉󠄏さんとか%    { } の中は U+9089 U+E010F
84 渡𫟪󠄂さんとか。% { } の中は U+2B7EA U+E0102
85 \end{quote}
86
87
88 \def\TEST{%
89   奈良県葛󠄀城市と東京都葛󠄁飾区.%
90   江戸川区葛西はどっち?
91 }
92
93 \paragraph{IVSとopentype featureの干渉テスト}
94
95 \begin{quote}
96  \Large
97  {\jfontspec{KozMinPr6N-Regular}\TEST}\\
98  {\jfontspec[CJKShape=JIS1978]{KozMinPr6N-Regular}\TEST}\\
99  {\jfontspec[CJKShape=JIS1990]{KozMinPr6N-Regular}\TEST}
100 \end{quote}
101
102 \newpage
103 \def\TABLE#1#2{%
104    \begin{center}
105    #1\par\medskip
106    \jfontspec{#2}
107    \Large
108    \begin{tabular}{c>{\tt}ll}
109       \toprule
110       文字&Unicode&異体字\\
111       \midrule
112       今&U+4ECA&\IVS?{今}\\
113       邉&U+9089&\IVS?{邉}\\
114       邊&U+908A&\IVS?{邊}\\
115       𫟪&U+2B7EA&\IVS?{𫟪}\\
116       葛&U+845B&\IVS?{葛}\\
117       \bottomrule
118    \end{tabular}
119    \end{center}
120 }
121
122 \TABLE{IPAmj明朝}{ipamjm}
123 \TABLE{小塚明朝 Pr6N R}{kozminpr6n-regular}
124 \TABLE{Source Han Serif Regular}{Source\space Han\space Serif\space Regular}
125
126 \begin{lstlisting}[basicstyle=\tt, columns=fixed, basewidth=.5em]
127 奈良県葛󠄀城市と東京都葛󠄁飾区.%
128 江戸川区葛西はどっち?
129 \end{lstlisting}
130
131 \end{document}