OSDN Git Service

ltj-setwidth.lua: better? criteria for rotating glyphs
[luatex-ja/luatexja.git] / src / ltj-setwidth.lua
index bc48fd8..5878595 100644 (file)
@@ -33,7 +33,6 @@ local setheight = node.direct.setheight
 local setdepth = node.direct.setdepth
 local setlist = node.direct.setlist
 
-local node_traverse_id = node.direct.traverse_id
 local node_traverse = node.direct.traverse
 local node_copy = node.direct.copy
 local node_remove = node.direct.remove
@@ -58,12 +57,14 @@ local sid_restore = node.subtype 'pdf_restore'
 local sid_matrix  = node.subtype 'pdf_setmatrix'
 local dir_tate = luatexja.dir_table.dir_tate
 
+local attr_yablshift = luatexbase.attributes['ltj@yablshift']
 local attr_ykblshift = luatexbase.attributes['ltj@ykblshift']
 local attr_tkblshift = luatexbase.attributes['ltj@tkblshift']
 local attr_icflag = luatexbase.attributes['ltj@icflag']
 local attr_vert_ori = luatexbase.attributes['ltj@vert@ori']
 
 local ltjf_font_extra_info = ltjf.font_extra_info
+local ltjs_orig_char_table = ltjs.orig_char_table
 
 local PACKED       = luatexja.icflag_table.PACKED
 local PROCESSED    = luatexja.icflag_table.PROCESSED
@@ -191,8 +192,15 @@ local function capsule_glyph_tate(p, met, char_data, head, dir)
       local feir = ltjf_font_extra_info[pf]
       if met.rotation and met.vert_activated then
           local f = font_getfont(pf)
-          local r, l = met.rotation[pc], f.properties and f.properties.language
-          if ((r==true) or (type(r)=="table" and not r[l])) and (get_attr(p, attr_vert_ori) or 0)<=0 then
+          local pco = ltjs_orig_char_table[p] or pc
+          local r = met.rotation[pco]
+          local l = f.properties and f.properties.language
+          r = (r==true) or (type(r)=="table" and not r[l])
+          if r then
+            r = met.rotation[pc]
+            r = (r==true) or (type(r)=="table" and not r[l])
+          end
+          if r and (get_attr(p, attr_vert_ori) or 0)<=0 then
             return capsule_glyph_tate_rot(p, met, char_data, head, dir,
               0.5*(get_ascender(pf)-get_descender(pf)))
           end
@@ -242,15 +250,30 @@ local function capsule_glyph_tate(p, met, char_data, head, dir)
 end
 luatexja.setwidth.capsule_glyph_tate = capsule_glyph_tate
 
-local function capsule_glyph_math(p, met, char_data)
+do
+local font_getfont, famfont = font.getfont, node.family_font
+local cap_math_aux = {
+  [-1]=function() return 1 end, [0]=function() return 1 end,
+  [1]=function()
+     local sf, tf = famfont(2,1), famfont(2,0)
+     return font_getfont(sf).size/font_getfont(tf).size
+  end,
+  [2]=function()
+     local ssf, tf = famfont(2,2), famfont(2,0)
+     return font_getfont(ssf).size/font_getfont(tf).size
+  end
+}
+setmetatable(cap_math_aux, {__index=function(t,k) return t[2] end})
+local function capsule_glyph_math(p, met, char_data, sty)
    if not char_data then return nil end
    local fwidth, pwidth = char_data.width, getwidth(p)
    fwidth = fwidth or pwidth
    fshift.down = char_data.down; fshift.left = char_data.left
    fshift = call_callback("luatexja.set_width", fshift, met, char_data)
    local fheight, fdepth = char_data.height, char_data.depth
-   local y_shift
-      = - getfield(p, 'yoffset') + (get_attr(p,attr_ykblshift) or 0)
+   local y_shift = - getfield(p, 'yoffset') 
+     + cap_math_aux[sty]()*
+       ((get_attr(p,attr_ykblshift) or 0) - (get_attr(p,attr_yablshift) or 0))
    setfield(p, 'yoffset', -fshift.down)
    setfield(p, 'xoffset', getfield(p, 'xoffset') + char_data.align*(fwidth-pwidth) - fshift.left)
    local box = node_new(id_hlist, nil, p);
@@ -261,11 +284,11 @@ local function capsule_glyph_math(p, met, char_data)
    return box
 end
 luatexja.setwidth.capsule_glyph_math = capsule_glyph_math
+end
 
 -- 数式の位置補正
 function luatexja.setwidth.apply_ashift_math(head, last, attr_ablshift)
-   for p in node_traverse(head) do
-      local pid = getid(p)
+   for p, pid in node_traverse(head) do
       if p==last then
          return
       elseif (get_attr(p, attr_icflag) or 0) ~= PROCESSED then
@@ -292,11 +315,12 @@ do
    local attr_tablshift = luatexbase.attributes['ltj@tablshift']
    local attr_ablshift
    local disc, tex_dir
+   local traverse_glyph = node.direct.traverse_glyph
    local function ashift_disc_inner(field)
       local head = getfield(disc, field)
       if not head then return end
       local y_adjust, node_depth, adj_depth = 0, 0, 0
-      for lp in node_traverse_id(id_glyph, head) do
+      for lp in traverse_glyph(head) do
          y_adjust = get_attr(lp,attr_ablshift) or 0
          local ld = getdepth(lp)
          node_depth = max(ld + min(y_adjust, 0), node_depth)