diff options
author | Hans Hagen <pragma@wxs.nl> | 2004-06-20 00:00:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2004-06-20 00:00:00 +0200 |
commit | 0bfaf7db3a4495c91871b17e20cebecdff4a5dde (patch) | |
tree | 6a8fcba94cba07f786eb5506ef665dc51e9ffbbc /metapost | |
parent | 51d573f4c0e8d3b8499bff7a3c6fba3dcd71d725 (diff) | |
download | context-0bfaf7db3a4495c91871b17e20cebecdff4a5dde.tar.gz |
stable 2004.06.20
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/metafun.mp | 55 | ||||
-rw-r--r-- | metapost/context/base/mp-core.mp | 11 | ||||
-rw-r--r-- | metapost/context/base/mp-figs.mp | 50 | ||||
-rw-r--r-- | metapost/context/base/mp-spec.mp | 158 | ||||
-rw-r--r-- | metapost/context/base/mp-text.mp | 321 | ||||
-rw-r--r-- | metapost/context/base/mp-tool.mp | 152 |
6 files changed, 240 insertions, 507 deletions
diff --git a/metapost/context/base/metafun.mp b/metapost/context/base/metafun.mp index 5071013c5..f8cab41bf 100644 --- a/metapost/context/base/metafun.mp +++ b/metapost/context/base/metafun.mp @@ -1,15 +1,15 @@ %D \module %D [ file=metafun.mp, %D version=2000.07.15, -%D title=\CONTEXT\ \METAPOST\ graphics, -%D subtitle=format generation file, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=format generation file, %D author=Hans Hagen, %D date=\currentdate, %D copyright={PRAGMA / Hans Hagen \& Ton Otten}] %C %C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. %D When generating many graphics at runtime, it can save run %D time to use a format file. We could have named this file @@ -21,29 +21,28 @@ %D (and as a result in buggy boundingbox and special %D handling). By using the name \type {metatex} we make sure %D that we use (unless overloaded) the settings of \type -%D {mpost}. - -if unknown ahangle : - input plain.mp ; % John Hobby's file -else : - let dump = relax ; -fi ; - -input mp-tool.mp ; -input mp-spec.mp ; -input mp-core.mp ; -input mp-page.mp ; -input mp-text.mp ; -input mp-shap.mp ; -input mp-butt.mp ; -input mp-char.mp ; -input mp-step.mp ; -input mp-grph.mp ; -input mp-figs.mp ; - -% mp-form.mp ; -input mp-grid.mp ; -input mp-func.mp ; +%D {mpost}. + +if unknown ahangle : + input plain.mp ; % John Hobby's file +else : + let dump = relax ; +fi ; + +input mp-tool.mp ; +input mp-spec.mp ; +input mp-core.mp ; +input mp-page.mp ; +input mp-text.mp ; +input mp-shap.mp ; +input mp-butt.mp ; +input mp-char.mp ; +input mp-step.mp ; +input mp-grph.mp ; + +% mp-form.mp ; +input mp-grid.mp ; +input mp-func.mp ; string metafunversion ; @@ -57,7 +56,7 @@ metafunversion = "metafun" & " " & let normalend = end ; def end = - ; message "" ; message metafunversion ; message "" ; normalend ; + message "" ; message metafunversion ; message "" ; normalend ; enddef ; dump ; endinput . diff --git a/metapost/context/base/mp-core.mp b/metapost/context/base/mp-core.mp index eb038163e..51d2d0025 100644 --- a/metapost/context/base/mp-core.mp +++ b/metapost/context/base/mp-core.mp @@ -520,12 +520,11 @@ par_hang_after := ra + estimated_par_lines(py-fy) ; if (par_hang_indent>0) and (par_hang_after<0) and obey_multi_par_hang : pair _ul_ ; _ul_ := (xpart ulcorner multipar, ypart snapped_multi_pos(ulxy[fpos])); pair _pa_ ; _pa_ := _ul_ shifted (0,par_hang_after*par_line_height) ; -% _pa_ := (xpart _pa_,max(ypart _pa_,ypart llcorner multipar)) ; - _pa_ := (xpart _pa_,max(ypart _pa_ -TopSkipCorrection,ypart llcorner multipar)) ; + _pa_ := (xpart _pa_,max(ypart _pa_,ypart llcorner multipar)) ; if same_area : -% _pa_ := (xpart _pa_,max(ypart _pa_,ypart llxy[tpos])) ; - _pa_ := (xpart _pa_,max(ypart _pa_ -TopSkipCorrection,ypart llxy[tpos])) ; + _pa_ := (xpart _pa_,max(ypart _pa_,ypart llxy[tpos])) ; fi ; +% vervalt: if obey_multi_par_more and (round(par_line_height)>0) : par_hang_after := min(0,round(par_hang_after + (ypart urxy[fpos]-ypart _pa_)/par_line_height)) ; @@ -540,8 +539,7 @@ par_hang_after := ra + estimated_par_lines(py-fy) ; vardef right_top_hang (expr same_area) = -% par_hang_after := ra - estimated_par_lines(py-fy) ; -par_hang_after := ra + estimated_par_lines(py-fy) ; +par_hang_after := ra - estimated_par_lines(py-fy) ; if (par_hang_indent<0) and (par_hang_after<0) and obey_multi_par_hang : pair _ur_ ; _ur_ := (xpart urcorner multipar, ypart snapped_multi_pos(urxy[fpos])) ; @@ -1242,7 +1240,6 @@ vardef PrepareSyncTasks(expr n, collapse, extendtop, prestartnext) = NOfSyncPaths := NOfSyncPaths + 1 ; if not ok : if i>1 : -% not yet correct when two of the same follow each other if sync_t[n][i-1] = sync_t[n][i] : SyncPaths[NOfSyncPaths] := SyncBox(n, i, SyncLeftOffset, SyncWidth, PaperHeight, -PaperHeight) ; SyncTasks[NOfSyncPaths] := i ; diff --git a/metapost/context/base/mp-figs.mp b/metapost/context/base/mp-figs.mp deleted file mode 100644 index aa6bc0399..000000000 --- a/metapost/context/base/mp-figs.mp +++ /dev/null @@ -1,50 +0,0 @@ -%D \module -%D [ file=mp-tool.mp, -%D version=2003.01.15, -%D title=\CONTEXT\ \METAPOST\ graphics, -%D subtitle=figures, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] -%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 unknown context_tool : input mp-tool ; fi ; -if known context_figs : endinput ; fi ; - -boolean context_figs ; context_figs := true ; - -% todo: check defined - -def registerfigure(expr name,width,height) = - begingroup ; - save s ; string s ; s := cleanstring(name) ; - scantokens( s & "_width := " & decimal(width)) ; - scantokens( s & "_height := " & decimal(width)) ; - endgroup ; -enddef ; - -vardef figuresize(expr name) = - save s ; string s ; s := cleanstring(name) ; - save p ; pair p ; - scantokens( "p := " & "(" & s & "_width" & "," & s & "_height" & ")" ) ; - p -enddef ; - -vardef figurewidth(expr name) = - xpart figuresize(name) -enddef ; - -vardef figureheight(expr name) = - ypart figuresize(name) -enddef ; - -def figuredimensions = figuresize enddef ; % for old times sake - -def naturalfigure(expr name) = - externalfigure name xyscaled(figuresize(name)) -enddef ; - -endinput diff --git a/metapost/context/base/mp-spec.mp b/metapost/context/base/mp-spec.mp index bef6cd2fa..b005eb381 100644 --- a/metapost/context/base/mp-spec.mp +++ b/metapost/context/base/mp-spec.mp @@ -414,106 +414,34 @@ resetspotcolors ; boolean spotcolors ; spotcolors := false ; % true string spotcolorpattern[] ; % needed for transparancies -% vardef spotcolor(expr p, s) = -% if spotcolors : -% save ok, pc_tag ; boolean ok ; string pc_tag ; -% pc_tag := "_pct_"&p ; -% if not unstringed(pc_tag) : -% _spotcolor_number_ := _spotcolor_number_ + 1 ; -% setunstringed(pc_tag,_spotcolor_number_) ; -% fi ; -% pp := getunstringed(pc_tag) ; -% if unknown spotcolorhash[pp][s] : -% ok := false ; % not yet defined -% elseif spotcolorhash[pp][s] = -1 : -% ok := false ; % locally defined and undefined -% else : -% ok := true ; % globally already defined -% fi ; -% if not ok : -% save ss ; string ss ; ss := p & " " & decimal s ; -% _spotcolor_counter_ := _spotcolor_counter_ + 1 ; -% spotcolorpattern[_spotcolor_counter_/1000] := ss ; -% spotcolorhash[pp][s] := _spotcolor_counter_ ; -% flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; -% _local_specials_ := _local_specials_ & -% "spotcolorhash["&decimal pp&"]["&decimal s&"]:=-1;" ; -% fi ; -% (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) -% else : -% (1-s,1-s,1-s) -% fi -% enddef ; - -% vardef spotcolor(expr p, s) = -% if spotcolors : -% save ok, pc_tag ; boolean ok ; string pc_tag ; -% pc_tag := "_pct_"&p ; -% if not unstringed(pc_tag) : -% _spotcolor_number_ := _spotcolor_number_ + 1 ; -% setunstringed(pc_tag,_spotcolor_number_) ; -% fi ; -% pp := getunstringed(pc_tag) ; -% if unknown spotcolorhash[pp][s] : -% ok := false ; % not yet defined -% elseif spotcolorhash[pp][s] = -1 : -% ok := false ; % locally defined and undefined -% else : -% ok := true ; % globally already defined -% fi ; -% if not ok : -% save ss ; string ss ; ss := p & " " & decimal s ; -% _spotcolor_counter_ := _spotcolor_counter_ + 1 ; -% spotcolorpattern[_spotcolor_counter_/1000] := ss ; -% spotcolorhash[pp][s] := _spotcolor_counter_ ; -% flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; -% _local_specials_ := _local_specials_ & -% "spotcolorhash["&decimal pp&"]["&decimal s&"]:=-1;" ; -% fi ; -% (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) -% else : -% (1-s,1-s,1-s) -% fi -% enddef ; - vardef spotcolor(expr p, s) = - multitonecolor(p, 1, "", decimal s) -enddef ; - -vardef multitonecolor(expr n, f, d, p) = % name fractions names factors if spotcolors : save ok, pc_tag ; boolean ok ; string pc_tag ; - pc_tag := "_pct_" & n ; + pc_tag := "_pct_"&p ; if not unstringed(pc_tag) : _spotcolor_number_ := _spotcolor_number_ + 1 ; setunstringed(pc_tag,_spotcolor_number_) ; fi ; pp := getunstringed(pc_tag) ; - pc_tag := "_pct_"& decimal f & "_" & if d = "" : n else : d fi & "_" & p ; % check for d empty - if not unstringed(pc_tag) : - _spotcolor_number_ := _spotcolor_number_ + 1 ; - setunstringed(pc_tag,_spotcolor_number_) ; - fi ; - ps := getunstringed(pc_tag) ; - if unknown spotcolorhash[pp][ps] : + if unknown spotcolorhash[pp][s] : ok := false ; % not yet defined - elseif spotcolorhash[pp][ps] = -1 : + elseif spotcolorhash[pp][s] = -1 : ok := false ; % locally defined and undefined else : ok := true ; % globally already defined fi ; if not ok : - save ss ; string ss ; ss := n & " " & decimal f & " " & if d = "" : n else : d fi & " " & p ; + save ss ; string ss ; ss := p & " " & decimal s ; _spotcolor_counter_ := _spotcolor_counter_ + 1 ; spotcolorpattern[_spotcolor_counter_/1000] := ss ; - spotcolorhash[pp][ps] := _spotcolor_counter_ ; - flush_special(2, 7, decimal _spotcolor_counter_ & " " & ss) ; + spotcolorhash[pp][s] := _spotcolor_counter_ ; + flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; _local_specials_ := _local_specials_ & - "spotcolorhash["&decimal pp&"]["&decimal ps&"]:=-1;" ; + "spotcolorhash["&decimal pp&"]["&decimal s&"]:=-1;" ; fi ; - (_special_signal_/1000,2/1000,spotcolorhash[pp][ps]/1000) + (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) else : - .5white + (1-s,1-s,1-s) fi enddef ; @@ -531,63 +459,6 @@ differencetransparent := 11 ; exclusiontransparent := 12 ; % fill fullcircle scaled 10cm withcolor transparant(.8,3,color) ; -% vardef transparent(expr n, t, c) = -% save s, ss, nn, cc, is_cmyk, is_spot, ok ; -% string s, ss ; numeric nn ; color cc ; boolean is_cmyk, is_spot, ok ; -% % transparancy type -% if string n : -% if expandafter known scantokens(n&"transparent") : -% nn := scantokens(n&"transparent") ; -% else : -% nn := 0 ; -% fi -% else : % nn := min(n,13) -% nn := if n<13 : n else : nn := 0 fi ; -% fi ; -% % we need to expand the color (can be cmyk(..) or predefined) -% cc := c ; % expand color -% % check for cmyk special -% is_cmyk := (redpart cc = _special_signal_/1000) -% and (greenpart cc = 1/1000) ; -% is_spot := (redpart cc = _special_signal_/1000) -% and (greenpart cc = 2/1000) ; -% % build special string, fetch cmyk components -% s := decimal nn & " " & decimal t & " " & -% if is_cmyk : cmykcolorpattern[bluepart cc] -% elseif is_spot : spotcolorpattern[bluepart cc] -% else : dddecimal cc fi ; -% % check if this one is already used -% ss := "tr_" & s ; -% % efficiency hack -% if expandafter unknown scantokens(ss) : -% ok := false ; % not yet defined -% elseif scantokens(ss) < 0 : -% ok := false ; % locally defined and undefined -% else : -% ok := true ; % globally already defined -% fi ; -% if not ok : -% if is_spot : -% flush_special(5, 6, s) ; -% elseif is_cmyk : -% flush_special(4, 8, s) ; -% else : -% flush_special(3, 7, s) ; -% fi ; -% scantokens(ss) := _special_counter_ ; -% _local_specials_ := _local_specials_ & -% "scantokens(" & ditto & ss & ditto & ") := -1 ;" ; -% fi ; -% % go ahead -% if is_spot : -% (_special_signal_/1000,5/1000,scantokens(ss)/1000) -% elseif is_cmyk : -% (_special_signal_/1000,4/1000,scantokens(ss)/1000) -% else : -% (_special_signal_/1000,3/1000,scantokens(ss)/1000) -% fi -% enddef ; - vardef transparent(expr n, t, c) = save s, ss, nn, cc, is_cmyk, is_spot, ok ; string s, ss ; numeric nn ; color cc ; boolean is_cmyk, is_spot, ok ; @@ -614,12 +485,7 @@ vardef transparent(expr n, t, c) = elseif is_spot : spotcolorpattern[bluepart cc] else : dddecimal cc fi ; % check if this one is already used - ss := cleanstring("tr_" & s) ; - % we now have rather unique names, i.e. a color spec of .234 becomes - % tr..._234.... and metapost gives a number overflow (parse error) - % for variables like tr_12345678 which may result from many decimal - % positions (imo mp bug) - ss := asciistring(ss) ; + ss := "tr_" & s ; % efficiency hack if expandafter unknown scantokens(ss) : ok := false ; % not yet defined @@ -630,7 +496,7 @@ vardef transparent(expr n, t, c) = fi ; if not ok : if is_spot : - flush_special(5, 8, s) ; + flush_special(5, 6, s) ; elseif is_cmyk : flush_special(4, 8, s) ; else : @@ -704,4 +570,4 @@ enddef ; % spotcolor is already scaled -endinput ; +endinput ;
\ No newline at end of file diff --git a/metapost/context/base/mp-text.mp b/metapost/context/base/mp-text.mp index 2e061df09..cb6bb3895 100644 --- a/metapost/context/base/mp-text.mp +++ b/metapost/context/base/mp-text.mp @@ -2,182 +2,165 @@ %D [ file=mp-text.mp, %D version=2000.07.10, %D title=\CONTEXT\ \METAPOST\ graphics, -%D subtitle=text support, +%D subtitle=text support, %D author=Hans Hagen, %D date=\currentdate, %D copyright={PRAGMA / Hans Hagen \& Ton Otten}] %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. +%C therefore copyrighted by \PRAGMA. See licen-en.pdf for +%C details. %D Under construction. -if unknown context_tool : input mp-tool ; fi ; -if known context_text : endinput ; fi ; +if unknown context_tool : input mp-tool ; fi ; +if known context_text : endinput ; fi ; -boolean context_text ; context_text := true ; +boolean context_text ; context_text := true ; -if unknown noftexpictures : - numeric noftexpictures ; noftexpictures := 0 ; -fi ; +if unknown noftexpictures : + numeric noftexpictures ; noftexpictures := 0 ; +fi ; -if unknown texpictures[1] : - picture texpictures[] ; -fi ; +if unknown texpictures[1] : + picture texpictures[] ; +fi ; -numeric textextoffset ; textextoffset := 0 ; +numeric textextoffset ; textextoffset := 0 ; -% vardef textext@#(expr txt) = -% interim labeloffset := textextoffset ; -% noftexpictures := noftexpictures + 1 ; -% if string txt : -% write "% figure " & decimal charcode & " : " & -% "texpictures[" & decimal noftexpictures & "] := btex " & -% txt & " etex ;" to jobname & ".mpt" ; -% if unknown texpictures[noftexpictures] : -% thelabel@#("unknown",origin) +% vardef textext@#(expr txt) = +% interim labeloffset := textextoffset ; +% noftexpictures := noftexpictures + 1 ; +% if string txt : +% write "% figure " & decimal charcode & " : " & +% "texpictures[" & decimal noftexpictures & "] := btex " & +% txt & " etex ;" to jobname & ".mpt" ; +% if unknown texpictures[noftexpictures] : +% thelabel@#("unknown",origin) % else : -% thelabel@#(texpictures[noftexpictures],origin) -% fi +% thelabel@#(texpictures[noftexpictures],origin) +% fi % else : -% thelabel@#(txt,origin) -% fi -% enddef ; - -boolean hobbiestextext ; hobbiestextext := false ; -% string textextstring ; textextstring := "" ; - -% def resettextextdirective = -% textextstring := "" ; -% enddef ; - -% def textextdirective text t = -% textextstring := textextstring & t ; -% enddef ; - -vardef textext@#(expr txt) = - save _s_ ; string _s_ ; - interim labeloffset := textextoffset ; - noftexpictures := noftexpictures + 1 ; - if string txt : -% if textextstring <> "" : -% _s_ := "verbatimtex " & textextstring & " etex ;" ; -% else : -% _s_ := "" ; -% fi ; +% thelabel@#(txt,origin) +% fi +% enddef ; + +boolean hobbiestextext ; hobbiestextext := false ; + +vardef textext@#(expr txt) = + interim labeloffset := textextoffset ; + noftexpictures := noftexpictures + 1 ; + if string txt : if hobbiestextext : % the tex.mp method as fallback (see tex.mp) -% write _s_ to "mptextmp.mp" ; - write _s_ & "btex " & txt & " etex" to "mptextmp.mp" ; + write "btex " & txt & " etex" to "mptextmp.mp" ; write EOF to "mptextmp.mp" ; scantokens "input mptextmp" else : -% write "% setup : " & _s_ to jobname & ".mpt" ; - write "% figure " & decimal charcode & " : " & - "texpictures[" & decimal noftexpictures & "] := btex " & - txt & " etex ;" to jobname & ".mpt" ; - if unknown texpictures[noftexpictures] : - thelabel@#("unknown",origin) + write "% figure " & decimal charcode & " : " & + "texpictures[" & decimal noftexpictures & "] := btex " & + txt & " etex ;" to jobname & ".mpt" ; + if unknown texpictures[noftexpictures] : + thelabel@#("unknown",origin) else : - thelabel@#(texpictures[noftexpictures],origin) + thelabel@#(texpictures[noftexpictures],origin) fi - fi + fi else : - thelabel@#(txt,origin) - fi -enddef ; - -string laboff_ ; laboff_ := "" ; -string laboff_c ; laboff_c := "" ; -string laboff_l ; laboff_l := ".lft" ; -string laboff_r ; laboff_r := ".rt" ; -string laboff_b ; laboff_b := ".bot" ; -string laboff_t ; laboff_t := ".top" ; -string laboff_lt ; laboff_lt := ".ulft" ; -string laboff_rt ; laboff_rt := ".urt" ; -string laboff_lb ; laboff_lb := ".llft" ; -string laboff_rb ; laboff_rb := ".lrt" ; -string laboff_tl ; laboff_tl := ".ulft" ; -string laboff_tr ; laboff_tr := ".urt" ; -string laboff_bl ; laboff_bl := ".llft" ; -string laboff_br ; laboff_br := ".lrt" ; - -vardef textextstr(expr s, a) = - save ss ; string ss ; - ss := "laboff_" & a ; - ss := scantokens ss ; + thelabel@#(txt,origin) + fi +enddef ; + +string laboff_ ; laboff_ := "" ; +string laboff_c ; laboff_c := "" ; +string laboff_l ; laboff_l := ".lft" ; +string laboff_r ; laboff_r := ".rt" ; +string laboff_b ; laboff_b := ".bot" ; +string laboff_t ; laboff_t := ".top" ; +string laboff_lt ; laboff_lt := ".ulft" ; +string laboff_rt ; laboff_rt := ".urt" ; +string laboff_lb ; laboff_lb := ".llft" ; +string laboff_rb ; laboff_rb := ".lrt" ; +string laboff_tl ; laboff_tl := ".ulft" ; +string laboff_tr ; laboff_tr := ".urt" ; +string laboff_bl ; laboff_bl := ".llft" ; +string laboff_br ; laboff_br := ".lrt" ; + +vardef textextstr(expr s, a) = + save ss ; string ss ; + ss := "laboff_" & a ; + ss := scantokens ss ; ss := "textext" & ss & "(" & ditto & s & ditto & ")" ; - scantokens ss -enddef ; + scantokens ss +enddef ; -pair laboff.origin ; laboff.origin = (infinity,infinity) ; -pair laboff.raw ; laboff.raw = (infinity,infinity) ; +pair laboff.origin ; laboff.origin = (infinity,infinity) ; +pair laboff.raw ; laboff.raw = (infinity,infinity) ; -vardef thelabel@#(expr s, z) = +vardef thelabel@#(expr s, z) = save p ; picture p ; p = s if not picture s : infont defaultfont scaled defaultscale fi ; - if laboff@#<>laboff.origin : - (p shifted (z + labeloffset*laboff@# - (labxf@#*lrcorner p + + if laboff@#<>laboff.origin : + (p shifted (z + labeloffset*laboff@# - (labxf@#*lrcorner p + labyf@#*ulcorner p + (1-labxf@#-labyf@#)*llcorner p))) else : (p shifted z) fi enddef; -def build_parshape (expr p, offset_or_path, dx, dy, +def build_parshape (expr p, offset_or_path, dx, dy, baselineskip, strutheight, strutdepth, topskip) = - - if unknown trace_parshape : - boolean trace_parshape ; trace_parshape := false ; + + if unknown trace_parshape : + boolean trace_parshape ; trace_parshape := false ; fi ; begingroup ; - save q, l, r, line, tt, bb, - n, hsize, vsize, vvsize, voffset, hoffset, width, indent, - ll, lll, rr, rrr, cp, cq, t, b ; + save q, l, r, line, tt, bb, + n, hsize, vsize, vvsize, voffset, hoffset, width, indent, + ll, lll, rr, rrr, cp, cq, t, b ; - path q, l, r, line, tt, bb ; + path q, l, r, line, tt, bb ; numeric n, hsize, vsize, vvsize, voffset, hoffset, width[], indent[] ; - pair ll, lll, rr, rrr, cp, cq, t, b ; + pair ll, lll, rr, rrr, cp, cq, t, b ; - n := 0 ; cp := center p ; + n := 0 ; cp := center p ; - if path offset_or_path : - q := offset_or_path ; cq := center q ; - voffset := dy ; - hoffset := dx ; - else : - q := p ; cq := center q ; + if path offset_or_path : + q := offset_or_path ; cq := center q ; + voffset := dy ; + hoffset := dx ; + else : + q := p ; cq := center q ; hoffset := offset_or_path + dx ; - voffset := offset_or_path + dy ; - fi ; + voffset := offset_or_path + dy ; + fi ; - hsize := xpart lrcorner q - xpart llcorner q ; - vsize := ypart urcorner q - ypart lrcorner q ; + hsize := xpart lrcorner q - xpart llcorner q ; + vsize := ypart urcorner q - ypart lrcorner q ; - q := p shifted - cp ; + q := p shifted - cp ; - startsavingdata ; + startsavingdata ; - savedata "\global\parvoffset " & decimal voffset&"bp " ; - savedata "\global\parhoffset " & decimal hoffset&"bp " ; - savedata "\global\parwidth " & decimal hsize&"bp " ; - savedata "\global\parheight " & decimal vsize&"bp " ; + savedata "\global\parvoffset " & decimal voffset&"bp " ; + savedata "\global\parhoffset " & decimal hoffset&"bp " ; + savedata "\global\parwidth " & decimal hsize&"bp " ; + savedata "\global\parheight " & decimal vsize&"bp " ; - if not path offset_or_path : - q := q xscaled ((hsize-2hoffset)/hsize) - yscaled ((vsize-2voffset)/vsize) ; - fi ; + if not path offset_or_path : + q := q xscaled ((hsize-2hoffset)/hsize) + yscaled ((vsize-2voffset)/vsize) ; + fi ; - hsize := xpart lrcorner q - xpart llcorner q ; - vsize := ypart urcorner q - ypart lrcorner q ; + hsize := xpart lrcorner q - xpart llcorner q ; + vsize := ypart urcorner q - ypart lrcorner q ; - t := (ulcorner q -- urcorner q) intersection_point q ; - b := (llcorner q -- lrcorner q) intersection_point q ; + t := (ulcorner q -- urcorner q) intersection_point q ; + b := (llcorner q -- lrcorner q) intersection_point q ; - if xpart directionpoint t of q < 0 : - q := reverse q ; + if xpart directionpoint t of q < 0 : + q := reverse q ; fi ; l := q cutbefore t ; @@ -186,82 +169,82 @@ def build_parshape (expr p, offset_or_path, dx, dy, r := q cutbefore b ; r := r if xpart point 0 of q > 0 : & q fi cutafter t ; -% tt := (ulcorner q -- urcorner q) shifted (0,-topskip) ; -% bb := (llcorner q -- lrcorner q) shifted (0,strutdepth) ; +% tt := (ulcorner q -- urcorner q) shifted (0,-topskip) ; +% bb := (llcorner q -- lrcorner q) shifted (0,strutdepth) ; % -% l := l cutbefore (l intersection_point tt) ; -% l := l cutafter (l intersection_point bb) ; -% r := r cutbefore (r intersection_point bb) ; -% r := r cutafter (r intersection_point tt) ; +% l := l cutbefore (l intersection_point tt) ; +% l := l cutafter (l intersection_point bb) ; +% r := r cutbefore (r intersection_point bb) ; +% r := r cutafter (r intersection_point tt) ; - if trace_parshape : + if trace_parshape : drawarrow p withpen pencircle scaled 2pt withcolor red ; drawarrow l shifted cp withpen pencircle scaled 1pt withcolor green ; drawarrow r shifted cp withpen pencircle scaled 1pt withcolor blue ; - fi ; + fi ; - vardef found_point (expr lin, pat, sig) = + vardef found_point (expr lin, pat, sig) = pair a, b ; a := pat intersection_point (lin shifted (0,strutheight)) ; - if intersection_found : + if intersection_found : a := a shifted (0,-strutheight) ; else : a := pat intersection_point lin ; fi ; b := pat intersection_point (lin shifted (0,-strutdepth)) ; - if intersection_found : - if sig : - if xpart b > xpart a : a := b shifted (0,strutdepth) fi ; - else : - if xpart b < xpart a : a := b shifted (0,strutdepth) fi ; - fi ; - fi ; - a + if intersection_found : + if sig : + if xpart b > xpart a : a := b shifted (0,strutdepth) fi ; + else : + if xpart b < xpart a : a := b shifted (0,strutdepth) fi ; + fi ; + fi ; + a enddef ; - if (strutheight+strutdepth<baselineskip) : - vvsize := vsize ; - else : - vvsize := (vsize div baselineskip) * baselineskip ; - fi ; + if (strutheight+strutdepth<baselineskip) : + vvsize := vsize ; + else : + vvsize := (vsize div baselineskip) * baselineskip ; + fi ; - for i=topskip step baselineskip until vvsize : + for i=topskip step baselineskip until vvsize : - line := (ulcorner q -- urcorner q) shifted (0,-i-eps) ; + line := (ulcorner q -- urcorner q) shifted (0,-i-eps) ; ll := found_point(line,l,true ) ; rr := found_point(line,r,false) ; - if trace_parshape : - fill (ll--rr--rr shifted (0,strutheight)--ll + if trace_parshape : + fill (ll--rr--rr shifted (0,strutheight)--ll shifted (0,strutheight)--cycle) shifted cp withcolor .5white ; - fill (ll--rr--rr shifted (0,-strutdepth)--ll + fill (ll--rr--rr shifted (0,-strutdepth)--ll shifted (0,-strutdepth)--cycle) shifted cp withcolor .7white ; - draw ll shifted cp withpen pencircle scaled 2pt ; - draw rr shifted cp withpen pencircle scaled 2pt ; + draw ll shifted cp withpen pencircle scaled 2pt ; + draw rr shifted cp withpen pencircle scaled 2pt ; draw (ll--rr) shifted cp withpen pencircle scaled .5pt ; - fi ; + fi ; - n := n + 1 ; + n := n + 1 ; indent[n] := abs(xpart ll - xpart llcorner q) ; width[n] := abs(xpart rr - xpart ll) ; - if (i=strutheight) and (width[n]<baselineskip) : - n := n - 1 ; - savedata "\global\chardef\parfirst=1 " ; + if (i=strutheight) and (width[n]<baselineskip) : + n := n - 1 ; + savedata "\global\chardef\parfirst=1 " ; fi ; - endfor ; + endfor ; - savedata "\global\parlines " & decimal n ; - savedata "\global\partoks{ " ; - for i=1 upto n: - savedata decimal indent[i]&"bp " & decimal width[i]&"bp " ; - endfor ; + savedata "\global\parlines " & decimal n ; + savedata "\global\partoks{ " ; + for i=1 upto n: + savedata decimal indent[i]&"bp " & decimal width[i]&"bp " ; + endfor ; savedata "}" ; - - stopsavingdata ; + + stopsavingdata ; endgroup ; -enddef ; +enddef ; diff --git a/metapost/context/base/mp-tool.mp b/metapost/context/base/mp-tool.mp index 1f299807a..d78ee43ea 100644 --- a/metapost/context/base/mp-tool.mp +++ b/metapost/context/base/mp-tool.mp @@ -1499,89 +1499,52 @@ enddef ; % nice: currentpicture := inverted currentpicture ; primarydef p uncolored c = - if color p : - c - p - else : - image - (for i within p : - addto currentpicture - if stroked i or filled i : - if filled i : contour else : doublepath fi pathpart i - dashed dashpart i withpen penpart i - else : - also i - fi - withcolor c-(redpart i, greenpart i, bluepart i) ; - endfor ; ) - fi + image + (for i within p : + addto currentpicture + if stroked i or filled i : + if filled i : contour else : doublepath fi pathpart i + dashed dashpart i withpen penpart i + else : + also i + fi + withcolor c-(redpart i, greenpart i, bluepart i) ; + endfor ; ) enddef ; vardef inverted primary p = (p uncolored white) enddef ; -% primarydef p softened c = -% if color p : -% tripled(c) * p -% else : -% image -% (save cc ; color cc ; cc := tripled(c) ; -% for i within p : -% addto currentpicture -% if stroked i or filled i : -% if filled i : contour else : doublepath fi pathpart i -% dashed dashpart i withpen penpart i -% else : -% also i -% fi -% withcolor (redpart cc * redpart i, -% greenpart cc * greenpart i, -% bluepart cc * bluepart i) ; -% endfor ;) -% fi -% enddef ; - primarydef p softened c = - begingroup - save cc ; color cc ; cc := tripled(c) ; - if color p : - (redpart cc * redpart p, - greenpart cc * greenpart p, - bluepart cc * bluepart p) - else : - image - (for i within p : - addto currentpicture - if stroked i or filled i : - if filled i : contour else : doublepath fi pathpart i - dashed dashpart i withpen penpart i - else : - also i - fi - withcolor (redpart cc * redpart i, - greenpart cc * greenpart i, - bluepart cc * bluepart i) ; - endfor ;) - fi - endgroup + image + (save cc ; color cc ; cc := tripled(c) ; + for i within p : + addto currentpicture + if stroked i or filled i : + if filled i : contour else : doublepath fi pathpart i + dashed dashpart i withpen penpart i + else : + also i + fi + withcolor (redpart cc * redpart i, + greenpart cc * greenpart i, + bluepart cc * bluepart i) ; + endfor ;) enddef ; vardef grayed primary p = - if color p : - tripled(.30redpart p+.59greenpart p+.11bluepart p) - else : - image - (for i within p : - addto currentpicture - if stroked i or filled i : - if filled i : contour else : doublepath fi pathpart i - dashed dashpart i withpen penpart i - else : - also i - fi - withcolor tripled(.30redpart i+.59greenpart i+.11bluepart i) ; - endfor ; ) - fi + image + (for i within p : + addto currentpicture + if stroked i or filled i : + if filled i : contour else : doublepath fi pathpart i + dashed dashpart i withpen penpart i + else : + also i + fi + withcolor tripled(.30redpart i+.59greenpart i+.11bluepart i) ; + endfor ; ) enddef ; % yes or no: "text" infont "cmr12" at 24pt ; @@ -1981,20 +1944,12 @@ vardef dodostraightened(expr sign, p) = fi enddef ; -% vardef simplified expr p = -% dostraightened(+1,p) -% enddef ; - -% vardef unspiked expr p = -% dostraightened(-1,p) -% enddef ; - vardef simplified expr p = - (reverse dostraightened(+1,dostraightened(+1,reverse p))) + dostraightened(+1,p) enddef ; vardef unspiked expr p = - (reverse dostraightened(-1,dostraightened(-1,reverse p))) + dostraightened(-1,p) enddef ; % path p ; @@ -2130,34 +2085,17 @@ enddef ; % obscure macros: create var from string and replace - and : % (needed for process color id's) -string _clean_ascii_[] ; - -def register_dirty_chars(expr str) = - for i = 0 upto length(str)-1 : - _clean_ascii_[ASCII substring(i,i+1) of str] := "_" ; - endfor ; -enddef ; +string _clean_ascii[] ; -register_dirty_chars("+-*/:;., ") ; +_clean_ascii[ASCII "-"] := "_" ; +_clean_ascii[ASCII ":"] := "_" ; +_clean_ascii[ASCII "."] := "_" ; vardef cleanstring (expr s) = - save ss ; string ss, si ; ss = "" ; save i ; + save ss ; string ss, si ; ss = "" ; for i=0 upto length(s) : si := substring(i,i+1) of s ; - ss := ss & if known _clean_ascii_[ASCII si] : _clean_ascii_[ASCII si] else : si fi ; - endfor ; - ss -enddef ; - -vardef asciistring (expr s) = - save ss ; string ss, si ; ss = "" ; save i ; - for i=0 upto length(s) : - si := substring(i,i+1) of s ; - if (ASCII si >= ASCII "0") and (ASCII si <= ASCII "9") : - ss := ss & char(scantokens(si) + ASCII "A") ; - else : - ss := ss & si ; - fi ; + ss := ss & if known _clean_ascii[ASCII si] : _clean_ascii[ASCII si] else : si fi ; endfor ; ss enddef ; @@ -2257,4 +2195,4 @@ enddef ; % done -endinput ; +endinput ;
\ No newline at end of file |