OSDN Git Service

test-zh-maqiyuan.tex: CRLF -> LF.
[luatex-ja/luatexja.git] / src / luatexja / setwidth.lua
index 0fb33a5..a74b37b 100644 (file)
@@ -35,9 +35,10 @@ local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
 local attr_icflag = luatexbase.attributes['ltj@icflag']
 
+local ltjf_font_metric_table = ltjf.font_metric_table
+
 local PACKED = 2
 
-met_tb = {}
 char_data = {}
 head = nil
 
@@ -46,32 +47,41 @@ local function is_japanese_glyph_node(p)
    return p.font==has_attr(p, attr_curjfnt)
 end
 
+luatexbase.create_callback("luatexja.set_width", "data", 
+                          function (fstable, fmtable, jchar_class) 
+                             return fstable 
+                          end)
+
+local fshift =  { down = 0, left = 0}
 -- mode: true iff p will be always encapsuled by a hbox
-function capsule_glyph(p, dir, mode)
-   local h, box, q, fwidth, fheight, fdepth
-   p.xoffset= p.xoffset - round(met_tb.size*char_data.left)
+function capsule_glyph(p, dir, mode, met, class)
+   local h, box, q, fwidth
    if char_data.width ~= 'prop' then
-      fwidth = round(char_data.width*met_tb.size)
+      fwidth = char_data.width
    else fwidth = p.width end
-   fheight = round(met_tb.size*char_data.height)
-   fdepth = round(met_tb.size*char_data.depth)
+   local fheight = char_data.height
+   local fdepth = char_data.depth
+   fshift.down = char_data.down; fshift.left = char_data.left
+   fshift = luatexbase.call_callback("luatexja.set_width", fshift, met, class)
+--   local ti = 
+   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 = -round(met_tb.size*char_data.down)
+      p.yoffset = -fshift.down
       head, q = node.remove(head, p)
       local total = fwidth - p.width
       if total == 0 then
         h = p; p.next = nil
       else
         h = node_new(id_kern); h.subtype = 0
-        if char_data.align=='left' then
-           h.kern = total; p.next = h; h = p
-        elseif char_data.align=='right' then
+        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/2); p.next = h
            h = node_new(id_kern); h.subtype = 0
            h.kern = total - round(total/2); h.next = p
+        else -- left
+           h.kern = total; p.next = h; h = p
         end
       end
       box = node_new(id_hlist); 
@@ -86,7 +96,7 @@ function capsule_glyph(p, dir, mode)
       end
       return q
    else
-      p.yoffset = p.yoffset - (has_attr(p, attr_yablshift) or 0) - round(met_tb.size*char_data.down)
+      p.yoffset = p.yoffset - (has_attr(p, attr_yablshift) or 0) - fshift.down
       return node_next(p)
    end
 end
@@ -97,9 +107,10 @@ function set_ja_width(ahead, dir)
    while p do
       if p.id==id_glyph then
         if is_japanese_glyph_node(p) then
-           met_tb = ltjf.font_metric_table[p.font]
-           char_data = ltjf.metrics[met_tb.jfm].char_type[has_attr(p, attr_jchar_class)]
-           p = capsule_glyph(p, dir, false)
+           local met = ltjf.font_metric_table[p.font]
+           local class = has_attr(p, attr_jchar_class)
+           char_data = ltjf.metrics[met.jfm].size_cache[met.size].char_type[class]
+           p = capsule_glyph(p, dir, false, met, class)
         else 
            p.yoffset = p.yoffset - (has_attr(p,attr_yablshift) or 0); p = node_next(p)
         end