Skip to content

Instantly share code, notes, and snippets.

@h-kitagawa
Created February 3, 2022 10:55
Show Gist options
  • Save h-kitagawa/baf11530e351db6d9f3e9f7766363fe0 to your computer and use it in GitHub Desktop.
Save h-kitagawa/baf11530e351db6d9f3e9f7766363fe0 to your computer and use it in GitHub Desktop.
和文ゴーストの実験(LuaTeX-ja: cb77093 コミット以降)
%#! lualatex
\documentclass{ltjsarticle}
\usepackage{graphicx}
\makeatletter
\newluafunction\ltj@@ghost@jachar@inner
\directlua{%
local GHOST_JACHAR = luatexbase.newuserwhatsitid('ghost of a jachar', 'luatexja')
luatexja.userid_table.GHOST_JACHAR = GHOST_JACHAR
local dnode = node.direct
local node_new, node_prev = dnode.new, dnode.getprev
local node_write, node_remove, node_free = dnode.write, dnode.remove, dnode.free
local id_whatsit = node.id 'whatsit'
local sid_user = node.subtype 'user_defined'
local setfield, getfield = dnode.setfield, dnode.getfield
local has_attr = node.direct.has_attribute
local function create_ghost_jachar_node(cl)
local tn = node_new(id_whatsit, sid_user)
setfield(tn, 'user_id', GHOST_JACHAR)
setfield(tn, 'type', 100)
setfield(tn, 'value', cl)
node_write(tn)
end
local function whatsit_callback(Np, lp, Nq)
if Np and Np.nuc then return Np
elseif Np and getfield(lp, 'user_id') == GHOST_JACHAR then
Np.first = lp; Np.nuc = lp; Np.last = lp; Np.class = getfield(lp,'value')
print(Np.class)
if Nq then
Np.met = Nq.met; Np.pre = 0; Np.post = 0; Np.xspc = 3
end
Np.auto_kspc, Np.auto_xspc = (has_attr(lp, attr_autospc)==1), (has_attr(lp, attr_autoxspc)==1)
return Np
else
return Np
end
end
local function whatsit_after_callback(s, Nq, Np, head)
if not s and getfield(Nq.nuc, 'user_id') == GHOST_JACHAR then
local x, y = node_prev(Nq.nuc), Nq.nuc
Nq.first, Nq.nuc, Nq.last = x, x, x
if Np then Nq.met = Np.met end
s = node_remove(head, y); node_free(y)
end
return s
end
luatexbase.add_to_callback("luatexja.jfmglue.whatsit_getinfo", whatsit_callback,
"ghost of a JACHAR", 1)
luatexbase.add_to_callback("luatexja.jfmglue.whatsit_after", whatsit_after_callback,
"ghost of a JACHAR", 1)
local t = lua.get_functions_table()
t[\the\ltj@@ghost@jachar@inner] = function() create_ghost_jachar_node(0) end
}
\protected\def\ltjghostjachar{\ifhmode\relax\luafunction\ltj@@ghost@jachar@inner\fi}
% for test
\DeclareKanjiFamily{JY3}{piyo}{}
\DeclareFontShape{JY3}{piyo}{m}{n}{<-> s*[\Cjascale] file:ipaexg.ttf:jfm=jlreq}{}
\makeatother
\begin{document}
\def\MYGUARDA#1{ \kern-\zw#1\kern-\zw  \ignorespaces}
\def\MYGUARDB#1{{\kanjifamily{mc}\selectfont  }%
\kern-\zw#1\kern-\zw{\kanjifamily{mc}\selectfont  }\ignorespaces}
\def\MYGUARDC#1{\ltjghostjachar#1\ltjghostjachar\ignorespaces}
\def\MYVRULE{\rotatebox{90}{漢}}
\paragraph{jfm: ujis}\
\leavevmode\hbox to 15\zw{◆\MYVRULE ◆◆◆◆$f$◆}\par
\leavevmode\hbox to 15\zw{◆\MYGUARDA{\MYVRULE}◆◆◆◆$f$◆} A
\paragraph{jfm: jlreq}\
\kanjifamily{piyo}\selectfont
\leavevmode\hbox to 15\zw{◆\MYVRULE ◆◆◆◆$f$◆}\par
\leavevmode\hbox to 15\zw{◆\MYGUARDA{\MYVRULE}◆◆◆◆$f$◆} A\par
\leavevmode\hbox to 15\zw{◆\MYGUARDB{\MYVRULE}◆◆◆◆$f$◆} B\par
\leavevmode\hbox to 15\zw{◆\MYGUARDC{\MYVRULE}◆◆◆◆$f$◆} C\par
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment