From: Hironori Kitagawa Date: Mon, 19 Sep 2011 00:48:05 +0000 (+0900) Subject: Changed the inplementation of \CID and \UTF. X-Git-Tag: 20120419.0~82^2~1^2~1 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=e8c88f11c34a3957a1fff1391109d353566d4a6a;p=luatex-ja%2Fluatexja.git Changed the inplementation of \CID and \UTF. --- diff --git a/src/luatexja-otf.sty b/src/luatexja-otf.sty index a01d49b..ac7a883 100644 --- a/src/luatexja-otf.sty +++ b/src/luatexja-otf.sty @@ -85,10 +85,10 @@ %! Main part of luatexja-otf \RequireLuaModule{luatexja.otf} -\protected\def\CID#1{\char\directlua{luatexja.otf.cid(#1)}\relax} +\protected\def\CID#1{\ifvmode\leavevmode\fi\directlua{luatexja.otf.cid(#1)}\relax} %% \UTF being compatible with the OTF package for pLaTeX -\protected\def\UTF#1{\char"#1\relax} +\protected\def\UTF#1{\ifvmode\leavevmode\fi\directlua{luatexja.otf.append_jglyph(0x#1)}} %%------------------ all done \ltj@otf@AtEnd diff --git a/src/luatexja/otf.lua b/src/luatexja/otf.lua index 1c8caf7..0b69241 100644 --- a/src/luatexja/otf.lua +++ b/src/luatexja/otf.lua @@ -10,8 +10,35 @@ luatexbase.provides_module({ module('luatexja.otf', package.seeall) require('luatexja.base'); local ltjb = luatexja.base +require('luatexja.jfont'); local ltjf = luatexja.jfont + +local id_glyph = node.id('glyph') +local id_whatsit = node.id('whatsit') +local sid_user = node.subtype('user_defined') + +local node_new = node.new +local node_remove = node.remove +local node_next = node.next +local node_free = node.free +local has_attr = node.has_attribute +local set_attr = node.set_attribute +local unset_attr = node.unset_attribute +local node_insert_after = node.insert_after local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] +local attr_jchar_class = luatexbase.attributes['ltj@charclass'] +local attr_yablshift = luatexbase.attributes['ltj@yablshift'] +local attr_ykblshift = luatexbase.attributes['ltj@ykblshift'] + +-- Append a whatsit node to the list. +-- This whatsit node will be extracted to a glyph_node +function append_jglyph(char) + local p = node_new(id_whatsit,sid_user) + local v = tex.attribute[attr_curjfnt] + p.user_id=30113; p.type=100; p.value=char + set_attr(p, attr_yablshift, tex.attribute[attr_ykblshift]) + node.write(p) +end function cid(key) local curjfnt = fonts.ids[tex.attribute[attr_curjfnt]] @@ -28,8 +55,45 @@ function cid(key) 'Use a font including the specified CID character.') return end - tex.print(char) + append_jglyph(char) end +function extract(head) + local p = head, v + while p do + if p.id==id_whatsit then + if p.subtype==sid_user and p.user_id==30113 then + local g = node_new(id_glyph) + g.subtype = 0; g.char = p.value + v = has_attr(p, attr_curjfnt); g.font = v + set_attr(g, attr_jchar_class, + ltjf.find_char_class(g.char, ltjf.font_metric_table[v].jfm)) + set_attr(g, attr_curjfnt, v) + v = has_attr(p, attr_yablshift) + if v then + set_attr(g, attr_yablshift, v) + else + unset_attr(g, attr_yablshift) + end + head = node_insert_after(head, p, g) + head = node_remove(head, p) + node_free(p); p = g + end + end + p = node_next(p) + end + return head +end + +luatexbase.add_to_callback('hpack_filter', + function (head) return extract(head) end,'ltj.hpack_filter_otf', + luatexbase.priority_in_callback('pre_linebreak_filter', + 'ltj.pre_linebreak_filter')) +luatexbase.add_to_callback('pre_linebreak_filter', + function (head) return extract(head) end, 'ltj.pre_linebreak_filter_otf', + luatexbase.priority_in_callback('pre_linebreak_filter', + 'ltj.pre_linebreak_filter')) + + -------------------- all done -- EOF diff --git a/src/luatexja/pretreat.lua b/src/luatexja/pretreat.lua index 286a0ba..7adeec9 100644 --- a/src/luatexja/pretreat.lua +++ b/src/luatexja/pretreat.lua @@ -54,7 +54,7 @@ local function suppress_hyphenate_ja(head) unset_attr(p, attr_yablshift) end if p.subtype%2==1 then p.subtype = p.subtype - 1 end - p.lang=lang_ja + -- p.lang=lang_ja end end lang.hyphenate(head) diff --git a/test/test10-otf.pdf b/test/test10-otf.pdf index 8e78e1e..6569150 100644 Binary files a/test/test10-otf.pdf and b/test/test10-otf.pdf differ diff --git a/test/test10-otf.tex b/test/test10-otf.tex index ebe448d..1ff53b5 100644 --- a/test/test10-otf.tex +++ b/test/test10-otf.tex @@ -4,6 +4,8 @@ \usepackage{luatexja-otf} \usepackage{luatexja-fontspec} \begin{document} +%\ltjsetparameter{yjabaselineshift=3pt,yalbaselineshift=1pt} + ※このファイルはフォントを埋め込んでいないため,代替されるフォントによっては正しく 表示されないでしょう. @@ -36,6 +38,9 @@ \begin{itemize} \item 欧文文字範囲に設定されている文字は CID で出力しても欧文フォントになる. 例: あ\CID{18}1あ + + \textgt{←一応和文文字扱いになるようにしたが,文字幅が問題. + 欧文文字範囲の文字は(フォントだけ)和文のにするのはどうか?} \item OpenType の feature が指定されているとそちらが優先される. 例: {\jfontspec[NoEmbed,CJKShape=JIS1978]{Ryumin-Light}\CID{3056}\CID{8267}} (左は一点,右は二点になってほしい.)