for i,_ in pairs(rot) do
dest = dest or {}
- dest[i] = dest[i] or {}
- dest[i].rotation = true
+ dest.rotation = dest.rotation or {}
+ dest.rotation[i] = true
end
end
return dest
-- vertical metrics
local prepare_fl_data
-local supply_vkern_table
do
- local fields = fontloader.fields
- local function glyph_vmetric(glyph)
- local flds = fields(glyph)
- local vw, tsb, vk = nil, nil, nil
- for _,i in ipairs(flds) do
- if i=='vkerns' then vk = glyph.vkerns end
- end
- return vw, tsb, vk
- end
-
local sort = table.sort
- local function add_fl_table(dest, glyphs, unitable, asc_des, units, id)
- local glyphmin, glyphmax = glyphs.glyphmin, glyphs.glyphmax
- if glyphmax < 0 then return dest end
- local tg = glyphs.glyphs
- for i = glyphmin, glyphmax do
- local gv = tg[i]
- if gv then
- if gv.altuni then
- for _,at in pairs(gv.altuni) do
- local bu, vsel = at.unicode, at.variant
- if vsel then
- if vsel>=0xE0100 then vsel = vsel - 0xE0100 end
- local uniq_flag = true
- if dest and dest[bu] then
- for i,_ in pairs(dest[bu]) do
- if i==vsel then uniq_flag = false; break end
- end
- end
- if uniq_flag then
- dest = dest or {}; dest[bu] = dest[bu] or {}
- dest[bu][vsel] = unitable[gv.name]
- end
- end
- end
- end
- -- vertical metric
- local vw, tsb, vk = glyph_vmetric(gv)
- local gi = unitable[gv.name]
- -- vertical kern
- if gi and vk then
- dest = dest or {};
- local dest_vk = dest.vkerns or {}; dest.vkerns = dest_vk
- for _,v in pairs(vk) do
- if unitable[v.char] then
- local vl = v.lookup
- if type(vl)=='table' then
- for _,vlt in pairs(vl) do
- dest_vk[vlt] = dest_vk[vlt] or {}
- dest_vk[vlt][gi] = dest_vk[vlt][gi] or {}
- dest_vk[vlt][gi][unitable[v.char]] = v.off
- end
- else
- dest_vk[vl] = dest_vk[vl] or {}
- dest_vk[vl][gi] = dest_vk[vl][gi] or {}
- dest_vk[vl][gi][unitable[v.char]] = v.off
- end
- end
- end
- end
- end
- end
- return dest
- end
prepare_fl_data = function (dest, id)
- local t = fontloader.info(id.filename)
- if not t then return dest end
- local fl
- if t.fontname then
- fl = fontloader.open(id.filename)
- else
- 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
- end
- if fl.glyphs then
- local tg, glyphmin, glyphmax = fl.glyphs, fl.glyphmin, fl.glyphmax
- if 0 <= glyphmax then
- for i = glyphmin, glyphmax do
- if tg[i] and tg[i].name then unicodes[tg[i].name] = ind_to_uni[i] end
- end
- end
- dest = add_fl_table(dest, fl, unicodes,
- fl.ascent + fl.descent, fl.units_per_em, id)
- end
- if fl.subfonts then
- for _,v in pairs(fl.subfonts) do
- local tg, glyphmin, glyphmax = v.glyphs, v.glyphmin, v.glyphmax
- if 0 <= glyphmax then
- for i = glyphmin, glyphmax do
- if tg[i] and tg[i].name then unicodes[tg[i].name] = ind_to_uni[i] end
- end
- end
- end
- for _,v in pairs(fl.subfonts) do
- dest = add_fl_table(dest, v, unicodes,
- fl.ascent + fl.descent, fl.units_per_em, id)
- end
+ local t = {}
+ for i,v in pairs(id.shared.rawdata.descriptions) do
+ t[v.index] = i
end
- if dest then dest.unicodes = unicodes end
- fontloader.close(fl); collectgarbage("collect")
+ dest = dest or {}; dest.ind_to_uni = t
return dest
end
- -- supply vkern table
- supply_vkern_table = function(id, bname)
- local bx = font_extra_basename[bname].vkerns
- local lookuphash = id.resources.lookuphash
- local desc = id.shared.rawdata.descriptions
- if bx and lookuphash then
- for i,v in pairs(bx) do
- lookuphash[i] = lookuphash[i] or v
- for j,w in pairs(v) do
- desc[j].kerns = desc[j].kerns or {}
- desc[j].kerns[i] = w
- end
- end
- end
- end
end
--
do
- local cache_ver = 17
+ local cache_ver = 18
local function prepare_extra_data_base(id)
if (not id) or (not id.filename) then return end
-- these function is executed one time per one fontfile
if jfm_file_name then
local bname = prepare_extra_data_base(tfmdata)
- if bname then supply_vkern_table(tfmdata, bname) end
end
return tfmdata
end,
local identifiers = fonts.hashes.identifiers
local ltjf_font_metric_table = ltjf.font_metric_table
+local ltjf_font_extra_info = ltjf.font_extra_info
local ltjf_find_char_class = ltjf.find_char_class
local ltjr_cidfont_data = ltjr.cidfont_data
local ltjc_is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char
local function get_ucs_from_rmlgbm(c)
- local v = (ivd_aj1 and ivd_aj1.table_ivd_aj1[c])
- if v==true then
- for i,w in pairs(ltjr_cidfont_data["Adobe-Japan1"].descriptions) do
- if w.index==v then v = i; break end
- end
- end
- v = v or 0
+ local v = (ivd_aj1 and ivd_aj1.table_ivd_aj1[c]
+ or ltjr_cidfont_data["Adobe-Japan1"].resources.unicodes["Japan1." .. tostring(c)])
+ or 0
if v>=0x200000 then -- table
local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
and attr_curtfnt or attr_curjfnt)
-- ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)')
return append_jglyph(get_ucs_from_rmlgbm(key))
else
- local char = ltjf_font_metric_table[curjfnt_num].cid_to_uni[key]
+ local char = ltjf_font_extra_info[curjfnt_num].ind_to_uni[key]
if not char then
- ltjb.package_warning('luatexja-otf',
- '"' ..curjfnt.psname..'" does not have CID character '
- ..tostring(key),
- 'Use a font including the specified CID character.')
+-- ltjb.package_warning('luatexja-otf',
+-- '"' ..curjfnt.psname..'" does not have CID character '
+-- ..tostring(key),
+-- 'Use a font including the specified CID character.')
char = 0
end
return append_jglyph(char)
-- additional callbacks
-- 以下は,LuaTeX-ja に用意された callback のサンプルになっている.
-- JFM の文字クラスの指定の所で,"AJ1-xxx" 形式での指定を可能とした.
--- これらの文字指定は,和文フォント定義ごとに,それぞれのフォントの
--- CID <-> グリフ 対応状況による変換テーブルが用意される.
--- 和文フォント読み込み時に,CID -> unicode 対応をとっておく.
-local function cid_to_uni(fmtable, fn)
+-- 和文フォント読み込み時に,ind -> unicode 対応をとっておく.
+local function ind_to_uni(fmtable, fn)
local fi = identifiers[fn]
- local t = {}; fmtable.cid_to_uni = t
- for i,v in pairs(fi.shared.rawdata.descriptions) do t[v.index] = i end
- if fi.resources and fi.resources.cidinfo
+ local t = ltjf_font_extra_info[fn].ind_to_uni
+ if t and fi.resources and fi.resources.cidinfo
and fi.resources.cidinfo.ordering == "Japan1" then
for i, v in pairs(fmtable.chars) do
local j = string.match(i, "^AJ1%-([0-9]*)")
return fmtable
end
luatexbase.add_to_callback("luatexja.define_jfont",
- cid_to_uni, "ltj.otf.define_jfont", 1)
+ ind_to_uni, "ltj.otf.define_jfont", 1)
-- 既に読み込まれているフォントに対しても,同じことをやらないといけない
for fn, v in pairs(ltjf_font_metric_table) do
- ltjf_font_metric_table[fn] = cid_to_uni(v, fn)
+ ltjf_font_metric_table[fn] = ind_to_uni(v, fn)
end
do
local pf = getfont(p)
local pc = getchar(p)
- local cei = ltjf_font_extra_info[pf] and ltjf_font_extra_info[pf][pc]
- if cei and met.vert_activated then
- if cei.rotation then
+ local feir = ltjf_font_extra_info[pf]
+ if feir and feir.rotation and met.vert_activated then
+ if feir.rotation[pc] then
return capsule_glyph_tate_rot(p, met, char_data, head, dir, 0.5*(ascent-descent))
end
end
local ident = fonts.hashes.identifiers[pf]
pwidth = (ident.descriptions and ident.descriptions[pc]
- and (ident.descriptions[pc].vheight / ident.units * met.size))
+ and ident.descriptions[pc].vheight
+ and ident.descriptions[pc].vheight / ident.units * met.size)
or (ascent+descent)
pwidth = pwidth + (met.v_advance[pc] or 0)
ascent = met.v_origin[pc] and ascent - met.v_origin[pc] or ascent
end
- print(fwidth, pwidth)
fwidth = fwidth or pwidth
fshift.down = char_data.down; fshift.left = char_data.left
fshift = call_callback("luatexja.set_width", fshift, met, char_data)