OSDN Git Service

ltj-rmlgbm.lua: "slant=..." and "extend=..." for non-embedded fonts now work again.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Wed, 8 May 2013 05:41:53 +0000 (14:41 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Wed, 8 May 2013 05:41:53 +0000 (14:41 +0900)
 * Fonts whose em size is not 1000 is not correctly drawn by LuaTeX.
   (This is not LuaTeX-ja specific;
    see http://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=1009)

 * \CID and commit 0c68dbd doesn't work correctly.
   e.g. luaotfload maps "Japan1.668" (fullwidth) to proportional glyph.

doc/luatexja.dtx
src/ltj-otf.lua
src/ltj-pretreat.lua
src/ltj-rmlgbm.lua
src/luatexja.lua

index 35387e6..f3fea0d 100644 (file)
@@ -682,85 +682,10 @@ To install the \LuaTeX-ja\ package, you will need:
 安装\LuaTeX-ja之前,需要如下:
 %</zh>
 \begin{itemize}
-%<*en>
-\item \LuaTeX\ (version 0.65.0-beta or later) and its supporting packages.
-
-You might need to add the following lines to 
-\texttt{lualatex.ini} (just before \verb+\dump+ in the last line), 
-if you are using recent \LuaTeX\ whose Lua is 5.2.
-%</en>
-%<*ja>
-\item \LuaTeX(バージョン 0.65.0-beta以降)とその支援パッケージ.
-
-Lua 5.2を用いた\LuaTeX(バージョン0.74.0-beta以降)では,\texttt{lualatex.ini}\ 
-に次の行を加える必要があるかもしれない(\verb+\dump+ の前に).
-%</ja>
-%<*!zh>
-\begin{lstlisting}
-{\catcode`\#=12\catcode`\~=12%
-\global\everyjob\expandafter{\the\everyjob%
-  \directlua{%
-    if not table.maxn then
-      table.maxn = function(t)
-          local r = 0
-          for i,_ in pairs(t) do
-            if type(i)=='number' then
-              if i>r then r=i end
-            end
-          end
-         return r
-      end
-    end
-    if not package.loaders then package.loaders=package.searchers end
-    if not string.explode then
-      string.explode = function (str, separator)
-        if not separator then separator=" +"  end
-        local t, nexti, pos = { }, 1, 1
-        while true do
-          local st, sp = str:find (separator, pos)
-          if not st then break end
-          if pos ~= st then
-            t [ nexti ] = str:sub ( pos , st - 1 )
-            nexti = nexti + 1
-          end
-          pos = sp + 1
-        end
-        t [ nexti ] = str:sub ( pos )
-        return t
-      end
-    end
-  }%
-}}%
-\end{lstlisting}
-%</!zh>
-%<*zh>
-\item \LuaTeX(版本号为大于0.65)和相关支持宏包。
-%如果用户使用的是\TeX Live2011以及最新版本的W32\TeX,可不考虑此项。
-%</zh>
-%<*en>
-\item The source archive of \LuaTeX-ja, of course\texttt{:)}
-%</en>
-%<*ja>
-\item \LuaTeX-jaのソースアーカイブ(もちろん\texttt{:)}).
-%</ja>
-%<*zh>
-\item \LuaTeX-ja的源码(当然喽\texttt{:)})。
-%</zh>
-%<*en>
-\item The \Pkg{xunicode} package, which version is \emph{just v0.981 (2011/09/09)}.\\
-If you have the \Pkg{fontspec} package, this \Pkg{xunicode} package must be exist.
-But be careful about the version; other versions may not work correctly with \LuaTeX-ja.
-%</en>
-%<*ja>
-\item \Pkg{xunicode}パッケージ(\textbf{2011/09/09,~v0.981}).\\
-\Pkg{fontspec}パッケージが導入されていればこのパッケージも導入されているはずであるが,
-このv0.981以外のバージョンでは\LuaTeX-ja上で正しく動作しない危険性がある.
-%</ja>
-%<*zh>
-\Pkg{xunicode}宏包,当前版本必须为\textit{v0.981(2011/09/09)}。\\
-如果你使用\Pkg{fontspec}宏包,\Pkg{xunicode}就必须存在。但是请注意该包的
-版本,其他版本可能不会正常工作。
-%</zh>
+\item \LuaTeX\ beta-0.74.0 (or later)
+\item \Pkg{luaotfload} v2.2~(2013/05/05)
+\item \Pkg{luatexbase} v0.6~(2013/05/04)
+\item \Pkg{xunicode} v0.981~(2011/09/09)
 \end{itemize}
 
 %<*en>
@@ -6421,7 +6346,7 @@ listing environments.
 また,行長と自然長との差の絶対値を計算し,それを\textit{total}とおく.
 
 \subsection{行末文字の位置調整}
-まず,行末が文字クラス$n$の\textbf{Jachar}であった場合,
+まず,行末が文字クラス$n$の\textbf{JAchar}であった場合,
 それを動かすことによって,\textbf{JAglue} が負担する調整量を少なくしようとする.
 この行末文字の左右の移動可能量は,JFM中にある文字クラス$n$の定義の
 \texttt{end\_stretch},~\texttt{end\_shrink}フィールドに全角単位の値として記述されている.
index 6884550..84b0cd3 100644 (file)
@@ -38,7 +38,7 @@ local ltjr_cidfont_data = ltjr.cidfont_data
 local OTF = luatexja.userid_table.OTF
 
 function get_ucs_from_rmlgbm(c)
-   local v = ltjr_cidfont_data["Adobe-Japan1"].unicodes["Japan1." .. tostring(c)]
+   local v = ltjr_cidfont_data["Adobe-Japan1"].resources.unicodes["Japan1." .. tostring(c)]
    if not v then -- AJ1 範囲外
       return 0
    elseif v<0xF0000 then -- 素直に Unicode にマップ可能
@@ -72,15 +72,16 @@ function append_jglyph(char)
 end
 
 function cid(key)
+   if key==0 then return append_jglyph(char) end
    local curjfnt = fonts.ids[tex.attribute[attr_curjfnt]]
    if not curjfnt.cidinfo or 
       curjfnt.cidinfo.ordering ~= "Japan1" and
       curjfnt.cidinfo.ordering ~= "GB1" and
       curjfnt.cidinfo.ordering ~= "CNS1" and
       curjfnt.cidinfo.ordering ~= "Korea1" then
-      ltjb.package_warning('luatexja-otf',
-                          'Current Japanese font (or other CJK font) "'
-                             ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)')
+--      ltjb.package_warning('luatexja-otf',
+--                        'Current Japanese font (or other CJK font) "'
+--                           ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)')
       return append_jglyph(get_ucs_from_rmlgbm(key))
    end
    local char = curjfnt.resources.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)]
@@ -91,9 +92,8 @@ function cid(key)
                               ..tostring(key)..')', 
                            'Use a font including the specified CID character.')
       char = 0
-      return
    end
-   append_jglyph(char)
+   return append_jglyph(char)
 end
 
 function extract(head)
index 4404327..24146c3 100644 (file)
@@ -91,21 +91,12 @@ local function suppress_hyphenate_ja(head)
            p.font = pf
            p.subtype = floor(p.subtype*0.5)*2
            set_attr(p, attr_orig_char, p.char)
+           local pfd = fonts_ids[pf]
            if ltjf_font_metric_table[pf] and ltjf_font_metric_table[pf].mono_flag then
-              local pfd = fonts_ids[pf]
               local pco = pfd.cidinfo.ordering
               for i,v in pairs(fwglyph) do
-                 if pco == i and pfd.shared.resources then
-                    -- print(pf, pfd.fullname, pfd)
-                    -- for j,w in pairs(pfd.resources) do
-                    --         print('["' .. j .. '"] = ' .. tostring(w))
-                    --         if type(w) == 'table' and j~='characters' then
-                    --            for k,x in pairs(w) do
-                    --               print('    ["' .. k .. '"] = ' .. tostring(x))
-                    --            end
-                    --         end
-                    -- end
-                    local fwc = pfd.shared.resources.unicodes[pco .. '.'.. tostring(v[p.char])]
+                 if pco == i and pfd.resources then
+                    local fwc = pfd.resources.unicodes[pco .. '.'.. tostring(v[p.char])]
                     if fwc then p.char = fwc end
                     break
                  end
index 4bafaf2..b7e9d8f 100644 (file)
@@ -23,7 +23,7 @@ local path           = {
 local cid_reg, cid_order, cid_supp, cid_name
 local taux_dir = 'luatex-cache/luatexja'
 local cid_replace = {
-   ["Adobe-Japan1"] = {"UniJIS2004-UTF32", 23057, 
+   ["Adobe-Japan1"] = {"UniJIS2004-UTF32", 23057, 6,
                       function (i)
                          if (231<=i and i<=632) or (8718<=i and i<=8719) 
                             or (12063<=i and i<=12087) then
@@ -35,20 +35,20 @@ local cid_replace = {
                          end
                       end},
                        -- 基本的には JIS X 0213:2004 に沿ったマッピング
-   ["Adobe-Korea1"] = {"UniKS-UTF32",  18351,
+   ["Adobe-Korea1"] = {"UniKS-UTF32",  18351, 2, 
                       function (i)
                          if 8094<=i and i<=8100 then 
                             return 327680 -- 655360/2
                          end
                       end},
-   ["Adobe-GB1"]    = {"UniGB-UTF32",  30283,
+   ["Adobe-GB1"]    = {"UniGB-UTF32",  30283, 5, 
                       function (i)
                          if (814<=i and i<=939) or (i==7716) 
                             or (22355<=i and i<=22357) then
                             return 327680 -- 655360/2
                          end
                       end},
-   ["Adobe-CNS1"]   = {"UniCNS-UTF32", 19155,
+   ["Adobe-CNS1"]   = {"UniCNS-UTF32", 19155, 6,
                       function (i)
                          if (13648<=i and i<=13742) or (i==17603) then
                             return 327680 -- 655360/2
@@ -119,14 +119,14 @@ do
       return {index = a} 
    end
    function make_cid_font()
+      local kx = cid_replace[cid_name]
       local k = {
-         cidinfo = { ordering=cid_order, registry=cid_reg, supplement=cid_supp },
+         cidinfo = { ordering=cid_order, registry=cid_reg, supplement=kx[3] },
          encodingbytes = 2, extend=1000, format = 'opentype',
          direction = 0, characters = {}, parameters = {}, embedding = "no", cache = "yes", 
          ascender = 0, descender = 0, factor = 0, hfactor = 0, vfactor = 0,
         tounicode = 1,
       }
-      local kx = cid_replace[cid_name]
       cidfont_data[cid_name] = k
 
       -- CID => Unicode 符号空間
@@ -175,8 +175,9 @@ do
                     end,
                     function(a) return a[1] ..string.format('%04X',a[2])  end)
       -- tt は cid -> tounicode になっているので cidm -> tounicode に変換
+      local kxf = kx[4]
       for i,v in ipairs(cidmo) do
-        k.characters[v].width = kx[3](i)
+        k.characters[v].width = kxf(i)
         if v>=0xF0000 then
            k.characters[v].tounicode = tt[i]
         end
@@ -232,10 +233,12 @@ local function read_cid_font()
 end
 
 -- High-level
+
+local definers = fonts.definers
 local function mk_rml(name, size, id)
-   local specification = fonts.definers.analyze(name,size)
-   specification = fonts.definers.resolve(specification)
-   local features = specification.features.normal
+   local specification = definers.analyze(name,size)
+   specification = definers.resolve(specification)
+   specification.detail = specification.detail or ''
 
    local fontdata = {}
    local cachedata = {}
@@ -259,44 +262,60 @@ local function mk_rml(name, size, id)
    -- characters & scaling
    if size < 0 then size = -size * 655.36 end
    local scale = size / 655360
-   local def_height =  0.88 * size -- character's default height (optimized for jfm-ujis.lua)
-   local def_depth =  0.12 * size  -- and depth.
-   if not cache_chars[cid_name][size] then
-      cache_chars[cid_name][size]  = {}
-      for k, v in pairs(cache_chars[cid_name][655360]) do
-         cache_chars[cid_name][size][k] = { 
-           index = v.index, width = v.width * scale, 
-           height = def_height, depth = def_depth, tounicode = v.tounicode,
-        }
+
+   do
+      local def_height =  0.88 * size 
+      -- character's default height (optimized for jfm-ujis.lua)
+      local def_depth =  0.12 * size  -- and depth.
+      if not cache_chars[cid_name][size] then
+        cache_chars[cid_name][size]  = {}
+        for k, v in pairs(cache_chars[cid_name][655360]) do
+           cache_chars[cid_name][size][k] = { 
+              index = v.index, width = v.width * scale, 
+              height = def_height, depth = def_depth, tounicode = v.tounicode,
+           }
+        end
       end
+      fontdata.characters = cache_chars[cid_name][size]
+      cachedata.characters = cache_chars[cid_name][size]
    end
-   fontdata.characters = cache_chars[cid_name][size]
-   cachedata.characters = cache_chars[cid_name][size]
 
-   local parameters = {}
-   for k, v in pairs(s.parameters) do
-      parameters[k] = v * scale
+   -- other parameters
+   do
+      local parameters = {}
+      for k, v in pairs(s.parameters) do
+        parameters[k] = v * scale
+      end
+      fontdata.parameters  = parameters
+      fontdata.ascender    = fontdata.ascender * scale
+      fontdata.descender   = fontdata.descender * scale
+      fontdata.factor      = fontdata.factor * scale
+      fontdata.hfactor     = fontdata.hfactor * scale
+      fontdata.vfactor     = fontdata.vfactor * scale
+      fontdata.size        = size
+      fontdata.resources   = s.resources
+      cachedata.parameters = parameters
+      cachedata.ascender   = fontdata.ascender
+      cachedata.descender  = fontdata.descender
+      cachedata.factor     = fontdata.factor
+      cachedata.hfactor    = fontdata.hfactor
+      cachedata.vfactor    = fontdata.vfactor
+      cachedata.size       = size
+      cachedata.resources  = s.resources
    end
-   fontdata.parameters = parameters;                cachedata.parameters = parameters
-   fontdata.ascender = fontdata.ascender * scale;   cachedata.ascender = fontdata.ascender
-   fontdata.descender = fontdata.descender * scale; cachedata.descender = fontdata.descender
-   fontdata.factor = fontdata.factor * scale;       cachedata.factor = fontdata.factor
-   fontdata.hfactor = fontdata.hfactor * scale;     cachedata.hfactor = fontdata.hfactor
-   fontdata.vfactor = fontdata.vfactor * scale;     cachedata.vfactor = fontdata.vfactor
-   fontdata.size = size;                            cachedata.size = size
-   fontdata.resources = s.resources
-   cachedata.resources = s.resources
-   
+
    -- no embedding
    local var = ''
-  --  if features.slant then 
-  --     fontdata.slant = features.slant*1000;         cachedata.slant = fontdata.slant
-  --     var = var .. 's' .. tostring(features.slant)
-  --  end
-  --  if features.extend then 
-  --     fontdata.extend = features.extend*1000;       cachedata.extend = fontdata.extend
-  --      var = var .. 'x' .. tostring(features.extend)
-  --  end
+   local s = string.match(specification.detail, 'slant=([+-]*[0-9]*%.[0-9]*)')
+   if s and e~=1  then 
+      s = s * 1000
+      var, fontdata.slant  = var .. 's' .. tostring(s), s
+   end
+   local e = string.match(specification.detail, 'extend=([+-]*[0-9]*%.[0-9]*)')
+   if e and e~=1  then 
+      e = e * 1000
+      var, fontdata.extend  = var .. 'x' .. tostring(e), e
+   end
    fontdata.name = specification.name .. size .. var; cachedata.name = fontdata.name
    fontdata.fullname = specification.name .. var; cachedata.fullname = fontdata.fullname
    fontdata.psname = specification.name; cachedata.psname = fontdata.psname
index de9da60..969284d 100644 (file)
@@ -1,5 +1,5 @@
 
-require('lualibs-table')
+require('lualibs')
 
 ------------------------------------------------------------------------
 -- naming:
@@ -263,6 +263,10 @@ luatexbase.add_to_callback('define_font',luatexja.font_callback,"luatexja.font_c
 
 do
 
+local node_type = node.type
+local node_next = node.next
+local has_attr = node.has_attribute
+
 local id_penalty = node.id('penalty')
 local id_glyph = node.id('glyph')
 local id_glue_spec = node.id('glue_spec')