diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib/luamplib.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 130 |
1 files changed, 85 insertions, 45 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua index dab385288c0..4969538ec15 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.01, - date = "2013/09/24", + version = 2.03, + date = "2013/12/11", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", }) @@ -310,53 +310,35 @@ local function flushconcatpath(path,open) end -local mplibcodepreamble = [[ -vardef textext@#(expr n, w, h, d) = - image( +local mplibcodepreamblefirst = [[ +def textext (expr t) = + image( special "%%mkTEXbox:"&t; ) +enddef; +let TEX = textext; +]] + +local mplibcodepreamblesecond = [[ +vardef textext (expr t) = + TEXBOX := TEXBOX + 1; + image ( addto currentpicture doublepath unitsquare - xscaled w - yscaled (h+d) - shifted (0,-d) - withprescript "%%textext:"&decimal n&":"&decimal w&":"&decimal(h+d); - ) + xscaled TEXBOXwd[TEXBOX] + yscaled (TEXBOXht[TEXBOX] + TEXBOXdp[TEXBOX]) + shifted (0, -TEXBOXdp[TEXBOX]) + withprescript "%%TEXtxtbox:" & + decimal TEXBOX & ":" & + decimal TEXBOXwd[TEXBOX] & ":" & + decimal(TEXBOXht[TEXBOX]+TEXBOXdp[TEXBOX]); +) enddef; +def TEX (expr t) = textext (t) enddef; ]] local factor = 65536*(7227/7200) -local function settexboxes (data) - local i = tex.count[14] -- newbox register - for _,c,_ in stringgmatch(data,"(%A)btex(%A.-%A)etex(%A)") do - i = i + 1 - c = stringgsub(c,"^%s*(.-)%s*$","%1") - texsprint(format("\\setbox%i\\hbox{%s}",i,c)) - end -end - -luamplib.settexboxes = settexboxes - -local function gettexboxes (data) - local i = tex.count[14] -- the same newbox register - data = stringgsub(data,"(%A)btex%A.-%Aetex(%A)", - function(pre,post) - i = i + 1 - local box = tex.box[i] - local boxmetr = format("textext(%i,%f,%f,%f)", - i, - box and (box.width/factor) or 0, - box and (box.height/factor) or 0, - box and (box.depth/factor) or 0) - return pre .. boxmetr .. post - end) - return mplibcodepreamble .. data -end - -luamplib.gettexboxes = gettexboxes - -local function puttexboxes (object) - local n,tw,th = stringmatch( - object.prescript, - "%%%%textext:(%d+):([%d%.%+%-]+):([%d%.%+%-]+)") +local function putTEXboxes (object) + local n,tw,th = stringmatch(object.prescript, + "%%%%TEXtxtbox:(%d+):([%d%.%+%-]+):([%d%.%+%-]+)") if n and tw and th then local op = object.path local first, second, fourth = op[1], op[2], op[4] @@ -371,6 +353,64 @@ local function puttexboxes (object) end end +local function domakeTEXboxes (data) + local num = tex.count[14] -- newbox register + if data and data.fig then + local figures = data.fig + for f=1, #figures do + local figure = figures[f] + local objects = getobjects(data,figure,f) + if objects then + for o=1,#objects do + local object = objects[o] + local prescript = object.prescript + if prescript and stringfind(prescript,"%%%%mkTEXbox:") then + num = num + 1 + stringgsub(prescript, "%%%%mkTEXbox:(.+)", + function(str) + texsprint(format("\\setbox%i\\hbox{%s}",num,str)) + end) + end + end + end + end + end +end + +local function makeTEXboxes (data) + data = stringgsub(data,"(%A)btex(%A.-%A)etex(%A)", + function(pre,texcode,post) + texcode = stringgsub(texcode,"^%s*(.-)%s*$","%1") + return pre .. "textext(\"" .. texcode .. "\")" .. post + end) + local mpx = luamplib.load(currentformat) + if mpx and data then + local result = mpx:execute(mplibcodepreamblefirst .. data) + domakeTEXboxes(result) + end + return data +end + +luamplib.makeTEXboxes = makeTEXboxes + +local function processwithTEXboxes (data) + local num = tex.count[14] -- the same newbox register + local prepreamble = "numeric TEXBOX, TEXBOXwd[], TEXBOXht[], TEXBOXdp[];\n".. + "TEXBOX := "..num..";\n" + while true do + num = num + 1 + local box = tex.box[num] + if not box then break end + prepreamble = prepreamble .. + "TEXBOXwd["..num.."] := "..box.width/factor ..";\n".. + "TEXBOXht["..num.."] := "..box.height/factor..";\n".. + "TEXBOXdp["..num.."] := "..box.depth /factor..";\n" + end + process(prepreamble .. mplibcodepreamblesecond .. data) +end + +luamplib.processwithTEXboxes = processwithTEXboxes + local function flush(result,flusher) if result then @@ -396,8 +436,8 @@ local function flush(result,flusher) local object = objects[o] local objecttype = object.type local prescript = object.prescript --- [be]tex patch - if prescript and stringfind(prescript,"%%%%textext:") then - puttexboxes(object) + if prescript and stringfind(prescript,"%%%%TEXtxtbox:") then + putTEXboxes(object) elseif objecttype == "start_bounds" or objecttype == "stop_bounds" then -- skip elseif objecttype == "start_clip" then |