OSDN Git Service

ltj-pretreat.lua etc.: optimize.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 10 Jan 2015 11:23:36 +0000 (20:23 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 10 Jan 2015 11:23:36 +0000 (20:23 +0900)
src/ltj-charrange.lua
src/ltj-jfmglue.lua
src/ltj-pretreat.lua

index 66bdcbc..b142d35 100644 (file)
@@ -31,6 +31,7 @@ for i = 0, 31*ATTR_RANGE-1 do
       return floor(has_attr(p, kcat_attr_table[i])/pow_table[i])%2 ~= jcr_noncjk
    end
 end
+fn_table[-1]= function() return false end -- for char --U+007F
 pow_table[31*ATTR_RANGE] = pow(2, 31)
 
 -- jcr_table_main[chr_code] = index
@@ -42,6 +43,7 @@ jcr_table_main = {}
 local jcr_table_main = jcr_table_main
 local ucs_out = 0x110000
 
+for i=0x0 ,0x7F       do jcr_table_main[i]=-1 end
 for i=0x80 ,0xFF      do jcr_table_main[i]=1 end
 for i=0x100,ucs_out-1 do jcr_table_main[i]=0 end
 
@@ -92,14 +94,10 @@ function is_ucs_in_japanese_char_node(p)
    end
 end
 is_ucs_in_japanese_char = is_ucs_in_japanese_char_node
+-- only ltj-otf.lua uses this version
 
-function is_ucs_in_japanese_char_direct(p)
-   local c = getchar(p)
-   if c<0x80 then
-      return false
-   else
-      return fn_table[jcr_table_main[c]](p)
-   end
+function is_ucs_in_japanese_char_direct(p ,c)
+   return fn_table[jcr_table_main[c or getchar(p)]](p)
 end
 
 function is_japanese_char_curlist(c) -- assume that c>=0x80
index 4091073..04e72ed 100644 (file)
@@ -319,7 +319,7 @@ local ltjw_apply_ashift_disc = ltjw.apply_ashift_disc
 local min, max = math.min, math.max
 local function calc_np_aux_glyph_common(lp)
    Np.nuc = lp
-   Np.id = npi
+   Np.first= (Np.first or lp)
    if getfield(lp, 'lang') == lang_ja then
       Np.id = id_jglyph
       set_np_xspc_jachar(Np, lp)
@@ -406,10 +406,7 @@ local function calc_np_aux_glyph_common(lp)
    end
 end
 local calc_np_auxtable = {
-   [id_glyph] = function (lp)
-      Np.first= (Np.first or lp)
-      return calc_np_aux_glyph_common(lp)
-   end,
+   [id_glyph] = calc_np_aux_glyph_common,
    [id_hlist] = function(lp)
       local op, flag
       head, lp, op, flag = ltjd_make_dir_whatsit(head, lp, list_dir, 'jfm hlist')
@@ -491,7 +488,6 @@ local calc_np_auxtable = {
       return true, node_next(lp)
    end,
    [id_kern] = function(lp)
-      Np.first = Np.first or lp
       if getsubtype(lp)==2 then
         set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
         set_attr(lp, attr_icflag, PROCESSED); lp = node_next(lp)
@@ -499,6 +495,7 @@ local calc_np_auxtable = {
         set_attr(lp, attr_icflag, PROCESSED);
         return calc_np_aux_glyph_common(lp)
       else
+        Np.first = Np.first or lp
         Np.id = id_kern; set_attr(lp, attr_icflag, PROCESSED)
         Np.last = lp; return true, node_next(lp)
       end
index 796ad70..45cf0bf 100644 (file)
@@ -61,51 +61,52 @@ do
    local start_time_measure, stop_time_measure
       = ltjb.start_time_measure, ltjb.stop_time_measure
    local head
-   local suppress_hyphenate_ja_aux = {}
-   suppress_hyphenate_ja_aux[id_glyph] = function(p)
-      if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p) then
-         local pc = getchar(p)
-        local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc)
-        setfield(p, 'font', pf); setfield(p, 'lang', lang_ja)
-        ltjs_orig_char_table[p] = pc
-      end
-      return p
-   end
-   suppress_hyphenate_ja_aux[id_math] = function(p)
-      return node_end_of_math(node_next(p)) end
-   suppress_hyphenate_ja_aux[50] = function(p) return p end
-   suppress_hyphenate_ja_aux[id_whatsit] = function(p)
-      if getsubtype(p)==sid_user then
-         local uid = getfield(p, 'user_id')
-         if uid==STCK then
-            wt[#wt+1] = p; node_remove(head, p)
-         elseif uid==DIR then
-           if has_attr(p, attr_icflag)<PROCESSED_BEGIN_FLAG  then
-              ltjs.list_dir = has_attr(p, attr_dir)
-           else
-              wtd[#wtd+1] = p; node_remove(head, p)
+   local suppress_hyphenate_ja_aux = {
+      [id_glyph] = function(p)
+        local pc = getchar(p)
+        if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p, pc) then
+           setfield(p, 'font', 
+                    ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc))
+           setfield(p, 'lang', lang_ja)
+           ltjs_orig_char_table[p] = pc
+        end
+        return node_next(p)
+      end,
+      [id_math] = function(p) return node_next(node_end_of_math(node_next(p))) end,
+      [id_whatsit] = function(p)
+        if getsubtype(p)==sid_user then
+           local uid = getfield(p, 'user_id')
+           if uid==STCK then
+              wt[#wt+1] = p; node_remove(head, p)
+           elseif uid==DIR then
+              if has_attr(p, attr_icflag)<PROCESSED_BEGIN_FLAG  then
+                 ltjs.list_dir = has_attr(p, attr_dir)
+              else
+                 wtd[#wtd+1] = p; node_remove(head, p)
+              end
            end
-         end
-      end
-      return p
-   end
-
-   local function suppress_hyphenate_ja (h,t)
+        end
+        return node_next(p)
+      end,
+   }
+   setmetatable(suppress_hyphenate_ja_aux, 
+               {
+                  __index = function() return node_next end,
+               })
+   local function suppress_hyphenate_ja_iter(_,p)
+      return (suppress_hyphenate_ja_aux[getid(p)])(p) end
+   local function suppress_hyphenate_ja (h)
       start_time_measure('ltj_hyphenate')
       head = to_direct(h)
-      local p = head
       for i = 1,#wt do wt[i]=nil end
       for i = 1,#wtd do wtd[i]=nil end
       for i,_ in pairs(ltjs_orig_char_table) do
         ltjs_orig_char_table[i] = nil
       end
       ltjs.list_dir=ltjd_get_dir_count()
-      while p and p~=t do
-        local pfunc = suppress_hyphenate_ja_aux[getid(p)]
-        p = node_next(pfunc and pfunc(p) or p)
-      end
+      for p in suppress_hyphenate_ja_iter, nil, head do end
       stop_time_measure('ltj_hyphenate'); start_time_measure('tex_hyphenate')
-      lang.hyphenate(h, t)
+      lang.hyphenate(h, nil)
       stop_time_measure('tex_hyphenate')
       return h
    end