From af2acbff50348fb036cf16336e7a80037f520417 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 23 Dec 2013 23:29:34 +0000 Subject: luamplib (23dec13) git-svn-id: svn://tug.org/texlive/trunk@32475 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/luatex/luamplib/luamplib.dtx | 112 ++++++++++++--------- 1 file changed, 64 insertions(+), 48 deletions(-) (limited to 'Master/texmf-dist/source/luatex') diff --git a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx index 558936a9864..9d5b3598268 100644 --- a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx +++ b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx @@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information. %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{luamplib.drv}% - [2013/12/19 v2.1 Interface for using the mplib library]% + [2013/12/23 v2.11 Interface for using the mplib library]% \documentclass{ltxdoc} \usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace} \usepackage[x11names]{xcolor} @@ -154,7 +154,7 @@ See source file '\inFileName' for licencing and contact information. % \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\ % Maintainer: LuaLaTeX Maintainers --- % Support: \email{lualatex-dev@tug.org}} -% \date{2013/12/19 v2.1} +% \date{2013/12/23 v2.11} % % \maketitle % @@ -225,8 +225,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.", }) @@ -355,6 +355,7 @@ else local preamble = [[ boolean mplib ; mplib := true ; let dump = endinput ; + let normalfontsize = fontsize; input %s ; ]] @@ -463,10 +464,13 @@ 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 % \end{macrocode} -% The following line has been slightly modified by Kim. +% The following three lines have been modified by Kim. % \begin{macrocode} + -- 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 @@ -567,32 +571,48 @@ end % % \begin{macrocode} -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) @@ -609,9 +629,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 @@ -657,7 +678,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 @@ -677,7 +698,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 @@ -737,21 +758,16 @@ local function flush(result,flusher) % % \begin{macrocode} 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 -% \end{macrocode} -% -% Change from \ConTeXt{} code: the following 5 lines are for properly supporting `withcolor' option -% -% \begin{macrocode} - 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 @@ -835,9 +851,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 @@ -858,7 +874,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 @@ -885,7 +901,7 @@ luamplib.colorconverter = colorconverter \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 -- cgit v1.2.3