summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luamplib
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-12-23 23:29:34 +0000
committerKarl Berry <karl@freefriends.org>2013-12-23 23:29:34 +0000
commitaf2acbff50348fb036cf16336e7a80037f520417 (patch)
treed17e7c1c3bfe7e3e7f243bf6b771c23017005fdc /Master/texmf-dist/tex/luatex/luamplib
parent95f3bfea27839033e3d7abd3fba2bba4dad16181 (diff)
luamplib (23dec13)
git-svn-id: svn://tug.org/texlive/trunk@32475 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua99
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.sty2
2 files changed, 61 insertions, 40 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index e818c56c1e4..53fa55ec823 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
@@ -18,8 +18,8 @@ luamplib.lastlog = ""
local err, warn, info, log = luatexbase.provides_module({
name = "luamplib",
- version = 2.1,
- date = "2013/12/19",
+ version = 2.11,
+ date = "2013/12/23",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
})
@@ -113,6 +113,7 @@ else
local preamble = [[
boolean mplib ; mplib := true ;
let dump = endinput ;
+ let normalfontsize = fontsize;
input %s ;
]]
@@ -217,7 +218,10 @@ end
luamplib.pdf_literalcode = pdf_literalcode
local function pdf_textfigure(font,size,text,width,height,depth)
- text = text:gsub(".","\\hbox{%1}") -- kerning happens in metapost
+ -- if text == "" then text = "\0" end -- char(0) has gone
+ text = text:gsub(".",function(c)
+ return format("\\hbox{\\char%i}",string.byte(c)) -- kerning happens in metapost
+ end)
texsprint(format("\\mplibtextext{%s}{%f}{%s}{%s}{%f}",font,size,text,0,-( 7200/ 7227)/65536*depth))
end
luamplib.pdf_textfigure = pdf_textfigure
@@ -310,32 +314,48 @@ local function flushconcatpath(path,open)
end
-local mplibcodepreamblefirst = [[
-def textext (expr t) =
- image( special "%%mkTEXbox:"&t; )
+local mplibcodepreamble = [[
+vardef rawtextext (expr t) =
+ if unknown TEXBOX_:
+ image( special "%%mkTEXbox:"&t; )
+ else:
+ TEXBOX_ := TEXBOX_ + 1;
+ image (
+ addto currentpicture doublepath unitsquare
+ xscaled TEXBOX_wd[TEXBOX_]
+ yscaled (TEXBOX_ht[TEXBOX_] + TEXBOX_dp[TEXBOX_])
+ shifted (0, -TEXBOX_dp[TEXBOX_])
+ withprescript "%%TEXtxtbox:" &
+ decimal TEXBOX_ & ":" &
+ decimal TEXBOX_wd[TEXBOX_] & ":" &
+ decimal(TEXBOX_ht[TEXBOX_]+TEXBOX_dp[TEXBOX_]);
+ )
+ fi
enddef;
-let TEX = textext;
-def VerbatimTeX (text t) = enddef;
-]]
-
-local mplibcodepreamblesecond = [[
-vardef textext (text t) =
- TEXBOX_ := TEXBOX_ + 1;
- image (
- addto currentpicture doublepath unitsquare
- xscaled TEXBOX_wd[TEXBOX_]
- yscaled (TEXBOX_ht[TEXBOX_] + TEXBOX_dp[TEXBOX_])
- shifted (0, -TEXBOX_dp[TEXBOX_])
- withprescript "%%TEXtxtbox:" &
- decimal TEXBOX_ & ":" &
- decimal TEXBOX_wd[TEXBOX_] & ":" &
- decimal(TEXBOX_ht[TEXBOX_]+TEXBOX_dp[TEXBOX_]);
- )
+if known context_mlib:
+ defaultfont := "cmtt10";
+ let infont = normalinfont;
+ let fontsize = normalfontsize;
+ vardef thelabel@#(expr p,z) =
+ if string p :
+ thelabel@#(p infont defaultfont scaled defaultscale,z)
+ else :
+ p shifted (z + labeloffset*mfun_laboff@# -
+ (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p +
+ (1-mfun_labxf@#-mfun_labyf@#)*llcorner p))
+ fi
+ enddef;
+else:
+ vardef textext@# (text t) = rawtextext (t) enddef;
+fi
+def externalfigure primary filename =
+ draw rawtextext("\includegraphics{"& filename &"}")
enddef;
-def TEX (text t) = textext (t) enddef;
+def TEX = textext enddef;
def VerbatimTeX (text t) =
- message "verbatimtex '"& t &"' is ignored";
+ if known TEXBOX_: message "verbatimtex '"& t &"' is ignored"; fi
enddef;
+def fontmapfile primary filename = enddef;
]]
local factor = 65536*(7227/7200)
@@ -352,9 +372,10 @@ local function putTEXboxes (object)
if sx == 0 then sx = 0.00001 end
if sy == 0 then sy = 0.00001 end
local cs = object.color
- if cs then cs = luamplib.colorconverter(cs) end
+ if cs and #cs > 0 then
+ pdf_literalcode(luamplib.colorconverter(cs))
+ end
pdf_literalcode("q %f %f %f %f %f %f cm",sx,rx,ry,sy,tx,ty)
- if cs then pdf_literalcode(cs) end
texsprint(format("\\mplibputtextbox{%i}",n))
pdf_literalcode("Q")
end
@@ -400,7 +421,7 @@ local function makeTEXboxes (data)
end)
local mpx = luamplib.load(currentformat)
if mpx and data then
- local result = mpx:execute(mplibcodepreamblefirst .. data)
+ local result = mpx:execute(mplibcodepreamble .. data)
domakeTEXboxes(result)
end
return data
@@ -420,7 +441,7 @@ local function processwithTEXboxes (data)
"TEXBOX_ht["..num.."] := "..box.height/factor..";\n"..
"TEXBOX_dp["..num.."] := "..box.depth /factor..";\n"
end
- process(prepreamble .. mplibcodepreamblesecond .. data)
+ process(prepreamble .. mplibcodepreamble .. data)
end
luamplib.processwithTEXboxes = processwithTEXboxes
@@ -466,16 +487,16 @@ local function flush(result,flusher)
elseif objecttype == "text" then
local ot = object.transform -- 3,4,5,6,1,2
local cs = object.color
- if cs then cs = luamplib.colorconverter(cs) end
+ if cs and #cs > 0 then
+ pdf_literalcode(luamplib.colorconverter(cs))
+ end
pdf_literalcode("q %f %f %f %f %f %f cm",ot[3],ot[4],ot[5],ot[6],ot[1],ot[2])
- if cs then pdf_literalcode(cs) end
pdf_textfigure(object.font,object.dsize,object.text,object.width,object.height,object.depth)
pdf_literalcode("Q")
else
- local cs, cr = object.color, nil
- if cs then
- cs, cr = luamplib.colorconverter(cs)
- if cs then pdf_literalcode(cs) end
+ local cs = object.color
+ if cs and #cs > 0 then
+ pdf_literalcode(luamplib.colorconverter(cs))
end
local ml = object.miterlimit
if ml and ml ~= miterlimit then
@@ -559,9 +580,9 @@ local function flush(result,flusher)
pdf_literalcode("Q")
end
end
- if cr then
- pdf_literalcode(cr)
- end
+-- if cr then
+-- pdf_literalcode(cr)
+-- end
end
end
end
@@ -582,7 +603,7 @@ local function colorconverter(cr)
elseif n == 3 then
local r, g, b = cr[1], cr[2], cr[3]
return format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b), "0 g 0 G"
- elseif n == 1 then
+ else
local s = cr[1]
return format("%.3f g %.3f G",s,s), "0 g 0 G"
end
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
index ceff5edcddb..d22255d4d92 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
@@ -14,7 +14,7 @@
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2013/12/19 v2.1 mplib package for LuaTeX]
+ [2013/12/23 v2.11 mplib package for LuaTeX]
\RequirePackage{luatexbase-modutils}
\RequirePackage{pdftexcmds}
\fi