diff options
author | Marius <mariausol@gmail.com> | 2011-02-08 18:20:12 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2011-02-08 18:20:12 +0200 |
commit | ba57766270809c52c95122555a32b30ccbb5eba1 (patch) | |
tree | e438922ed248b36e4884c6c1c36165d228aec7c0 /tex/generic | |
parent | 9c6992a3436a0db6a01790b29d7c0c3c65460f94 (diff) | |
download | context-ba57766270809c52c95122555a32b30ccbb5eba1.tar.gz |
beta 2011.02.08 17:08
Diffstat (limited to 'tex/generic')
-rw-r--r-- | tex/generic/context/luatex-fonts-demo-vf-1.lua | 36 | ||||
-rw-r--r-- | tex/generic/context/luatex-fonts-merged.lua | 356 | ||||
-rw-r--r-- | tex/generic/context/luatex-fonts.lua | 3 | ||||
-rw-r--r-- | tex/generic/context/luatex-test.tex | 4 |
4 files changed, 222 insertions, 177 deletions
diff --git a/tex/generic/context/luatex-fonts-demo-vf-1.lua b/tex/generic/context/luatex-fonts-demo-vf-1.lua new file mode 100644 index 000000000..31ac4b87b --- /dev/null +++ b/tex/generic/context/luatex-fonts-demo-vf-1.lua @@ -0,0 +1,36 @@ +return function(specification) + local f1, id1 = fonts.tfm.readanddefine('lmroman10-regular', specification.size) + local f2, id2 = fonts.tfm.readanddefine('lmsans10-regular', specification.size) + local f3, id3 = fonts.tfm.readanddefine('lmtypewriter10-regular',specification.size) + if f1 and f2 and f3 then + f1.name = specification.name + f1.virtualized = true + f1.fonts = { + { id = id1 }, + { id = id2 }, + { id = id3 }, + } + local color = { [0] = + { "special", "pdf:0 g" }, + { "special", "pdf:1 0 0 rg" }, + { "special", "pdf:0 1 0 rg" }, + { "special", "pdf:0 0 1 rg" }, + } + local chars = { + fonts.identifiers[id1].characters, + fonts.identifiers[id2].characters, + fonts.identifiers[id3].characters, + } + for u, v in next, f1.characters do + local n = math.floor(math.random(1,3)+0.5) + local c = chars[n][u] or v + v.commands = { color[n], { 'slot', n, u }, color[0] } + v.kerns = nil + v.width = c.width + v.height = c.height + v.depth = c.depth + v.italic = nil + end + end + return f1 +end diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 4312d66ab..b9a85a292 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 02/08/11 10:06:31 +-- merge date : 02/08/11 17:08:08 do -- begin closure to overcome local limits and interference @@ -2399,7 +2399,6 @@ storage = { -- probably no longer needed logs = { new = function() return dummyfunction end, report = dummyfunction, - simple = dummyfunction, } callbacks = { register = function(n,f) return callback.register(n,f) end, @@ -2432,8 +2431,12 @@ local remapper = { function resolvers.findfile(name,kind) name = string.gsub(name,"\\","\/") - kind = string.lower(kind) - return kpse.find_file(name,(kind and kind ~= "" and (remapper[kind] or kind)) or file.extname(name,"tex")) + kind = kind and string.lower(kind) + local found = kpse.find_file(name,(kind and kind ~= "" and (remapper[kind] or kind)) or file.extname(name,"tex")) + if not found or found == "" then + found = kpse.find_file(name,"other text file") + end + return found end function resolvers.findbinfile(name,kind) @@ -3418,6 +3421,10 @@ function fonts.fontformat(filename,default) end end +-- readers + +fonts.tfm.readers = fonts.tfm.readers or { } + end -- closure do -- begin closure to overcome local limits and interference @@ -3461,7 +3468,9 @@ fonts.initializers = fonts.initializers or { } fonts.initializers.common = fonts.initializers.common or { } local set_attribute = node.set_attribute +local findbinfile = resolvers.findbinfile +local readers = fonts.tfm.readers local fontdata = fonts.identifiers local nodecodes = nodes.nodecodes @@ -3480,9 +3489,7 @@ tfm.fontnamemode = "fullpath" tfm.enhance = tfm.enhance or function() end -fonts.formats.tfm = "type1" -- we need to have at least a value here - -function tfm.read_from_tfm(specification) +local function read_from_tfm(specification) local fname, tfmdata = specification.filename or "", nil if fname ~= "" then if trace_defining then @@ -3493,7 +3500,7 @@ function tfm.read_from_tfm(specification) tfmdata.descriptions = tfmdata.descriptions or { } if tfm.resolvevirtualtoo then fonts.logger.save(tfmdata,file.extname(fname),specification) -- strange, why here - fname = resolvers.findbinfile(specification.name, 'ovf') + fname = findbinfile(specification.name, 'ovf') if fname and fname ~= "" then local vfdata = font.read_vf(fname,specification.size) -- not cached, fast enough if vfdata then @@ -4169,10 +4176,10 @@ function tfm.checkedfilename(metadata,whatever) local askedfilename = metadata.filename or "" if askedfilename ~= "" then askedfilename = resolvers.resolve(askedfilename) -- no shortcut - foundfilename = resolvers.findbinfile(askedfilename,"") or "" + foundfilename = findbinfile(askedfilename,"") or "" if foundfilename == "" then report_defining("source file '%s' is not found",askedfilename) - foundfilename = resolvers.findbinfile(file.basename(askedfilename),"") or "" + foundfilename = findbinfile(file.basename(askedfilename),"") or "" if foundfilename ~= "" then report_defining("using source file '%s' (cache mismatch)",foundfilename) end @@ -4193,6 +4200,44 @@ statistics.register("fonts load time", function() return statistics.elapsedseconds(fonts) end) +-- readers + +fonts.formats.tfm = "type1" -- we need to have at least a value here + +local function check_tfm(specification,fullname) + -- ofm directive blocks local path search unless set; btw, in context we + -- don't support ofm files anyway as this format is obsolete + local foundname = findbinfile(fullname, 'tfm') or "" -- just to be sure + if foundname == "" then + foundname = findbinfile(fullname, 'ofm') or "" -- bonus for usage outside context + end + if foundname == "" then + foundname = fonts.names.getfilename(fullname,"tfm") + end + if foundname ~= "" then + specification.filename, specification.format = foundname, "ofm" + return read_from_tfm(specification) + end +end + +readers.check_tfm = check_tfm + +function readers.tfm(specification) + local fullname, tfmtable = specification.filename or "", nil + if fullname == "" then + local forced = specification.forced or "" + if forced ~= "" then + tfmtable = check_tfm(specification,specification.name .. "." .. forced) + end + if not tfmtable then + tfmtable = check_tfm(specification,specification.name) + end + else + tfmtable = check_tfm(specification,fullname) + end + return tfmtable +end + end -- closure do -- begin closure to overcome local limits and interference @@ -5596,6 +5641,56 @@ end -- closure do -- begin closure to overcome local limits and interference +if not modules then modules = { } end modules ['font-lua'] = { + version = 1.001, + comment = "companion to font-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end) + +local report_lua = logs.new("fonts","lua loading") + +fonts.formats.lua = "lua" + +local readers = fonts.tfm.readers + +local function check_lua(specification,fullname) + -- standard tex file lookup + local fullname = resolvers.findfile(fullname) or "" + if fullname ~= "" then + local loader = loadfile(fullname) + loader = loader and loader() + return loader and loader(specification) + end +end + +function readers.lua(specification) + local original = specification.specification + if trace_defining then + report_lua("using lua reader for '%s'",original) + end + local fullname, tfmtable = specification.filename or "", nil + if fullname == "" then + local forced = specification.forced or "" + if forced ~= "" then + tfmtable = check_lua(specification,specification.name .. "." .. forced) + end + if not tfmtable then + tfmtable = check_lua(specification,specification.name) + end + else + tfmtable = check_lua(specification,fullname) + end + return tfmtable +end + +end -- closure + +do -- begin closure to overcome local limits and interference + if not modules then modules = { } end modules ['font-otf'] = { version = 1.001, comment = "companion to font-ini.mkiv", @@ -5634,6 +5729,8 @@ local report_otf = logs.new("fonts","otf loading") local starttiming, stoptiming, elapsedtime = statistics.starttiming, statistics.stoptiming, statistics.elapsedtime +local findbinfile = resolvers.findbinfile + local fonts = fonts fonts.otf = fonts.otf or { } @@ -5653,6 +5750,7 @@ enhancers.patches = { } local patches = enhancers.patches local definers = fonts.definers +local readers = fonts.tfm.readers otf.glists = { "gsub", "gpos" } @@ -7209,11 +7307,6 @@ end -- we cannot share descriptions as virtual fonts might extend them (ok, we could -- use a cache with a hash -fonts.formats.dfont = "truetype" -fonts.formats.ttc = "truetype" -fonts.formats.ttf = "truetype" -fonts.formats.otf = "opentype" - local function copytotfm(data,cache_id) -- we can save a copy when we reorder the tma to unicode (nasty due to one->many) if data then local glyphs, pfminfo, metadata = data.glyphs or { }, data.pfminfo or { }, data.metadata or { } @@ -7429,7 +7522,7 @@ end otf.features.register('mathsize') -function tfm.read_from_otf(specification) -- wrong namespace +local function read_from_otf(specification) -- wrong namespace local tfmtable = otftotfm(specification) if tfmtable then local otfdata = tfmtable.shared.otfdata @@ -7516,6 +7609,59 @@ function otf.collectlookups(otfdata,kind,script,language) return nil, nil end +-- readers + +fonts.formats.dfont = "truetype" +fonts.formats.ttc = "truetype" +fonts.formats.ttf = "truetype" +fonts.formats.otf = "opentype" + +local function check_otf(forced,specification,suffix,what) + local name = specification.name + if forced then + name = file.addsuffix(name,suffix,true) + end + local fullname, tfmtable = findbinfile(name,suffix) or "", nil -- one shot + -- if false then -- can be enabled again when needed + -- if fullname == "" then + -- local fb = fonts.names.old_to_new[name] + -- if fb then + -- fullname = findbinfile(fb,suffix) or "" + -- end + -- end + -- if fullname == "" then + -- local fb = fonts.names.new_to_old[name] + -- if fb then + -- fullname = findbinfile(fb,suffix) or "" + -- end + -- end + -- end + if fullname == "" then + fullname = fonts.names.getfilename(name,suffix) + end + if fullname ~= "" then + specification.filename, specification.format = fullname, what -- hm, so we do set the filename, then + tfmtable = read_from_otf(specification) -- we need to do it for all matches / todo + end + return tfmtable +end + +function readers.opentype(specification,suffix,what) + local forced = specification.forced or "" + if forced == "otf" then + return check_otf(true,specification,forced,"opentype") + elseif forced == "ttf" or forced == "ttc" or forced == "dfont" then + return check_otf(true,specification,forced,"truetype") + else + return check_otf(false,specification,suffix,what) + end +end + +function readers.otf (specification) return readers.opentype(specification,"otf","opentype") end +function readers.ttf (specification) return readers.opentype(specification,"ttf","truetype") end +function readers.ttc (specification) return readers.opentype(specification,"ttf","truetype") end -- !! +function readers.dfont(specification) return readers.opentype(specification,"ttf","truetype") end -- !! + end -- closure do -- begin closure to overcome local limits and interference @@ -15303,7 +15449,6 @@ trackers.register("fonts.loading", "fonts.defining", "otf.loading", "afm.loading trackers.register("fonts.all", "fonts.*", "otf.*", "afm.*", "tfm.*") local report_defining = logs.new("fonts","defining") -local report_afm = logs.new("fonts","afm loading") --[[ldx-- <p>Here we deal with defining fonts. We do so by intercepting the @@ -15320,7 +15465,7 @@ tfm.readers = tfm.readers or { } tfm.fonts = allocate() local readers = tfm.readers -local sequence = allocate { 'otf', 'ttf', 'afm', 'tfm' } +local sequence = allocate { 'otf', 'ttf', 'afm', 'tfm', 'lua' } readers.sequence = sequence tfm.version = 1.01 @@ -15476,10 +15621,10 @@ function tfm.hashfeatures(specification) t[tn] = v .. '=' .. tostring(vtf[v]) end end - --~ if specification.mathsize then - --~ tn = tn + 1 - --~ t[tn] = "mathsize=" .. specification.mathsize - --~ end + -- if specification.mathsize then + -- tn = tn + 1 + -- t[tn] = "mathsize=" .. specification.mathsize + -- end if tn > 0 then return concat(t,"+") end @@ -15507,21 +15652,21 @@ function tfm.hashinstance(specification,force) size = math.round(tfm.scaled(size,fonts.designsizes[hash])) specification.size = size end ---~ local mathsize = specification.mathsize or 0 ---~ if mathsize > 0 then ---~ local textsize = specification.textsize ---~ if fallbacks then ---~ return hash .. ' @ ' .. tostring(size) .. ' [ ' .. tostring(mathsize) .. ' : ' .. tostring(textsize) .. ' ] @ ' .. fallbacks ---~ else ---~ return hash .. ' @ ' .. tostring(size) .. ' [ ' .. tostring(mathsize) .. ' : ' .. tostring(textsize) .. ' ]' ---~ end ---~ else + -- local mathsize = specification.mathsize or 0 + -- if mathsize > 0 then + -- local textsize = specification.textsize + -- if fallbacks then + -- return hash .. ' @ ' .. tostring(size) .. ' [ ' .. tostring(mathsize) .. ' : ' .. tostring(textsize) .. ' ] @ ' .. fallbacks + -- else + -- return hash .. ' @ ' .. tostring(size) .. ' [ ' .. tostring(mathsize) .. ' : ' .. tostring(textsize) .. ' ]' + -- end + -- else if fallbacks then return hash .. ' @ ' .. tostring(size) .. ' @ ' .. fallbacks else return hash .. ' @ ' .. tostring(size) end ---~ end + -- end end --[[ldx-- @@ -15691,149 +15836,6 @@ function tfm.readanddefine(name,size) -- no id end --[[ldx-- -<p>Next follow the readers. This code was written while <l n='luatex'/> -evolved. Each one has its own way of dealing with its format.</p> ---ldx]]-- - -local function check_tfm(specification,fullname) - -- ofm directive blocks local path search unless set; btw, in context we - -- don't support ofm files anyway as this format is obsolete - local foundname = findbinfile(fullname, 'tfm') or "" -- just to be sure - if foundname == "" then - foundname = findbinfile(fullname, 'ofm') or "" -- bonus for usage outside context - end - if foundname == "" then - foundname = fonts.names.getfilename(fullname,"tfm") - end - if foundname ~= "" then - specification.filename, specification.format = foundname, "ofm" - return tfm.read_from_tfm(specification) - end -end - -local function check_afm(specification,fullname) - local foundname = findbinfile(fullname, 'afm') or "" -- just to be sure - if foundname == "" then - foundname = fonts.names.getfilename(fullname,"afm") - end - if foundname == "" and tfm.autoprefixedafm then - local encoding, shortname = match(fullname,"^(.-)%-(.*)$") -- context: encoding-name.* - if encoding and shortname and fonts.enc.known[encoding] then - shortname = findbinfile(shortname,'afm') or "" -- just to be sure - if shortname ~= "" then - foundname = shortname - if trace_loading then - report_afm("stripping encoding prefix from filename %s",afmname) - end - end - end - end - if foundname ~= "" then - specification.filename, specification.format = foundname, "afm" - return tfm.read_from_afm(specification) - end -end - -function readers.tfm(specification) - local fullname, tfmtable = specification.filename or "", nil - if fullname == "" then - local forced = specification.forced or "" - if forced ~= "" then - tfmtable = check_tfm(specification,specification.name .. "." .. forced) - end - if not tfmtable then - tfmtable = check_tfm(specification,specification.name) - end - else - tfmtable = check_tfm(specification,fullname) - end - return tfmtable -end - -function readers.afm(specification,method) - local fullname, tfmtable = specification.filename or "", nil - if fullname == "" then - local forced = specification.forced or "" - if forced ~= "" then - tfmtable = check_afm(specification,specification.name .. "." .. forced) - end - if not tfmtable then - method = method or definers.method or "afm or tfm" - if method == "tfm" then - tfmtable = check_tfm(specification,specification.name) - elseif method == "afm" then - tfmtable = check_afm(specification,specification.name) - elseif method == "tfm or afm" then - tfmtable = check_tfm(specification,specification.name) or check_afm(specification,specification.name) - else -- method == "afm or tfm" or method == "" then - tfmtable = check_afm(specification,specification.name) or check_tfm(specification,specification.name) - end - end - else - tfmtable = check_afm(specification,fullname) - end - return tfmtable -end - -function readers.pfb(specification,method) -- only called when forced - local original = specification.specification - if trace_loading then - report_afm("using afm reader for '%s'",original) - end - specification.specification = gsub(original,"%.pfb",".afm") - specification.forced = "afm" - return readers.afm(specification,method) -end - --- maybe some day a set of names - -local function check_otf(forced,specification,suffix,what) - local name = specification.name - if forced then - name = file.addsuffix(name,suffix,true) - end - local fullname, tfmtable = findbinfile(name,suffix) or "", nil -- one shot - -- if false then -- can be enabled again when needed - -- if fullname == "" then - -- local fb = fonts.names.old_to_new[name] - -- if fb then - -- fullname = findbinfile(fb,suffix) or "" - -- end - -- end - -- if fullname == "" then - -- local fb = fonts.names.new_to_old[name] - -- if fb then - -- fullname = findbinfile(fb,suffix) or "" - -- end - -- end - -- end - if fullname == "" then - fullname = fonts.names.getfilename(name,suffix) - end - if fullname ~= "" then - specification.filename, specification.format = fullname, what -- hm, so we do set the filename, then - tfmtable = tfm.read_from_otf(specification) -- we need to do it for all matches / todo - end - return tfmtable -end - -function readers.opentype(specification,suffix,what) - local forced = specification.forced or "" - if forced == "otf" then - return check_otf(true,specification,forced,"opentype") - elseif forced == "ttf" or forced == "ttc" or forced == "dfont" then - return check_otf(true,specification,forced,"truetype") - else - return check_otf(false,specification,suffix,what) - end -end - -function readers.otf (specification) return readers.opentype(specification,"otf","opentype") end -function readers.ttf (specification) return readers.opentype(specification,"ttf","truetype") end -function readers.ttc (specification) return readers.opentype(specification,"ttf","truetype") end -- !! -function readers.dfont(specification) return readers.opentype(specification,"ttf","truetype") end -- !! - ---[[ldx-- <p>We need to check for default features. For this we provide a helper function.</p> --ldx]]-- @@ -16112,13 +16114,13 @@ fonts = fonts or { } -- general fonts.otf.pack = false -- only makes sense in context -fonts.tfm.resolvevirtualtoo = false -- context specific (du eto resolver) +fonts.tfm.resolvevirtualtoo = false -- context specific (due to resolver) fonts.tfm.fontnamemode = "specification" -- somehow latex needs this (changed name!) -- readers fonts.tfm.readers = fonts.tfm.readers or { } -fonts.tfm.readers.sequence = { 'otf', 'ttf', 'tfm' } +fonts.tfm.readers.sequence = { 'otf', 'ttf', 'tfm', 'lua' } fonts.tfm.readers.afm = nil -- define diff --git a/tex/generic/context/luatex-fonts.lua b/tex/generic/context/luatex-fonts.lua index 5fffecb47..cff1800e7 100644 --- a/tex/generic/context/luatex-fonts.lua +++ b/tex/generic/context/luatex-fonts.lua @@ -112,6 +112,7 @@ else loadmodule('font-cid.lua') loadmodule('font-ott.lua') -- might be split loadmodule('font-map.lua') -- for loading lum file (will be stripped) + loadmodule('font-lua.lua') loadmodule('font-otf.lua') loadmodule('font-otd.lua') loadmodule('font-oti.lua') @@ -126,6 +127,8 @@ else end +resolvers.loadmodule = loadmodule + -- In order to deal with the fonts we need to initialize some -- callbacks. One can overload them later on if needed. diff --git a/tex/generic/context/luatex-test.tex b/tex/generic/context/luatex-test.tex index 594039053..9f57cfea9 100644 --- a/tex/generic/context/luatex-test.tex +++ b/tex/generic/context/luatex-test.tex @@ -48,4 +48,8 @@ endfig ; \endmplibcode +\font\mine=file:luatex-fonts-demo-vf-1.lua at 12pt + +\mine \input tufte \par + \end |