--
luatexbase.provides_module({
name = 'luatexja.jfont',
- date = '2017/08/09',
+ date = '2017/09/04',
description = 'Loader for Japanese fonts',
})
module('luatexja.jfont', package.seeall)
end
do
+ local gmatch = string.gmatch
-- extract jfm_file_name and jfm_var
-- normalize position of 'jfm=' and 'jfmvar=' keys
local function extract_metric(name)
- local is_braced = name:match('^{(.*)}$')
- name= is_braced or name
+ do
+ local nametemp
+ nametemp = name:match('^{(.*)}$')
+ if nametemp then name = nametemp
+ else
+ nametemp = name:match('^"(.*)"$')
+ name = nametemp or name
+ end
+ end
jfm_file_name = ''; jfm_var = ''; jfm_ksp = true
local tmp, index = name:sub(1, 5), 1
if tmp == 'file:' or tmp == 'name:' or tmp == 'psft:' then
local p = name:find(":", index); index = p and (p+1) or index
while index do
local l = name:len()+1
- local q = name:find(";", index+1) or l
+ local q = name:find(";", index) or l
if name:sub(index, index+3)=='jfm=' and q>index+4 then
jfm_file_name = name:sub(index+4, q-1)
if l~=q then
name = name .. 'jfmvar=' .. jfm_var
end
end
- for x in string.gmatch (name, "[:;]([+%%-]?)ltjks") do
+ for x in gmatch (name, "[:;]([+%%-]?)ltjks") do
jfm_ksp = not (x=='-')
end
if jfm_dir == 'tate' then
is_vert_enabled = (not name:match('[:;]%-vert')) and (not name:match('[:;]%-vrt2'))
- auto_enable_vrt2 = (not name:match('vert') and not name:match('vrt2'))
+ auto_enable_vrt2
+ = (not name:match('[:;][+%-]?vert')) and (not name:match('[:;][+%-]?vrt2'))
else
is_vert_enabled, auto_enable_vrt2 = nil, nil
end
- return is_braced and ('{' .. name .. '}') or name
+ return name
end
-- define_font callback
if i.order[1]== 'vert' and i.type == 'gsub_single' and i.steps then
for _,j in pairs(i.steps) do
if type(j)=='table' then
- if type(j,coverage)=='table' then
+ if type(j.coverage)=='table' then
for i,_ in pairs(j.coverage) do rot[i]=nil end
end
end
end
prepare_fl_data = function (dest, id)
local t = fontloader.info(id.filename)
+ if not t then return dest end
local fl
- if t.filename then
+ if t.fontname then
fl = fontloader.open(id.filename)
else
- fl = fontloader.open(id.filename, id.fullname)
+ fl = fontloader.open(id.filename, id.fontname) -- マニュアルにはこっちで書いてあるが?
+ if not fl then
+ local index
+ for i,v in ipairs(t) do
+ if v.fontname == id.fontname then index=i; break end
+ end
+ fl = fontloader.open(id.filename, index)
+ end
end
+ if not fl then fontloader.close(fl); return dest end
local ind_to_uni, unicodes = {}, {}
for i,v in pairs(id.characters) do
ind_to_uni[v.index] = i
font_extra_basename[bname] = dat or {}
ltjb.save_cache( v,
{
- chksum = checksum(id.filename),
+ chksum = newsum,
version = cache_ver,
dat,
})
------------------------------------------------------------------------
-- VERT VARIANT TABLE
------------------------------------------------------------------------
+ local provides_feature = luaotfload.aux.provides_feature
local vert_form_table = {
[0x3001]=0xFE11, [0x3002]=0xFE12, [0x3016]=0xFE17, [0x3017]=0xFE18,
[0x2026]=0xFE19,
[0x300C]=0xFE41, [0x300D]=0xFE42, [0x300E]=0xFE43, [0x300F]=0xFE44,
[0xFF3B]=0xFE47, [0xFF3D]=0xFE48,
}
- local function add_vform(coverage, vform, ft)
+ local function add_vform(coverage, vform, ft, add_vert)
if type(coverage)~='table' then return end
for i,v in pairs(vert_form_table) do
- if (not coverage[i]) and ft.characters[v] then
+ if not coverage[i] and ft.characters[v] then
vform[i] = v
end
end
+ if add_vert then -- vert feature が有効にならない場合
+ for i,v in pairs(coverage) do vform[i] = vform[i] or v end
+ end
end
luatexbase.add_to_callback(
"luatexja.define_jfont",
function (fmtable, fnum)
local vform = {}; fmtable.vform = vform
- local ft = font_getfont(fnum)
- if ft.specification and ft.resources then
- for _,i in pairs(ft.resources.sequences) do
- if i.order[1]== 'vert' and i.type == 'gsub_single' and i.steps then
- for _,j in pairs(i.steps) do
- if type(j)=='table' then add_vform(j.coverage,vform, ft) end
- end
- end
+ local t = font_getfont(fnum)
+ if t.specification and t.resources then
+ local add_vert
+ = not (provides_feature(fnum, t.properties.script, t.properties.language, 'vert'))
+ and not (provides_feature(fnum, t.properties.script, t.properties.language, 'vrt2'))
+ -- 現在の language, script で vert もvrt2 も有効にできない場合,強制的に vert 適用
+ for _,i in pairs(t.resources.sequences) do
+ if i.order[1]== 'vert' and i.type == 'gsub_single' and i.steps then
+ for _,j in pairs(i.steps) do
+ if type(j)=='table' then add_vform(j.coverage,vform, t, add_vert) end
+ end
+ end
end
end
return fmtable