OSDN Git Service

Optimized capsule_glyph() in ltj-setwidth.lua.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 17 Jul 2012 08:39:57 +0000 (17:39 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 17 Jul 2012 08:39:57 +0000 (17:39 +0900)
src/ltj-jfmglue.lua
src/ltj-math.lua
src/ltj-otf.lua
src/ltj-setwidth.lua
src/ltj-stack.lua

index b3602ea..4d9c6ca 100644 (file)
@@ -192,12 +192,10 @@ local function check_box(box_ptr, box_end)
       end
       if pid==id_hlist then
         if has_attr(p, attr_icflag)==PACKED then
-           for q in node.traverse_id(id_glyph, p.head) do
-              if find_first_char then
-                 first_char = q; find_first_char = false
-              end
-              last_char = q; found_visible_node = true; break
+           if find_first_char then
+              first_char = p.head; find_first_char = false
            end
+           last_char = p.head; found_visible_node = true
         else
            if p.shift==0 then
               if check_box(p.head, nil) then found_visible_node = true end
@@ -427,23 +425,17 @@ end
 -- 和文文字のデータを取得
 function set_np_xspc_jachar(Nx, x)
    local m = ltjf.font_metric_table[x.font]
-   Nx.var  = m.var
    local c = has_attr(x, attr_orig_char) or 0
    local cls = ltjf.find_char_class(x.char, m) or 0
    if cls==0 and c ~= x.char then cls = ltjf.find_char_class(-c, m) end
-   set_attr(x, attr_jchar_class, cls)
-   Nx.class = cls
-   Nx.char = c
-   Nx.met = m
+   Nx.class = cls; set_attr(x, attr_jchar_class, cls)
+   Nx.lend = m.size_cache.char_type[cls].kern[fast_find_char_class('lineend', m)] or 0
+   Nx.met, Nx.var, Nx.char = m, m.var, c
    Nx.pre = ltjs.get_penalty_table('pre', c, 0, box_stack_level)
    Nx.post = ltjs.get_penalty_table('post', c, 0, box_stack_level)
-   local z = fast_find_char_class('lineend', m)
-   Nx.lend = m.size_cache.char_type[Nx.class].kern[z] or 0
    local y = ltjs.get_penalty_table('xsp', c, 3, box_stack_level)
-   Nx.xspc_before = (y%2==1)
-   Nx.xspc_after  = (y>=2)
-   Nx.auto_kspc = (has_attr(x, attr_autospc)==1)
-   Nx.auto_xspc = (has_attr(x, attr_autoxspc)==1)
+   Nx.xspc_before, Nx.xspc_after = (y%2==1), (y>=2)
+   Nx.auto_kspc, Nx.auto_xspc = (has_attr(x, attr_autospc)==1), (has_attr(x, attr_autoxspc)==1)
 end
 
 -- 欧文文字のデータを取得
index bf5185f..784a55f 100644 (file)
@@ -108,12 +108,9 @@ function (p, sty)
            local r = node_new(id_glyph); r.next = nil
            r.char = p.char; r.font = f; r.subtype = 256
            set_attr(r, attr_yablshift, 0)
-           local met = ltjf_font_metric_table[f]
-           local class = ltjf_find_char_class(p.char, met)
-           set_attr(r, attr_jchar_class, class)
            set_attr(r, attr_icflag, PROCESSED)
-           ltjw.char_data = met.size_cache.char_type[class]
-           ltjw.head = r; ltjw.capsule_glyph(r, tex.mathdir , true, met, class);
+           local met = ltjf_font_metric_table[f]
+           ltjw.head = r; ltjw.capsule_glyph(r, tex.mathdir , true, met, ltjf_find_char_class(p.char, met));
            q.head = ltjw.head; node_free(p); p=q;
         end
       end
index 4619570..71f9749 100644 (file)
@@ -74,8 +74,6 @@ function extract(head)
            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]))
            set_attr(g, attr_curjfnt, v)
            v = has_attr(p, attr_yablshift)
            if v then 
index 2cfbb1d..d3e7c2e 100644 (file)
@@ -42,7 +42,6 @@ local PACKED = 2
 local PROCESSED = 8
 local IC_PROCESSED = 9
 
-char_data = {}
 head = nil
 
 -- return true if and only if p is a Japanese character node
@@ -58,37 +57,27 @@ luatexbase.create_callback("luatexja.set_width", "data",
 local fshift =  { down = 0, left = 0}
 -- mode: true iff p will be always encapsuled by a hbox
 function capsule_glyph(p, dir, mode, met, class)
-   local h, box, q, fwidth
+   local char_data = met.size_cache.char_type[class]
+   if not char_data then return node_next(p) end
    if char_data.width ~= 'prop' then
       fwidth = char_data.width
    else fwidth = p.width end
-   local fheight = char_data.height
-   local fdepth = char_data.depth
+   local fheight, fdepth = char_data.height, char_data.depth
    fshift.down = char_data.down; fshift.left = char_data.left
    fshift = luatexbase.call_callback("luatexja.set_width", fshift, met, class)
-   p.xoffset = p.xoffset - fshift.left
    if (mode or p.width ~= fwidth or p.height ~= fheight or p.depth ~= fdepth) then
-      local y_shift = - p.yoffset + (has_attr(p,attr_yablshift) or 0)
-      p.yoffset = -fshift.down
-      head, q = node.remove(head, p)
-      local total = fwidth - p.width
-      if total == 0 then
-        h = p; p.next = nil
+      local y_shift, total = - p.yoffset + (has_attr(p,attr_yablshift) or 0), fwidth - p.width
+      local q; head, q = node.remove(head, p)
+      p.yoffset, p.next = -fshift.down, nil
+      if total ~= 0 and char_data.align~='left' then
+        p.xoffset = p.xoffset - fshift.left
+           + (((char_data.align=='right') and total) or round(total*0.5))
       else
-        h = node_new(id_kern); h.subtype = 0
-        if char_data.align=='right' then
-           h.kern = total; p.next = nil; h.next = p
-        elseif char_data.align=='middle' then
-           h.kern = round(total*0.5); p.next = h
-           h = node_new(id_kern); h.subtype = 0
-           h.kern = total - round(total*0.5); h.next = p
-        else -- left
-           h.kern = total; p.next = h; h = p
-        end
+        p.xoffset = p.xoffset - fshift.left
       end
-      box = node_new(id_hlist); 
-      box.width = fwidth; box.height = fheight; box.depth = fdepth
-      box.glue_set = 0; box.glue_order = 0; box.head = h
+      local box = node_new(id_hlist); 
+      box.width, box.height, box.depth = fwidth, fheight, fdepth
+      box.glue_set, box.glue_order, box.head = 0, 0, p
       box.shift = y_shift; box.dir = dir or 'TLT'
       set_attr(box, attr_icflag, PACKED)
       set_attr(box, attr_uniqid, has_attr(p, attr_uniqid) or 0)
@@ -99,6 +88,7 @@ function capsule_glyph(p, dir, mode, met, class)
       end
       return q
    else
+      p.xoffset = p.xoffset - fshift.left
       p.yoffset = p.yoffset - (has_attr(p, attr_yablshift) or 0) - fshift.down
       return node_next(p)
    end
@@ -110,16 +100,8 @@ function set_ja_width(ahead, dir)
    while p do
       if (p.id==id_glyph) and (has_attr(p, attr_icflag, PROCESSED) or 0)<=0  then
         if is_japanese_glyph_node(p) then
-           local met = ltjf_font_metric_table[p.font]
-           local class = has_attr(p, attr_jchar_class)
-           char_data = met.size_cache.char_type[class]
            set_attr(p, attr_icflag, PROCESSED)
-            if char_data then
-               p = capsule_glyph(p, dir, false, met, class)
-            else
-               p = node_next(p)
-            end
-              
+           p = capsule_glyph(p, dir, false, ltjf_font_metric_table[p.font], has_attr(p, attr_jchar_class))
         else
            set_attr(p, attr_icflag, PROCESSED) 
            p.yoffset = p.yoffset - (has_attr(p,attr_yablshift) or 0); p = node_next(p)
index 88d2a67..6ac1024 100644 (file)
@@ -153,17 +153,14 @@ function set_stack_skip(g,m,sp)
   end
 end
 
--- mode: nil iff it is called in callbacks
 function get_skip_table(m, idx)
-   local i = charprop_stack_table[idx][m]
-   return i or { width = 0, stretch = 0, shrink = 0,
-                stretch_order = 0, shrink_order = 0 }
+   return charprop_stack_table[idx][m] 
+      or { width = 0, stretch = 0, shrink = 0, stretch_order = 0, shrink_order = 0 }
 end
 
 function get_penalty_table(m,c,d, idx)
    local i = charprop_stack_table[idx][m]
-   if i then i=i[c] end
-   return i or d
+   return (i and i[c]) or d
 end
 
 -- EOF