From 7b6c6ddcc6dd3d71cc41454b5485982e66070a16 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Fri, 26 Sep 2014 12:15:03 +0200 Subject: 2014-09-26 11:44:00 --- tex/context/base/char-ini.mkiv | 1 + tex/context/base/cont-new.mkiv | 2 +- tex/context/base/context-version.pdf | Bin 4390 -> 4386 bytes tex/context/base/context.mkiv | 2 +- tex/context/base/font-ctx.lua | 118 ++++++++++++++++++--- tex/context/base/font-ini.mkvi | 17 +++ tex/context/base/font-mis.lua | 2 +- tex/context/base/font-otf.lua | 61 +++++++++-- tex/context/base/lxml-ini.mkiv | 1 - tex/context/base/status-files.pdf | Bin 24752 -> 24748 bytes tex/context/base/status-lua.pdf | Bin 325239 -> 325287 bytes tex/generic/context/luatex/luatex-fonts-merged.lua | 56 ++++++++-- 12 files changed, 227 insertions(+), 33 deletions(-) diff --git a/tex/context/base/char-ini.mkiv b/tex/context/base/char-ini.mkiv index 4fb63d93e..e130e200f 100644 --- a/tex/context/base/char-ini.mkiv +++ b/tex/context/base/char-ini.mkiv @@ -16,6 +16,7 @@ \registerctxluafile{char-fio}{1.001} \registerctxluafile{char-map}{1.001} % maybe we will load this someplace else \registerctxluafile{char-tex}{1.001} +\registerctxluafile{char-ent}{1.001} \unprotect diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index a9ae0d52a..58f53214e 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2014.09.25 18:58} +\newcontextversion{2014.09.26 11:42} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf index 3cdfd0e80..71b88d27b 100644 Binary files a/tex/context/base/context-version.pdf and b/tex/context/base/context-version.pdf differ diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 617c2423f..509472134 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -28,7 +28,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2014.09.25 18:58} +\edef\contextversion{2014.09.26 11:42} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index e366f746d..5920501dd 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -1467,9 +1467,109 @@ local function indextoslot(index) end end +do -- else too many locals -helpers.nametoslot = nametoslot -helpers.indextoslot = indextoslot + local entities = characters.entities + local lowered = { } -- delayed initialization + + table.setmetatableindex(lowered,function(t,k) + for k, v in next, entities do + local l = lower(k) + if not entities[l] then + lowered[l] = v + end + end + table.setmetatableindex(lowered,nil) + return lowered[k] + end) + + local methods = { + -- entity + e = function(name) + return entities[name] or lowered[name] or name + end, + -- hexadecimal unicode + x = function(name) + local n = tonumber(name,16) + return n and utfchar(n) or name + end, + -- decimal unicode + d = function(name) + local n = tonumber(name) + return n and utfchar(n) or name + end, + -- hexadecimal index (slot) + s = function(name) + local n = tonumber(name,16) + local n = n and indextoslot(n) + return n and utfchar(n) or name + end, + -- decimal index + i = function(name) + local n = tonumber(name) + local n = n and indextoslot(n) + return n and utfchar(n) or name + end, + -- name + n = function(name) + local n = nametoslot(name) + return n and utfchar(n) or name + end, + -- char + c = function(name) + return name + end, + } + + -- -- nicer: + -- + -- table.setmetatableindex(methods,function(t,k) return methods.c end) + -- + -- local splitter = (C(1) * P(":") + Cc("c")) * C(P(1)^1) / function(method,name) + -- return methods[method](name) + -- end + -- + -- -- more efficient: + + local splitter = C(1) * P(":") * C(P(1)^1) / function(method,name) + local action = methods[method] + return action and action(name) or name + end + + local function tochar(str) + local t = type(str) + if t == "number" then + return utfchar(str) + elseif t == "string" then + return lpegmatch(splitter,str) or str + end + end + + helpers.nametoslot = nametoslot + helpers.indextoslot = indextoslot + helpers.tochar = tochar + + -- interfaces: + + function commands.fontchar(n) + n = nametoslot(n) + if n then + context_char(n) + end + end + + function commands.fontcharbyindex(n) + n = indextoslot(n) + if n then + context_char(n) + end + end + + function commands.tochar(str) + context(tochar(str)) + end + +end -- this will change ... @@ -1617,20 +1717,6 @@ local context_getvalue = context.getvalue local commands_doifelse = commands.doifelse -function commands.fontchar(n) - n = nametoslot(n) - if n then - context_char(n) - end -end - -function commands.fontcharbyindex(n) - n = indextoslot(n) - if n then - context_char(n) - end -end - function commands.doifelsecurrentfonthasfeature(name) -- can be made faster with a supportedfeatures hash local f = fontdata[currentfont()] f = f and f.shared diff --git a/tex/context/base/font-ini.mkvi b/tex/context/base/font-ini.mkvi index 556816f6d..c427c2f89 100644 --- a/tex/context/base/font-ini.mkvi +++ b/tex/context/base/font-ini.mkvi @@ -2175,6 +2175,23 @@ \unexpanded\def\fontcharbyindex#index% unofficial command, for idris' font building {\ctxcommand{fontcharbyindex(\number#index)}} +%D The \type {\tochar} commmand takes a specification: +%D +%D \starttabulate[|l|l|l|] +%D \NC e \NC entity \NC e:eacute \NC \NR +%D \NC x \NC hexadecimal unicode \NC x:013D \NC \NR +%D \NC d \NC decimal unicode \NC d:123 \NC \NR +%D \NC s \NC hexadecimal index (slot) \NC s:210D \NC \NR +%D \NC i \NC decimal index \NC i:456 \NC \NR +%D \NC n \NC name \NC n:eight \NC \NR +%D \NC c \NC name \NC c:x \NC \NR +%D \stoptabulate +%D +%D This is an expandable command! + +\def\tochar#specifications% + {\ctxcommand{tochar("#specifications")}} % expanded (also used in edef) + %D The next auxilliary macro is an alternative to \type %D {\fontname}. diff --git a/tex/context/base/font-mis.lua b/tex/context/base/font-mis.lua index ea7fe803a..1b50977ea 100644 --- a/tex/context/base/font-mis.lua +++ b/tex/context/base/font-mis.lua @@ -22,7 +22,7 @@ local handlers = fonts.handlers handlers.otf = handlers.otf or { } local otf = handlers.otf -otf.version = otf.version or 2.759 +otf.version = otf.version or 2.760 otf.cache = otf.cache or containers.define("fonts", "otf", otf.version, true) function otf.loadcached(filename,format,sub) diff --git a/tex/context/base/font-otf.lua b/tex/context/base/font-otf.lua index 688989596..c1b23983d 100644 --- a/tex/context/base/font-otf.lua +++ b/tex/context/base/font-otf.lua @@ -48,7 +48,7 @@ local otf = fonts.handlers.otf otf.glists = { "gsub", "gpos" } -otf.version = 2.759 -- beware: also sync font-mis.lua +otf.version = 2.760 -- beware: also sync font-mis.lua otf.cache = containers.define("fonts", "otf", otf.version, true) local fontdata = fonts.hashes.identifiers @@ -203,7 +203,6 @@ local valid_fields = table.tohash { "extrema_bound", "familyname", "fontname", - "fontname", "fontstyle_id", "fontstyle_name", "fullname", @@ -480,6 +479,8 @@ function otf.load(filename,sub,featurefile) -- second argument (format) is gone lookuptypes = { }, }, + warnings = { + }, metadata = { -- raw metadata, not to be used }, @@ -1789,6 +1790,12 @@ end -- future versions will remove _ +local valid = (lpeg.R("\x00\x7E") - lpeg.S("(){}[]<>%/ \n\r\f\v"))^0 * lpeg.P(-1) + +local function valid_ps_name(str) + return str and str ~= "" and #str < 64 and lpegmatch(valid,str) and true or false +end + actions["check metadata"] = function(data,filename,raw) local metadata = data.metadata for _, k in next, mainfields do @@ -1808,9 +1815,38 @@ actions["check metadata"] = function(data,filename,raw) end -- if metadata.validation_state and table.contains(metadata.validation_state,"bad_ps_fontname") then - local name = file.nameonly(filename) - metadata.fontname = "bad-fontname-" .. name - metadata.fullname = "bad-fullname-" .. name + -- the ff library does a bit too much (and wrong) checking ... so we need to catch this + -- at least for now + local function valid(what) + local names = raw.names + for i=1,#names do + local list = names[i] + local names = list.names + if names then + local name = names[what] + if name and valid_ps_name(name) then + return name + end + end + end + end + local function check(what) + local oldname = metadata[what] + if valid_ps_name(oldname) then + report_otf("ignoring warning %a because %s %a is proper ASCII","bad_ps_fontname",what,oldname) + else + local newname = valid(what) + if not newname then + newname = formatters["bad-%s-%s"](what,file.nameonly(filename)) + end + local warning = formatters["overloading %s from invalid ASCII name %a to %a"](what,oldname,newname) + data.warnings[#data.warnings+1] = warning + report_otf(warning) + metadata[what] = newname + end + end + check("fontname") + check("fullname") end -- end @@ -1964,6 +2000,7 @@ end local function copytotfm(data,cache_id) if data then local metadata = data.metadata + local warnings = data.warnings local resources = data.resources local properties = derivetable(data.properties) local descriptions = derivetable(data.descriptions) @@ -2058,6 +2095,7 @@ local function copytotfm(data,cache_id) local filename = constructors.checkedfilename(resources) local fontname = metadata.fontname local fullname = metadata.fullname or fontname + local psname = fontname or fullname local units = metadata.units_per_em or 1000 -- if units == 0 then -- catch bugs in fonts @@ -2151,11 +2189,21 @@ local function copytotfm(data,cache_id) properties.filename = filename properties.fontname = fontname properties.fullname = fullname - properties.psname = fontname or fullname + properties.psname = psname properties.name = filename or fullname -- -- properties.name = specification.name -- properties.sub = specification.sub + -- + if warnings and #warnings > 0 then + report_otf("warnings for font: %s",filename) + report_otf() + for i=1,#warnings do + report_otf(" %s",warnings[i]) + end + report_otf() + end + -- return { characters = characters, descriptions = descriptions, @@ -2164,6 +2212,7 @@ local function copytotfm(data,cache_id) resources = resources, properties = properties, goodies = goodies, + warnings = warnings, } end end diff --git a/tex/context/base/lxml-ini.mkiv b/tex/context/base/lxml-ini.mkiv index 759fda78a..017152777 100644 --- a/tex/context/base/lxml-ini.mkiv +++ b/tex/context/base/lxml-ini.mkiv @@ -21,7 +21,6 @@ %registerctxluafile{lxml-xml}{1.001} % xml finalizers %registerctxluafile{lxml-aux}{1.001} % extras using parser %registerctxluafile{lxml-mis}{1.001} % extras independent of parser -\registerctxluafile{char-ent}{1.001} \registerctxluafile{lxml-ent}{1.001} % entity hacks \registerctxluafile{lxml-tex}{1.001} % tex finalizers \registerctxluafile{lxml-dir}{1.001} % ctx hacks diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index d80f65499..6898e14f2 100644 Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf index 8c8e0b9b0..aa73bb159 100644 Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 22149730b..4aa03e6a4 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 09/25/14 18:58:26 +-- merge date : 09/26/14 11:42:21 do -- begin closure to overcome local limits and interference @@ -6706,7 +6706,7 @@ local report_otf=logs.reporter("fonts","otf loading") local fonts=fonts local otf=fonts.handlers.otf otf.glists={ "gsub","gpos" } -otf.version=2.759 +otf.version=2.760 otf.cache=containers.define("fonts","otf",otf.version,true) local fontdata=fonts.hashes.identifiers local chardata=characters and characters.data @@ -6832,7 +6832,6 @@ local valid_fields=table.tohash { "extrema_bound", "familyname", "fontname", - "fontname", "fontstyle_id", "fontstyle_name", "fullname", @@ -7067,6 +7066,7 @@ function otf.load(filename,sub,featurefile) }, lookuptypes={}, }, + warnings={}, metadata={ }, properties={ @@ -8194,6 +8194,10 @@ actions["check glyphs"]=function(data,filename,raw) description.glyph=nil end end +local valid=(lpeg.R("\x00\x7E")-lpeg.S("(){}[]<>%/ \n\r\f\v"))^0*lpeg.P(-1) +local function valid_ps_name(str) + return str and str~="" and #str<64 and lpegmatch(valid,str) and true or false +end actions["check metadata"]=function(data,filename,raw) local metadata=data.metadata for _,k in next,mainfields do @@ -8211,9 +8215,36 @@ actions["check metadata"]=function(data,filename,raw) end end if metadata.validation_state and table.contains(metadata.validation_state,"bad_ps_fontname") then - local name=file.nameonly(filename) - metadata.fontname="bad-fontname-"..name - metadata.fullname="bad-fullname-"..name + local function valid(what) + local names=raw.names + for i=1,#names do + local list=names[i] + local names=list.names + if names then + local name=names[what] + if name and valid_ps_name(name) then + return name + end + end + end + end + local function check(what) + local oldname=metadata[what] + if valid_ps_name(oldname) then + report_otf("ignoring warning %a because %s %a is proper ASCII","bad_ps_fontname",what,oldname) + else + local newname=valid(what) + if not newname then + newname=formatters["bad-%s-%s"](what,file.nameonly(filename)) + end + local warning=formatters["overloading %s from invalid ASCII name %a to %a"](what,oldname,newname) + data.warnings[#data.warnings+1]=warning + report_otf(warning) + metadata[what]=newname + end + end + check("fontname") + check("fullname") end end actions["cleanup tables"]=function(data,filename,raw) @@ -8334,6 +8365,7 @@ end local function copytotfm(data,cache_id) if data then local metadata=data.metadata + local warnings=data.warnings local resources=data.resources local properties=derivetable(data.properties) local descriptions=derivetable(data.descriptions) @@ -8408,6 +8440,7 @@ local function copytotfm(data,cache_id) local filename=constructors.checkedfilename(resources) local fontname=metadata.fontname local fullname=metadata.fullname or fontname + local psname=fontname or fullname local units=metadata.units_per_em or 1000 if units==0 then units=1000 @@ -8489,8 +8522,16 @@ local function copytotfm(data,cache_id) properties.filename=filename properties.fontname=fontname properties.fullname=fullname - properties.psname=fontname or fullname + properties.psname=psname properties.name=filename or fullname + if warnings and #warnings>0 then + report_otf("warnings for font: %s",filename) + report_otf() + for i=1,#warnings do + report_otf(" %s",warnings[i]) + end + report_otf() + end return { characters=characters, descriptions=descriptions, @@ -8499,6 +8540,7 @@ local function copytotfm(data,cache_id) resources=resources, properties=properties, goodies=goodies, + warnings=warnings, } end end -- cgit v1.2.3