X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-otf.lua;h=faef663d239eeba93273a649c3ead3e08bdb47b7;hb=cf51a2259a27eeed9a3d5d0c40c767a5e6bc403e;hp=461957000ee3b86c84fbcf9dd061ad745371a800;hpb=820a1ed4d6946ca55f412e77f6a1e63cb30ab229;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-otf.lua b/src/ltj-otf.lua index 4619570..faef663 100644 --- a/src/ltj-otf.lua +++ b/src/ltj-otf.lua @@ -3,14 +3,13 @@ -- luatexbase.provides_module({ name = 'luatexja.otf', - date = '2011/09/09', - version = '0.1', + date = '2013/05/11', description = 'The OTF Lua module for LuaTeX-ja', }) -module('luatexja.otf', package.seeall) luatexja.load_module('base'); local ltjb = luatexja.base luatexja.load_module('jfont'); local ltjf = luatexja.jfont +luatexja.load_module('rmlgbm'); local ltjr = luatexja.rmlgbm local id_glyph = node.id('glyph') local id_whatsit = node.id('whatsit') @@ -32,50 +31,77 @@ local attr_ykblshift = luatexbase.attributes['ltj@ykblshift'] local ltjf_font_metric_table = ltjf.font_metric_table local ltjf_find_char_class = ltjf.find_char_class - +local ltjr_cidfont_data = ltjr.cidfont_data + +local OTF = luatexja.userid_table.OTF + +local function get_ucs_from_rmlgbm(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 にマップ可能 + return v + else + local w = ltjr_cidfont_data["Adobe-Japan1"].characters[v]. tounicode + -- must be non-nil! + local i = string.len(w) + if i==4 then -- UCS2 + return tonumber(w,16) + elseif i==8 then + i,w = tonumber(string.sub(w,1,4),16), tonumber(string.sub(w,-4),16) + if (w>=0xD800) and (w<=0xDB7F) and (i>=0xDC00) and (i<=0xDFFF) then -- Surrogate pair + return (w-0xD800)*0x400 + (i-0xDC00) + else + return 0 + end + end + end +end -- Append a whatsit node to the list. -- This whatsit node will be extracted to a glyph_node -function append_jglyph(char) +local function append_jglyph(char) local p = node_new(id_whatsit,sid_user) local v = tex.attribute[attr_curjfnt] - p.user_id=30113; p.type=100; p.value=char + p.user_id=OTF; p.type=100; p.value=char set_attr(p, attr_yablshift, tex.attribute[attr_ykblshift]) node.write(p) end -function cid(key) +local function cid(key) + if key==0 then return append_jglyph(char) end local curjfnt = fonts.ids[tex.attribute[attr_curjfnt]] - if curjfnt.cidinfo.ordering ~= "Japan1" and - curjfnt.cidinfo.ordering ~= "GB1" and - curjfnt.cidinfo.ordering ~= "CNS1" and - curjfnt.cidinfo.ordering ~= "Korea1" then - ltjb.package_error('luatexja-otf', - 'Current Japanese font (or other CJK font) "'..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)', - 'Select a CID-Keyed font using \jfont.') - return + 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.)') + return append_jglyph(get_ucs_from_rmlgbm(key)) end - local char = curjfnt.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)] + local char = curjfnt.resources.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)] if not char then ltjb.package_warning('luatexja-otf', - 'Current Japanese font (or other CJK font) "'..curjfnt.psname..'" does not include the specified CID character ('..tostring(key)..')', - 'Use a font including the specified CID character.') - return + 'Current Japanese font (or other CJK font) "' + ..curjfnt.psname..'" does not have the specified CID character (' + ..tostring(key)..')', + 'Use a font including the specified CID character.') + char = 0 end - append_jglyph(char) + return append_jglyph(char) end -function extract(head) +local function extract(head) local p = head local v while p do if p.id==id_whatsit then - if p.subtype==sid_user and p.user_id==30113 then + if p.subtype==sid_user and p.user_id==OTF then local g = node_new(id_glyph) g.subtype = 0; g.char = p.value v = has_attr(p, attr_curjfnt); g.font = v - set_attr(g, attr_jchar_class, - ltjf_find_char_class(g.char, ltjf_font_metric_table[v])) set_attr(g, attr_curjfnt, v) v = has_attr(p, attr_yablshift) if v then @@ -114,10 +140,10 @@ local function cid_to_char(fmtable, fn) local fi = fonts.ids[fn] if fi.cidinfo and fi.cidinfo.ordering == "Japan1" then fmtable.cid_char_type = {} - for i, v in pairs(fmtable.size_cache.chars) do + for i, v in pairs(fmtable.chars) do local j = string.match(i, "^AJ1%-([0-9]*)") if j then - j = tonumber(fi.unicodes['Japan1.'..tostring(j)]) + j = tonumber(fi.resources.unicodes['Japan1.'..tostring(j)]) if j then fmtable.cid_char_type[j] = v end @@ -145,4 +171,9 @@ luatexbase.add_to_callback("luatexja.find_char_class", cid_set_char_class, "ltj.otf.find_char_class", 1) -------------------- all done +luatexja.otf = { + append_jglyph = append_jglyph, + cid = cid, +} + -- EOF