summaryrefslogtreecommitdiff
path: root/graphics/MF-PS/mftoeps
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/MF-PS/mftoeps
Initial commit
Diffstat (limited to 'graphics/MF-PS/mftoeps')
-rw-r--r--graphics/MF-PS/mftoeps/0mftoeps.doc218
l---------graphics/MF-PS/mftoeps/README1
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/0m2esamp.doc35
l---------graphics/MF-PS/mftoeps/m2esamp/README1
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/clipcir.mf39
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/clipsqu.mf39
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/holeclip.mf20
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/holeclip.tex22
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/holefill.mf21
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/polygons.mf32
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/rectan.mf19
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/rectan_.bat4
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample1a.mf24
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample1b.mf28
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample2a.mf23
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample2b.mf23
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample2c.mf23
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample2d.mf23
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample2e.mf23
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample3.mf53
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample4.mf45
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/sample5.mf38
-rw-r--r--graphics/MF-PS/mftoeps/m2esamp/stereo.mf53
-rw-r--r--graphics/MF-PS/mftoeps/mftoeps.mf748
24 files changed, 1555 insertions, 0 deletions
diff --git a/graphics/MF-PS/mftoeps/0mftoeps.doc b/graphics/MF-PS/mftoeps/0mftoeps.doc
new file mode 100644
index 0000000000..4edfd06cd3
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/0mftoeps.doc
@@ -0,0 +1,218 @@
+This file belongs to the MFTOEPS package.
+
+-----------------------------------------------------------------------------
+
+OVERVIEW
+
+The package MFTOEPS belongs to the public domain. You are entitled to do with
+the files of which it consists whatever you wish. If you alter a file,
+however, please remove the line containing the comment
+
+ `This file belongs to the MFTOEPS package.'
+
+in order to avoid a mess.
+
+The kernel of this little package is the METAFONT program MFTOEPS.MF written
+by Bogus\l{}aw Jackowski, Piotr Pianowski and Marek Ry\'cko. The aim of the
+program is to produce EPS (encapsulated PostScript) files readable by
+CorelDRAW!(R), Adobe Illustrator(TM) and Fontographer(R).
+
+The user of the package is supposed to be familiar a bit with METAFONT and
+PostScript. Donald E. Knuth's ``The METAFONTbook'' and Adobe's ``PostScript
+Language Reference Manual'' (both by Addison-Wesley Publishing Company, Inc.)
+should be consulted in the case of doubts.
+
+There is a bunch of simple examples in the subdirectory M2ESAMP. The
+directory ../PROGS contains DOS batch files and other programs which,
+possibly after some adjustments, can be used to generate EPS files.
+
+Roughly, the machinery works as follows: the resulting PostScript code
+is written by METAFONT to a LOG file; the LOG file is then processed
+either by AWK or by TeX (see the PROGS subdirectory) in order to extract
+the PostScript code. The idea seems straightforward; however, even
+a partial conciliation of the worlds of CorelDRAW! and Adobe Illustrator
+was not so much straightforward.
+
+-----------------------------------------------------------------------------
+
+In addition to the main MFTOEPS package, there are two ``bonus'' packages in
+directories ../EPSTOMF and ../ROEX. EPSTOMF converts ``canonical'' EPS files,
+i.e., files conforming the structure of the files generated by the MFTOEPS
+package, into the METAFONT lingo; ROEX is a set of METAFONT macros
+accomplishing the task of removing overlaps and expanding strokes (for
+details see there).
+
+-----------------------------------------------------------------------------
+
+INTERFACE SYNOPSIS
+
+Conventions: In the following we shall use words `number,' `pair,' `string,'
+and `path' as an abbreviation for `numeric expression,' `pair expression,'
+`string expression,' and `path expression,' respectively. The signs `less'
+and `greater,' used for marking parameters of macros, are
+``meta-characters,'' i.e., they do not belong to the METAFONT code.
+
+There are fifteen interface macros defined in the MFTOEPS.MF file:
+ eps_mode_setup
+ write_preamble
+ write_postamble
+ set_BB
+ find_BB
+ reset_BB
+ fill_C
+ draw_C
+ clip_C
+ fix_line_width
+ fix_line_join
+ fix_line_cap
+ fix_line_miter_limit
+ fix_fill_cmyk
+ fix_draw_cmyk
+
+COMMAND eps_mode_setup
+USAGE eps_mode_setup <an optional number (0 or 1)>;
+REMARKS This command should be used instead of the usual |mode_setup|
+ command. The forms |EPS_mode_setup| and |EPS_mode_setup 1|
+ are equivalent. One of them (preferably the former one) should
+ be used for normal processing. Invoking |EPS_mode_setup 0|
+ is meant primariliy for testing purposes and is supposed
+ to be used by experienced programmers who know what they are doing.
+ There are two predefined constants in MFTOEPS.MF to be used in this
+ context, namely, |no_export_level=0| and |compatibility_level=1|.
+ It is advisable to use the names of the constants rather than
+ bare numbers.
+
+COMMAND write_preamble
+USAGE write_preamble <string>;
+REMARKS This command initialises the process of writing of the PostScript
+ code. The string expression is the name (without extension)
+ of the resulting EPS file; the extension is always |.EPS|.
+ METAFONT is switched to the |batchmode| in order to avoid
+ slowing down the process by writing mess(ages) to the terminal.
+ The inspection of the log file is thus highly recommended.
+
+COMMAND write_postamble
+USAGE write_postamble;
+REMARKS This command ends writing of the PostScript code, switches METAFONT
+ back to the |errorstopmode|, and performs neccessary ``last minute''
+ actions (see below).
+
+COMMANDS set_BB find_BB reset_BB
+USAGE set_BB <four numbers or two pairs separated by commas>;
+ find_BB <a list of paths separated by commas>;
+ reset_BB;
+REMARKS Commands |set_BB| or |find_BB| should be invoked prior to
+ invoking |write_preamble|. |set_BB| sets the coordinates of
+ the corners of the bounding box of a graphic object; it is
+ useful when the bounding box of a graphic object is
+ known in advance or if it is required to force an artificial
+ bounding box. |find_BB| computes the respective bounding box
+ for a list of paths; if several |find_BB| statements are
+ used, the common bounding box is calculated for all paths
+ that appeared in the arguments. The result is stored in the
+ variables |xl_crd|, |yl_crd|, |xh_crd|, and |yh_crd|. There
+ are two functions, |llxy| and |urxy|, returning pairs
+ |(xl_crd,yl_crd)| and |(xh_crd,yh_crd)|, respectively. The
+ last command, |reset_BB|, makes |xl_crd|, |yl_crd|,
+ |xh_crd|, and |yh_crd| undefined (the initial situation);
+ |reset_BB| is performed by the |write_postamble| macro,
+ which is convenient in the case of generating several
+ several EPS files in a single METAFONT run.
+
+COMMANDS fill_C draw_C
+USAGE fill_C <a list of paths separated by commas>;
+ draw_C <a list of paths separated by commas>;
+REMARKS These commands are to be used instead of the usual
+ METAFONT |fill| and |draw| ones. They cause that a list of paths
+ followed by the PostScript operation |eofill| (|fill_C|) or |stroke|
+ (|draw_C|) is translated to a PostScript code. The list of paths
+ constitutes a single curve in the sense of PostScript.
+
+COMMAND clip_C
+USAGE clip_C <a list of paths separated by commas, possibly empty>;
+REMARKS The macro |clip_C| with a non-empty parameter works similarly to
+ the |fill_C| command, except that the |eoclip| operator is issued
+ instead of |eofill|. This causes an appropriate change of
+ the current clipping area. According to PostScript's principles,
+ the resulting area is a set product of the current clipping
+ area and the area specified in the argument of the |eoclip|
+ command. The empty parameter marks the end of the scope
+ of the most recent |clip_C| command with a non-empty parameter.
+ In other words, nested |clip_C| commands form a ``stack'' structure.
+ If needed, the appropriate number of parameterless |clip_C|
+ commands is issued by the |write_postamble| macro, thus
+ the user needs not to care about it.
+ WARNING: files produced with the use of |clip_C| are
+ interpreted properly by Adobe Illustrator (provided paths
+ directions are defined properly) but not by CorelDRAW! (ver. 3.0).
+
+COMMANDS fix_line_width fix_line_join fix_line_cap fix_miter_limit fix_dash
+USAGE fix_line_width <a non-negative number (dimension)>;
+ fix_line_join <a number (0, 1 or 2)>;
+ fix_line_cap <a number (0, 1 or 2)>;
+ fix_miter_limit <a number greater or equal 1>;
+ fix_dash (<a list of numbers (dimensions), possibly empty>)
+ <number (dimension)>;
+REMARKS These command are to be used in connection with the |draw_C|
+ command. |fix_line_width| fixes the thickness of the outline.
+ The other three commands correspond to PostScript operations
+ |setlinejoin|, |setlinecap|, |setmiterlimit|, and |setdash| (see
+ ``PostScript Language Reference Journal'' for details).
+
+ All commands should be used after |write_preamble|, as
+ |write_preamble| sets the default thickness (0.4pt), default
+ line join (0), default line cap (0), default miter limit (10),
+ and a solid line as a default for stroking (|fix_dash () 0|).
+
+COMMANDS fix_fill_cmyk fix_draw_cmyk
+USAGE fix_fill_cmyk <four numbers separated by commas>;
+ fix_draw_cmyk <four numbers separated by commas>;
+REMARKS These commands define the colours of the interiors of graphic
+ objects (|fix_fill_cmyk|) and colours of outlines (|fix_draw_cmyk|)
+ using cyan-magenta-yellow-black model (basic model). They should
+ be used after |write_preamble| (because |write_preamble| defines
+ the black colour as a default for both macros) and prior to invoking
+ the corresponding |fill_C| and |draw_C| commands, respectively.
+ There are also (just in case) macros |fix_fill_rgb| and
+ |fix_draw_rgb| using red-green-blue model; the argument to both
+ macros is a triple of numbers. (The user can control the process
+ of conversion from RGB to CMYK by the redefinition of macros
+ |under_color_removal| and |black_generation|.) The numbers
+ forming the arguments of the macros are supposed to belong to
+ the interval [0..1].
+
+ADDITIONAL FUNCTIONS pos_turn neg_turn
+USAGE pos_turn <primary path expression>
+ neg_turn <primary path expression>
+REMARKS Each function returns the path passed as the argument,
+ except that the orientation of the path is changed, if
+ necessary: |pos_turn| returns paths oriented anti-clockwise,
+ |neg_turn|---oriented clockwise. This may be
+ usefull for creation pictures which are to be processed
+ further by Adobe Illustrator, because this program is
+ sensitive to the orientation of paths.
+
+CONTROL VARIABLES yeseps yesEPS YESEPS
+REMARKS No EPS file will be generated unless one variable among
+ |yeseps| or |yesEPS| or |YESEPS| is assigned a definite value.
+ It is advisable to set this variable in a command line
+ (see M2E.BAT and M2E-ALT.BAT in the PROGS directory).
+ In fact, using |yeseps| is reccomended. Aliases |yesEPS|
+ and |YESEPS| were introduced for ``historical'' reasons.
+
+CONTROL VARIABLE testing
+REMARKS If the variable |testing| is assigned a definite value, the whole
+ PostScript code is flushed to the terminal, thus slowing
+ down significantly the process of generation of an EPS file
+ (cf. the description of the |write_preamble| command).
+
+-----------------------------------------------------------------------------
+
+ENCOURAGEMENT
+
+The inspection of the source code of the MFTOEPS.MF program may reveal
+a few more useful macros.
+
+-----------------------------------------------------------------------------
+
+END OF THE 0MFTOEPS.DOC FILE
diff --git a/graphics/MF-PS/mftoeps/README b/graphics/MF-PS/mftoeps/README
new file mode 120000
index 0000000000..42494cf21b
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/README
@@ -0,0 +1 @@
+0mftoeps.doc \ No newline at end of file
diff --git a/graphics/MF-PS/mftoeps/m2esamp/0m2esamp.doc b/graphics/MF-PS/mftoeps/m2esamp/0m2esamp.doc
new file mode 100644
index 0000000000..fd27e761c4
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/0m2esamp.doc
@@ -0,0 +1,35 @@
+This file belongs to the MFTOEPS package.
+
+The directory M2ESAMP contains the following files:
+ 0M2ESAMP.DOC this file
+ CLIPCIR.MF a bogus application of clipping: a variation of CLIPSQR.MF
+ CLIPSQR.MF a bogus application of clipping: Sierpi\'nski's carpet
+ HOLECLIP.MF a nearly trivial example
+ HOLECLIP.TEX an example of using HOLECLIP.EPS
+ HOLEFILL.MF a nearly trivial example
+ POLYGONS.MF input for SAMPLE*.MF files
+ RECTAN.MF a truly trivial example
+ RECTAN_.BAT DOS batch file for RECTAN.MF (generates RECTAN.EPS)
+ SAMPLE1A.MF less trivial example
+ SAMPLE1B.MF modification of SAMPLE1A.MF
+ SAMPLE2A.MF regular polygon with circumscribed ``flex'' polygon
+ SAMPLE2B.MF ditto---a variation
+ SAMPLE2C.MF ditto---a variation
+ SAMPLE2D.MF ditto---a variation
+ SAMPLE2E.MF ditto---a variation
+ SAMPLE3.MF four pictures (``flowers'')
+ SAMPLE4.MF four pictures (``galaxies'')
+ SAMPLE5.MF four pictures (``shells'')
+ STEREO.MF two pictures that can be used for
+ constructing a simple stereogram
+
+You are entitled to do with these files whatever you wish. If you alter
+a file, however, please remove the comment line:
+
+ `This file belongs to the MFTOEPS package.'
+
+in order to avoid mess.
+
+-----------------------------------------------------------------------------
+
+END OF THE 0M2ESAMP.DOC FILE
diff --git a/graphics/MF-PS/mftoeps/m2esamp/README b/graphics/MF-PS/mftoeps/m2esamp/README
new file mode 120000
index 0000000000..f0f79bedea
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/README
@@ -0,0 +1 @@
+0m2esamp.doc \ No newline at end of file
diff --git a/graphics/MF-PS/mftoeps/m2esamp/clipcir.mf b/graphics/MF-PS/mftoeps/m2esamp/clipcir.mf
new file mode 100644
index 0000000000..50cf091764
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/clipcir.mf
@@ -0,0 +1,39 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% CLIPCIR.MF
+% ---
+input mftoeps; eps_mode_setup;
+% ---
+def ^ = ** enddef; % syntactic sugar
+primarydef i // n = % ditto
+ (if n=0: 0 else: i/n fi)
+% why not to divide by 0?
+enddef;
+def shifted_accordingly(expr i,j,n,D)=
+ shifted ((i//n)[1/2D,w-1/2D],(j//n)[1/2D,w-1/2D])
+enddef;
+% ---
+w#=16mm#; h#=16mm#; define_pixels(w,h);
+for N:=1,2,3,4: % 5, 6, ..., infinity
+ set_BB 0,0,w,h;
+ write_preamble jobname & decimal(N);
+ D:=2w;
+ for n:=0 for q:=1 upto N-1: , 2^q-1 endfor:
+% i.e., |for n:=0, 2^1-1, 2^2-1, ..., 2^(N-1)-1:|
+ path p[], q[]; D:=1/2D; k:=-1;
+ for i:=0 upto n: for j:=0 upto n:
+ k:=k+1;
+ p[k]=fullcircle scaled D
+ shifted_accordingly(i,j,n,D);
+ q[k]=reverse fullcircle scaled 1/3D
+ shifted_accordingly(i,j,n,D);
+ endfor; endfor;
+ clip_C p0, q0 for i:=1 upto k: , p[i], q[i] endfor;
+ endfor;
+ fill_C unitsquare scaled w;
+ write_postamble;
+endfor;
+% ---
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/clipsqu.mf b/graphics/MF-PS/mftoeps/m2esamp/clipsqu.mf
new file mode 100644
index 0000000000..266ec217ae
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/clipsqu.mf
@@ -0,0 +1,39 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% CLIPSQU.MF (Sierpi\'nski's carpet)
+% ---
+input mftoeps; eps_mode_setup;
+% ---
+def ^ = ** enddef; % syntactic sugar
+primarydef i // n = % ditto
+ (if n=0: 0 else: i/n fi)
+% why not to divide by 0?
+enddef;
+def shifted_accordingly(expr i,j,n,D)=
+ shifted ((i//n)[0,w-D],(j//n)[0,w-D])
+enddef;
+% ---
+w#=16mm#; h#=16mm#; define_pixels(w,h);
+for N:=1,2,3: % 4, 5, 6, ..., infinity
+ set_BB 0,0,w,h;
+ write_preamble jobname & decimal(N);
+ D:=3w;
+ for n:=0 for q:=1 upto N-1: , 3^q-1 endfor:
+% i.e., |for n:=0, 3^1-1, 3^2-1, ..., 3^(N-1)-1:|
+ path p[], q[]; D:=1/3D; k:=-1;
+ for i:=0 upto n: for j:=0 upto n:
+ k:=k+1;
+ p[k]=unitsquare scaled D
+ shifted_accordingly(i,j,n,D);
+ q[k]=reverse unitsquare scaled 1/3D
+ shifted (1/3D,1/3D) shifted_accordingly(i,j,n,D);
+ endfor; endfor;
+ clip_C p0, q0 for i:=1 upto k: , p[i], q[i] endfor;
+ endfor;
+ fill_C unitsquare scaled w;
+ write_postamble;
+endfor;
+% ---
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/holeclip.mf b/graphics/MF-PS/mftoeps/m2esamp/holeclip.mf
new file mode 100644
index 0000000000..0b5850a889
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/holeclip.mf
@@ -0,0 +1,20 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% HOLECLIP.MF---a nearly trivial example
+% ---
+input mftoeps; eps_mode_setup;
+w#=4cm#; h#=2cm#; define_pixels(w,h);
+set_BB origin, (w,h);
+write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ for oper:="draw_C", "clip_C":
+ scantokens oper
+% outer edge:
+ fullcircle xscaled w yscaled h shifted (.5w,.5h),
+% inner edge:
+ reverse fullcircle xscaled .7w yscaled .7h shifted (.5w,.5h);
+ endfor
+write_postamble;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/holeclip.tex b/graphics/MF-PS/mftoeps/m2esamp/holeclip.tex
new file mode 100644
index 0000000000..8f314a6ba8
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/holeclip.tex
@@ -0,0 +1,22 @@
+\input epsf
+
+\centerline{
+\setbox0\vbox{
+ \hbox{It is a clipped text.}\hbox{It is a clipped text.}
+ \hbox{It is a clipped text.}\hbox{It is a clipped text.}
+ \vss % no depth
+}%
+\special{ps:
+ /mftoeps_save save def % the snapshoot of a current stage
+ /mftoeps_bhook {/q {} def /Q {} def} def
+ /CM matrix currentmatrix def
+ currentpoint /cy exch def /cx exch def
+ /ori@endspecial /@endspecial load def
+ /@endspecial {} def % neutralize /@endspecial locally
+}
+\hbox to\wd0{\hss\epsfysize\ht0\epsffile{holeclip.eps}\hss}% perform clipping
+\special{ps:cx cy moveto CM setmatrix}\llap{\copy0}% set the text
+\special{ps:ori@endspecial mftoeps_save restore}% restore a previous stage
+}
+
+\end
diff --git a/graphics/MF-PS/mftoeps/m2esamp/holefill.mf b/graphics/MF-PS/mftoeps/m2esamp/holefill.mf
new file mode 100644
index 0000000000..7478df585d
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/holefill.mf
@@ -0,0 +1,21 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% HOLEFILL.MF---a nearly trivial example
+% ---
+input mftoeps; eps_mode_setup;
+w#=4cm#; h#=2cm#; define_pixels(w,h);
+set_BB origin, (w,h);
+write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ fix_line_width 1pt;
+ for oper:="draw_C", "fill_C":
+ scantokens oper
+% outer edge:
+ fullcircle xscaled w yscaled h shifted (.5w,.5h),
+% inner edge:
+ reverse fullcircle xscaled .7w yscaled .7h shifted (.5w,.5h);
+ endfor
+write_postamble;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/polygons.mf b/graphics/MF-PS/mftoeps/m2esamp/polygons.mf
new file mode 100644
index 0000000000..29d370d8ee
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/polygons.mf
@@ -0,0 +1,32 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% POLYGONS.MF
+% ---
+vardef regular_polygon(expr n) =
+% |n| is the number of vertices; the diameter of the circumscribed circle
+% is equal to 1, its center is in the origin
+ (up % first vertex
+ for i:=1 upto n-1:
+ -- (up rotated (i*(360/n))) % next vertices
+ endfor
+ -- cycle) scaled .5
+enddef;
+vardef flex_polygon(expr n,a,b) =
+% |n| is the number of vertices, |a|, |b| are the angles (at vertices)
+% between a tangent to a ``flex side'' and the corresponding secant
+ save zz; pair zz[ ]; % array of vertices
+ for i:=0 upto n-1:
+ zz[i]:=up rotated (i*(360/n));
+ endfor
+ (zz[0] {(zz[1]-zz[0]) rotated a}
+ for i:=1 upto n-1:
+ .. {(zz[i]-zz[i-1]) rotated b}
+ zz[i]
+ {(zz[(i+1) mod n]-zz[i]) rotated a}
+ endfor
+ .. {(zz[0]-zz[n-1]) rotated b} cycle)
+ scaled .5
+enddef;
+endinput
diff --git a/graphics/MF-PS/mftoeps/m2esamp/rectan.mf b/graphics/MF-PS/mftoeps/m2esamp/rectan.mf
new file mode 100644
index 0000000000..63802ab54d
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/rectan.mf
@@ -0,0 +1,19 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% RECTAN.MF---a trivial example
+% ---
+input mftoeps;
+EPS_mode_setup;
+beginchar(48, % ASCII code (unimportant)
+ 2cm#, % width
+ 1cm#, % height
+ 0cm# % depth
+ );
+ set_BB 0,-d,w,h; % coordinates of the corners of the bounding box
+ write_preamble "rectan";
+ fill_C unitsquare xscaled w yscaled h;
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/rectan_.bat b/graphics/MF-PS/mftoeps/m2esamp/rectan_.bat
new file mode 100644
index 0000000000..596fd4710a
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/rectan_.bat
@@ -0,0 +1,4 @@
+::
+:: This file belongs to the MFTOEPS package.
+::
+call m2e rectan
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample1a.mf b/graphics/MF-PS/mftoeps/m2esamp/sample1a.mf
new file mode 100644
index 0000000000..cd34bd3307
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample1a.mf
@@ -0,0 +1,24 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE1A.MF
+% ---
+input polygons; % the definition of the |regular_polygon| function
+input mftoeps;
+eps_mode_setup;
+beginchar(0,2cm#,2cm#,0);
+ path P[ ]; % ,,room'' for polygons
+ N:=25; % the number of polygons
+% preparing:
+ for i:=1 upto N:
+ P[i]:=regular_polygon(7)
+ scaled ((i/N)**2*w) rotated (i/N*360) shifted (.5w,.5h);
+ endfor;
+% exporting:
+ find_BB for i:=1 upto N-1: P[i], endfor P[N];
+ write_preamble jobname;
+ draw_C for i:=1 upto N-1: P[i], endfor P[N];
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample1b.mf b/graphics/MF-PS/mftoeps/m2esamp/sample1b.mf
new file mode 100644
index 0000000000..499650af1f
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample1b.mf
@@ -0,0 +1,28 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE1B.MF
+% ---
+input polygons; % the definition of the |regular_polygon| function
+input mftoeps;
+eps_mode_setup;
+beginchar(0,2cm#,2cm#,0);
+ path P[ ]; % ,,room'' for polygons
+ N:=25; % the number of polygons
+% preparing:
+ for i:=1 upto N:
+ P[i]:=regular_polygon(7)
+ scaled ((i/N)**2*w) rotated (i/N*360) shifted (.5w,.5h);
+ endfor;
+% exporting:
+ find_BB for i:=1 upto N-1: P[i], endfor P[N];
+ write_preamble jobname;
+% Adobe Illustrator likes to control the orientation of paths
+ fill_C
+ for i:=1 upto N-1:
+ if odd(N-i+1): pos_turn else: neg_turn fi P[i],
+ endfor pos_turn P[N];
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample2a.mf b/graphics/MF-PS/mftoeps/m2esamp/sample2a.mf
new file mode 100644
index 0000000000..ef34b34ea8
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample2a.mf
@@ -0,0 +1,23 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE2A.MF
+% ---
+input polygons;
+input mftoeps;
+eps_mode_setup;
+beginchar(0,16mm#,16mm#,0);
+ path P[ ]; % ``room'' for two polygons
+% preparing:
+ P[1]:=regular_polygon(7) scaled w shifted (.5w,.5h);
+ P[2]:=flex_polygon(7,0,0) scaled w shifted (.5w,.5h);
+% exporting:
+ find_BB P[1], P[2];
+ write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ fix_line_width 1pt;
+ fill_C P1; draw_C P2;
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample2b.mf b/graphics/MF-PS/mftoeps/m2esamp/sample2b.mf
new file mode 100644
index 0000000000..e6d82b3175
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample2b.mf
@@ -0,0 +1,23 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE2B.MF
+% ---
+input polygons;
+input mftoeps;
+eps_mode_setup;
+beginchar(0,16mm#,16mm#,0);
+ path P[ ]; % ``room'' for two polygons
+% preparing:
+ P[1]:=regular_polygon(7) scaled w shifted (.5w,.5h);
+ P[2]:=flex_polygon(7,-180/7,180/7) scaled w shifted (.5w,.5h);
+% exporting:
+ find_BB P[1], P[2];
+ write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ fix_line_width 1pt;
+ fill_C P1; draw_C P2;
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample2c.mf b/graphics/MF-PS/mftoeps/m2esamp/sample2c.mf
new file mode 100644
index 0000000000..2a2ebffb4f
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample2c.mf
@@ -0,0 +1,23 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE2C.MF
+% ---
+input polygons;
+input mftoeps;
+eps_mode_setup;
+beginchar(0,16mm#,16mm#,0);
+ path P[ ]; % ``room'' for two polygons
+% preparing:
+ P[1]:=regular_polygon(7) scaled w shifted (.5w,.5h);
+ P[2]:=flex_polygon(7,45,45) scaled w shifted (.5w,.5h);
+% exporting:
+ find_BB P[1], P[2];
+ write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ fix_line_width 1pt;
+ fill_C P1; draw_C P2;
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample2d.mf b/graphics/MF-PS/mftoeps/m2esamp/sample2d.mf
new file mode 100644
index 0000000000..8fe9f9bfb5
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample2d.mf
@@ -0,0 +1,23 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE2D.MF
+% ---
+input polygons;
+input mftoeps;
+eps_mode_setup;
+beginchar(0,16mm#,16mm#,0);
+ path P[ ]; % ``room'' for two polygons
+% preparing:
+ P[1]:=regular_polygon(7) scaled w shifted (.5w,.5h);
+ P[2]:=flex_polygon(7,-45,45) scaled w shifted (.5w,.5h);
+% exporting:
+ find_BB P[1], P[2];
+ write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ fix_line_width 1pt;
+ fill_C P1; draw_C P2;
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample2e.mf b/graphics/MF-PS/mftoeps/m2esamp/sample2e.mf
new file mode 100644
index 0000000000..9411c1db40
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample2e.mf
@@ -0,0 +1,23 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE2E.MF
+% ---
+input polygons;
+input mftoeps;
+eps_mode_setup;
+beginchar(0,16mm#,16mm#,0);
+ path P[ ]; % ``room'' for two polygons
+% preparing:
+ P[1]:=regular_polygon(7) scaled w shifted (.5w,.5h);
+ P[2]:=flex_polygon(7,45,-45) scaled w shifted (.5w,.5h);
+% exporting:
+ find_BB P[1], P[2];
+ write_preamble jobname;
+ fix_fill_cmyk 0,0,0,.25; % 25 percent of black
+ fix_line_width 1pt;
+ fill_C P1; draw_C P2;
+ write_postamble;
+endchar;
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample3.mf b/graphics/MF-PS/mftoeps/m2esamp/sample3.mf
new file mode 100644
index 0000000000..c58756e37a
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample3.mf
@@ -0,0 +1,53 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE3.MF
+% ---
+input mftoeps;
+input polygons;
+eps_mode_setup;
+% unpercent the following line if the coloured version is needed
+% coloured:=1;
+% ---
+def write_paths(expr name) =
+ find_BB elem_path1;
+ write_preamble name;
+ for i:=1 upto objects:
+ coeff:=
+ if objects=1: 0 else: .5(1-cosd(((i-1)/(objects-1))[alpha1,alpha2])) fi;
+ fix_fill_cmyk forsuffixes $:=cyan, magenta, yellow: coeff[$1,$2], endfor
+ coeff[black1,black2];
+ fill_C elem_path[i];
+ endfor;
+ write_postamble;
+enddef;
+% ---
+ch_max:=3;
+% ---
+for ch:=0 upto ch_max:
+ beginchar(char(ASCII("a")+ch), 1in#, 1in#, 0);
+ path elem_path[\\];
+ objects:=100; transitions:=3;
+ sca1:=w; sca2:=.02w;
+ rot1:=0; rot2:=(ch/ch_max)[25,180];
+ skew1:=45; skew2:=0;
+ alpha1:=0; alpha2:=transitions*360;
+ if known coloured:
+ cyan1:=0; magenta1:=0; yellow1:=1; black1:=0;
+ cyan2:=0.35294; magenta2:=0.8353; yellow2:=0.8353; black2:=0; % brown
+ else:
+ cyan1:=0; magenta1:=0; yellow1:=0; black1:=0.7;
+ cyan2:=0; magenta2:=0; yellow2:=0; black2:=0.15;
+ fi
+ for i:=1 upto objects:
+ coeff:=if objects=1: 0 else: (i-1)/(objects-1) fi;
+ elem_path[i]:=flex_polygon(5,coeff[skew1,skew2],coeff[skew1,skew2])
+ scaled (coeff[sca1,sca2])
+ rotated (coeff[rot1,rot2]) shifted (.5w,.5h);
+ endfor
+ write_paths(jobname & char(ASCII("a")+ch));
+ endchar;
+endfor
+% ---
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample4.mf b/graphics/MF-PS/mftoeps/m2esamp/sample4.mf
new file mode 100644
index 0000000000..37acefb4d0
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample4.mf
@@ -0,0 +1,45 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE4.MF
+% ---
+input mftoeps;
+input polygons;
+eps_mode_setup;
+% ---
+def write_paths(expr name) =
+ find_BB elem_path1;
+ write_preamble name;
+ for i:=1 upto objects:
+ coeff:=
+ if objects=1: 0 else: .5(1-cosd(((i-1)/(objects-1))[alpha1,alpha2])) fi;
+ fix_fill_cmyk forsuffixes $:=cyan, magenta, yellow: coeff[$1,$2], endfor
+ coeff[black1,black2];
+ fill_C elem_path[i];
+ endfor;
+ write_postamble;
+enddef;
+% ---
+ch_max:=3;
+% ---
+for ch:=0 upto ch_max:
+ beginchar(char(ASCII("a")+ch), 1in#, 1in#, 0);
+ path elem_path[\\];
+ objects:=100; transitions:=.5; % regular 2
+ sca1:=w; sca2:=.05w;
+ rot1:=0; rot2:=(ch/ch_max)[0,-360];
+ alpha1:=0; alpha2:=transitions*360;
+ cyan1:=0; magenta1:=0; yellow1:=0; black1:=0.05;
+ cyan2:=0; magenta2:=0; yellow2:=0; black2:=0.9;
+ for i:=1 upto objects:
+ coeff:=if objects=1: 0 else: (i-1)/(objects-1) fi;
+ elem_path[i]:= flex_polygon(6,(coeff**.1)[-30,0],(coeff**.1)[30,0])
+ scaled (coeff[sca1,sca2])
+ rotated (coeff[rot1,rot2]+30) shifted (.5w,.5h);
+ endfor
+ write_paths(jobname & char(ASCII("a")+ch));
+ endchar;
+endfor
+% ---
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/sample5.mf b/graphics/MF-PS/mftoeps/m2esamp/sample5.mf
new file mode 100644
index 0000000000..c7e0c7742b
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/sample5.mf
@@ -0,0 +1,38 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% SAMPLE5.MF
+% ---
+input mftoeps;
+input polygons;
+eps_mode_setup;
+% ---
+def soft_polygon (expr n,a) = flex_polygon(n,a-180/n,a+180/n) enddef;
+% ---
+def write_paths(expr name) =
+ find_BB for i:=1 upto objects: elem_path[i], endfor elem_path[objects];
+ write_preamble name;
+ fix_line_width .2pt; for i:=1 upto objects: draw_C elem_path[i]; endfor;
+ write_postamble;
+enddef;
+% ---
+ch_max:=3;
+% ---
+for ch:=0 upto ch_max:
+ beginchar(char(ASCII("a")+ch), 1in#, 1in#, 0);
+ path elem_path[\\];
+ objects:=17;
+ sca1:=.85w; sca2:=.02w;
+ rot1:=0; rot2:=(ch/ch_max)[5,120];
+ skew1:=(ch/ch_max)[60,30]; skew2:=0;
+ for i:=1 upto objects:
+ coeff:=if objects=1: 0 else: (i-1)/(objects-1) fi;
+ elem_path[i]:= soft_polygon(7,coeff[skew1,skew2])
+ scaled (coeff[sca1,sca2]) rotated (coeff[rot1,rot2]+30) shifted (.5w,.5h);
+ endfor
+ write_paths(jobname & char(ASCII("a")+ch));
+ endchar;
+endfor
+% ---
+end.
diff --git a/graphics/MF-PS/mftoeps/m2esamp/stereo.mf b/graphics/MF-PS/mftoeps/m2esamp/stereo.mf
new file mode 100644
index 0000000000..c3e85ec53f
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/m2esamp/stereo.mf
@@ -0,0 +1,53 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+% ---
+% STEREO.MF
+% ---
+input mftoeps;
+input polygons;
+eps_mode_setup;
+% ---
+def soft_polygon (expr n,a) = flex_polygon(n,a-180/n,a+180/n) enddef;
+% ---
+def write_paths(expr name) =
+ find_BB for i:=1 upto objects: elem_path[i], endfor elem_path[objects];
+ write_preamble name;
+ for i:=1 upto objects:
+ coeff:=
+ if objects=1: 0 else: .5(1-cosd(((i-1)/(objects-1))[alpha1,alpha2])) fi;
+ coeff:=if coeff>.5: 1 else: 0 fi;
+ fix_fill_cmyk forsuffixes $:=cyan, magenta, yellow: coeff[$1,$2], endfor
+ coeff[black1,black2];
+ fill_C elem_path[i];
+ endfor;
+ write_postamble;
+enddef;
+% ---
+for ch:=0,1:
+ beginchar("0",117pt#, 117pt#, 0);
+ path elem_path[\\];
+ objects:=100; transitions:=7;
+ pair cent[\\];
+ sca1:=.5w; sca2:=.01w;
+ skew1:=60; skew2:=0;
+ alpha1:=0; alpha2:=transitions*360;
+ cshift0:=-.02w; cshift1:=-cshift0;
+ cent1:=(.5w,.5h);
+ rot1:=0; rot2:=rot1+60;
+ cent2:=(.5w+cshift[ch],.49h);
+ cyan1:=0; magenta1:=0; yellow1:=0; black1:=1;
+ cyan2:=0; magenta2:=0; yellow2:=0; black2:=0;
+ for i:=1 upto objects:
+ if objects=1: coeff:=0; else: coeff:=(i-1)/(objects-1); fi
+ elem_path[i]:= soft_polygon(4,coeff[skew1,skew2])
+ scaled (coeff[sca1,sca2])
+ rotated (coeff[rot1,rot2]+30)
+ shifted (coeff[cent1,cent2]);
+ endfor
+ write_paths(jobname & decimal(ch));
+endchar;
+
+endfor
+
+end.
diff --git a/graphics/MF-PS/mftoeps/mftoeps.mf b/graphics/MF-PS/mftoeps/mftoeps.mf
new file mode 100644
index 0000000000..46bc5a1cb9
--- /dev/null
+++ b/graphics/MF-PS/mftoeps/mftoeps.mf
@@ -0,0 +1,748 @@
+%%%%
+%%%% This file belongs to the MFTOEPS package.
+%%%%
+%%% mod div
+%%% length cycle pos_turn neg_turn
+%%% endchar ori_endchar
+%%% draw eofill killtext
+%%% draw find_BB set_BB reset_BB
+%%% draw draw_C normal_draw_C no_export_draw_C
+%%% draw fill_C normal_fill_C no_export_fill_C
+%%% draw clip_C normal_clip_C
+%%% draw write_preamble normal_write_preamble no_export_write_preamble
+%%% endchar write_postamble normal_write_postamble no_export_write_postamble
+%%% endchar g_save g_restore
+%%% message write_PS normal_write_PS
+%%% draw write_def
+%%% draw fix_line_width set_line_width
+%%% draw fix_line_join set_line_join fix_line_cap set_line_cap
+%%% draw fix_miter_limit set_miter_limit fix_dash set_dash
+%%% draw fix_fill_cmyk set_fill_cmyk fix_draw_cmyk set_draw_cmyk
+%%% draw fix_fill_rgb set_fill_rgb fix_draw_rgb set_draw_rgb
+%%% xpart norm_color
+%%% mode_setup ori_mode_setup eps_mode_setup EPS_mode_setup
+%%% draw mftoeps_default
+%%\vsize245mm
+%%\font\titfnt cmtt10 at 48 pt
+%%{\let\makefootline\empty \let\makeheadline\empty
+%%\vglue0ptplus1fill
+%%\centerline{\titfnt MFTOEPS.MF}
+%%\bigskip
+%%\centerline{ver. 0.68 (Tuesday, March 4th, 1997)}
+%%\vfill\vfill\eject}
+% ---
+% \MF format for exporting to EPS via LOG-file + AWK-like utility
+% ---
+% NAME: MFTOEPS.MF
+% AUTHORS: B. Jackowski, P. Pianowski, M. Ry\'cko
+% HISTORY:
+% Version 0.5 (Friday, May 5th, 1995): first public domain release
+% Version 0.6 (Thursday, July 27th, 1995): major revision
+% * macro |reset_BB| added (it was silly not to have it)
+% * |pickup pencircle scaled 0.4pt| performed by |no_export_write_preamble|
+% * `mftoeps_bhook' and `mftoeps_ehook' introduced
+% * `setlinecap', `setlinejoin', `setmiterlimit', and `setdash' included
+% * switching between no export and compatibility modes made more tidy
+% * colours are forced to fall into the interval [0..1]
+% * formatting, comments and internal naming altered
+% Version 0.65 (Friday, September 1st, 1995):
+% A lot of small changes introduced introduced during the work over
+% PSTOEPS and EPSTOMF converters, and over ROEX macros:
+% * defaults for line joins and caps changed (WARNING: incompatibility
+% with the version 0.6 described in proceedings of 9th European \TeX
+% Conference, Arnhem, Holland); now they are compatible with PostScript,
+% not with our predilections
+% * `gsave'/`grestore' grouping added (macros |g_save| and |g_restore|);
+% the graphic object is embedded into a `gsave'/`grestore' pair
+% * |set_BB| and |find_BB| available also in no-export mode
+% * string variable |extra_eps_setup| added
+% * a general purpose macro |make_list| added
+% * version number appears in the header of EPS file
+% * |reset_BB| performed by newly introduced |no_export_write_postamble|
+% * definitions of EPS header more robust
+% * macros |pos_turn|, |neg_turn|, and |is_line| more robust
+% * global defaults defined as in ROEX (macro |mftoeps_default|)
+% * code optimized, formatting slightly altered (e.g., the underscore
+% character ending a name appears as a superscript asterisk)
+% This version was released during the 9th EuroTeX meeting in Arnhem
+% Version 0.66 (Tuesday, September 19th, 1995):
+% * |find_BB| a bit more robust
+% * |is_line| is exactly the same as in ROEX.MF (it should have been
+% in version 0.65...)
+% This version was released during the CyrTUG-95 meeting in Moscow
+% Version 0.67 (Friday, October 27th, 1995):
+% * |miter_limit| used to be a dimen; it was my mistake (BJ),
+% in PostScript it is a dimensionless quantity
+% Version 0.68 (Tuesday, March 4th, 1997):
+% * |extra_preamble| and |extra_postamble| added
+% ---
+if known mftoeps: expandafter endinput fi % no double loading
+mftoeps:=1;
+vardef mftoeps_ver ="0.68" enddef;
+% ---
+% DECLARATIONS (only explicitly needed):
+no_export_level=0; compatibility_level=1; % constants
+let ori_mode_setup=mode_setup;
+let ori_endchar=endchar;
+boolean closed_path; % set by |normal_fill_C|, |normal_draw_C|,
+ % |close_op|, and just before writing definitions
+ % of |mid_draw_op|; checked by |mid_draw_op|;
+boolean dash_array_empty; % used locally by |set_dash|
+boolean known_yes_eps; % used by |eps_mode_setup|
+string extra_eps_setup; % used by |eps_mode| for last-minute adjustments
+extra_eps_setup=""; % usually there's nothing special to do
+string extra_preamble, extra_postamble; % for special comments and/or defs
+extra_preamble=extra_postamble=""; % usually there's nothing special to add
+% We follow the naming convention of The \MF{}book:
+% ``Private tokens always end with the underscore character.''
+% Since the underscore is a rather illegible character, in a ``neat''
+% printing (using MFT utility) it will appear as an superscript asterisk.
+%% % an innocent formatting trick: the underscore character ending a name
+%% % will be typeset as an superscript asterisk
+%% \let\oriunderscore\_
+%% \newif\ifbgroupopen \bgroupopenfalse
+%% \def\altdblbackslash#1{\bgroup\bgroupopentrue\it#1}
+%% \def\optegroup{\ifbgroupopen\egroup\fi}
+%% \def\underscoreasasterisk#1{%
+%% \ifx#1\relax\optegroup^*\else\oriunderscore#1\fi}
+%% \def\\#1{%
+%% \let\_\underscoreasasterisk
+%% \altdblbackslash{#1\relax}\optegroup
+%% \let\_\oriunderscore}
+% ---
+def make_list(expr k,l) suffix s =
+ for i_:=k upto l: if i_>k: , fi \\ s[i_] endfor
+enddef;
+% ---
+vardef distance(expr za,zb) = length(za-zb) enddef; % in fact, an alias
+% ---
+vardef pos_turn primary p =
+ interim autorounding:=0;
+ if check_turn(p)=0: show p;
+ errhelp "I will leave the path intact, continue with crossed fingers.";
+ errmessage "Cannot make positive turn (check_turn=0)";
+ elseif check_turn(p)<0: reverse fi \\ p
+enddef;
+% ---
+vardef neg_turn primary p =
+ interim autorounding:=0;
+ if check_turn(p)=0: show p;
+ errhelp "I will leave the path intact, continue with crossed fingers.";
+ errmessage "Cannot make negative turn (check_turn=0)";
+ elseif check_turn(p)>0: reverse fi \\ p
+enddef;
+% ---
+vardef check_turn primary p = % seems more adequate than |turningnumber|
+% |epsilon|=|totalweight currentpicture| after |fill unitsquare|,
+% |eps/epsilon=32|, i.e., we admit accuracy of 32 pixels (isn't it too many?)
+ save r_,currentpicture; picture currentpicture;
+ interim turningcheck:=0; interim autorounding:=0;
+ currentpicture:=nullpicture; fill p; r_:=totalweight(currentpicture);
+ if r_>eps: 1 elseif r_<-eps: -1 else: turningnumber(p) fi
+enddef;
+% ---
+vardef is_line(expr B) =
+% checks if a B\'ezier segment |B| is an almost straight line;
+% recall that |z reflectedabout (origin,right)=1/z| for a complex
+% number |z| such that |length(z)=1|; recall also that the multiplication
+% of complex numbers (|zscale| operation) implies the addition of
+% their angle arguments
+ save pa_,pb_,pc_,pd_,ba_,da_,dc_; pair pa_,pb_,pc_,pd_,ba_,da_,dc_;
+ pa_:=point 0 of B; pd_:=point 1 of B;
+ if distance(pa_,pd_)<epsil.dist:
+ false % either really not a line or an uncertain situation (rounding errors)
+ else:
+ da_=unitvector(pd_-pa_) reflectedabout (origin,right);
+ pb_:=postcontrol 0 of B; if distance(pa_,pb_)<epsil.dist: pb_:=pa_; fi
+ pc_:=precontrol 1 of B; if distance(pd_,pc_)<epsil.dist: pc_:=pd_; fi
+ if (pa_=pb_) and (pc_=pd_): true
+ elseif (pa_=pb_):
+ dc_=unitvector(pd_-pc_); abs(angle(dc_ zscaled da_))<epsil.ang
+ elseif (pc_=pd_):
+ ba_=unitvector(pb_-pa_); abs(angle(ba_ zscaled da_))<epsil.ang
+ else:
+ ba_=unitvector(pb_-pa_); dc_=unitvector(pd_-pc_);
+ (abs(angle(ba_ zscaled da_))<epsil.ang)
+ and (abs(angle(dc_ zscaled da_))<epsil.ang)
+ fi
+ fi
+enddef;
+% ---
+def eofill expr P =
+ begingroup save pp_; picture pp_;
+ interim turningcheck:=0;
+% the following |addto|s are supposed to fill disjoint areas:
+ pp_:=nullpicture; addto pp_ contour P.t_;
+ cull pp_ keeping (1,infinity); addto currentpicture also pp_;
+ pp_:=nullpicture; addto pp_ contour reverse P.t_;
+ cull pp_ keeping (1,infinity); addto currentpicture also pp_;
+ cull currentpicture keeping(1,1);
+ endgroup
+enddef;
+% ---
+def normal_write_PS expr s = if s<>"": message ":PS: " & s; fi enddef;
+% ---
+def write_P (expr op,P) =
+% writes a point |P| in PostScript, followed by the operation |op|
+ write_PS bp_pair(P) & op;
+enddef;
+% ---
+def write_B (expr op,B) =
+% writes a B\'ezier segment |B| in PostScript, followed by the operation |op|
+ write_PS bp_pair(postcontrol 0 of B) & bp_pair(precontrol 1 of B) &
+ bp_pair(point 1 of B) & op;
+enddef;
+% ---
+def write_L (expr op,L) =
+% writes a line |L| in PostScript, followed by the operation |op|
+ write_PS bp_pair(point 1 of L) & op;
+enddef;
+% ---
+vardef write_C (expr C) =
+% writes a B\'ezier curve |C| in PostScript followed by an operation
+% which depends on whether |C| is cyclic or not
+ save ll_;
+ ll_:= % |(length(C)-ll_,length(C)-ll_+1)| is the last segment processed
+ if (cycle C) and ((point length(C) of C) = (point length(C)-1 of C)):
+ 2 % artificial situation related to an old EPS2MF converter
+ else: 1 fi;
+ write_P(move_op,point 0 of C);
+ for tt_:=0 upto length(C)-ll_:
+ if is_line(subpath (tt_,tt_+1) of C):
+ write_L(line_op,subpath (tt_,tt_+1) of C);
+ else:
+ write_B(bezi_op,subpath (tt_,tt_+1) of C);
+ fi
+ endfor
+ if cycle C: write_PS close_op; fi
+enddef;
+% ---
+def no_export_fill_C text t =
+ begingroup
+ save rr_; picture rr_; % must not be |pp_| (see |eofill|)
+ begingroup
+ save currentpicture; def currentpicture = rr_ enddef; % danger!
+ currentpicture:=nullpicture; for qq_:=t: eofill qq_; endfor
+ endgroup;
+ addto currentpicture also rr_; cullit;
+ endgroup
+enddef;
+% ---
+def normal_fill_C text t =
+ write_PS beg_path_op;
+ set_fill_cmyk;
+ for pp_:=t:
+ write_C(pp_); write_PS mid_fill_op; closed_path:=false;
+ endfor
+ write_PS end_path_op;
+enddef;
+% ---
+def no_export_draw_C text t = for pp_:=t: draw pp_; endfor enddef;
+% ---
+def normal_draw_C text t =
+ write_PS beg_path_op;
+ set_draw_cmyk; set_line_width;
+ set_line_join; set_line_cap;
+ set_miter_limit; set_dash;
+ for pp_:=t:
+ write_C(pp_); write_PS mid_draw_op; closed_path:=false;
+ endfor
+ write_PS end_path_op;
+enddef;
+% ---
+def normal_clip_C text t =
+ clipping_count:=0; % local
+ for pp_:=t: clipping_count:=clipping_count+1; endfor
+ if clipping_count=0:
+ if clipping_level>0: g_restore; clipping_level:=clipping_level-1; fi
+ else:
+ clipping_level:=clipping_level+1; g_save;
+ write_PS beg_path_op;
+ for pp_:=t: write_C(pp_); write_PS mid_clip_op; endfor
+ write_PS end_path_op;
+ fi
+enddef;
+% ---
+vardef update_BC(expr C)(suffix xl,yl,xh,yh) =
+% updates variables |xl|, |yl|, |xh|, |yh| by finding extremal points
+% of a B\'ezier curve |C|
+ if xl>xpart(point 0 of C): xl:=xpart(point 0 of C); fi
+ if xh<xpart(point 0 of C): xh:=xpart(point 0 of C); fi
+ if yl>ypart(point 0 of C): yl:=ypart(point 0 of C); fi
+ if yh<ypart(point 0 of C): yh:=ypart(point 0 of C); fi
+ for tt_:=0 upto length(C)-1:
+ update_BB(subpath (tt_,tt_+1) of C,xl,yl,xh,yh);
+ endfor
+enddef;
+% ---
+vardef update_BB(expr B) (suffix xl,yl,xh,yh) =
+% updates variables |xl|, |yl|, |xh|, |yh| by finding extremal points
+% of a B\'ezier segment |B|; the |point 0 of B| is not taken into account
+ save Bx_,By_,ta_,tb_,vv_; path Bx_, By_; numeric ta_,tb_,vv_;
+%
+ Bx_=(0,xpart(point 0 of B))
+ ..controls
+ (0,xpart(postcontrol 0 of B)) and (1000,xpart(precontrol 1 of B))
+ ..(1000,xpart(point 1 of B));
+ By_=(0,ypart(point 0 of B))
+ ..controls
+ (0,ypart(postcontrol 0 of B)) and (1000,ypart(precontrol 1 of B))
+ ..(1000,ypart(point 1 of B));
+%
+ ta_:=directiontime right of Bx_;
+ if ta_>0:
+ vv_:=ypart (point ta_ of Bx_);
+ if vv_<xl: xl:=vv_; fi\\ if vv_>xh: xh:=vv_; fi
+ tb_:=directiontime right of subpath (ta_+eps,1) of Bx_;
+ if tb_>=0:
+ vv_:=ypart (point tb_ of (subpath (ta_+eps,1) of Bx_));
+ if vv_<xl: xl:=vv_; fi\\ if vv_>xh: xh:=vv_; fi
+ fi
+ fi
+ vv_:=ypart (point 1 of Bx_); if vv_<xl: xl:=vv_; fi\\ if vv_>xh: xh:=vv_; fi
+%
+ ta_:=directiontime right of By_;
+ if ta_>0:
+ vv_:=ypart (point ta_ of By_);
+ if vv_<yl: yl:=vv_; fi\\ if vv_>yh: yh:=vv_; fi
+ tb_:=directiontime right of subpath (ta_+eps,1) of By_;
+ if tb_>=0:
+ vv_:=ypart (point tb_ of (subpath (ta_+eps,1) of By_));
+ if vv_<yl: yl:=vv_; fi\\ if vv_>yh: yh:=vv_; fi
+ fi
+ fi
+ vv_:=ypart (point 1 of By_); if vv_<yl: yl:=vv_; fi\\ if vv_>yh: yh:=vv_; fi
+enddef;
+% ---
+% |xl|, |yl|, |xh|, and |yh| can likely be used in a program, hence
+% longer names: |xl_crd|, |yl_crd|, |xh_crd|, and |yh_crd|, respectively
+def reset_BB =
+ xl_crd:=whatever; yl_crd:=whatever; xh_crd:=whatever; yh_crd:=whatever;
+enddef;
+% ---
+def find_BB text t =
+ for CC_:=t: % |t| may be empty
+ if unknown xl_crd: xl_crd=yl_crd=-xh_crd=-yh_crd=infinity; fi
+ update_BC(CC_)(xl_crd,yl_crd,xh_crd,yh_crd);
+ endfor
+enddef;
+% ---
+vardef llxy = (xl_crd,yl_crd) enddef;
+vardef urxy = (xh_crd,yh_crd) enddef;
+% ---
+def set_BB text t =
+% it may happen that |t| refers to the previously fixed coordinates of the
+% bounding box, therefore the coordinates should not be changed too early
+ numeric xl_crd_, yl_crd_, xh_crd_, yh_crd_;
+ for rr_:=t: % syntax trick
+ if pair rr_:
+ for ss_:=xpart rr_, ypart rr_:
+ if unknown xl_crd_: xl_crd_:=ss_;
+ elseif unknown yl_crd_: yl_crd_:=ss_;
+ elseif unknown xh_crd_: xh_crd_:=ss_;
+ elseif unknown yh_crd_: yh_crd_:=ss_;
+ fi
+ endfor
+ else:
+ if unknown xl_crd_: xl_crd_:=rr_;
+ elseif unknown yl_crd_: yl_crd_:=rr_;
+ elseif unknown xh_crd_: xh_crd_:=rr_;
+ elseif unknown yh_crd_: yh_crd_:=rr_;
+ fi
+ fi
+ endfor
+ numeric xl_crd, yl_crd, xh_crd, yh_crd;
+ xl_crd:=xl_crd_; yl_crd:=yl_crd_; xh_crd:=xh_crd_; yh_crd:=yh_crd_;
+enddef;
+% ---
+% somewhat unusual formula was employed in the definition of |bp_num|
+% because |(72/300)*x| is not equivalent to |72/300x|: the latter yields
+% better accuracy
+vardef bp_num primary x =
+ decimal(scantokens("72/" & decimal(pixels_per_inch))x)
+enddef;
+vardef bp_pair primary z =
+ bp_num(xpart(z)) & " " & bp_num(ypart(z)) & " "
+enddef;
+% ---
+mode_def eps_mode =
+ proofing:=0; % no, we're not making proofs
+ fontmaking:=0; % no, we're not making a TFM file
+ tracingtitles:=1; % yes, show titles online
+ pixels_per_inch:=300; % standard laser printer resolution
+ blacker:=0; % no additional blackness
+ fillin:=0; % no compensation for fillin
+ o_correction:=1; % no reduction in overshoot
+ mag:=1; % standard magnification
+ autorounding:=0; % removing pimples is unimportant
+ scantokens extra_eps_setup; % the user's special last-minute adjustments
+enddef;
+% ---
+mode_def vicar_mode =
+ proofing:=0; % no, we're not making proofs
+ fontmaking:=0; % no, we're not making a TFM file
+ tracingtitles:=1; % yes, show titles online
+ pixels_per_inch:=300; % standard laser printer resolution
+ blacker:=0; % no additional blackness
+ fillin:=0; % no compensation for fillin
+ o_correction:=1; % no reduction in overshoot
+ mag:=1; % standard magnification
+enddef;
+% ---
+def EPS_mode_setup = eps_mode_setup enddef; % an alias (upward compatibility)
+def eps_mode_setup suffix e_l =
+% fixing |export_level|:
+ known_yes_eps:=(known yesEPS) or (known YESEPS) or (known yeseps);
+ if not known_yes_eps: export_level:=no_export_level;
+ elseif str e_l="": export_level:=compatibility_level;
+ else:
+ if
+ (if known e_l:
+ (e_l=no_export_level) or (e_l=compatibility_level)
+ else:
+ false
+ fi):
+ export_level:=e_l;
+ else:
+ message "Default export level assumed.";
+ export_level:=compatibility_level;
+ fi
+ fi
+% |mode_setup| hackery (last chance to abandon exporting):
+ if export_level<>no_export_level:
+ if not (string mode): mode:=vicar_mode; fi % for hackers only
+ mode_setup; % trial setup
+ if proofing>0: export_level:=no_export_level; fi % proofing has priority
+ fi
+% now either |export_level=no_export_level|
+% or |export_level=compatibility_level):
+ if export_level=no_export_level:
+ let mode_setup=ori_mode_setup; mode_setup;
+ let endchar=ori_endchar;
+ let write_PS=killtext;
+ let write_preamble=no_export_write_preamble;
+ let write_postamble=no_export_write_postamble;
+ let fill_C=no_export_fill_C;
+ let draw_C=no_export_draw_C;
+ let clip_C=killtext;
+ else: % |error_level=compatibility_level|
+ if not (string mode): mode:=eps_mode; fi % for hackers only
+ mode_setup; % set private mode
+ let mode_setup=relax; % no more |mode_setup|s
+ def endchar = % no shipping characters out
+ scantokens extra_endchar; endgroup
+ enddef;
+ let write_PS=normal_write_PS;
+ let write_preamble=normal_write_preamble;
+ let write_postamble=normal_write_postamble;
+ let fill_C=normal_fill_C;
+ let draw_C=normal_draw_C;
+ let clip_C=normal_clip_C;
+ fi
+enddef;
+% ---
+def plain_new_path_op = "newpath" enddef;
+def plain_close_op = "closepath" enddef;
+def plain_move_op = "moveto" enddef;
+def plain_line_op = "lineto" enddef;
+def plain_bezi_op = "curveto" enddef;
+def plain_fill_op = "eofill" enddef;
+def plain_draw_op = "stroke" enddef;
+def plain_clip_op = "eoclip" enddef;
+def plain_set_line_width_op = "setlinewidth" enddef;
+def plain_set_fill_cmyk_op = "setcmykcolor" enddef;
+def plain_set_draw_cmyk_op = "setcmykcolor" enddef;
+def plain_set_line_join_op = "setlinejoin" enddef;
+def plain_set_line_cap_op = "setlinecap" enddef;
+def plain_set_miter_limit_op = "setmiterlimit" enddef;
+def plain_set_dash_op = "setdash" enddef;
+def plain_g_save_op = "gsave" enddef;
+def plain_g_restore_op = "grestore" enddef;
+% ---
+% there is some inconsistency between Corel and AI (it could be said that
+% even between Corel and Corel, and between AI and AI), therefore the code
+% for filling, drawing and clipping operations is somewhat messy...
+% ---
+def close_op = begingroup closed_path:=true; "" endgroup enddef;
+def close_path_op = "h" enddef;
+def move_op = "m" enddef;
+def line_op = "l" enddef;
+def bezi_op = "c" enddef;
+def beg_path_op = "*u" enddef;
+def end_path_op = "*U" enddef;
+let beg_fill_op=beg_path_op;
+def mid_fill_op = "f" enddef;
+def end_fill_op = "*U*f" enddef;
+let beg_draw_op=beg_path_op;
+def mid_draw_op = if closed_path: "s" else: "S" fi enddef;
+def end_draw_op = "*U*d" enddef;
+let beg_clip_op=beg_path_op;
+def prep_clip_op = "W" enddef; % AI-oriented, here just empty
+def do_clip_op = "n" enddef;
+def mid_clip_op =
+ close_path_op & " " & prep_clip_op & " " & do_clip_op
+enddef;
+def end_clip_op = "*U*c" enddef;
+def set_line_width_op = "w" enddef;
+def set_fill_cmyk_op = "k" enddef;
+def set_draw_cmyk_op = "K" enddef;
+def set_line_join_op = "j" enddef;
+def set_line_cap_op = "J" enddef;
+def set_miter_limit_op = "M" enddef;
+def set_dash_op = "d" enddef;
+def g_save_op = "q" enddef;
+def g_restore_op = "Q" enddef;
+% ---
+def mark_null = "/oper_kind -1 def" enddef;
+def mark_fill = "/oper_kind 0 def" enddef;
+def mark_draw = "/oper_kind 1 def" enddef;
+def mark_clip = "/oper_kind 2 def" enddef;
+def check_fill = "0 oper_kind eq" enddef;
+def check_draw = "1 oper_kind eq" enddef;
+def check_clip = "2 oper_kind eq" enddef;
+% ---
+def write_def(expr p,q) =
+ if p<>"": write_PS "/" & p & " {" & q & "} def"; fi
+enddef;
+% ---
+def no_export_write_preamble expr s = pickup pencircle scaled 0.4pt; enddef;
+def normal_write_preamble expr s =
+ message "generating " & s & ".eps";
+ if unknown testing:
+ batchmode; % don't write mess to the terminal
+ fi
+ message ":EPS FILE NAME: " & s;
+ write_PS "%!PS-Adobe-2.0 EPSF-2.0";
+ write_PS "%%Creator: MFTOEPS ver. " & mftoeps_ver;
+ if (known xl_crd) and (known yl_crd) and (known xh_crd) and (known yh_crd):
+ write_PS "%%BoundingBox: " & bp_num(xl_crd) & " " & bp_num(yl_crd)
+ & " " & bp_num(xh_crd) & " " & bp_num(yh_crd);
+ else:
+ xl_crd:=0; xh_crd:=72bp; yl_crd:=0; yh_crd:=72bp;
+ if unknown testing:
+ errorstopmode; % switch temporarily to the usual mode
+ fi
+ message "Unknown bounding box (0 0 72 72 assumed)";
+ if unknown testing:
+ batchmode; % again don't write mess to the terminal
+ fi
+ write_PS "%%BoundingBox: 0 0 72 72";
+ fi
+ write_PS "%%Title: " & s & ".eps";
+ write_PS "%%CreationDate: " & decimal(day) & "." if month<10: & "0" fi
+ & decimal(month) & "." & decimal(year) & " " & decimal(time div 60)
+ & ":" if (time mod 60)<10: & "0" fi & decimal(time mod 60);
+ write_PS "%%DocumentStyle: compatibility "
+ & "(CorelDRAW! & Adobe Illustrator oriented)";
+ write_PS "%%DocumentFonts:";
+ write_PS "%%EndComments";
+ write_PS "%%BeginProlog";
+ write_PS "/mftoeps_export 100 dict def % you may wish to add some entries";
+ write_PS "mftoeps_export begin";
+ write_def (close_op,plain_close_op);
+ write_def (close_path_op,plain_close_op);
+ write_def (move_op,plain_move_op);
+ write_def (bezi_op,plain_bezi_op);
+ write_def (line_op,plain_line_op);
+ write_def (set_fill_cmyk_op,plain_set_fill_cmyk_op);
+ write_def (set_draw_cmyk_op,plain_set_draw_cmyk_op);
+ write_def (beg_path_op,mark_null);
+ write_def (end_path_op,
+ end_fill_op & " " & end_draw_op & " " & end_clip_op);
+ write_def (mid_fill_op,mark_fill);
+ write_def (end_fill_op,check_fill & " {" & plain_fill_op & "} if")
+ closed_path:=true;
+ write_def (mid_draw_op, plain_close_op & " " & mark_draw);
+ closed_path:=false;
+ write_def (mid_draw_op, mark_draw);
+ write_def (end_draw_op,check_draw & " {" & plain_draw_op & "} if")
+ write_def (prep_clip_op,"");
+ write_def (do_clip_op, mark_clip);
+ write_def (end_clip_op,check_clip &
+ " {" & plain_clip_op & " " & plain_new_path_op & "} if");
+ write_def (set_line_width_op,plain_set_line_width_op);
+ write_def (set_line_join_op,plain_set_line_join_op);
+ write_def (set_line_cap_op,plain_set_line_cap_op);
+ write_def (set_miter_limit_op,plain_set_miter_limit_op);
+ write_def (set_dash_op,plain_set_dash_op);
+ write_PS "/setcmykcolor where {pop}";
+ write_PS " {/setcmykcolor {1 sub /mf exch def";
+ write_PS " 3 {mf add neg dup 0 lt {pop 0} if 3 1 roll} repeat";
+ write_PS " setrgbcolor} def} ifelse";
+ write_def (g_save_op,plain_g_save_op);
+ write_def (g_restore_op,plain_g_restore_op);
+ write_PS "/mftoeps_bhook where {pop mftoeps_bhook} {} ifelse";
+ scantokens extra_preamble;
+ write_PS "%%EndProlog";
+ write_PS "%%BeginSetup"; % important structural comment
+ write_PS "%%EndSetup"; % ditto
+ g_save;
+ fix_line_width 0.4pt;
+ fix_fill_cmyk 0,0,0,1;
+ fix_draw_cmyk 0,0,0,1;
+ fix_line_join default_line_join;
+ fix_line_cap default_line_cap;
+ fix_miter_limit default_miter_limit;
+ clipping_level:=0;
+ fix_dash () 0;
+enddef;
+% ---
+def no_export_write_postamble = reset_BB; enddef;
+def normal_write_postamble =
+ forever: exitif clipping_level=0; clip_C; endfor
+ g_restore;
+ write_PS "%%Trailer";
+ write_PS "/mftoeps_ehook where {pop mftoeps_ehook} {} ifelse";
+ scantokens extra_postamble;
+ write_PS "end showpage";
+ if unknown testing:
+ errorstopmode; % switch to the usual mode
+ fi
+ message "";
+ reset_BB;
+enddef;
+% ---
+def g_save = write_PS g_save_op enddef;
+def g_restore = write_PS g_restore_op enddef;
+% ---
+def fix_dash (text t) expr x =
+ def current_dash_array = t enddef; current_dash_offset:=x;
+enddef;
+def set_dash =
+ dash_array_empty:=true;
+ write_PS "["
+ for dash_array:=current_dash_array: if not dash_array_empty: & " " fi
+ & hide(dash_array_empty:=false) bp_num(dash_array)
+ endfor
+ & "] " & bp_num(current_dash_offset) & " " & set_dash_op;
+enddef;
+% ---
+def fix_line_width expr p =
+ current_line_width:=max(p,0); pickup pencircle scaled current_line_width;
+enddef;
+def set_line_width =
+ write_PS bp_num(if known current_line_width: current_line_width
+ else: .5[pen_rt-pen_lft,pen_top-pen_bot] fi) & " " & set_line_width_op;
+enddef;
+% ---
+def fix_line_join expr p =
+ current_line_join:=
+ if (round(p)<0) or (round(p)>2): default_line_join else: round(p) fi;
+enddef;
+def set_line_join =
+ write_PS decimal(if known current_line_join: current_line_join
+ else: default_line_join fi) & " " & set_line_join_op;
+enddef;
+% ---
+def fix_line_cap expr p =
+ current_line_cap:=
+ if (round(p)<0) or (round(p)>2): default_line_cap else: round(p) fi;
+enddef;
+def set_line_cap =
+ write_PS decimal(if known current_line_cap: current_line_cap
+ else: default_line_cap fi) & " " & set_line_cap_op;
+enddef;
+% ---
+def fix_miter_limit expr p =
+ current_miter_limit:=if p<1: default_miter_limit else: p fi;
+enddef;
+def set_miter_limit =
+ write_PS decimal(if known current_miter_limit: current_miter_limit
+ else: default_miter_limit fi) & " " & set_miter_limit_op;
+enddef;
+% ---
+def set_fill_cmyk =
+ write_PS decimal(fill_cyan) & " " & decimal(fill_magenta) &
+ " " & decimal(fill_yellow) & " " & decimal(fill_black) & " " &
+ set_fill_cmyk_op;
+enddef;
+def set_draw_cmyk =
+ write_PS decimal(draw_cyan) & " " & decimal(draw_magenta) &
+ " " & decimal(draw_yellow) & " " & decimal(draw_black) & " " &
+ set_draw_cmyk_op;
+enddef;
+% ---
+vardef norm_color expr c = min(1,max(0,c)) enddef;
+def fix_fill_cmyk text t = % syntax trick
+ fill_cyan:=whatever; fill_magenta:=whatever;
+ fill_yellow:=whatever; fill_black:=whatever;
+ for vv_:=t:
+ if unknown fill_cyan: fill_cyan:=norm_color vv_;
+ elseif unknown fill_magenta: fill_magenta:=norm_color vv_;
+ elseif unknown fill_yellow: fill_yellow:=norm_color vv_;
+ elseif unknown fill_black: fill_black:=norm_color vv_;
+ fi
+ endfor
+enddef;
+def fix_draw_cmyk text t = % syntax trick
+ draw_cyan:=whatever; draw_magenta:=whatever;
+ draw_yellow:=whatever; draw_black:=whatever;
+ for vv_:=t:
+ if unknown draw_cyan: draw_cyan:=norm_color vv_;
+ elseif unknown draw_magenta: draw_magenta:=norm_color vv_;
+ elseif unknown draw_yellow: draw_yellow:=norm_color vv_;
+ elseif unknown draw_black: draw_black:=norm_color vv_;
+ fi
+ endfor
+enddef;
+% ---
+def fix_fill_rgb text t = % syntax trick
+ begingroup
+ save R_,G_,B_;
+ for vv_:=t:
+ if unknown R_: R_:=norm_color vv_;
+ elseif unknown G_: G_:=norm_color vv_;
+ elseif unknown B_: B_:=norm_color vv_;
+ fi
+ endfor
+ convert_rgb_to_cmyk(R_,G_,B_)
+ (fill_cyan, fill_magenta, fill_yellow, fill_black);
+ endgroup
+enddef;
+def fix_draw_rgb text t = % syntax trick
+ begingroup
+ save R_,G_,B_;
+ for vv_:=t:
+ if unknown R_: R_:=norm_color vv_;
+ elseif unknown G_: G_:=norm_color vv_;
+ elseif unknown B_: B_:=norm_color vv_;
+ fi
+ endfor
+ convert_rgb_to_cmyk(R_,G_,B_)
+ (draw_cyan, draw_magenta, draw_yellow, draw_black);
+ endgroup
+enddef;
+% ---
+def convert_rgb_to_cmyk (expr R,G,B)(suffix C,M,Y,K) =
+ begingroup
+ save C_,M_,Y_,K_; C_:=1-R; M_:=1-G; Y_:=1-B; K_:=min(C_,M_,Y_);
+ C:=min(1, max(0,C_-under_color_removal(K_)));
+ M:=min(1, max(0,M_-under_color_removal(K_)));
+ Y:=min(1, max(0,Y_-under_color_removal(K_)));
+ K:=min(1, max(0,black_generation(K_)));
+ endgroup
+enddef;
+% ---
+% DEFAULTS:
+def mftoeps_default text t = % main global defaults
+ forsuffixes S_:=t:
+ if str S_ = "under_color_removal":
+ vardef under_color_removal(expr k) = 0 enddef; % modify if you know better
+ elseif str S_ = "black_generation":
+ vardef black_generation(expr k) = 0 enddef; % ditto
+ elseif str S_ = "default_miter_limit":
+ default_miter_limit:=10; % as in PostScript
+% incidentally, |10bp| would convert to |10.00002| during export at |300dpi|
+ elseif str S_ = "default_line_join": default_line_join:=0; % as in PostScript
+ elseif str S_ = "default_line_cap": default_line_cap:=0; % ditto
+ elseif str S_ = "epsil.ang": epsil.ang:=.1; % in degrees
+ elseif str S_ = "epsil.dist": epsil.dist:=1/10pt; % ca |2/5|pxl at |300dpi|
+ fi
+ endfor
+enddef;
+%
+mftoeps_default under_color_removal, black_generation, default_miter_limit,
+ default_line_join, default_line_cap, epsil.ang, epsil.dist;
+% ---
+endinput;
+%%\end