OSDN Git Service

jfm: new property "round_threshold" (only yoko direction now)
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 21 Apr 2020 03:23:14 +0000 (12:23 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 21 Apr 2020 03:23:14 +0000 (12:23 +0900)
 文字クラス 0 でしか指定できない数値.
 もしこの数値 d が指定されており,かつ文字クラス 0 の文字 p に対して
 q = p.width / (JFM で指定された文字クラス 0 の文字の幅)が
 整数から ±d 未満の範囲に収まっていたとしたら,
 「JFM で指定された文字の幅」を q に最も近い整数倍にして処理する.

 主な適用対象は #40431 で報告されたような「私用領域にある n 倍角の合字」.
 なお「ちょうど整数倍しか許さない」と 0 を指定するのは現実的ではない
 (sp 単位で計算することによる誤差が考えられるため).
 jfm-ujis.lua で指定した 0.01 とか,ひょっとしたら 0.001 とかが適当な値か?

src/jfm-ujis.lua
src/ltj-jfont.lua
src/ltj-setwidth.lua

index 10b44d8..0d5da01 100644 (file)
@@ -28,6 +28,7 @@ local t = {
         [8] = { 0, 0, 0, kanjiskip_shrink=1 },
       },
       kern = { [307] = 0 },     
+      round_threshold = 0.01,
    },
 
    [1] = { -- 開き括弧類
index 2d73f5c..8d1ddc3 100644 (file)
@@ -108,6 +108,8 @@ function luatexja.jfont.define_jfm(to)
          if type(v.down)~='number' then
             v.down = 0.0
          end
+         v.round_threshold = ((t.version>=3)and(i==0)and(type(v.round_threshold)=='number'))
+            and v.round_threshold or nil
          if t.version>=2 then
             if v.end_stretch then defjfm_res= nil; return end
             if v.end_shrink  then defjfm_res= nil; return end
@@ -218,7 +220,8 @@ do
                   width = w[1], stretch = w[2], shrink = w[3],
                   kanjiskip_natural = w.kanjiskip_natural and w.kanjiskip_natural/sz,
                   kanjiskip_stretch = w.kanjiskip_stretch and w.kanjiskip_stretch/sz,
-                  kanjiskip_shrink =  w.kanjiskip_shrink  and w.kanjiskip_shrink/sz,
+                 kanjiskip_shrink =  w.kanjiskip_shrink  and w.kanjiskip_shrink/sz,
+                 round_threshold = w.round_threshold and w.round_threshold/zw,
                }
             end
             for k,w in pairs(v.kern) do
@@ -331,7 +334,7 @@ do
       local fmtable = { jfm = j, size = f.size, var = jfm_var,
                         with_kanjiskip = jfm_ksp,
                         zw = sz.zw, zh = sz.zh,
-                        chars = sz.chars, char_type = sz.char_type,
+                       chars = sz.chars, char_type = sz.char_type,
                         kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip,
                         chars_cbcache = {},
                         vert_activated = vert_activated,
index f21c005..0d684ef 100644 (file)
@@ -87,7 +87,7 @@ local call_callback = luatexbase.call_callback
 
 local fshift =  { down = 0, left = 0 }
 
-local min, max = math.min, math.max
+local min, max, floor, abs = math.min, math.max, math.floor, math.abs
 
 local rule_subtype = (status.luatex_version>=85) and 3 or 0
 
@@ -129,6 +129,11 @@ local function capsule_glyph_yoko(p, met, char_data, head, dir)
 
    local q
    head, q = node_remove(head, p)
+   if char_data.round_threshold then
+      local frac = abs(pwidth / fwidth); 
+      local quot = floor(frac)
+      if frac-quot <char_data.round_threshold then fwidth = fwidth * quot end
+   end
    local xo, yo = getoffsets(p)
    setoffsets(p, xo + char_data.align*(fwidth-pwidth) - fshift.left,
               yo - fshift.down);