diff options
author | Karl Berry <karl@freefriends.org> | 2015-04-18 22:52:45 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-04-18 22:52:45 +0000 |
commit | 16aa5a7c87f18a2483d0d61795899f886781b51c (patch) | |
tree | 1d72f00b2a4185425393598402fe055c61d1de58 /Master/texmf-dist/metapost | |
parent | e68dc4d5506d46bf72823234f902bc76d1f70352 (diff) |
context, from www.pragma-ade.com/context/beta/cont-tmf.zip (18apr15)
git-svn-id: svn://tug.org/texlive/trunk@36923 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/metapost')
11 files changed, 1032 insertions, 455 deletions
diff --git a/Master/texmf-dist/metapost/context/base/metafun.mpiv b/Master/texmf-dist/metapost/context/base/metafun.mpiv index 095b84b0ecc..b1d4f32e7ee 100644 --- a/Master/texmf-dist/metapost/context/base/metafun.mpiv +++ b/Master/texmf-dist/metapost/context/base/metafun.mpiv @@ -15,6 +15,9 @@ %D prevent dependency problems and in the end even may use a patched version, %D we prefer to use a copy. +prologues := 0 ; +mpprocset := 1 ; + input "mp-base.mpiv" ; input "mp-tool.mpiv" ; input "mp-mlib.mpiv" ; @@ -47,6 +50,7 @@ let normalend = end ; if known mplib : def end = ; message "" ; message metafunversion ; message "" ; endinput ; enddef ; + def bye = ; message "" ; message metafunversion ; message "" ; endinput ; enddef ; else : def end = ; message "" ; message metafunversion ; message "" ; normalend ; enddef ; fi ; diff --git a/Master/texmf-dist/metapost/context/base/mp-bare.mpiv b/Master/texmf-dist/metapost/context/base/mp-bare.mpiv new file mode 100644 index 00000000000..c6194b1ee00 --- /dev/null +++ b/Master/texmf-dist/metapost/context/base/mp-bare.mpiv @@ -0,0 +1,93 @@ +%D \module +%D [ file=mp-bare.mpiv, +%D version=2014.10.31, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=plain plugins, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See licen-en.pdf for +%C details. + +if known context_bare : endinput ; fi ; +boolean context_bare ; context_bare := true ; + +numeric mfun_tt_w[], mfun_tt_h[], mfun_tt_d[] ; +numeric mfun_tt_n ; mfun_tt_n := 0 ; +picture mfun_tt_p ; mfun_tt_p := nullpicture ; +picture mfun_tt_o ; mfun_tt_o := nullpicture ; +picture mfun_tt_c ; mfun_tt_c := nullpicture ; + +if unknown mfun_trial_run : + boolean mfun_trial_run ; + mfun_trial_run := false ; +fi ; + +if unknown mfun_first_run : + boolean mfun_first_run ; + mfun_first_run := true ; +fi ; + +def mfun_reset_tex_texts = + mfun_tt_n := 0 ; + mfun_tt_p := nullpicture ; + mfun_tt_o := nullpicture ; % redundant + mfun_tt_c := nullpicture ; % redundant +enddef ; + +def mfun_flush_tex_texts = + addto currentpicture also mfun_tt_p +enddef ; + +extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; +extra_endfig := "mfun_flush_tex_texts ; mfun_reset_tex_texts ; " & extra_endfig ; + +vardef colordecimals primary c = + if cmykcolor c : + decimal cyanpart c & ":" & decimal magentapart c & ":" & decimal yellowpart c & ":" & decimal blackpart c + elseif rgbcolor c : + decimal redpart c & ":" & decimal greenpart c & ":" & decimal bluepart c + else : + decimal c + fi +enddef ; + +vardef rawtextext(expr str) = % todo: avoid currentpicture + if str = "" : + nullpicture + else : + mfun_tt_n := mfun_tt_n + 1 ; + mfun_tt_c := nullpicture ; + if mfun_trial_run : + mfun_tt_o := nullpicture ; + addto mfun_tt_o doublepath origin _op_ ; % save drawoptions + addto mfun_tt_c doublepath unitsquare + withprescript "tx_number=" & decimal mfun_tt_n + withprescript "tx_stage=trial" + withprescript "tx_color=" & colordecimals colorpart mfun_tt_o + withpostscript str ; + addto mfun_tt_p also mfun_tt_c ; + elseif known mfun_tt_d[mfun_tt_n] : + addto mfun_tt_c doublepath unitsquare + xscaled mfun_tt_w[mfun_tt_n] + yscaled (mfun_tt_h[mfun_tt_n] + mfun_tt_d[mfun_tt_n]) + shifted (0,-mfun_tt_d[mfun_tt_n]) + withprescript "tx_number=" & decimal mfun_tt_n + withprescript "tx_stage=final" ; + else : + addto mfun_tt_c doublepath unitsquare ; % unitpicture + fi ; + mfun_tt_c + fi +enddef ; + +primarydef str infont name = % nasty hack + if name = "" : + rawtextext(str) + else : + rawtextext("\definedfont[" & name & "]" & str) + fi +enddef ; + diff --git a/Master/texmf-dist/metapost/context/base/mp-base.mpiv b/Master/texmf-dist/metapost/context/base/mp-base.mpiv index 94379050bc8..28eb57fb895 100644 --- a/Master/texmf-dist/metapost/context/base/mp-base.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-base.mpiv @@ -195,7 +195,8 @@ yellow := (1,1,0) ; background := white ; % obsolete let graypart = greypart ; -let graycolor = greycolor ; +let greycolor = numeric ; +let graycolor = numeric ; % color part (will be overloaded) @@ -865,7 +866,7 @@ vardef labels@#(text t) = endfor enddef ; -% til lhere +% till lhere vardef dotlabels@#(text t) = forsuffixes $=t: @@ -881,17 +882,19 @@ vardef penlabels@#(text t) = endfor enddef ; +% range 4 thru 10 + def range expr x = - numtok[x] + _numtok_[x] enddef ; -def numtok suffix x = +def _numtok_ suffix x = x enddef ; tertiarydef m thru n = m for x=m+1 step 1 until n : - , numtok[x] + , _numtok_[x] endfor enddef ; diff --git a/Master/texmf-dist/metapost/context/base/mp-chem.mpiv b/Master/texmf-dist/metapost/context/base/mp-chem.mpiv index a316a1a30cb..b861d3f123e 100644 --- a/Master/texmf-dist/metapost/context/base/mp-chem.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-chem.mpiv @@ -11,7 +11,8 @@ %C therefore copyrighted by \PRAGMA. See licen-en.pdf for %C details. -%D This module is incomplete and experimental. +%D This module is incomplete and experimental. Okay, it's not that bad but we do need +%D some disclaimer. % either consistent setting or not @@ -131,6 +132,8 @@ vardef chem_init_some (suffix $) (expr e) = fi if not chem_star[$] : scaled (.5/(sind .5chem_num1)) + % carbon-carbon benzene bond length + scaled (1.4/1.54) fi ; fi ; @@ -300,7 +303,6 @@ enddef ; chem_init_all ; % WHY does this not work unless defined and then called? - % Like most often in ConTeXt, we will trap but then silently ignore mistaken use, % unless of course the error be too harmful... @@ -529,6 +531,17 @@ vardef chem_set (suffix $) = % This is a fairly complicated optimization and ajustement. It took some % thinking to get right, so beware! + % And then even more time fixing a bug of a rotation +- half the symmetry + % angle of a structure depending on the scale and/or the font size + % (through chem_b_length). + + % first save the symmetry angle of the structure (as in chem_rot): + chem_num0 := if chem_stacked[$] : 3 else : 0 fi ; + chem_num9 := if chem_tetra[$] : 360 else : + abs(angle(point 0+chem_num0 of chem_b_path[$]) - + angle(point 1+chem_num0 of chem_b_path[$])) + fi ; + if (chem_adjacent<>0) and chem_star[P] and chem_star[$] : % nop chem_adjacent := 0 ; @@ -581,7 +594,8 @@ vardef chem_set (suffix $) = -((point (chem_adjacent-1) of chem_b_path[P]) chem_transformed(P)) ; fi % adjust the bond angles - chem_rotation := (chem_rotation + angle(chem_pair1)-angle(chem_pair3)) mod 360 ; + chem_num4 := (angle(chem_pair1)-angle(chem_pair3)) zmod chem_num9 ; + chem_rotation := chem_rotation + chem_num4 ; if not chem_star[$] : chem_pair4 := if chem_star[P] : @@ -666,7 +680,8 @@ vardef chem_set (suffix $) = fi endfor if not chem_front[$] : % adjust rotation - chem_rotation := (chem_rotation + angle(chem_pair1)-angle(chem_pair3)) mod 360 ; + chem_num4 := angle(chem_pair1)-angle(chem_pair3) ; + chem_rotation := (chem_rotation + chem_num4) mod 360 ; fi ; chem_t := identity chem_transformed($) ; chem_pair4 := (point chem_num3 of chem_b_path[$]) transformed chem_t ; @@ -674,6 +689,9 @@ vardef chem_set (suffix $) = currentpicture := currentpicture shifted chem_pair4 ; chem_origin := chem_origin shifted chem_pair4 ; fi + if not chem_front[$] : % adjust rotation + chem_rotation := chem_rotation zmod chem_num9 ; + fi fi chem_substituent := 0 ; fi ; @@ -1571,9 +1589,9 @@ vardef chem_rot (suffix $) (expr d, s) = % ROT chem_rotation := 0 else : chem_num0 := if chem_stacked[$] : 3 else : 0 fi ; - chem_num1 := .5(angle(point d+chem_num0 of chem_b_path[$]) - + chem_num1 := .5(angle(point d+chem_num0 of chem_b_path[$]) - angle(point d+chem_num0-1 of chem_b_path[$])) ; - chem_rotation := (chem_rotation + s*chem_num1) mod 360 ; + chem_rotation := (chem_rotation + s*chem_num1) zmod 360 ; fi fi enddef ; @@ -1584,7 +1602,7 @@ vardef chem_mir (suffix $) (expr d, s) = % MIR if not chem_front[$] : if d=0 : % inversion if chem_mirror=origin : - chem_rotation := (chem_rotation + 180*s) mod 360 ; + chem_rotation := (chem_rotation + 180*s) zmod 360 ; else : chem_mirror := chem_mirror rotated 90 ; fi @@ -1600,7 +1618,7 @@ vardef chem_mir (suffix $) (expr d, s) = % MIR chem_num0 := -360 - chem_num0 ; fi chem_num0 := chem_num0 * s ; - chem_rotation := (chem_rotation + 2chem_num0) mod 360 ; + chem_rotation := (chem_rotation + 2chem_num0) zmod 360 ; chem_mirror := origin ; fi fi diff --git a/Master/texmf-dist/metapost/context/base/mp-func.mpiv b/Master/texmf-dist/metapost/context/base/mp-func.mpiv index 58df711f2f3..b1b9d6d5d22 100644 --- a/Master/texmf-dist/metapost/context/base/mp-func.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-func.mpiv @@ -23,30 +23,36 @@ mfun_pathconnectors[0] := "," ; mfun_pathconnectors[1] := "--" ; mfun_pathconnectors[2] := ".." ; mfun_pathconnectors[3] := "..." ; +mfun_pathconnectors[4] := "---" ; def pathconnectors = mfun_pathconnectors enddef ; vardef mfun_function (expr f) (expr u, t, b, e, s) = save x ; numeric x ; + save c ; string c ; c := if string f : f else : mfun_pathconnectors[f] fi ; for xx := b step s until e : hide (x := xx ;) if xx > b : - scantokens(mfun_pathconnectors[f]) + scantokens(c) fi (scantokens(u),scantokens(t)) endfor enddef ; -def function = mfun_function enddef ; % let doesn't work here -def punkedfunction = mfun_function (1) enddef ; -def curvedfunction = mfun_function (2) enddef ; -def tightfunction = mfun_function (3) enddef ; +def function = mfun_function enddef ; % let doesn't work here +def constructedfunction = mfun_function enddef ; +def straightfunction = mfun_function (1) enddef ; +def curvedfunction = mfun_function (2) enddef ; + +% def punkedfunction = mfun_function (1) enddef ; % same as straightfunction +% def tightfunction = mfun_function (3) enddef ; % same as curvedfunction vardef mfun_constructedpath (expr f) (text t) = save ok ; boolean ok ; ok := false ; + save c ; string c ; c := if string f : f else : mfun_pathconnectors[f] fi ; for i=t : if ok : - scantokens(mfun_pathconnectors[f]) + scantokens(c) else : ok := true ; fi @@ -55,24 +61,27 @@ vardef mfun_constructedpath (expr f) (text t) = enddef ; def constructedpath = mfun_constructedpath enddef ; % let doesn't work here -def punkedpath = mfun_constructedpath (1) enddef ; +def straightpath = mfun_constructedpath (1) enddef ; def curvedpath = mfun_constructedpath (2) enddef ; -def tightpath = mfun_constructedpath (3) enddef ; + +% def punkedpath = mfun_constructedpath (1) enddef ; % same as straightpath +% def tightpath = mfun_constructedpath (3) enddef ; % same as curvedpath vardef mfun_constructedpairs (expr f) (text p) = save i ; i := -1 ; + save c ; string c ; c := if string f : f else : mfun_pathconnectors[f] fi ; forever : exitif unknown p[incr(i)] ; if i>0 : - scantokens(mfun_pathconnectors[f]) + scantokens(c) fi p[i] endfor enddef ; def constructedpairs = mfun_constructedpairs enddef ; % let doesn't work here -def punkedpairs = mfun_constructedpairs (1) enddef ; +def straightpairs = mfun_constructedpairs (1) enddef ; def curvedpairs = mfun_constructedpairs (2) enddef ; -def tightpairs = mfun_constructedpairs (3) enddef ; - +% def punkedpairs = mfun_constructedpairs (1) enddef ; % same as straightpairs +% def tightpairs = mfun_constructedpairs (3) enddef ; % same as curvedpairs diff --git a/Master/texmf-dist/metapost/context/base/mp-grap.mpiv b/Master/texmf-dist/metapost/context/base/mp-grap.mpiv index 6d2924c5263..4fd8ee5bd59 100644 --- a/Master/texmf-dist/metapost/context/base/mp-grap.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-grap.mpiv @@ -17,7 +17,10 @@ boolean context_grap ; context_grap := true ; % Below is a modified graph.mp -if epsilon/4 = 0 : % numbersystem="scaled" : (not reliable...) +show numbersystem, numberprecision ; + +%if epsilon/4 = 0 : +if numbersystem <> "double" : errmessage "The graph macros require the double precision number system." ; endinput ; fi @@ -75,7 +78,7 @@ newinternal mlogten ; mlogten := mlog(10) ; newinternal largestmantissa ; largestmantissa := 2**52 ; % internal double warningcheck newinternal singleinfinity ; singleinfinity := 2**128 ; newinternal doubleinfinity ; doubleinfinity := 2**1024 ; -Mzero := -largestmantissa ; % Note that we get arithmetic overflows if we set to -doubleinfinity +%Mzero := -largestmantissa ; % Note that we get arithmetic overflows if we set to -doubleinfinity % Safely convert a number to mlog form, trapping zero. @@ -428,13 +431,15 @@ vardef graph_pair_adjust(expr p)(suffix tx, ty) = (tx xpart p, ty ypart p) endde vardef graph_convert_user_path_to_internal primary p = interim warningcheck :=0 ; - graph_scan_path(p, - (abs X_.graph_coordinate_type<>linear) or (abs Y_.graph_coordinate_type<>linear), - if abs X_.graph_coordinate_type=log : graph_mlog fi, - if abs Y_.graph_coordinate_type=log : graph_mlog fi) - transformed (identity - if X_.graph_coordinate_type<0 : xscaled -1 fi - if Y_.graph_coordinate_type<0 : yscaled -1 fi) + if known p : + graph_scan_path(p, + (abs X_.graph_coordinate_type<>linear) or (abs Y_.graph_coordinate_type<>linear), + if abs X_.graph_coordinate_type=log : graph_mlog fi, + if abs Y_.graph_coordinate_type=log : graph_mlog fi) + transformed (identity + if X_.graph_coordinate_type<0 : xscaled -1 fi + if Y_.graph_coordinate_type<0 : yscaled -1 fi) + fi enddef ; % Convert label location t_ from user graph coords to internal graph coords. @@ -520,10 +525,11 @@ enddef ; % Execute c for each line of data read from file f, and stop at the first % line with no data. Commands c can use line number i and tokens $1, $2, ... +% and j is the number of fields. def gdata(expr f)(suffix $)(text c) = - boolean flag ; - for i=1 upto infinity : + %boolean flag ; % not used? + for i=1 upto largestmantissa : exitunless graph_read_line$(f) ; c endfor diff --git a/Master/texmf-dist/metapost/context/base/mp-luas.mpiv b/Master/texmf-dist/metapost/context/base/mp-luas.mpiv index b926b586c46..c919ba2159c 100644 --- a/Master/texmf-dist/metapost/context/base/mp-luas.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-luas.mpiv @@ -13,6 +13,15 @@ if known context_luas : endinput ; fi ; +% When I prototyped the runscript primitive I was just thinking of a usage like +% the original \directlua primitive in luatex: genererate something and pipe +% that back to metapost, and have access to some internals. Instead of compiling +% the code a the metapost end here we delegate that to the lua end. Only strings +% get passed. Of course in the end the real usage got a bit beyong the intended +% usage. So, in addition to some definitions here there are and will be use in +% other metafun modules too. Of course in retrospect I should have done this five +% years earlier. + boolean context_luas ; context_luas := true ; % First variant: diff --git a/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv b/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv index 56815028e8f..b19f47f1e55 100644 --- a/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv @@ -60,32 +60,70 @@ def namedcolor (expr n) = withprescript "sp_name=" & n enddef ; +% def spotcolor(expr n, v) = +% 1 +% withprescript "sp_type=spot" +% withprescript "sp_name=" & n +% withprescript "sp_value=" & (if numeric v : decimal v else : v fi) +% enddef ; +% +% def multitonecolor(expr name, fractions, components, value) = +% 1 +% withprescript "sp_type=multitone" +% withprescript "sp_name=" & name +% withprescript "sp_fractions=" & decimal fractions +% withprescript "sp_components=" & components +% withprescript "sp_value=" & value +% enddef ; + def spotcolor(expr n, v) = 1 withprescript "sp_type=spot" withprescript "sp_name=" & n - withprescript "sp_value=" & v + withprescript "sp_value=" & colordecimals v enddef ; -def multitonecolor(expr name, fractions, components, value) = +def multitonecolor(expr name)(text t) = 1 withprescript "sp_type=multitone" - withprescript "sp_name=" & name - withprescript "sp_fractions=" & decimal fractions - withprescript "sp_components=" & components - withprescript "sp_value=" & value + withprescript "sp_name=" & name + withprescript "sp_value=" & colordecimalslist(t) enddef ; -def transparent(expr alternative, transparency)(text c) = +def transparent(expr a, t)(text c) = % use withtransparency instead 1 % this permits withcolor x intoshade y - withprescript "tr_alternative=" & decimal transparency_alternative_to_number(alternative) - withprescript "tr_transparency=" & decimal transparency + withprescript "tr_alternative=" & decimal transparency_alternative_to_number(a) + withprescript "tr_transparency=" & decimal t withcolor c enddef ; -def withtransparency(expr alternative, transparency) = - withprescript "tr_alternative=" & decimal transparency_alternative_to_number(alternative) - withprescript "tr_transparency=" & decimal transparency +% def withtransparency(expr a, t) = +% withprescript "tr_alternative=" & decimal transparency_alternative_to_number(a) +% withprescript "tr_transparency=" & decimal t +% enddef ; + +let transparency = pair ; + +% def withtransparency expr t = +% withprescript "tr_alternative=" & decimal transparency_alternative_to_number(xpart t) +% withprescript "tr_transparency=" & decimal ypart t +% enddef ; +% +% withtransparency (1,.5) +% withtransparency ("normal",.5) + +def withtransparency (expr t) (text rest) = + if pair t : + withprescript "tr_alternative=" & decimal transparency_alternative_to_number(xpart t) + withprescript "tr_transparency=" & decimal ypart t + else : + mfun_with_transparency (transparency_alternative_to_number(t)) + fi rest +enddef ; + +def mfun_with_transparency (expr a) expr t = + withprescript "tr_alternative=" & decimal a + withprescript "tr_transparency=" & decimal t enddef ; def cmyk(expr c, m, y, k) = % provided for downward compability @@ -96,7 +134,8 @@ enddef ; newinternal textextoffset ; textextoffset := 0 ; -numeric mfun_tt_w[], mfun_tt_h[], mfun_tt_d[] ; % we can consider using colors (less hash space) +%%%%%%% mfun_tt_w[], mfun_tt_h[], mfun_tt_d[] ; % we can consider using colors (less hash space) +color mfun_tt_b ; numeric mfun_tt_n ; mfun_tt_n := 0 ; picture mfun_tt_p ; mfun_tt_p := nullpicture ; picture mfun_tt_o ; mfun_tt_o := nullpicture ; @@ -135,44 +174,10 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; % flush twice: once in location in order to pick up e.g. color properties, % and once at the end because we need to flush missing ones. -% vardef rawtextext(expr str) = -% if str = "" : -% nullpicture -% elseif mfun_trial_run : -% mfun_tt_n := mfun_tt_n + 1 ; -% mfun_tt_o := image(draw origin) ; % save drawoptions -% addto mfun_tt_p doublepath unitsquare -% withprescript "tx_number=" & decimal mfun_tt_n -% withprescript "tx_stage=extra" -% withpostscript str ; -% image ( -% addto currentpicture doublepath unitsquare -% withprescript "tx_number=" & decimal mfun_tt_n -% withprescript "tx_stage=trial" -% withprescript "tx_color=" & colordecimals colorpart mfun_tt_o -% withpostscript str -% ; ) -% else : -% mfun_tt_n := mfun_tt_n + 1 ; -% if known mfun_tt_d[mfun_tt_n] : -% image ( -% addto currentpicture doublepath unitsquare -% xscaled mfun_tt_w[mfun_tt_n] -% yscaled (mfun_tt_h[mfun_tt_n] + mfun_tt_d[mfun_tt_n]) -% withprescript "tx_number=" & decimal mfun_tt_n -% withprescript "tx_stage=final" -% % withpostscript str ; % for tracing -% ; ) shifted (0,-mfun_tt_d[mfun_tt_n]) -% else : -% image ( -% addto currentpicture doublepath unitsquare -% ; ) -% fi -% fi -% enddef ; +% see mp-keep.mpiv for older code -% vardef rawtextext(expr str) = % todo: avoid currentpicture -% if str = "" : +% vardef rawtextext(expr s) = % todo: avoid currentpicture +% if s = "" : % nullpicture % else : % mfun_tt_n := mfun_tt_n + 1 ; @@ -180,15 +185,12 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; % if mfun_trial_run : % mfun_tt_o := nullpicture ; % addto mfun_tt_o doublepath origin _op_ ; % save drawoptions -% addto mfun_tt_p doublepath unitsquare -% withprescript "tx_number=" & decimal mfun_tt_n -% withprescript "tx_stage=extra" -% withpostscript str ; % addto mfun_tt_c doublepath unitsquare % withprescript "tx_number=" & decimal mfun_tt_n % withprescript "tx_stage=trial" % withprescript "tx_color=" & colordecimals colorpart mfun_tt_o -% withpostscript str ; +% withpostscript s ; +% addto mfun_tt_p also mfun_tt_c ; % elseif known mfun_tt_d[mfun_tt_n] : % addto mfun_tt_c doublepath unitsquare % xscaled mfun_tt_w[mfun_tt_n] @@ -203,8 +205,8 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; % fi % enddef ; -vardef rawtextext(expr str) = % todo: avoid currentpicture - if str = "" : +vardef rawtextext(expr s) = % todo: avoid currentpicture + if s = "" : nullpicture else : mfun_tt_n := mfun_tt_n + 1 ; @@ -216,17 +218,16 @@ vardef rawtextext(expr str) = % todo: avoid currentpicture withprescript "tx_number=" & decimal mfun_tt_n withprescript "tx_stage=trial" withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - withpostscript str ; + withpostscript s ; addto mfun_tt_p also mfun_tt_c ; - elseif known mfun_tt_d[mfun_tt_n] : + else : + mfun_tt_b := lua.mp.tt_dimensions(mfun_tt_n) ; addto mfun_tt_c doublepath unitsquare - xscaled mfun_tt_w[mfun_tt_n] - yscaled (mfun_tt_h[mfun_tt_n] + mfun_tt_d[mfun_tt_n]) - shifted (0,-mfun_tt_d[mfun_tt_n]) + xscaled redpart mfun_tt_b + yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b) + shifted (0,- bluepart mfun_tt_b) withprescript "tx_number=" & decimal mfun_tt_n withprescript "tx_stage=final" ; - else : - addto mfun_tt_c doublepath unitsquare ; % unitpicture fi ; mfun_tt_c fi @@ -234,7 +235,10 @@ enddef ; % More text -defaultfont := "Mono" ; % was cmr10, could be lmmono10-regular, but is fed into context anyway +defaultfont := "Mono" ; +defaultscale := 1 ; + +extra_beginfig := extra_beginfig & "defaultscale:=1;" ; vardef fontsize expr name = save size ; numeric size ; @@ -403,19 +407,171 @@ enddef ; let normalinfont = infont ; -primarydef str infont name = % nasty hack +primarydef s infont name = % nasty hack if name = "" : - textext(str) + textext(s) else : - textext("\definedfont[" & name & "]" & str) + textext("\definedfont[" & name & "]" & s) fi enddef ; +% Helper + +string mfun_prescript_separator ; mfun_prescript_separator := char(13) ; + % Shades -newinternal shadefactor ; shadefactor := 1 ; -pair shadeoffset ; shadeoffset := origin ; -boolean trace_shades ; trace_shades := false ; +% for while we had this: + +newinternal shadefactor ; shadefactor := 1 ; % currently obsolete +pair shadeoffset ; shadeoffset := origin ; % currently obsolete +boolean trace_shades ; trace_shades := false ; % still there + +% def withlinearshading (expr a, b) = +% withprescript "sh_type=linear" +% withprescript "sh_domain=0 1" +% withprescript "sh_factor=" & decimal shadefactor +% withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) +% withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) +% enddef ; +% +% def withcircularshading (expr a, b, ra, rb) = +% withprescript "sh_type=circular" +% withprescript "sh_domain=0 1" +% withprescript "sh_factor=" & decimal shadefactor +% withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) +% withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) +% withprescript "sh_radius_a=" & decimal ra +% withprescript "sh_radius_b=" & decimal rb +% enddef ; +% +% def withshading (expr how)(text rest) = +% if how = "linear" : +% withlinearshading(rest) +% elseif how = "circular" : +% withcircularshading(rest) +% else : +% % nothing +% fi +% enddef ; +% +% def withfromshadecolor expr t = +% withprescript "sh_color=into" +% withprescript "sh_color_a=" & colordecimals t +% enddef ; + +% def withtoshadecolor expr t = +% withprescript "sh_color=into" +% withprescript "sh_color_b=" & colordecimals t +% enddef ; + +% but this is nicer + +path mfun_shade_path ; + +primarydef p withshademethod m = + hide(mfun_shade_path := p ;) + p + withprescript "sh_domain=0 1" + withprescript "sh_color=into" + withprescript "sh_color_a=" & colordecimals white + withprescript "sh_color_b=" & colordecimals black + if m = "linear" : + withprescript "sh_type=linear" + withprescript "sh_factor=1" + withprescript "sh_center_a=" & ddecimal llcorner p + withprescript "sh_center_b=" & ddecimal urcorner p + else : + withprescript "sh_type=circular" + withprescript "sh_factor=1.2" + withprescript "sh_center_a=" & ddecimal center p + withprescript "sh_center_b=" & ddecimal center p + withprescript "sh_radius_a=" & decimal 0 + withprescript "sh_radius_b=" & decimal ( max ( + (xpart center p - xpart llcorner p) ++ (ypart center p - ypart llcorner p), + (xpart center p - xpart ulcorner p) ++ (ypart ulcorner p - ypart center p), + (xpart lrcorner p - xpart center p) ++ (ypart center p - ypart lrcorner p), + (xpart urcorner p - xpart center p) ++ (ypart urcorner p - ypart center p) + ) ) + fi +enddef ; + +def withshadevector expr a = + withprescript "sh_center_a=" & ddecimal (point xpart a of mfun_shade_path) + withprescript "sh_center_b=" & ddecimal (point ypart a of mfun_shade_path) +enddef ; + +def withshadecenter expr a = + withprescript "sh_center_a=" & ddecimal ( + center mfun_shade_path shifted ( + xpart a * bbwidth (mfun_shade_path)/2, + ypart a * bbheight(mfun_shade_path)/2 + ) + ) +enddef ; + +def withshadedomain expr d = + withprescript "sh_domain=" & ddecimal d +enddef ; + +def withshadefactor expr f = + withprescript "sh_factor=" & decimal f +enddef ; + +def withshadecolors (expr a, b) = + withprescript "sh_color=into" + withprescript "sh_color_a=" & colordecimals a + withprescript "sh_color_b=" & colordecimals b +enddef ; + +primarydef a shadedinto b = % withcolor red shadedinto green + 1 % does not work with transparency + withprescript "sh_color=into" + withprescript "sh_color_a=" & colordecimals a + withprescript "sh_color_b=" & colordecimals b +enddef ; + +primarydef p withshade sc = + p withprescript mfun_defined_cs_pre[sc] +enddef ; + +def defineshade suffix s = + mfun_defineshade(str s) +enddef ; + +def mfun_defineshade (expr s) text t = + expandafter def scantokens s = t enddef ; +enddef ; + +def shaded text s = + s +enddef ; + +% Old macros: + +def withcircularshade (expr a, b, ra, rb, ca, cb) = + withprescript "sh_type=circular" + withprescript "sh_domain=0 1" + withprescript "sh_factor=1" + withprescript "sh_color_a=" & colordecimals ca + withprescript "sh_color_b=" & colordecimals cb + withprescript "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + withprescript "sh_center_b=" & ddecimal b % (b shifted shadeoffset) + withprescript "sh_radius_a=" & decimal ra + withprescript "sh_radius_b=" & decimal rb +enddef ; + +def withlinearshade (expr a, b, ca, cb) = + withprescript "sh_type=linear" + withprescript "sh_domain=0 1" + withprescript "sh_factor=1" + withprescript "sh_color_a=" & colordecimals ca + withprescript "sh_color_b=" & colordecimals cb + withprescript "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + withprescript "sh_center_b=" & ddecimal b % (b shifted shadeoffset) +enddef ; + +% replaced (obsolete): def set_linear_vector (suffix a,b)(expr p,n) = if (n=1) : a := llcorner p ; b := urcorner p ; @@ -430,7 +586,7 @@ def set_linear_vector (suffix a,b)(expr p,n) = fi ; enddef ; -def set_circular_vector (suffix ab, r)(expr p,n) = +def set_circular_vector (suffix ab,r)(expr p,n) = if (n=1) : ab := llcorner p ; elseif (n=2) : ab := lrcorner p ; elseif (n=3) : ab := urcorner p ; @@ -453,7 +609,7 @@ enddef ; def linear_shade (expr p, n, ca, cb) = begingroup ; - save a, b, sh ; pair a, b ; + save a, b ; pair a, b ; set_linear_vector(a,b)(p,n) ; fill p withlinearshade(a,b,ca,cb) ; if trace_shades : @@ -462,43 +618,19 @@ def linear_shade (expr p, n, ca, cb) = endgroup ; enddef ; -def withcircularshade (expr a, b, ra, rb, ca, cb) = - withprescript "sh_type=circular" - withprescript "sh_domain=0 1" - withprescript "sh_factor=" & decimal shadefactor - withprescript "sh_color_a=" & colordecimals ca - withprescript "sh_color_b=" & colordecimals cb - withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) - withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) - withprescript "sh_radius_a=" & decimal ra - withprescript "sh_radius_b=" & decimal rb -enddef ; - -def withlinearshade (expr a, b, ca, cb) = - withprescript "sh_type=linear" - withprescript "sh_domain=0 1" - withprescript "sh_factor=" & decimal shadefactor - withprescript "sh_color_a=" & colordecimals ca - withprescript "sh_color_b=" & colordecimals cb - withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) - withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) -enddef ; - string mfun_defined_cs_pre[] ; numeric mfun_defined_cs ; mfun_defined_cs := 0 ; -string mfun_prescript_separator ; mfun_prescript_separator := char(13) ; - vardef define_circular_shade (expr a, b, ra, rb, ca, cb) = mfun_defined_cs := mfun_defined_cs + 1 ; mfun_defined_cs_pre[mfun_defined_cs] := "sh_type=circular" - & mfun_prescript_separator & "sh_domain=0 1" - & mfun_prescript_separator & "sh_factor=" & decimal shadefactor - & mfun_prescript_separator & "sh_color_a=" & colordecimals ca - & mfun_prescript_separator & "sh_color_b=" & colordecimals cb - & mfun_prescript_separator & "sh_center_a=" & ddecimal (a shifted shadeoffset) - & mfun_prescript_separator & "sh_center_b=" & ddecimal (b shifted shadeoffset) - & mfun_prescript_separator & "sh_radius_a=" & decimal ra - & mfun_prescript_separator & "sh_radius_b=" & decimal rb + & mfun_prescript_separator & "sh_domain=0 1" + & mfun_prescript_separator & "sh_factor=1" + & mfun_prescript_separator & "sh_color_a=" & colordecimals ca + & mfun_prescript_separator & "sh_color_b=" & colordecimals cb + & mfun_prescript_separator & "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + & mfun_prescript_separator & "sh_center_b=" & ddecimal b % (b shifted shadeoffset) + & mfun_prescript_separator & "sh_radius_a=" & decimal ra + & mfun_prescript_separator & "sh_radius_b=" & decimal rb ; mfun_defined_cs enddef ; @@ -506,52 +638,49 @@ enddef ; vardef define_linear_shade (expr a, b, ca, cb) = mfun_defined_cs := mfun_defined_cs + 1 ; mfun_defined_cs_pre[mfun_defined_cs] := "sh_type=linear" - & mfun_prescript_separator & "sh_domain=0 1" - & mfun_prescript_separator & "sh_factor=" & decimal shadefactor - & mfun_prescript_separator & "sh_color_a=" & colordecimals ca - & mfun_prescript_separator & "sh_color_b=" & colordecimals cb - & mfun_prescript_separator & "sh_center_a=" & ddecimal (a shifted shadeoffset) - & mfun_prescript_separator & "sh_center_b=" & ddecimal (b shifted shadeoffset) + & mfun_prescript_separator & "sh_domain=0 1" + & mfun_prescript_separator & "sh_factor=1" + & mfun_prescript_separator & "sh_color_a=" & colordecimals ca + & mfun_prescript_separator & "sh_color_b=" & colordecimals cb + & mfun_prescript_separator & "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + & mfun_prescript_separator & "sh_center_b=" & ddecimal b % (b shifted shadeoffset) ; mfun_defined_cs enddef ; -primarydef p withshade sc = - p withprescript mfun_defined_cs_pre[sc] -enddef ; - - -vardef define_sampled_linear_shade(expr a,b,n)(text t) = - mfun_defined_cs := mfun_defined_cs + 1 ; - mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=linear" - & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset) - & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset) - & mfun_prescript_separator & "ssh_nofcolors=" & decimal n - & mfun_prescript_separator & "ssh_domain=" & domstr - & mfun_prescript_separator & "ssh_extend=" & extstr - & mfun_prescript_separator & "ssh_colors=" & colstr - & mfun_prescript_separator & "ssh_bounds=" & bndstr - & mfun_prescript_separator & "ssh_ranges=" & ranstr - ; - mfun_defined_cs -enddef ; - -vardef define_sampled_circular_shade(expr a,b,ra,rb,n)(text t) = - mfun_defined_cs := mfun_defined_cs + 1 ; - mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=circular" - & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset) - & mfun_prescript_separator & "ssh_radius_a=" & decimal ra - & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset) - & mfun_prescript_separator & "ssh_radius_b=" & decimal rb - & mfun_prescript_separator & "ssh_nofcolors=" & decimal n - & mfun_prescript_separator & "ssh_domain=" & domstr - & mfun_prescript_separator & "ssh_extend=" & extstr - & mfun_prescript_separator & "ssh_colors=" & colstr - & mfun_prescript_separator & "ssh_bounds=" & bndstr - & mfun_prescript_separator & "ssh_ranges=" & ranstr - ; - mfun_defined_cs -enddef ; +% I lost the example code that uses this: +% +% vardef define_sampled_linear_shade(expr a,b,n)(text t) = +% mfun_defined_cs := mfun_defined_cs + 1 ; +% mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=linear" +% & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset) +% & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset) +% & mfun_prescript_separator & "ssh_nofcolors=" & decimal n +% & mfun_prescript_separator & "ssh_domain=" & domstr +% & mfun_prescript_separator & "ssh_extend=" & extstr +% & mfun_prescript_separator & "ssh_colors=" & colstr +% & mfun_prescript_separator & "ssh_bounds=" & bndstr +% & mfun_prescript_separator & "ssh_ranges=" & ranstr +% ; +% mfun_defined_cs +% enddef ; +% +% vardef define_sampled_circular_shade(expr a,b,ra,rb,n)(text t) = +% mfun_defined_cs := mfun_defined_cs + 1 ; +% mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=circular" +% & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset) +% & mfun_prescript_separator & "ssh_radius_a=" & decimal ra +% & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset) +% & mfun_prescript_separator & "ssh_radius_b=" & decimal rb +% & mfun_prescript_separator & "ssh_nofcolors=" & decimal n +% & mfun_prescript_separator & "ssh_domain=" & domstr +% & mfun_prescript_separator & "ssh_extend=" & extstr +% & mfun_prescript_separator & "ssh_colors=" & colstr +% & mfun_prescript_separator & "ssh_bounds=" & bndstr +% & mfun_prescript_separator & "ssh_ranges=" & ranstr +% ; +% mfun_defined_cs +% enddef ; % vardef predefined_linear_shade (expr p, n, ca, cb) = % save a, b, sh ; pair a, b ; @@ -566,53 +695,6 @@ enddef ; % define_circular_shade(ab,ab,0,r,ca,cb) % enddef ; -% NEW EXPERIMENTAL CODE - -def withlinearshading (expr a, b) = - withprescript "sh_type=linear" - withprescript "sh_domain=0 1" - withprescript "sh_factor=" & decimal shadefactor - withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) - withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) -enddef ; - -def withcircularshading (expr a, b, ra, rb) = - withprescript "sh_type=circular" - withprescript "sh_domain=0 1" - withprescript "sh_factor=" & decimal shadefactor - withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) - withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) - withprescript "sh_radius_a=" & decimal ra - withprescript "sh_radius_b=" & decimal rb -enddef ; - -def withfromshadecolor expr t = - withprescript "sh_color=into" - withprescript "sh_color_a=" & colordecimals t -enddef ; - -def withtoshadecolor expr t = - withprescript "sh_color=into" - withprescript "sh_color_b=" & colordecimals t -enddef ; - -def withshading (expr how)(text rest) = - if how = "linear" : - withlinearshading(rest) - elseif how = "circular" : - withcircularshading(rest) - else : - % nothing - fi -enddef ; - -primarydef a shadedinto b = - 1 % does not work with transparency - withprescript "sh_color=into" - withprescript "sh_color_a=" & colordecimals a - withprescript "sh_color_b=" & colordecimals b -enddef ; - % Layers def onlayer primary name = @@ -657,10 +739,10 @@ enddef ; % Positions -def register (expr label, width, height, offset) = +def register (expr tag, width, height, offset) = % draw image ( addto currentpicture doublepath unitsquare xscaled width yscaled height shifted offset - withprescript "ps_label=" & label ; + withprescript "ps_label=" & tag ; % ) ; % no transformations enddef ; @@ -672,8 +754,8 @@ extra_endfig := extra_endfig & "mfun_reset_tex_texts ; " ; % Bonus -vardef verbatim(expr str) = - ditto & "\detokenize{" & str & "}" & ditto +vardef verbatim(expr s) = + ditto & "\detokenize{" & s & "}" & ditto enddef ; % New @@ -749,7 +831,7 @@ primarydef t asgroup s = % s = isolated|knockout endgroup enddef ; -% Also experimental +% Also experimental ... needs to be made better ... so it can change! string mfun_auto_align[] ; @@ -826,6 +908,10 @@ vardef mfun_cmykcolor_to_string(expr c) = decimal blackpart c enddef ; +vardef mfun_greycolor_to_string(expr n) = + decimal n +enddef ; + vardef mfun_path_to_string(expr p) = mfun_point_to_string(p,0) for i=1 upto length(p) : & " " & mfun_point_to_string(p,i) endfor enddef ; @@ -852,6 +938,7 @@ vardef tostring(expr value) = elseif pair value : mfun_pair_to_string(value) elseif rgbcolor value : mfun_rgbcolor_to_string(value) elseif cmykcolor value : mfun_cmykcolor_to_string(value) + elseif greycolor value : mfun_greycolor_to_string(value) elseif boolean value : mfun_boolean_to_string(value) elseif path value : mfun_path_to_string(value) elseif transform value : mfun_transform_to_string(value) @@ -1047,23 +1134,80 @@ enddef ; % moved here from mp-grap.mpiv +% vardef escaped_format(expr s) = +% "" for n=0 upto length(s) : & +% if ASCII substring (n,n+1) of s = 37 : +% "@" +% else : +% substring (n,n+1) of s +% fi +% endfor +% enddef ; + +numeric mfun_esc_b ; % begin +numeric mfun_esc_l ; % length +string mfun_esc_s ; % character + +mfun_esc_s := "%" ; % or: char(37) + +% this one is the fastest when we have a match + +% vardef escaped_format(expr s) = +% "" for n=0 upto length(s)-1 : & +% % if ASCII substring (n,n+1) of s = 37 : +% if substring (n,n+1) of s = mfun_esc_s : +% "@" +% else : +% substring (n,n+1) of s +% fi +% endfor +% enddef ; + +% this one wins when we have no match + vardef escaped_format(expr s) = - "" for n=0 upto length(s) : & - if ASCII substring (n,n+1) of s = 37 : - "@" - else : - substring (n,n+1) of s + mfun_esc_b := 0 ; + mfun_esc_l := length(s) ; + for n=0 upto mfun_esc_l-1 : + % if ASCII substring (n,n+1) of s = 37 : + if substring (n,n+1) of s = mfun_esc_s : + if mfun_esc_b = 0 : + "" + fi + if n >= mfun_esc_b : + & (substring (mfun_esc_b,n) of s) + exitif numeric begingroup mfun_esc_b := n+1 endgroup ; % hide + fi + & "@" fi endfor + if mfun_esc_b = 0 : + s + % elseif mfun_esc_b > 0 : + elseif mfun_esc_b < mfun_esc_l : + & (substring (mfun_esc_b,mfun_esc_l) of s) + fi enddef ; -vardef strfmt(expr f, x) = % maybe use mfun_ namespace - "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" -enddef ; - -vardef varfmt(expr f, x) = % maybe use mfun_ namespace - "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" -enddef ; +vardef strfmt(expr f, x) = "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" enddef ; +vardef varfmt(expr f, x) = "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" enddef ; vardef format (expr f, x) = textext(strfmt(f, x)) enddef ; vardef formatted(expr f, x) = textext(varfmt(f, x)) enddef ; + +% could be this (something to discuss with alan as it involves graph): +% +% vardef format (expr f,x) = lua.mp.graphformat(f,mfun_tagged_string(x) enddef ; +% vardef formatted(expr f,x) = lua.mp.format (f, x) enddef ; +% +% def strfmt = format enddef ; % old +% def varfmt = formatted enddef ; % old + +% new + +def eofill text t = fill t withpostscript "evenodd" enddef ; +%%% eoclip text t = clip t withpostscript "evenodd" enddef ; % no postscripts yet + +% def withrule expr r = +% if (t = "even-odd") or (t = "evenodd") : withpostscript "evenodd" fi +% enddef ; diff --git a/Master/texmf-dist/metapost/context/base/mp-page.mpiv b/Master/texmf-dist/metapost/context/base/mp-page.mpiv index 9c538d42a65..7a6e576bd98 100644 --- a/Master/texmf-dist/metapost/context/base/mp-page.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-page.mpiv @@ -11,73 +11,300 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -%D This module is rather preliminary and subjected to -%D changes. +%D This module is rather preliminary and subjected to changes. if known context_page : endinput ; fi ; boolean context_page ; context_page := true ; +% def LoadPageState = +% % now always set +% enddef ; +% +% if unknown PageStateAvailable : +% boolean PageStateAvailable ; +% PageStateAvailable := false ; +% fi ; +% +% if unknown OnRightPage : +% boolean OnRightPage ; +% OnRightPage := true ; +% fi ; +% +% if unknown OnOddPage : +% boolean OnOddPage ; +% OnOddPage := true ; +% fi ; +% +% if unknown InPageBody : +% boolean InPageBody ; +% InPageBody := false ; +% fi ; +% +% string CurrentLayout ; +% +% CurrentLayout := "default" ; +% +% PageNumber := 0 ; +% PaperHeight := 845.04684pt ; +% PaperWidth := 597.50787pt ; +% PrintPaperHeight := 845.04684pt ; +% PrintPaperWidth := 597.50787pt ; +% TopSpace := 71.12546pt ; +% BottomSpace := 0.0pt ; +% BackSpace := 71.13275pt ; +% CutSpace := 0.0pt ; +% MakeupHeight := 711.3191pt ; +% MakeupWidth := 426.78743pt ; +% TopHeight := 0.0pt ; +% TopDistance := 0.0pt ; +% HeaderHeight := 56.90294pt ; +% HeaderDistance := 0.0pt ; +% TextHeight := 597.51323pt ; +% FooterDistance := 0.0pt ; +% FooterHeight := 56.90294pt ; +% BottomDistance := 0.0pt ; +% BottomHeight := 0.0pt ; +% LeftEdgeWidth := 0.0pt ; +% LeftEdgeDistance := 0.0pt ; +% LeftMarginWidth := 75.58197pt ; +% LeftMarginDistance := 11.99829pt ; +% TextWidth := 426.78743pt ; +% RightMarginDistance := 11.99829pt ; +% RightMarginWidth := 75.58197pt ; +% RightEdgeDistance := 0.0pt ; +% RightEdgeWidth := 0.0pt ; +% +% PageOffset := 0.0pt ; +% PageDepth := 0.0pt ; +% +% LayoutColumns := 0 ; +% LayoutColumnDistance:= 0.0pt ; +% LayoutColumnWidth := 0.0pt ; +% +% LeftEdge := -4 ; Top := -40 ; +% LeftEdgeSeparator := -3 ; TopSeparator := -30 ; +% LeftMargin := -2 ; Header := -20 ; +% LeftMarginSeparator := -1 ; HeaderSeparator := -10 ; +% Text := 0 ; Text := 0 ; +% RightMarginSeparator := +1 ; FooterSeparator := +10 ; +% RightMargin := +2 ; Footer := +20 ; +% RightEdgeSeparator := +3 ; BottomSeparator := +30 ; +% RightEdge := +4 ; Bottom := +40 ; +% +% Margin := LeftMargin ; % obsolete +% Edge := LeftEdge ; % obsolete +% InnerMargin := RightMargin ; % obsolete +% InnerEdge := RightEdge ; % obsolete +% OuterMargin := LeftMargin ; % obsolete +% OuterEdge := LeftEdge ; % obsolete +% +% InnerMarginWidth := 0pt ; +% OuterMarginWidth := 0pt ; +% InnerMarginDistance := 0pt ; +% OuterMarginDistance := 0pt ; +% +% InnerEdgeWidth := 0pt ; +% OuterEdgeWidth := 0pt ; +% InnerEdgeDistance := 0pt ; +% OuterEdgeDistance := 0pt ; +% +% % path Area[][] ; +% % pair Location[][] ; +% % path Field[][] ; +% +% % numeric Hstep[] ; +% % numeric Hsize[] ; +% % numeric Vstep[] ; +% % numeric Vsize[] ; +% +% path Page ; +% +% numeric HorPos ; +% numeric VerPos ; +% +% % for VerPos=Top step 10 until Bottom: +% % for HorPos=LeftEdge step 1 until RightEdge: +% % Area[HorPos][VerPos] := origin--cycle ; +% % Area[VerPos][HorPos] := Area[HorPos][VerPos] ; +% % Location[HorPos][VerPos] := origin ; +% % Location[VerPos][HorPos] := Location[HorPos][VerPos] ; +% % Field[HorPos][VerPos] := origin--cycle ; +% % Field[VerPos][HorPos] := Field[HorPos][VerPos] ; +% % endfor ; +% % endfor ; +% +% % def LoadPageState = +% % scantokens "input mp-state.tmp" ; +% % enddef ; +% +% numeric mfun_temp ; +% +% def SwapPageState = +% if not OnRightPage : +% BackSpace := PaperWidth-MakeupWidth-BackSpace ; +% CutSpace := PaperWidth-MakeupWidth-CutSpace ; +% mfun_temp := LeftMarginWidth ; +% LeftMarginWidth := RightMarginWidth ; +% RightMarginWidth := mfun_temp ; +% mfun_temp := LeftMarginDistance ; +% LeftMarginDistance := RightMarginDistance ; +% RightMarginDistance := mfun_temp ; +% mfun_temp := LeftEdgeWidth ; +% LeftEdgeWidth := RightEdgeWidth ; +% RightEdgeWidth := mfun_temp ; +% mfun_temp := LeftEdgeDistance ; +% LeftEdgeDistance := RightEdgeDistance ; +% RightEdgeDistance := mfun_temp ; +% +% % these are now available as ..Width and ..Distance +% +% Margin := LeftMargin ; +% Edge := LeftEdge ; +% InnerMargin := RightMargin ; +% InnerEdge := RightEdge ; +% OuterMargin := LeftMargin ; +% OuterEdge := LeftEdge ; +% else : +% Margin := RightMargin ; +% Edge := RightEdge ; +% InnerMargin := LeftMargin ; +% InnerEdge := LeftEdge ; +% OuterMargin := RightMargin ; +% OuterEdge := RightEdge ; +% fi ; +% enddef ; + +% the new way: + +def LoadPageState = + % now always set +enddef ; + if unknown PageStateAvailable : boolean PageStateAvailable ; PageStateAvailable := false ; fi ; -if unknown OnRightPage : - boolean OnRightPage ; - OnRightPage := true ; -fi ; +string CurrentLayout ; CurrentLayout := "default" ; + +vardef PaperHeight = lua.mp.PaperHeight () enddef ; +vardef PaperWidth = lua.mp.PaperWidth () enddef ; +vardef PrintPaperHeight = lua.mp.PrintPaperHeight () enddef ; +vardef PrintPaperWidth = lua.mp.PrintPaperWidth () enddef ; +vardef TopSpace = lua.mp.TopSpace () enddef ; +vardef BottomSpace = lua.mp.BottomSpace () enddef ; +vardef BackSpace = lua.mp.BackSpace () enddef ; +vardef CutSpace = lua.mp.CutSpace () enddef ; +vardef MakeupHeight = lua.mp.MakeupHeight () enddef ; +vardef MakeupWidth = lua.mp.MakeupWidth () enddef ; +vardef TopHeight = lua.mp.TopHeight () enddef ; +vardef TopDistance = lua.mp.TopDistance () enddef ; +vardef HeaderHeight = lua.mp.HeaderHeight () enddef ; +vardef HeaderDistance = lua.mp.HeaderDistance () enddef ; +vardef TextHeight = lua.mp.TextHeight () enddef ; +vardef FooterDistance = lua.mp.FooterDistance () enddef ; +vardef FooterHeight = lua.mp.FooterHeight () enddef ; +vardef BottomDistance = lua.mp.BottomDistance () enddef ; +vardef BottomHeight = lua.mp.BottomHeight () enddef ; +vardef LeftEdgeWidth = lua.mp.LeftEdgeWidth () enddef ; +vardef LeftEdgeDistance = lua.mp.LeftEdgeDistance () enddef ; +vardef LeftMarginWidth = lua.mp.LeftMarginWidth () enddef ; +vardef LeftMarginDistance = lua.mp.LeftMarginDistance () enddef ; +vardef TextWidth = lua.mp.TextWidth () enddef ; +vardef RightMarginDistance = lua.mp.RightMarginDistance () enddef ; +vardef RightMarginWidth = lua.mp.RightMarginWidth () enddef ; +vardef RightEdgeDistance = lua.mp.RightEdgeDistance () enddef ; +vardef RightEdgeWidth = lua.mp.RightEdgeWidth () enddef ; +vardef InnerMarginDistance = lua.mp.InnerMarginDistance () enddef ; +vardef InnerMarginWidth = lua.mp.InnerMarginWidth () enddef ; +vardef OuterMarginDistance = lua.mp.OuterMarginDistance () enddef ; +vardef OuterMarginWidth = lua.mp.OuterMarginWidth () enddef ; +vardef InnerEdgeDistance = lua.mp.InnerEdgeDistance () enddef ; +vardef InnerEdgeWidth = lua.mp.InnerEdgeWidth () enddef ; +vardef OuterEdgeDistance = lua.mp.OuterEdgeDistance () enddef ; +vardef OuterEdgeWidth = lua.mp.OuterEdgeWidth () enddef ; +vardef PageOffset = lua.mp.PageOffset () enddef ; +vardef PageDepth = lua.mp.PageDepth () enddef ; +vardef LayoutColumns = lua.mp.LayoutColumns () enddef ; +vardef LayoutColumnDistance = lua.mp.LayoutColumnDistance() enddef ; +vardef LayoutColumnWidth = lua.mp.LayoutColumnWidth () enddef ; + +vardef OnRightPage = lua.mp.OnRightPage () enddef ; +vardef OnOddPage = lua.mp.OnOddPage () enddef ; +vardef InPageBody = lua.mp.InPageBody () enddef ; + +vardef RealPageNumber = lua.mp.RealPageNumber () enddef ; +vardef PageNumber = lua.mp.PageNumber () enddef ; +vardef NOfPages = lua.mp.NOfPages () enddef ; +vardef LastPageNumber = lua.mp.LastPageNumber () enddef ; % duplicates + +vardef CurrentColumn = lua.mp.CurrentColumn () enddef ; +vardef NOfColumns = lua.mp.NOfColumns () enddef ; + +vardef BaseLineSkip = lua.mp.BaseLineSkip () enddef ; +vardef LineHeight = lua.mp.LineHeight () enddef ; +vardef BodyFontSize = lua.mp.BodyFontSize () enddef ; + +vardef TopSkip = lua.mp.TopSkip () enddef ; +vardef StrutHeight = lua.mp.StrutHeight () enddef ; +vardef StrutDepth = lua.mp.StrutDepth () enddef ; + +vardef CurrentWidth = lua.mp.CurrentWidth () enddef ; +vardef CurrentHeight = lua.mp.CurrentHeight () enddef ; + +vardef HSize = lua.mp.HSize () enddef ; % duplicates +vardef VSize = lua.mp.VSize () enddef ; % duplicates + +vardef EmWidth = lua.mp.EmWidth () enddef ; +vardef ExHeight = lua.mp.ExHeight () enddef ; + +vardef PageFraction = lua.mp.PageFraction () enddef ; + +vardef SpineWidth = lua.mp.SpineWidth () enddef ; +vardef PaperBleed = lua.mp.PaperBleed () enddef ; + +boolean mfun_swapped ; -if unknown OnOddPage : - boolean OnOddPage ; - OnOddPage := true ; -fi ; +def SwapPageState = + mfun_swapped := true ; +enddef ; -if unknown InPageBody : - boolean InPageBody ; - InPageBody := false ; -fi ; +extra_beginfig := extra_beginfig & "mfun_swapped := false ;" ; + +vardef BackSpace = if (mfun_swapped and not OnRightPage) : PaperWidth - MakeupWidth - fi lua.mp.BackSpace() enddef ; +vardef CutSpace = if (mfun_swapped and not OnRightPage) : PaperWidth - MakeupWidth - fi lua.mp.CutSpace () enddef ; + +vardef LeftMarginWidth = if mfun_swapped and not OnRightPage : lua.mp.RightMarginWidth () else : lua.mp.LeftMarginWidth () fi enddef ; +vardef RightMarginWidth = if mfun_swapped and not OnRightPage : lua.mp.LeftMarginWidth () else : lua.mp.RightMarginWidth () fi enddef ; +vardef LeftMarginDistance = if mfun_swapped and not OnRightPage : lua.mp.RightMarginDistance() else : lua.mp.LeftMarginDistance () fi enddef ; +vardef RightMarginDistance = if mfun_swapped and not OnRightPage : lua.mp.LeftMarginDistance () else : lua.mp.RightMarginDistance() fi enddef ; +vardef LeftEdgeWidth = if mfun_swapped and not OnRightPage : lua.mp.RightEdgeWidth () else : lua.mp.LeftEdgeWidth () fi enddef ; +vardef RightEdgeWidth = if mfun_swapped and not OnRightPage : lua.mp.LeftEdgeWidth () else : lua.mp.RightEdgeWidth () fi enddef ; +vardef LeftEdgeDistance = if mfun_swapped and not OnRightPage : lua.mp.RightEdgeDistance () else : lua.mp.LeftEdgeDistance () fi enddef ; +vardef RightEdgeDistance = if mfun_swapped and not OnRightPage : lua.mp.LeftEdgeDistance () else : lua.mp.RightEdgeDistance () fi enddef ; + +% vardef Margin = if OnRightPage : lua.mp.RightMarginWidth else : lua.mp.LeftMarginWidth fi enddef ; +% vardef Edge = if OnRightPage : lua.mp.RightEdgeWidth else : lua.mp.LeftEdgeWidth fi enddef ; +% vardef InnerMargin = if OnRightPage : lua.mp.LeftMarginWidth else : lua.mp.RightMarginWidth fi enddef ; +% vardef InnerEdge = if OnRightPage : lua.mp.LeftEdgeWidth else : lua.mp.RightEdgeWidth fi enddef ; +% vardef OuterMargin = if OnRightPage : lua.mp.RightMarginWidth else : lua.mp.LeftMarginWidth fi enddef ; +% vardef OuterEdge = if OnRightPage : lua.mp.RightEdgeWidth else : lua.mp.LeftEdgeWidth fi enddef ; + +% vardef CurrentLayout = lua.mp.CurrentLayout () enddef ; -string CurrentLayout ; - -CurrentLayout := "default" ; - -PageNumber := 0 ; -PaperHeight := 845.04684pt ; -PaperWidth := 597.50787pt ; -PrintPaperHeight := 845.04684pt ; -PrintPaperWidth := 597.50787pt ; -TopSpace := 71.12546pt ; -BottomSpace := 0.0pt ; -BackSpace := 71.13275pt ; -CutSpace := 0.0pt ; -MakeupHeight := 711.3191pt ; -MakeupWidth := 426.78743pt ; -TopHeight := 0.0pt ; -TopDistance := 0.0pt ; -HeaderHeight := 56.90294pt ; -HeaderDistance := 0.0pt ; -TextHeight := 597.51323pt ; -FooterDistance := 0.0pt ; -FooterHeight := 56.90294pt ; -BottomDistance := 0.0pt ; -BottomHeight := 0.0pt ; -LeftEdgeWidth := 0.0pt ; -LeftEdgeDistance := 0.0pt ; -LeftMarginWidth := 75.58197pt ; -LeftMarginDistance := 11.99829pt ; -TextWidth := 426.78743pt ; -RightMarginDistance := 11.99829pt ; -RightMarginWidth := 75.58197pt ; -RightEdgeDistance := 0.0pt ; -RightEdgeWidth := 0.0pt ; - -PageOffset := 0.0pt ; -PageDepth := 0.0pt ; - -LayoutColumns := 0 ; -LayoutColumnDistance:= 0.0pt ; -LayoutColumnWidth := 0.0pt ; +vardef OverlayWidth = lua.mp.OverlayWidth () enddef ; +vardef OverlayHeight = lua.mp.OverlayHeight () enddef ; +vardef OverlayDepth = lua.mp.OverlayDepth () enddef ; +vardef OverlayLineWidth = lua.mp.OverlayLineWidth() enddef ; +vardef OverlayOffset = lua.mp.OverlayOffset () enddef ; + +vardef defaultcolormodel = lua.mp.defaultcolormodel() enddef ; + +% def OverlayLineColor = lua.mp.OverlayLineColor() enddef ; +% def OverlayColor = lua.mp.OverlayColor () enddef ; + +% Next we implement the the page area model. First some constants. LeftEdge := -4 ; Top := -40 ; LeftEdgeSeparator := -3 ; TopSeparator := -30 ; @@ -89,37 +316,28 @@ RightMargin := +2 ; Footer := +20 ; RightEdgeSeparator := +3 ; BottomSeparator := +30 ; RightEdge := +4 ; Bottom := +40 ; -Margin := LeftMargin ; % obsolete -Edge := LeftEdge ; % obsolete -InnerMargin := RightMargin ; % obsolete -InnerEdge := RightEdge ; % obsolete -OuterMargin := LeftMargin ; % obsolete -OuterEdge := LeftEdge ; % obsolete +% Margin := LeftMargin ; % obsolete +% Edge := LeftEdge ; % obsolete +% InnerMargin := RightMargin ; % obsolete +% InnerEdge := RightEdge ; % obsolete +% OuterMargin := LeftMargin ; % obsolete +% OuterEdge := LeftEdge ; % obsolete -InnerMarginWidth := 0pt ; -OuterMarginWidth := 0pt ; -InnerMarginDistance := 0pt ; -OuterMarginDistance := 0pt ; +numeric HorPos ; HorPos := 0 ; +numeric VerPos ; VerPos := 0 ; -InnerEdgeWidth := 0pt ; -OuterEdgeWidth := 0pt ; -InnerEdgeDistance := 0pt ; -OuterEdgeDistance := 0pt ; +% We used to initialize these variables each (sub)run but at some point MP +% became too slow for this. See later. % path Area[][] ; % pair Location[][] ; % path Field[][] ; - +% % numeric Hstep[] ; % numeric Hsize[] ; % numeric Vstep[] ; % numeric Vsize[] ; - -path Page ; - -numeric HorPos ; -numeric VerPos ; - +% % for VerPos=Top step 10 until Bottom: % for HorPos=LeftEdge step 1 until RightEdge: % Area[HorPos][VerPos] := origin--cycle ; @@ -130,46 +348,8 @@ numeric VerPos ; % Field[VerPos][HorPos] := Field[HorPos][VerPos] ; % endfor ; % endfor ; - -% def LoadPageState = -% scantokens "input mp-state.tmp" ; -% enddef ; - -def SwapPageState = - if not OnRightPage : - BackSpace := PaperWidth-MakeupWidth-BackSpace ; - CutSpace := PaperWidth-MakeupWidth-CutSpace ; - i := LeftMarginWidth ; - LeftMarginWidth := RightMarginWidth ; - RightMarginWidth := i ; - i := LeftMarginDistance ; - LeftMarginDistance := RightMarginDistance ; - RightMarginDistance := i ; - i := LeftEdgeWidth ; - LeftEdgeWidth := RightEdgeWidth ; - RightEdgeWidth := i ; - i := LeftEdgeDistance ; - LeftEdgeDistance := RightEdgeDistance ; - RightEdgeDistance := i ; - - % these are now available as ..Width and ..Distance - - Margin := LeftMargin ; - Edge := LeftEdge ; - InnerMargin := RightMargin ; - InnerEdge := RightEdge ; - OuterMargin := LeftMargin ; - OuterEdge := LeftEdge ; - else : - Margin := RightMargin ; - Edge := RightEdge ; - InnerMargin := LeftMargin ; - InnerEdge := LeftEdge ; - OuterMargin := RightMargin ; - OuterEdge := RightEdge ; - fi ; -enddef ; - +% +% % def SetPageAreas = % % numeric Vsize[], Hsize[], Vstep[], Hstep[] ; @@ -338,29 +518,55 @@ def SetPageField = endfor ; enddef ; -def SetPagePage = - path Page ; - Page := unitsquare xscaled PaperWidth yscaled PaperHeight ; +def mfun_page_Area = hide(SetPageArea ;) Area enddef ; +def mfun_page_Location = hide(SetPageLocation ;) Location enddef ; +def mfun_page_Field = hide(SetPageField ;) Field enddef ; +def mfun_page_Vsize = hide(SetPageVsize ;) Vsize enddef ; +def mfun_page_Hsize = hide(SetPageHsize ;) Hsize enddef ; +def mfun_page_Vstep = hide(SetPageVstep ;) Vstep enddef ; +def mfun_page_Hstep = hide(SetPageHstep ;) Hstep enddef ; + +def SetAreaVariables = + let Area = mfun_page_Area ; + let Location = mfun_page_Location ; + let Field = mfun_page_Field ; + let Vsize = mfun_page_Vsize ; + let Hsize = mfun_page_Hsize ; + let Vstep = mfun_page_Vstep ; + let Hstep = mfun_page_Hstep ; enddef ; -def mfun_page_Area = hide(SetPageArea ;) Area enddef ; -def mfun_page_Location = hide(SetPageLocation ;) Location enddef ; -def mfun_page_Field = hide(SetPageField ;) Field enddef ; -def mfun_page_Vsize = hide(SetPageVsize ;) Vsize enddef ; -def mfun_page_Hsize = hide(SetPageHsize ;) Hsize enddef ; -def mfun_page_Vstep = hide(SetPageVstep ;) Vstep enddef ; -def mfun_page_Hstep = hide(SetPageHstep ;) Hstep enddef ; -def mfun_page_Page = hide(SetPagePage ;) Page enddef ; +% we should make Page no path .. from now on don't assume this .. for a while we keek it + +vardef FrontPageWidth = PaperWidth enddef ; +vardef BackPageWidth = PaperWidth enddef ; +vardef CoverWidth = 2 * PaperWidth + SpineWidth enddef ; +vardef CoverHeight = PaperHeight enddef ; + +vardef FrontPageHeight = PaperHeight enddef ; +vardef BackPageHeight = PaperHeight enddef ; +vardef SpineHeight = PaperHeight enddef ; + +def SetPagePage = path Page ; Page := unitsquare xscaled PaperWidth yscaled PaperHeight ; enddef ; +def SetPageCoverPage = path CoverPage ; CoverPage := unitsquare xscaled CoverWidth yscaled CoverHeight ; enddef ; +def SetPageSpine = path Spine ; Spine := unitsquare xscaled SpineWidth yscaled CoverHeight shifted (BackPageWidth,0) ; enddef ; +def SetPageBackPage = path BackPage ; BackPage := unitsquare xscaled BackPageWidth yscaled CoverHeight ; enddef ; +def SetPageFrontPage = path FrontPage ; FrontPage := unitsquare xscaled FrontPageWidth yscaled CoverHeight shifted (BackPageWidth+SpineWidth,0) ; enddef ; + +def mfun_page_Page = hide(SetPagePage ;) Page enddef ; +def mfun_page_CoverPage = hide(SetPageCoverPage;) CoverPage enddef ; +def mfun_page_Spine = hide(SetPageSpine ;) Spine enddef ; +def mfun_page_BackPage = hide(SetPageBackPage ;) BackPage enddef ; +def mfun_page_FrontPage = hide(SetPageFrontPage;) FrontPage enddef ; def SetPageVariables = - let Area = mfun_page_Area ; - let Location = mfun_page_Location ; - let Field = mfun_page_Field ; - let Vsize = mfun_page_Vsize ; - let Hsize = mfun_page_Hsize ; - let Vstep = mfun_page_Vstep ; - let Hstep = mfun_page_Hstep ; - let Page = mfun_page_Page ; + SetAreaVariables ; + % + let Page = mfun_page_Page ; + let CoverPage = mfun_page_CoverPage ; + let Spine = mfun_page_Spine ; + let BackPage = mfun_page_BackPage ; + let FrontPage = mfun_page_FrontPage ; enddef ; SetPageVariables ; @@ -393,45 +599,10 @@ enddef ; def BoundCoverAreas = % todo: add cropmarks - bboxmargin := 0 ; setbounds currentpicture to Paper enlarged PaperBleed ; + bboxmargin := 0 ; setbounds currentpicture to CoverPage enlarged PaperBleed ; enddef ; -def SetCoverAreas = - - if unknown SpineWidth : - SpineWidth := 8mm ; - fi ; - - if unknown PaperBleed : - PaperBleed := 0 ; - fi ; - - FrontPageWidth := PaperWidth ; - BackPageWidth := PaperWidth ; - PaperWidth := 2 * PaperWidth + SpineWidth ; - - FrontPageHeight := PaperHeight ; - BackPageHeight := PaperHeight ; - PaperHeight := PaperHeight ; - SpineHeight := PaperHeight ; - - path Paper ; Paper := unitsquare xscaled PaperWidth yscaled PaperHeight ; - path Spine ; Spine := unitsquare xscaled SpineWidth yscaled PaperHeight shifted (BackPageWidth,0); - path BackPage ; BackPage := unitsquare xscaled BackPageWidth yscaled PaperHeight ; - path FrontPage ; FrontPage := unitsquare xscaled FrontPageWidth yscaled PaperHeight shifted (BackPageWidth+SpineWidth,0) ; - -enddef ; - -% def StartCover = -% begingroup ; -% if PageStateAvailable : -% LoadPageState ; -% % SwapPageState ; -% fi ; -% SetPageAreas ; -% SetCoverAreas ; -% BoundCoverAreas ; -% enddef ; +let SetCoverAreas = SetPageVariables ; % compatiblity def StartCover = begingroup ; diff --git a/Master/texmf-dist/metapost/context/base/mp-tool.mpii b/Master/texmf-dist/metapost/context/base/mp-tool.mpii index 62bd122f590..a5bb345a1a3 100644 --- a/Master/texmf-dist/metapost/context/base/mp-tool.mpii +++ b/Master/texmf-dist/metapost/context/base/mp-tool.mpii @@ -1407,7 +1407,7 @@ primarydef pct along pat = % also negative enddef ; primarydef len on pat = % no outer ( ) .. somehow fails - (arctime if len>0 : len else : (arclength(pat)+len) fi of pat) of pat + (arctime if len>=0 : len else : (arclength(pat)+len) fi of pat) of pat enddef ; % this cuts of a piece from both ends diff --git a/Master/texmf-dist/metapost/context/base/mp-tool.mpiv b/Master/texmf-dist/metapost/context/base/mp-tool.mpiv index 7845467a46c..e497e2f7242 100644 --- a/Master/texmf-dist/metapost/context/base/mp-tool.mpiv +++ b/Master/texmf-dist/metapost/context/base/mp-tool.mpiv @@ -57,8 +57,15 @@ mpprocset := 1 ; % % protect ; -string space ; space := char 32 ; -string CRLF ; CRLF := char 10 & char 13 ; +string space ; space := char 32 ; +string percent ; percent := char 37 ; +string crlf ; crlf := char 10 & char 13 ; +string dquote ; dquote := char 34 ; + +let SPACE = space ; +let CRLF = crlf ; +let DQUOTE = dquote ; +let PERCENT = percent ; vardef ddecimal primary p = decimal xpart p & " " & decimal ypart p @@ -90,8 +97,8 @@ newinternal graycolormodel ; graycolormodel := 3 ; newinternal rgbcolormodel ; rgbcolormodel := 5 ; newinternal cmykcolormodel ; cmykcolormodel := 7 ; -let grayscale = numeric ; -let greyscale = numeric ; +let grayscale = graycolor ; +let greyscale = greycolor ; vardef colorpart expr c = if not picture c : @@ -141,6 +148,39 @@ vardef colordecimals primary c = fi enddef ; +vardef colordecimalslist(text t) = + save b ; boolean b ; b := false ; + for s=t : + if b : & " " & fi + colordecimals(s) + hide(b := true ;) + endfor +enddef ; + +% vardef _ctx_color_spec_ primary c = +% if cmykcolor c : +% "c=" & decimal cyanpart c & +% ",m=" & decimal magentapart c & +% ",y=" & decimal yellowpart c & +% ",k=" & decimal blackpart c +% elseif rgbcolor c : +% "r=" & decimal redpart c & +% ",g=" & decimal greenpart c & +% ",b=" & decimal bluepart c +% else : +% "s=" & decimal c +% fi +% enddef ; +% +% vardef _ctx_color_spec_list_(text t) = +% save b ; boolean b ; b := false ; +% for s=t : +% if b : & " " & fi +% _ctx_color_spec_(s) +% hide(b := true ;) +% endfor +% enddef ; + %D We have standardized data file names: def job_name = @@ -152,7 +192,8 @@ def data_mpd_file = enddef ; %D Because \METAPOST\ has a hard coded limit of 4~datafiles, -%D we need some trickery when we have multiple files. +%D we need some trickery when we have multiple files. This will +%D be redone (via \LUA). if unknown collapse_data : boolean collapse_data ; @@ -292,12 +333,12 @@ enddef; %D Some missing functions can be implemented rather straightforward (thanks to %D Taco and others): -pi := 3.14159265358979323846 ; radian := 180/pi ; % 2pi*radian = 360 ; +% oldpi := 3.14159265358979323846 ; % from <math.h> +pi := 3.14159265358979323846264338327950288419716939937510 ; % 50 digits +radian := 180/pi ; % 2pi*radian = 360 ; % let +++ = ++ ; -numeric Pi ; Pi := pi ; % for some old compatibility reasons i guess - vardef sqr primary x = x*x enddef ; vardef log primary x = if x=0: 0 else: mlog(x)/mlog(10) fi enddef ; vardef ln primary x = if x=0: 0 else: mlog(x)/256 fi enddef ; @@ -328,6 +369,11 @@ vardef asinh primary x = ln(x+(x++1)) enddef ; vardef sinh primary x = save xx ; xx = exp x ; (xx-1/xx)/2 enddef ; vardef cosh primary x = save xx ; xx = exp x ; (xx+1/xx)/2 enddef ; +%D Like mod, but useful for anglesl it returns (-.5d,+.5d] and is used +%D in for instance mp-chem. + +primarydef a zmod b = (-((b/2 - a) mod b) + b/2) enddef ; + %D Sometimes this is handy: def undashed = @@ -774,8 +820,8 @@ vardef whitecolor(expr c) = if cmykcolor c : (0,0,0,0) elseif rgbcolor c : (1,1,1) else : 1 fi enddef ; -vardef blackcolor(expr c) = - if cmykcolor c : (0,0,0,1) elseif rgbcolor c : (0,0,0) else : 0 fi +vardef blackcolor expr c = + if cmykcolor c : (0,0,0,1) elseif rgbcolor c : (0,0,0) else : 0 fi enddef ; %D Well, this is the dangerous and naive version: @@ -1324,7 +1370,7 @@ primarydef pct along pat = % also negative enddef ; primarydef len on pat = % no outer ( ) .. somehow fails - (arctime if len>0 : len else : (arclength(pat)+len) fi of pat) of pat + (arctime if len>=0 : len else : (arclength(pat)+len) fi of pat) of pat enddef ; % this cuts of a piece from both ends @@ -1545,9 +1591,13 @@ primarydef p softened c = enddef ; vardef grayed primary p = - if color p : + if rgbcolor p : tripled(.30redpart p+.59greenpart p+.11bluepart p) - else : + elseif cmykcolor p : + tripled(.30*(1-cyanpart i)+.59*(1-magentapart i)+.11*(1-yellowpart i)+blackpart i) + elseif greycolor p : + p + elseif picture p : image ( for i within p : addto currentpicture @@ -1563,12 +1613,24 @@ vardef grayed primary p = else : also i fi - withcolor tripled(.30redpart i+.59greenpart i+.11bluepart i) ; + if unknown colorpart i : + % nothing + elseif rgbcolor colorpart i : + withcolor tripled(.30redpart i+.59greenpart i+.11bluepart i) ; + elseif cmykcolor colorpart i : + withcolor tripled(.30*(1-cyanpart i)+.59*(1-magentapart i)+.11*(1-yellowpart i)+blackpart i) ; + else : + withcolor colorpart i ; + fi endfor ; ) - fi + else : + p + fi enddef ; +let greyed = grayed ; + % yes or no: "text" infont "cmr12" at 24pt ; % let normalinfont = infont ; @@ -2036,7 +2098,7 @@ enddef ; % handy def withgray primary g = - withcolor (g,g,g) + withcolor g enddef ; % for metafun @@ -2259,7 +2321,7 @@ enddef ; %D Handy: def break = - exitif true fi ; + exitif true ; % fi enddef ; %D New too: @@ -2272,23 +2334,31 @@ primarydef p ystretched h = ( p if (bbheight(p)>0) and (h>0) : yscaled (h/bbheight(p)) fi ) enddef ; -primarydef p snapped s = - hide ( - if path p : - forever : - exitif (bbheight(p) <= s) and (bbwidth(p) <= s) ; - p := p scaled (1/2) ; - endfor ; - elseif numeric p : - forever : - exitif p <= s ; - p := p scaled (1/2) ; - endfor ; - fi ; - ) - p +%D Newer: + +vardef area expr p = + % we could calculate the boundingbox once + (xpart llcorner boundingbox p,0) -- p -- + (xpart lrcorner boundingbox p,0) -- cycle enddef ; +vardef basiccolors[] = + if @ = 0 : + white + else : + save n ; n := @ mod 7 ; + if n = 1 : red + elseif n = 2 : green + elseif n = 3 : blue + elseif n = 4 : cyan + elseif n = 5 : magenta + elseif n = 6 : yellow + else : black + fi + fi +enddef ; + + % vardef somecolor = (1,1,0,0) enddef ; % fill OverlayBox withcolor (rcomponent somecolor,gcomponent somecolor,bcomponent somecolor) ; @@ -2335,7 +2405,6 @@ vardef undecorated (text imagedata) text decoration = currentpicture enddef ; - if metapostversion < 1.770 : vardef decorated (text imagedata) text decoration = @@ -2455,25 +2524,76 @@ enddef ; % ) % enddef ; +vardef mfun_snapped(expr p, s) = + if p < 0 : - ( - else : ( fi p div s) * s % the less tokens the better +enddef ; + +vardef mfun_applied(expr p, s)(suffix a) = + if path p : + if pair s : + for i=0 upto length(p)-1 : + (a(xpart point i of p,xpart s),a(ypart point i of p,ypart s)) -- + endfor + if cycle p : + cycle + else : + (a(xpart point length(p) of p,xpart s),a(ypart point length(p) of p,ypart s)) + fi + else : + for i=0 upto length(p)-1 : + (a(xpart point i of p,s),a(ypart point i of p,s)) -- + endfor + if cycle p : + cycle + else : + (a(xpart point length(p) of p,s),a(ypart point length(p) of p,s)) + fi + fi + elseif pair p : + if pair s : + (a(xpart p,xpart s),a(ypart p,ypart s)) + else : + (a(xpart p,s),a(ypart p,s)) + fi + elseif cmykcolor p : + (a(cyanpart p,s),a(magentapart p,s),a(yellowpart p,s),a(blackpart p,s)) + elseif rgbcolor p : + (a(redpart p,s),a(greenpart p,s),a(bluepart p,s)) + elseif graycolor p : + a(p,s) + elseif numeric p : + a(p,s) + else + p + fi +enddef ; + +primarydef p snapped s = + mfun_applied(p,s)(mfun_snapped) % so we can play with variants +enddef ; + %D New helpers: +newinternal charscale ; charscale := 1 ; % persistent so one needs to 'reset' it to 0 or 1 + def beginglyph(expr unicode, width, height, depth) = beginfig(unicode) ; % the number is irrelevant charcode := unicode ; charwd := width ; charht := height ; chardp := depth ; + % charscale := 1 ; % can be set for a whole font, so no reset here enddef ; def endglyph = setbounds currentpicture to (boundingbox unitsquare xscaled charwd yscaled (charht + chardp) shifted (0,-chardp)) ; - if known charscale : + if known charscale : if (charscale > 0) and (charscale <> 1) : currentpicture := currentpicture scaled charscale ; - fi ; + fi ; fi ; endfig ; enddef ; -%D Dimensions have bever been an issue as traditional MP can't make that large +%D Dimensions have never been an issue as traditional MP can't make that large %D pictures, but with double mode we need a catch: newinternal maxdimensions ; maxdimensions := 14000 ; |