summaryrefslogtreecommitdiff
path: root/tex/generic/context
diff options
context:
space:
mode:
Diffstat (limited to 'tex/generic/context')
-rw-r--r--tex/generic/context/luatex/luatex-fonts-merged.lua157
-rw-r--r--tex/generic/context/luatex/luatex-fonts-otn.lua28
-rw-r--r--tex/generic/context/luatex/luatex-fonts.lua20
-rw-r--r--tex/generic/context/luatex/luatex-mplib.lua114
-rw-r--r--tex/generic/context/luatex/luatex-mplib.tex21
-rw-r--r--tex/generic/context/luatex/luatex-plain.tex23
-rw-r--r--tex/generic/context/luatex/luatex-test.tex20
7 files changed, 306 insertions, 77 deletions
diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua
index d8095a285..dee3ebec7 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 : 05/24/15 12:42:55
+-- merge date : 06/12/15 10:06:12
do -- begin closure to overcome local limits and interference
@@ -57,21 +57,33 @@ if not package.loaders then
end
local print,select,tostring=print,select,tostring
local inspectors={}
-function setinspector(inspector)
- inspectors[#inspectors+1]=inspector
+function setinspector(kind,inspector)
+ inspectors[kind]=inspector
end
function inspect(...)
for s=1,select("#",...) do
local value=select(s,...)
- local done=false
- for i=1,#inspectors do
- done=inspectors[i](value)
- if done then
- break
+ if value==nil then
+ print("nil")
+ else
+ local done=false
+ local kind=type(value)
+ local inspector=inspectors[kind]
+ if inspector then
+ done=inspector(value)
+ if done then
+ break
+ end
+ end
+ for kind,inspector in next,inspectors do
+ done=inspector(value)
+ if done then
+ break
+ end
+ end
+ if not done then
+ print(tostring(value))
end
- end
- if not done then
- print(tostring(value))
end
end
end
@@ -112,7 +124,7 @@ local floor=math.floor
local P,R,S,V,Ct,C,Cs,Cc,Cp,Cmt=lpeg.P,lpeg.R,lpeg.S,lpeg.V,lpeg.Ct,lpeg.C,lpeg.Cs,lpeg.Cc,lpeg.Cp,lpeg.Cmt
local lpegtype,lpegmatch,lpegprint=lpeg.type,lpeg.match,lpeg.print
if setinspector then
- setinspector(function(v) if lpegtype(v) then lpegprint(v) return true end end)
+ setinspector("lpeg",function(v) if lpegtype(v) then lpegprint(v) return true end end)
end
lpeg.patterns=lpeg.patterns or {}
local patterns=lpeg.patterns
@@ -995,9 +1007,10 @@ function string.valid(str,default)
return (type(str)=="string" and str~="" and str) or default or nil
end
string.itself=function(s) return s end
-local pattern=Ct(C(1)^0)
-function string.totable(str)
- return lpegmatch(pattern,str)
+local pattern_c=Ct(C(1)^0)
+local pattern_b=Ct((C(1)/byte)^0)
+function string.totable(str,bytes)
+ return lpegmatch(bytes and pattern_b or pattern_c,str)
end
local replacer=lpeg.replacer("@","%%")
function string.tformat(fmt,...)
@@ -1884,7 +1897,7 @@ function table.print(t,...)
end
end
if setinspector then
- setinspector(function(v) if type(v)=="table" then serialize(print,v,"table") return true end end)
+ setinspector("table",function(v) if type(v)=="table" then serialize(print,v,"table") return true end end)
end
function table.sub(t,i,j)
return { unpack(t,i,j) }
@@ -2937,7 +2950,13 @@ function string.autosingle(s,sep)
end
return ("'"..tostring(s).."'")
end
-local tracedchars={}
+local tracedchars={ [0]=
+ "[null]","[soh]","[stx]","[etx]","[eot]","[enq]","[ack]","[bel]",
+ "[bs]","[ht]","[lf]","[vt]","[ff]","[cr]","[so]","[si]",
+ "[dle]","[dc1]","[dc2]","[dc3]","[dc4]","[nak]","[syn]","[etb]",
+ "[can]","[em]","[sub]","[esc]","[fs]","[gs]","[rs]","[us]",
+ "[space]",
+}
string.tracedchars=tracedchars
strings.tracers=tracedchars
function string.tracedchar(b)
@@ -7176,7 +7195,7 @@ local report_otf=logs.reporter("fonts","otf loading")
local fonts=fonts
local otf=fonts.handlers.otf
otf.glists={ "gsub","gpos" }
-otf.version=2.812
+otf.version=2.814
otf.cache=containers.define("fonts","otf",otf.version,true)
local hashes=fonts.hashes
local definers=fonts.definers
@@ -7353,10 +7372,11 @@ local ordered_enhancers={
"reorganize subtables",
"check glyphs",
"check metadata",
- "check extra features",
"prepare tounicode",
"check encoding",
"add duplicates",
+ "expand lookups",
+ "check extra features",
"cleanup tables",
"compact lookups",
"purge names",
@@ -7526,6 +7546,7 @@ function otf.load(filename,sub,featurefile)
data={
size=size,
time=time,
+ subfont=sub,
format=otf_format(filename),
featuredata=featurefiles,
resources={
@@ -7810,25 +7831,25 @@ actions["prepare glyphs"]=function(data,filename,raw)
glyph=glyph,
}
descriptions[unicode]=description
-local altuni=glyph.altuni
-if altuni then
- for i=1,#altuni do
- local a=altuni[i]
- local u=a.unicode
- if u~=unicode then
- local v=a.variant
- if v then
- local vv=variants[v]
- if vv then
- vv[u]=unicode
- else
- vv={ [u]=unicode }
- variants[v]=vv
- end
- end
- end
- end
-end
+ local altuni=glyph.altuni
+ if altuni then
+ for i=1,#altuni do
+ local a=altuni[i]
+ local u=a.unicode
+ if u~=unicode then
+ local v=a.variant
+ if v then
+ local vv=variants[v]
+ if vv then
+ vv[u]=unicode
+ else
+ vv={ [u]=unicode }
+ variants[v]=vv
+ end
+ end
+ end
+ end
+ end
end
end
else
@@ -8353,12 +8374,15 @@ local function r_uncover(splitter,cache,cover,replacements)
end
actions["reorganize lookups"]=function(data,filename,raw)
if data.lookups then
- local splitter=data.helpers.tounicodetable
+ local helpers=data.helpers
+ local duplicates=data.resources.duplicates
+ local splitter=helpers.tounicodetable
local t_u_cache={}
local s_u_cache=t_u_cache
local t_h_cache={}
local s_h_cache=t_h_cache
local r_u_cache={}
+ helpers.matchcache=t_h_cache
for _,lookup in next,data.lookups do
local rules=lookup.rules
if rules then
@@ -8504,6 +8528,44 @@ actions["reorganize lookups"]=function(data,filename,raw)
end
end
end
+actions["expand lookups"]=function(data,filename,raw)
+ if data.lookups then
+ local cache=data.helpers.matchcache
+ if cache then
+ local duplicates=data.resources.duplicates
+ for key,hash in next,cache do
+ local done=nil
+ for key in next,hash do
+ local unicode=duplicates[key]
+ if not unicode then
+ elseif type(unicode)=="table" then
+ for i=1,#unicode do
+ local u=unicode[i]
+ if hash[u] then
+ elseif done then
+ done[u]=key
+ else
+ done={ [u]=key }
+ end
+ end
+ else
+ if hash[unicode] then
+ elseif done then
+ done[unicode]=key
+ else
+ done={ [unicode]=key }
+ end
+ end
+ end
+ if done then
+ for u in next,done do
+ hash[u]=true
+ end
+ end
+ end
+ end
+ end
+end
local function check_variants(unicode,the_variants,splitter,unicodes)
local variants=the_variants.variants
if variants then
@@ -12871,9 +12933,9 @@ local function normal_handle_contextchain(head,start,kind,chainname,contexts,seq
end
else
local i=1
- while true do
+ while start and true do
if skipped then
- while true do
+ while true do
local char=getchar(start)
local ccd=descriptions[char]
if ccd then
@@ -12902,17 +12964,20 @@ local function normal_handle_contextchain(head,start,kind,chainname,contexts,seq
head,start,ok,n=cp(head,start,last,kind,chainname,ck,lookuphash,chainlookup,chainlookupname,i,sequence)
if ok then
done=true
- i=i+(n or 1)
- else
- i=i+1
+ if n and n>1 then
+ if i+n>nofchainlookups then
+ break
+ else
+ end
+ end
end
+ i=i+1
end
end
- if i>nofchainlookups then
+ if i>nofchainlookups or not start then
break
elseif start then
start=getnext(start)
- else
end
end
end
diff --git a/tex/generic/context/luatex/luatex-fonts-otn.lua b/tex/generic/context/luatex/luatex-fonts-otn.lua
index dd3aa6153..d2ad07689 100644
--- a/tex/generic/context/luatex/luatex-fonts-otn.lua
+++ b/tex/generic/context/luatex/luatex-fonts-otn.lua
@@ -1929,9 +1929,9 @@ local function normal_handle_contextchain(head,start,kind,chainname,contexts,seq
end
else
local i = 1
- while true do
+ while start and true do
if skipped then
- while true do
+ while true do -- todo: use properties
local char = getchar(start)
local ccd = descriptions[char]
if ccd then
@@ -1946,10 +1946,11 @@ local function normal_handle_contextchain(head,start,kind,chainname,contexts,seq
end
end
end
+ -- see remark in ms standard under : LookupType 5: Contextual Substitution Subtable
local chainlookupname = chainlookups[i]
local chainlookup = lookuptable[chainlookupname]
if not chainlookup then
- -- okay, n matches, < n replacements
+ -- we just advance
i = i + 1
else
local cp = chainmores[chainlookup.type]
@@ -1963,19 +1964,26 @@ local function normal_handle_contextchain(head,start,kind,chainname,contexts,seq
-- messy since last can be changed !
if ok then
done = true
- -- skip next one(s) if ligature
- i = i + (n or 1)
- else
- i = i + 1
+ if n and n > 1 then
+ -- we have a ligature (cf the spec we advance one but we really need to test it
+ -- as there are fonts out there that are fuzzy and have too many lookups
+ if i + n > nofchainlookups then
+ -- if trace_contexts then
+ -- logprocess("%s: quitting lookups",cref(kind,chainname))
+ -- end
+ break
+ else
+ -- we need to carry one
+ end
+ end
end
+ i = i + 1
end
end
- if i > nofchainlookups then
+ if i > nofchainlookups or not start then
break
elseif start then
start = getnext(start)
- else
- -- weird
end
end
end
diff --git a/tex/generic/context/luatex/luatex-fonts.lua b/tex/generic/context/luatex/luatex-fonts.lua
index c81e8cd1a..fe0e9de77 100644
--- a/tex/generic/context/luatex/luatex-fonts.lua
+++ b/tex/generic/context/luatex/luatex-fonts.lua
@@ -27,16 +27,16 @@ if not modules then modules = { } end modules ['luatex-fonts'] = {
-- also add more helper code here, but that depends to what extend metatex (sidetrack of context)
-- evolves into a low level layer (depends on time, as usual).
-texio.write_nl("")
-texio.write_nl("--------------------------------------------------------------------------------")
-texio.write_nl("The font code has been brought in sync with the context version of 2014.12.21 so")
-texio.write_nl("if things don't work out as expected the interfacing needs to be checked. When")
-texio.write_nl("this works as expected a second upgrade will happen that gives a more complete")
-texio.write_nl("support and another sync with the context code (that new code is currently being")
-texio.write_nl("tested. The base pass is now integrated in the main pass. The results can differ")
-texio.write_nl("from those in context because there we integrate some mechanisms differently.")
-texio.write_nl("--------------------------------------------------------------------------------")
-texio.write_nl("")
+-- texio.write_nl("")
+-- texio.write_nl("--------------------------------------------------------------------------------")
+-- texio.write_nl("The font code has been brought in sync with the context version of 2014.12.21 so")
+-- texio.write_nl("if things don't work out as expected the interfacing needs to be checked. When")
+-- texio.write_nl("this works as expected a second upgrade will happen that gives a more complete")
+-- texio.write_nl("support and another sync with the context code (that new code is currently being")
+-- texio.write_nl("tested. The base pass is now integrated in the main pass. The results can differ")
+-- texio.write_nl("from those in context because there we integrate some mechanisms differently.")
+-- texio.write_nl("--------------------------------------------------------------------------------")
+-- texio.write_nl("")
utf = utf or unicode.utf8
diff --git a/tex/generic/context/luatex/luatex-mplib.lua b/tex/generic/context/luatex/luatex-mplib.lua
index c6628acb3..c093b8333 100644
--- a/tex/generic/context/luatex/luatex-mplib.lua
+++ b/tex/generic/context/luatex/luatex-mplib.lua
@@ -22,7 +22,9 @@ if metapost and metapost.version then
else
- local format, concat, abs, match = string.format, table.concat, math.abs, string.match
+ local format, match, gsub = string.format, string.match, string.gsub
+ local concat = table.concat
+ local abs = math.abs
local mplib = require ('mplib')
local kpse = require ('kpse')
@@ -144,10 +146,101 @@ else
metapost.make = metapost.make or function()
end
+ local template = [[
+ \pdfoutput=1
+ \pdfpkresolution600
+ \pdfcompresslevel=9
+ %s\relax
+ \hsize=100in
+ \vsize=\hsize
+ \hoffset=-1in
+ \voffset=\hoffset
+ \topskip=0pt
+ \setbox0=\hbox{%s}\relax
+ \pdfpageheight=\ht0
+ \pdfpagewidth=\wd0
+ \box0
+ \bye
+ ]]
+
+ metapost.texrunner = "mtxrun --script plain"
+
+ local texruns = 0 -- per document
+ local texhash = { } -- per document
+
+ function metapost.maketext(mpd,str,what)
+ -- inefficient but one can always use metafun .. it's more a test
+ -- feature
+ local verbatimtex = mpd.verbatimtex
+ if not verbatimtex then
+ verbatimtex = { }
+ mpd.verbatimtex = verbatimtex
+ end
+ if what == 1 then
+ table.insert(verbatimtex,str)
+ else
+ local texcode = format(template,concat(verbatimtex,"\n"),str)
+ local texdone = texhash[texcode]
+ local jobname = tex.jobname
+ if not texdone then
+ texruns = texruns + 1
+ texdone = texruns
+ texhash[texcode] = texdone
+ local texname = format("%s-mplib-%s.tmp",jobname,texdone)
+ local logname = format("%s-mplib-%s.log",jobname,texdone)
+ local pdfname = format("%s-mplib-%s.pdf",jobname,texdone)
+ io.savedata(texname,texcode)
+ os.execute(format("%s %s",metapost.texrunner,texname))
+ os.remove(texname)
+ os.remove(logname)
+ end
+ return format('"image::%s-mplib-%s.pdf" infont defaultfont',jobname,texdone)
+ end
+ end
+
+ local function mpprint(buffer,...)
+ for i=1,select("#",...) do
+ local value = select(i,...)
+ if value ~= nil then
+ local t = type(value)
+ if t == "number" then
+ buffer[#buffer+1] = format("%.16f",value)
+ elseif t == "string" then
+ buffer[#buffer+1] = value
+ elseif t == "table" then
+ buffer[#buffer+1] = "(" .. concat(value,",") .. ")"
+ else -- boolean or whatever
+ buffer[#buffer+1] = tostring(value)
+ end
+ end
+ end
+ end
+
+ function metapost.runscript(mpd,code)
+ local code = loadstring(code)
+ if type(code) == "function" then
+ local buffer = { }
+ function metapost.print(...)
+ mpprint(buffer,...)
+ end
+ code()
+ -- mpd.buffer = buffer -- for tracing
+ return concat(buffer,"")
+ end
+ return ""
+ end
+
function metapost.load(name)
+ local mpd = {
+ buffer = { },
+ verbatim = { }
+ }
local mpx = mplib.new {
ini_version = true,
- find_file = metapost.finder,
+ find_file = metapost.finder,
+ make_text = function(...) return metapost.maketext (mpd,...) end,
+ run_script = function(...) return metapost.runscript(mpd,...) end,
+ extensions = 1,
}
local result
if not mpx then
@@ -217,8 +310,8 @@ else
return figure:objects()
end
- function metapost.convert(result, flusher)
- metapost.flush(result, flusher)
+ function metapost.convert(result,flusher)
+ metapost.flush(result,flusher)
return true -- done
end
@@ -239,8 +332,13 @@ else
end
function pdf_textfigure(font,size,text,width,height,depth)
- text = text:gsub(".","\\hbox{%1}") -- kerning happens in metapost
- tex.sprint(format("\\MPLIBtextext{%s}{%s}{%s}{%s}{%s}",font,size,text,0,-( 7200/ 7227)/65536*depth))
+ local how, what = match(text,"^(.-)::(.+)$")
+ if how == "image" then
+ tex.sprint(format("\\MPLIBpdftext{%s}{%s}",what,depth))
+ else
+ text = gsub(text,".","\\hbox{%1}") -- kerning happens in metapost
+ tex.sprint(format("\\MPLIBtextext{%s}{%s}{%s}{%s}",font,size,text,depth))
+ end
end
local bend_tolerance = 131/65536
@@ -375,8 +473,10 @@ else
pdf_literalcode("Q")
else
local cs = object.color
+ local cr = false
if cs and #cs > 0 then
- pdf_literalcode(metapost.colorconverter(cs))
+ cs, cr = metapost.colorconverter(cs)
+ pdf_literalcode(cs)
end
local ml = object.miterlimit
if ml and ml ~= miterlimit then
diff --git a/tex/generic/context/luatex/luatex-mplib.tex b/tex/generic/context/luatex/luatex-mplib.tex
index 09dd179f3..f9de4b223 100644
--- a/tex/generic/context/luatex/luatex-mplib.tex
+++ b/tex/generic/context/luatex/luatex-mplib.tex
@@ -106,15 +106,14 @@
%D Text items have a special handler:
-\def\MPLIBtextext#1#2#3#4#5%
+\def\MPLIBtextext#1#2#3#4%
{\begingroup
\setbox\mplibscratchbox\hbox
{\font\temp=#1 at #2bp%
\temp
#3}%
\setbox\mplibscratchbox\hbox
- {\hskip#4 bp%
- \raise#5 bp%
+ {\raise#4sp%
\box\mplibscratchbox}%
\wd\mplibscratchbox0pt%
\ht\mplibscratchbox0pt%
@@ -122,4 +121,20 @@
\box\mplibscratchbox
\endgroup}
+\def\MPLIBpdftext#1#2%
+ {\ifcsname mplib::#1\endcsname
+ % already done, forgotten outside convert group
+ \message{<reusing mplib: #1>}%
+ \else
+ \message{<embedding mplib: #1>}%
+ \immediate\pdfximage{#1}% we cannot remove the file as it is included last
+ \expandafter\edef\csname mplib::#1\endcsname{\the\pdflastximage}%
+ \fi
+ \setbox\mplibscratchbox\hbox
+ {\raise#2sp\hbox{\pdfrefximage\csname mplib::#1\endcsname}}%
+ \wd\mplibscratchbox0pt%
+ \ht\mplibscratchbox0pt%
+ \dp\mplibscratchbox0pt%
+ \box\mplibscratchbox}
+
\endinput
diff --git a/tex/generic/context/luatex/luatex-plain.tex b/tex/generic/context/luatex/luatex-plain.tex
index c9a9e36cf..f209f4792 100644
--- a/tex/generic/context/luatex/luatex-plain.tex
+++ b/tex/generic/context/luatex/luatex-plain.tex
@@ -11,7 +11,26 @@
\directlua {tex.enableprimitives('', tex.extraprimitives())}
-\pdfoutput=1
+% We assume that pdf is used.
+
+\pdfoutput 1
+
+% We set the page dimensions because otherwise the backend does weird things
+% when we have for instance this on a line of its own:
+%
+% \hbox to 100cm {\hss wide indeed\hss}
+%
+% The page dimension calculation is a fuzzy one as there are some compensations
+% for the \hoffset and \voffset and such. I remember long discussions and much
+% trial and error in figuring this out during pdftex development times. Where
+% a dvi driver will project on a papersize (and thereby clip) the pdf backend
+% has to deal with the lack of a page concept on tex by some guessing. Normally
+% a macro package will set the dimensions to something reasonable anyway.
+
+\pdfpagewidth 8.5in
+\pdfpageheight 11.0in
+
+% We load some code at runtime:
\everyjob \expandafter {%
\the\everyjob
@@ -23,6 +42,8 @@
% \input {luatex-gadgets}%
}
+% We also patch the version number:
+
\edef\fmtversion{\fmtversion+luatex}
\dump
diff --git a/tex/generic/context/luatex/luatex-test.tex b/tex/generic/context/luatex/luatex-test.tex
index 6f48e0ced..a1398ef48 100644
--- a/tex/generic/context/luatex/luatex-test.tex
+++ b/tex/generic/context/luatex/luatex-test.tex
@@ -1,3 +1,5 @@
+% texformat=luatex-plain
+
%D \module
%D [ file=luatex-test,
%D version=2009.12.01,
@@ -48,12 +50,30 @@
\setmplibformat{plain}
+\directlua {
+ function MpTest()
+ metapost.print("fullcircle scaled 3cm")
+ end
+}
+
\mplibcode
beginfig(1) ;
draw fullcircle
scaled 10cm
withcolor red
withpen pencircle xscaled 4mm yscaled 2mm rotated 30 ;
+ draw "test" infont defaultfont scaled 4 ;
+ verbatimtex \sl etex;
+ draw btex some more test etex scaled 2 ;
+ currentpicture := currentpicture shifted (0,1cm) ;
+ verbatimtex \bf etex;
+ draw btex another test etex scaled 2 ;
+ currentpicture := currentpicture shifted (0,1cm) ;
+ draw btex another test etex scaled 2 ;
+ draw
+ runscript("MpTest()")
+ withcolor green
+ withpen pencircle xscaled 2mm yscaled 1mm rotated 20 ;
endfig ;
\endmplibcode