diff options
author | Karl Berry <karl@freefriends.org> | 2017-08-21 20:44:33 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-08-21 20:44:33 +0000 |
commit | 628c275dde621846d34bf7d180995a91efa1c631 (patch) | |
tree | ce7899cc51975a0a500f8efd5aeba5243c68d52c /Master/texmf-dist/scripts | |
parent | 461d66c062a616f36e5e3e5e51497596acf2086e (diff) |
placeat (21aug17)
git-svn-id: svn://tug.org/texlive/trunk@45087 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-x | Master/texmf-dist/scripts/placeat/placeat.lua | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/Master/texmf-dist/scripts/placeat/placeat.lua b/Master/texmf-dist/scripts/placeat/placeat.lua index 69db376aa35..898ff9a3ca7 100755 --- a/Master/texmf-dist/scripts/placeat/placeat.lua +++ b/Master/texmf-dist/scripts/placeat/placeat.lua @@ -8,7 +8,7 @@ -- -- EXPERIMENTAL CODE -- --- This package is copyright © 2014 Arno L. Trautmann. It may be distributed and/or +-- This package is copyright © 2017 Arno L. Trautmann. It may be distributed and/or -- modified under the conditions of the LaTeX Project Public License, either version 1.3c -- of this license or (at your option) any later version. This work has the LPPL mainten- -- ance status ‘maintained’. @@ -27,7 +27,7 @@ function move (p1,p2) end end -function line (p1,p2) +function line(p1,p2) pdf_print(p1,p2,"l") end @@ -42,11 +42,15 @@ function curve(p11,p12,p21,p22,p31,p32) p3[1], p3[2], "c") end -function linewidth (w) +function linewidth(w) pdf_print(w,"w") end -function stroke () +function fill() + pdf_print("f") +end + +function stroke() pdf_print("S") end @@ -64,7 +68,7 @@ function placelineat(x1,y1,x2,y2) xfac = tex.pagewidth/gridnrx/65536 -- factors to convert given number to absolute coordinates yfac = tex.pageheight/gridnry/65536 -- should both be global! xar = (x2-x1)*xfac -- end point of the arrow - yar = (y2-y1)*yfac -- + yar = (y1-y2)*yfac -- move(0,0) -- start line(xar,yar) -- draw main line stroke() @@ -74,7 +78,7 @@ function placearrowat(x1,y1,x2,y2) xfac = tex.pagewidth/gridnrx/65536 -- factors to convert given number to absolute coordinates yfac = tex.pageheight/gridnry/65536 -- should both be global! xar = (x2-x1)*xfac -- end point of the arrow - yar = (y2-y1)*yfac -- + yar = (y1-y2)*yfac -- parx = xar/math.sqrt(xar^2+yar^2) -- direction of the arrow pary = yar/math.sqrt(xar^2+yar^2) -- perpx = -pary -- perp of the arrow direction @@ -82,36 +86,37 @@ function placearrowat(x1,y1,x2,y2) move(0,0) -- start line(xar,yar) -- draw main line move(xar,yar) - line(xar-5*parx+5*perpx,yar-5*pary+5*perpy) -- draw arrowhead + line(xar-arrowheadlength*parx+arrowheadlength*perpx,yar-arrowheadlength*pary+arrowheadlength*perpy) -- draw arrowhead move(xar,yar) - line(xar-5*parx-5*perpx,yar-5*pary-5*perpy) + line(xar-arrowheadlength*parx-arrowheadlength*perpx,yar-arrowheadlength*pary-arrowheadlength*perpy) stroke() end -- better circle-approximation by using quarter circles, according to wikipedia article about Bézier curves -function placecircleat(radius) - local k = 0.55228 +-- k = 1 gives a circle, everything else something else … +function placecircleat(r,k,filled) local P0,P1,P2,P3 + r = r * 59.5 -- next arbitrary scale factor; the circle has radius "1" in x-units + local rk = 0.55228*r*k - P0 = {radius,0} P1 = {radius,radius*k} - P2 = {radius*k,radius} P3 = {0,radius} - - move (P0[1],P0[2]) curve (P1,P2,P3) + P0 = {r,0} + move (P0[1],P0[2]) - P0 = {-radius,0} P1 = {-radius,radius*k} - P2 = {-radius*k,radius} P3 = {0,radius} + P1 = {r,rk} P2 = {rk,r} P3 = {0,r} + curve (P1,P2,P3) - move (P0[1],P0[2]) curve (P1,P2,P3) + P1 = {-rk,r} P2 = {-r,rk} P3 = {-r,0} + curve (P1,P2,P3) - P0 = {-radius,0} P1 = {-radius,-radius*k} - P2 = {-radius*k,-radius} P3 = {0,-radius} + P1 = {-r,-rk} P2 = {-rk,-r} P3 = {0,-r} + curve (P1,P2,P3) - move (P0[1],P0[2]) curve (P1,P2,P3) + P1 = {rk,-r} P2 = {r,-rk} P3 = {r,0} + curve (P1,P2,P3) - P0 = {radius,0} P1 = {radius,-radius*k} - P2 = {radius*k,-radius} P3 = {0,-radius} - - move (P0[1],P0[2]) curve (P1,P2,P3) + if filled then + fill() + end stroke() end @@ -124,29 +129,34 @@ function placesquareat(length) stroke() end -function placerectangleat(x1,y1,x2,y2) +function placecurveat(x1,y1,x2,y2,x3,y3,x4,y4) -- start point and three numbers. Start is only offset. + xfac = tex.pagewidth/gridnrx/65536 -- factors to convert given number to absolute coordinates + yfac = tex.pageheight/gridnry/65536 -- should both be global! + x2 = (x2-x1)*xfac + y2 = (y2-y1)*yfac + x3 = (x3-x1)*xfac + y3 = (y3-y1)*yfac + x4 = (x4-x1)*xfac + y4 = (y4-y1)*yfac + move(0,0) -- start + curve(x2,-y2,x3,-y3,x4,-y4) -- coordinates for Bezier curve + stroke() +end + +function placerectangleat(x1,y1,x2,y2,filled) xfac = tex.pagewidth/gridnrx/65536 yfac = tex.pageheight/gridnry/65536 x2 = (x2-x1)*xfac - y2 = (y2-y1)*yfac + y2 = (y1-y2)*yfac move(0,0) line(x2,0) line(x2,y2) line(0,y2) line(0,0) + if filled then + fill() + end stroke() end - -function placefilledrectangleat(x1,y1,x2,y2) - xfac = tex.pagewidth/gridnrx/65536 - yfac = tex.pageheight/gridnry/65536/1.0035 -- well, yes. Another random factor. lalala - x2 = (x2-x1)*xfac - y2 = (y2-y1)*yfac - linewidth(y2) - move(0,y2/2) - line(x2,y2/2) - stroke() - linewidth(1) -end -- -- End of File `placeat.lua'. |