OSDN Git Service

mapped internal charrange number 0 to external charrange number 217
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 18 Jan 2014 06:52:42 +0000 (15:52 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 18 Jan 2014 06:52:42 +0000 (15:52 +0900)
Now \ltjgetparameter{chartorange}{"CFFFF} returns 217, instead of 0.

-- index : internal 0,   1, 2, ..., 216
--         external 217  1  2       216

src/ltj-adjust.lua
src/ltj-charrange.lua
src/luatexja.lua

index c81930a..458fe98 100644 (file)
@@ -244,3 +244,7 @@ function disable_cb()
       is_reg = false
    end
 end
+
+luatexja.unary_pars.adjust = function(t)
+   return is_reg and 1 or 0
+end
index e3478ab..bc6fc4a 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.charrange',
-  date = '2012/10/21',
+  date = '2014/01/19',
   description = 'Handling the range of Japanese characters',
 })
 module('luatexja.charrange', package.seeall)
@@ -24,8 +24,8 @@ end
 pow_table[31*ATTR_RANGE] = pow(2, 31)
 
 -- jcr_table_main[chr_code] = index
--- index : internal 0, 1, 2, ..., 216               0: 'other'
---         external    1  2       216, (out of range): 'other'
+-- index : internal 0,   1, 2, ..., 216               0: 'other'
+--         external 217, 1  2       216, 217 and (out of range): 'other'
 
 -- initialize
 jcr_table_main = {}
@@ -37,11 +37,11 @@ for i=0x100,ucs_out-1 do jcr_table_main[i]=0 end
 
 -- EXT: add characters to a range
 function add_char_range(b,e,ind) -- ind: external range number
-   if not ind or ind<0 or ind>=31*ATTR_RANGE then -- 0 は error にしない(隠し)
+   if not ind or ind<0 or ind>31*ATTR_RANGE then -- 0 はエラーにしない(隠し)
       ltjb.package_error('luatexja',
                         "invalid character range number (" .. ind .. ")",
                         "A character range number should be in the range 1.."
-                          .. 31*ATTR_RANGE-1 .. ",\n" ..
+                          .. 31*ATTR_RANGE .. ",\n" ..
                          "ignored.")
       return
    elseif b<0x80 or e>=ucs_out then
@@ -51,20 +51,24 @@ function add_char_range(b,e,ind) -- ind: external range number
    elseif b>e then
       local j=b; e=b; b=j
    end
+   if ind == 31*ATTR_RANGE then ind=0 end
    for i=math.max(0x80,b),math.min(ucs_out-1,e) do
       jcr_table_main[i]=ind
    end
 end
 
-function char_to_range(c) -- return the (external) range number
+function char_to_range(c) -- return the external range number
    if not c or c<0 or c>0x10FFFF then
         ltjb.package_error('luatexja',
                            'bad character code (' .. tostring(c) .. ')',
                            'A character number must be between 0 and 0x10ffff.\n' ..
                             'So I changed this one to zero.')
-        c=0
+        return -1
    elseif c<0x80 then return -1
-   else return  jcr_table_main[c] or 0 end
+   else 
+      local r = jcr_table_main[c] or 217
+      return (r and r~=0) and r or 217 
+   end
 end
 
 function get_range_setting(i) -- i: internal range number
index c6ccda5..ec27e8e 100644 (file)
@@ -132,39 +132,48 @@ end
 ------------------------------------------------------------------------
 
 -- EXT: print parameters that don't need arguments
-function luatexja.ext_get_parameter_unary(k)
-   local t = tex.getcount('ltj@@stack')
-   if k == 'yalbaselineshift' then
-      tex.write(print_scaled(tex.getattribute('ltj@yablshift'))..'pt')
-   elseif k == 'yjabaselineshift' then
-      tex.write(print_scaled(tex.getattribute('ltj@ykblshift'))..'pt')
-   elseif k == 'kanjiskip' then
-      tex.write(print_spec(ltjs.get_skip_table('kanjiskip', t)))
-   elseif k == 'xkanjiskip' then
-      tex.write(print_spec(ltjs.get_skip_table('xkanjiskip', t)))
-   elseif k == 'jcharwidowpenalty' then
-      tex.write(ltjs.get_penalty_table(stack_table_index.JWP, 0, t))
-   elseif k == 'autospacing' then
-      tex.write(tex.getattribute('ltj@autospc'))
-   elseif k == 'autoxspacing' then
-      tex.write(tex.getattribute('ltj@autoxspc'))
-   elseif k == 'differentjfm' then
-      if luatexja.jfmglue.diffmet_rule == math.max then
-        tex.write('large')
-      elseif luatexja.jfmglue.diffmet_rule == math.min then
-        tex.write('small')
-      elseif luatexja.jfmglue.diffmet_rule == math.two_average then
-        tex.write('average')
-      elseif luatexja.jfmglue.diffmet_rule == math.two_paverage then
-        tex.write('paverage')
-      elseif luatexja.jfmglue.diffmet_rule == math.two_pleft then
-        tex.write('pleft')
-      elseif luatexja.jfmglue.diffmet_rule == math.two_pright then
-        tex.write('pright')
-      elseif luatexja.jfmglue.diffmet_rule == math.two_add then
-        tex.write('both')
-      else -- This can't happen.
-        tex.write('???')
+do
+   luatexja.unary_pars = {
+      yalbaselineshift = function(t) 
+        return print_scaled(tex.getattribute('ltj@yablshift'))..'pt'
+      end,
+      yjabaselineshift = function(t) 
+        return print_scaled(tex.getattribute('ltj@ykblshift'))..'pt'
+      end,
+      kanjiskip = function(t) 
+        return print_spec(ltjs.get_skip_table('kanjiskip', t))
+      end,
+      xkanjiskip = function(t) 
+        return print_spec(ltjs.get_skip_table('xkanjiskip', t))
+      end,
+      jcharwidowpenalty = function(t)
+        return ltjs.get_penalty_table(stack_table_index.JWP, 0, t)
+      end,
+      autospacing = function(t)
+        return tex.getattribute('ltj@autospc')
+      end,
+      autoxspacing = function(t)
+        return tex.getattribute('ltj@autoxspc')
+      end,
+      differentjfm = function(t)
+        local f, r = luatexja.jfmglue.diffmet_rule, '???'
+        if f == math.max then r = 'large'
+        elseif f == math.min then r = 'small'
+        elseif f == math.two_average then r = 'average'
+        elseif f == math.two_paverage then r = 'paverage'
+        elseif f == math.two_pleft then r = 'pleft'
+        elseif f == math.two_pright then r = 'pright'
+        elseif f == math.two_add then r = 'both'
+        end
+        return r
+      end
+   }
+
+   local unary_pars = luatexja.unary_pars
+   function luatexja.ext_get_parameter_unary(k)
+      local t = tex.getcount('ltj@@stack')
+      if unary_pars[k] then
+        tex.write(tostring(unary_pars[k](tex.getcount('ltj@@stack'))))
       end
    end
 end
@@ -180,16 +189,17 @@ function luatexja.ext_get_parameter_binary(k,c)
       c=0
    end
    if k == 'jacharrange' then
-      if c>=31*ltjc.ATTR_RANGE then 
+      if c<=0 or c>31*ltjc.ATTR_RANGE then 
         ltjb.package_error('luatexja',
                            'invalid character range number (' .. c .. ')',
-                           'A character range number should be in the range 0..'
-                               .. 31*ltjc.ATTR_RANGE-1 .. ",\n"..
-                            'So I changed this one to zero.')
-        c=0
+                           'A character range number should be in the range 1..'
+                               .. 31*ltjc.ATTR_RANGE .. ",\n"..
+                            'So I changed this one to ' .. 31*ltjc.ATTR_RANGE .. ".")
+        c=0 -- external range 217 == internal range 0
+      elseif c==31*ltjc.ATTR_RANGE then c=0
       end
       -- 負の値は <U+0080 の文字の文字範囲,として出てくる.この時はいつも欧文文字なので 1 を返す
-      tex.write( (c<0) and -1 or ltjc.get_range_setting(c))
+      tex.write( (c<0) and 1 or ltjc.get_range_setting(c))
    else
       if c<0 or c>0x10FFFF then
         ltjb.package_error('luatexja',