From: Hironori Kitagawa Date: Wed, 17 Aug 2022 03:18:07 +0000 (+0900) Subject: bit op (require Lua 5.3) X-Git-Tag: 20221002.0~13 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=42d92eea842ddea5330205f6fe6e3e7f561dd584;p=luatex-ja%2Fluatexja.git bit op (require Lua 5.3) --- diff --git a/src/ltj-charrange.lua b/src/ltj-charrange.lua index 46075b2..e4a2a8c 100644 --- a/src/ltj-charrange.lua +++ b/src/ltj-charrange.lua @@ -3,7 +3,7 @@ -- luatexbase.provides_module({ name = 'luatexja.charrange', - date = '2020-07-30', + date = '2020-08-17', description = 'Handling the range of Japanese characters', }) luatexja.charrange = {} @@ -14,6 +14,7 @@ local has_attr = node.direct.has_attribute local has_attr_node = node.has_attribute local tex_getattr = tex.getattribute +local UNSET = -0x7FFFFFFF local ATTR_RANGE = 7 luatexja.charrange.ATTR_RANGE = ATTR_RANGE local jcr_cjk, jcr_noncjk = 0, 1 @@ -23,11 +24,10 @@ local pow_table = {} local fn_table = {} -- used in is_ucs_in_japanese_char_direct local nfn_table = {} -- used in is_ucs_in_japanese_char_node for i = 0, 31*ATTR_RANGE-1 do - local ka, pw = luatexbase.attributes['ltj@kcat'..floor(i/31)], 1/(2^(i%31)) - local jcr_noncjk = jcr_noncjk - kcat_attr_table[i], pow_table[i] = ka, 2^(i%31) - fn_table[i] = function(p) return floor(has_attr(p, ka)*pw)%2 ~= jcr_noncjk end - nfn_table[i] = function(p) return floor(has_attr_node(p, ka)*pw)%2 ~= jcr_noncjk end + local ka, pw = luatexbase.attributes['ltj@kcat'..floor(i/31)], 2^(i%31) + kcat_attr_table[i], pow_table[i] = ka, pw + fn_table[i] = function(p) return has_attr(p, ka)&pw==0 end + nfn_table[i] = function(p) return has_attr_node(p, ka)&pw==0 end end fn_table[-1] = function() return false end -- for char --U+007F nfn_table[-1] = function() return false end -- for char --U+007F @@ -71,7 +71,8 @@ function luatexja.charrange.char_to_range(c) -- return the external range number end local function get_range_setting(i) -- i: internal range number - return floor(tex_getattr(kcat_attr_table[i])/pow_table[i])%2 + local a = tex_getattr(kcat_attr_table[i]) + return floor((a==UNSET and 0 or a)/pow_table[i])%2 end -- glyph_node p は和文文字か? @@ -96,12 +97,9 @@ function luatexja.charrange.toggle_char_range(g, i) -- i: external range number elseif i==0 then return else local kc - if i>0 then kc=0 else kc=1; i=-i end - if i>=31*ATTR_RANGE then i=0 end - local attr = kcat_attr_table[i] - local a = tex_getattr(attr) - tex.setattribute(g, attr, - (floor(a/pow_table[i+1])*2+kc)*pow_table[i]+a%pow_table[i]) + if i>0 then kc=0 else kc=1; i=-i end; if i>=31*ATTR_RANGE then i=0 end + local attr, p = kcat_attr_table[i], pow_table[i] + tex.setattribute(g, attr, (tex_getattr(attr)&~p)+kc*p) end end diff --git a/src/ltj-ruby.lua b/src/ltj-ruby.lua index 782835d..5f66166 100644 --- a/src/ltj-ruby.lua +++ b/src/ltj-ruby.lua @@ -584,7 +584,7 @@ luatexbase.add_to_callback('hpack_filter', pre_high, 'ltj.ruby.pre', 100) local post_lown do local function write_aux(wv, num, bool) - local id = has_attr(wv, attr_ruby_id) + local id = has_attr(wv, attr_ruby_id) or 0 if id>0 and cache_handle then cache_handle:write( 'lrob[' .. tostring(id) .. ']=' .. num .. '\nlrob[' .. tostring(-id) .. ']=' .. tostring(bool) .. '\n') diff --git a/src/luatexja-core.sty b/src/luatexja-core.sty index cc49fbd..12caebd 100644 --- a/src/luatexja-core.sty +++ b/src/luatexja-core.sty @@ -65,7 +65,7 @@ \expandafter\let\csname ifltj@in@latex\expandafter\endcsname \csname iftrue\endcsname \NeedsTeXFormat{LaTeX2e} - \ProvidesPackage{luatexja-core}[2022-01-12 Core of LuaTeX-ja] + \ProvidesPackage{luatexja-core}[2022-08-17 Core of LuaTeX-ja] \fi % %% Load prerequisite packages. @@ -97,10 +97,10 @@ \expandafter\endinput\fi\relax %% Check LuaTeX version. -\ifnum\luatexversion<100 +\ifnum\luatexversion<110 \@PackageError{luatexja-core} {This LuaTeX engine is too old for this package;\MessageBreak - at least 1.0.0 is needed} + at least 1.10.0 is needed} {Package loading is aborted now.\MessageBreak} \expandafter\endinput\fi\relax @@ -162,7 +162,7 @@ \loop\ifnum\ltj@tempcnta<7 \expandafter\newattribute% \csname ltj@kcat\the\ltj@tempcnta\endcsname - \csname ltj@kcat\the\ltj@tempcnta\endcsname=0 + \csname ltj@kcat\the\ltj@tempcnta\endcsname=\z@ \advance\ltj@tempcnta\@ne \repeat @@ -516,7 +516,7 @@ t[\the\ltj@alljachar@inner] = function() font.current(get_attr(attr_curjfnt)); tex.language=lang_ja; for i=0,6 do - set_attr(luatexbase.attributes['ltj@kcat' .. floor(i)],0) + set_attr(luatexbase.attributes['ltj@kcat' .. floor(i)], 0) end end }