X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-rmlgbm.lua;h=5ee567b5b872b5c6bd1c068415950c298c7074e2;hb=c35bc9236b8c249d3089a824fe197d0d1cde7e78;hp=37b07a310ed35c9d4dbfdc78c548ea65ba1205a8;hpb=2388b858f1f2cb1c58cb2fcd79b165fb7f513183;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-rmlgbm.lua b/src/ltj-rmlgbm.lua index 37b07a3..5ee567b 100644 --- a/src/ltj-rmlgbm.lua +++ b/src/ltj-rmlgbm.lua @@ -3,27 +3,24 @@ -- luatexbase.provides_module({ name = 'luatexja.rmlgbm', - date = '2012/02/17', - version = '0.2', - description = 'Definitions of non-embedded Japanese fonts', + date = '2012/04/21', + version = '0.3', + description = 'Definitions of non-embedded Japanese (or other CJK) fonts', }) module('luatexja.rmlgbm', package.seeall) local err, warn, info, log = luatexbase.errwarinf(_NAME) -require('luatexja.base'); local ltjb = luatexja.base +luatexja.load_module('base'); local ltjb = luatexja.base -local round = tex.round local cidfont_data = {} local cache_chars = {} -local cid_reg, cid_order, cid_supp, cid_name -local taux_dir = 'luatex-cache/luatexja' local path = { localdir = file.join(kpse.expand_var("$TEXMFVAR"), aux_dir), systemdir = file.join(kpse.expand_var("$TEXMFSYSVAR"), aux_dir), } -- -local function read_cid_font() +local function read_cid_font(cid_name) local v = "ltj-cid-" .. string.lower(cid_name) .. ".lua" local localpath = file.join(path.localdir, v) local systempath = file.join(path.systemdir, v) @@ -31,21 +28,23 @@ local function read_cid_font() if kpsefound and file.isreadable(kpsefound) then cidfont_data[cid_name] = require(kpsefound) cache_chars[cid_name] = { [655360] = cidfont_data[cid_name].characters } - return elseif file.isreadable(localpath) then cidfont_data[cid_name] = require(localpath) cache_chars[cid_name] = { [655360] = cidfont_data[cid_name].characters } - return elseif file.isreadable(systempath) then cidfont_data[cid_name] = require(systempath) cache_chars[cid_name] = { [655360] = cidfont_data[cid_name].characters } - return end - -- + if cidfont_data[cid_name] then + for i,v in pairs(cidfont_data[cid_name].characters) do + if not v.width then v.width = 655360 end + v.height, v.depth = 576716.8, 78643.2 -- optimized for jfm-ujis.lua + end + end end -- High-level -local function mk_rml(name, size, id) +local function mk_rml(name, size, id, cid_name) local specification = fonts.define.analyze(name,size) specification = fonts.define.specify[':'](specification) local features = specification.features.normal @@ -53,10 +52,6 @@ local function mk_rml(name, size, id) local fontdata = {} local cachedata = {} local s = cidfont_data[cid_name] - if not s then - -- error message? - s = cidfont_data["Adobe-Japan1"] - end for k, v in pairs(s) do fontdata[k] = v cachedata[k] = v @@ -80,13 +75,13 @@ 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 = round(0.88 * size) -- character's default height (optimized for jfm-ujis.lua) - local def_depth = round(0.12 * size) -- and depth. + 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 = round(v.width * scale), + index = v.index, width = v.width * scale, height = def_height, depth = def_depth, tounicode = v.tounicode, } end @@ -128,6 +123,7 @@ local dr_orig = fonts.define.read function fonts.define.read(name, size, id) local p = utf.find(name, ":") or utf.len(name)+1 if utf.sub(name, 1, p-1) == 'psft' then + local cid_reg, cid_order, cid_name local s = "Adobe-Japan1-6" local basename = utf.sub(name,p+1) local p = utf.find(basename, ":") @@ -142,12 +138,27 @@ function fonts.define.read(name, size, id) if utf.len(xname)+1==q then p = nil else p = q + 1 end end end - cid_reg, cid_order, cid_supp = string.match(s, "(.-)%-(.-)%-(%d-)") + cid_reg, cid_order = string.match(s, "^(.-)%-(.-)%-(%d-)$") + if not cid_reg then + cid_reg, cid_order = string.match(s, "^(.-)%-(.-)$") + end cid_name = cid_reg .. '-' .. cid_order - if not cidfont_data[cid_name] then read_cid_font() end - return mk_rml(basename, size, id) + if not cidfont_data[cid_name] then + read_cid_font(cid_name) + if not cidfont_data[cid_name] then + ltjb.package_error('luatexja', + "bad cid key `" .. s .. "'", + "I couldn't find any non-embedded font information for the CID\n" .. + '`' .. s .. "'. For now, I'll use `Adobe-Japan1-6'.\n".. + 'Please contact the LuaTeX-ja project team.') + cid_name = "Adobe-Japan1" + end + end + return mk_rml(basename, size, id, cid_name) else return dr_orig(name, size, id) end end + +read_cid_font("Adobe-Japan1") \ No newline at end of file