From ac3c55a3216b5988f0e48ba9414ddb059f19a699 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 11 Jan 2006 22:58:36 +0000 Subject: trunk/Master/texmf-dist/metapost git-svn-id: svn://tug.org/texlive/trunk@104 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/metapost/exteps/exteps.mp | 176 ++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Master/texmf-dist/metapost/exteps/exteps.mp (limited to 'Master/texmf-dist/metapost/exteps') diff --git a/Master/texmf-dist/metapost/exteps/exteps.mp b/Master/texmf-dist/metapost/exteps/exteps.mp new file mode 100644 index 00000000000..0ec3626f26b --- /dev/null +++ b/Master/texmf-dist/metapost/exteps/exteps.mp @@ -0,0 +1,176 @@ +% Copyright 2005 by Palle Jørgensen +% +% This file is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +% General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place - Suite 330, Boston, +% MA 02111-1307, USA. +% +% This is version 0.1 Wed Aug 10 2005 +% +% The module is documentet in exteps.pdf + +picture epspicture; + +%% String handling tool +string string_split[]; +def splitstring expr S = + begingroup + save __splitctr; numeric __splitctr; __splitctr = 0; + save __prevchar; string __prevchar, __currentchar; __prevchar = " "; + for i = 0 upto infinity: + __currentchar := substring(i, i+1) of S; + if (__currentchar = " ") and (__prevchar = " "): + relax; + elseif (__currentchar <> " ") and (__prevchar = " "): + string_split[__splitctr] := __currentchar; + elseif (__currentchar <> " ") and (__prevchar <> " "): + string_split[__splitctr] := string_split[__splitctr] & __currentchar; + elseif (__currentchar = " ") and (__prevchar <> " "): + __splitctr := __splitctr+1; + fi + __prevchar := __currentchar; + endfor + endgroup; +enddef; +%% End string handling tool + +def begineps text F = + begingroup; + save file; string file; file = F; + save angle; numeric angle; angle = 0; + save clip; boolean clip; clip = false; + save scale; pair scale; scale = (1,1); + save base; pair base; base = origin; + save __bbxfound; boolean __bbxfound; __bbxfound = false; + save grid; boolean grid; grid = false; + save gridstep; numeric gridstep; gridstep = 10; + save __base; pair __base; + save __eps__currentline; string __eps__currentline; + save __bbxline; string __bbxline; + save llx, lly, urx, ury; numeric llx, lly, urx, ury; + save pct; numeric pct; + save width; numeric width; + save height; numeric height; +%% Finding the bounding box + forever: + __eps__currentline := readfrom F; + if substring(0,14) of __eps__currentline = "%%BoundingBox:": + __bbxline := substring(14, infinity) of __eps__currentline; + __bbxfound := true; + splitstring __bbxline; + llx = scantokens string_split[0]; + lly = scantokens string_split[1]; + urx = scantokens string_split[2]; + ury = scantokens string_split[3]; + fi + exitif __bbxfound; + endfor + closefrom F; + __base = -(llx,lly); + pct = (urx - llx)/100; +%% To ensure the right bounding box of the output file +%% a picture with the same size as the eps figure is added. + epspicture := nullpicture; + setbounds epspicture to ((0,0)--(0,ury-lly)--(urx-llx,ury-lly)--(urx-llx,0)--cycle); +enddef; + +def endeps = +%% Drawing the grid + if grid: + for i = 0 step gridstep*pct until (urx - llx): + epsdraw (i,0)--(i,ury - lly); + epslabel.bot(((decimal.(i/pct) & "%") infont defaultfont) rotated -90, (i,0)); + endfor + for i = 0 step gridstep*pct until (epsilon + ury - lly): + epsdraw (0,i)--(urx - llx,i); + epslabel.lft(((decimal.(i/pct) & "%") infont defaultfont), (0,i)); + endfor + fi +%% Calculating scale if width and/or height is known + if (known width) and (known height): + scale := (width/(urx - llx),height/(ury - lly)); + elseif known width: + scale := (width/(urx - llx),width/(urx - llx)); + elseif known height: + scale := (height/(ury - lly),height/(ury - lly)); + fi +%% The graphics inclusion commands + special "gsave"; + if base <> origin: + special decimal.xpart.base & " " & decimal.ypart.base & " translate"; + fi + if scale <> (1,1): + special decimal xpart.scale & " " & decimal ypart.scale & " scale"; + fi + if angle <> 0: + special decimal angle & " rotate"; + epspicture := epspicture rotatedaround(origin)(angle); + fi + if __base <> origin: + special decimal.xpart.__base & " " & decimal.ypart.__base & " translate"; + fi + if scale <> (1,1): + epspicture := epspicture scaled xpart.scale + if xpart.scale <> ypart.scale: + yscaled (ypart.scale/xpart.scale) + fi; + fi + if clip: + special "newpath "; + special decimal llx & " " & decimal lly & " moveto"; + special decimal llx & " " & decimal ury & " lineto"; + special decimal urx & " " & decimal ury & " lineto"; + special decimal urx & " " & decimal lly & " lineto"; + special decimal llx & " " & decimal lly & " lineto"; + special "closepath clip"; + fi + special "%%BeginDocument: " & file; + forever: + __eps__currentline := readfrom file; + exitunless __eps__currentline <> EOF; + special __eps__currentline; + endfor + special "%%EndDocument: " & file; + special "grestore"; + closefrom file; + if base <> (0,0): + epspicture := epspicture shifted base; + fi + addto currentpicture also epspicture; +endgroup; +enddef; + +%% Special drawing commands +def epsfill expr c = addto epspicture contour c _op_ enddef; + +def epsdraw expr p = + addto epspicture + if picture p: + also p + else: + doublepath p withpen currentpen + fi + _op_ +enddef; + +def epsfilldraw expr c = + addto epspicture contour c withpen currentpen + _op_ enddef; + +def epsdrawdot expr z = + addto epspicture contour makepath currentpen shifted z + _op_ enddef; + +def epslabel = epsdraw thelabel enddef; + +endinput -- cgit v1.2.3