From 57f1545214ebba9625b9be722d4e4f9357dab87a Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sun, 15 Aug 2004 00:00:00 +0200 Subject: stable 2004.08.15 --- metapost/context/base/mp-core.mp | 11 +- metapost/context/base/mp-spec.mp | 153 +++++++++++++++++-- metapost/context/base/mp-text.mp | 321 +++++++++++++++++++++------------------ metapost/context/base/mp-tool.mp | 22 ++- 4 files changed, 335 insertions(+), 172 deletions(-) (limited to 'metapost') diff --git a/metapost/context/base/mp-core.mp b/metapost/context/base/mp-core.mp index 51d2d0025..b905d85ce 100644 --- a/metapost/context/base/mp-core.mp +++ b/metapost/context/base/mp-core.mp @@ -520,11 +520,12 @@ 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_,ypart llcorner multipar)) ; + _pa_ := (xpart _pa_,max(ypart _pa_ -TopSkipCorrection,ypart llcorner multipar)) ; if same_area : - _pa_ := (xpart _pa_,max(ypart _pa_,ypart llxy[tpos])) ; +% _pa_ := (xpart _pa_,max(ypart _pa_,ypart llxy[tpos])) ; + _pa_ := (xpart _pa_,max(ypart _pa_ -TopSkipCorrection,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)) ; @@ -539,7 +540,8 @@ 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])) ; @@ -1240,6 +1242,7 @@ vardef PrepareSyncTasks(expr n, collapse, extendtop, prestartnext) = NOfSyncPaths := NOfSyncPaths + 1 ; if not ok : if i>1 : +% not yet correct when two of teh 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-spec.mp b/metapost/context/base/mp-spec.mp index b005eb381..ceff7fe90 100644 --- a/metapost/context/base/mp-spec.mp +++ b/metapost/context/base/mp-spec.mp @@ -414,34 +414,106 @@ 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_"&p ; + pc_tag := "_pct_" & n ; 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] : + 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] : ok := false ; % not yet defined - elseif spotcolorhash[pp][s] = -1 : + elseif spotcolorhash[pp][ps] = -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 ; + save ss ; string ss ; ss := n & " " & decimal f & " " & if d = "" : n else : d fi & " " & p ; _spotcolor_counter_ := _spotcolor_counter_ + 1 ; spotcolorpattern[_spotcolor_counter_/1000] := ss ; - spotcolorhash[pp][s] := _spotcolor_counter_ ; - flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; + spotcolorhash[pp][ps] := _spotcolor_counter_ ; + flush_special(2, 7, decimal _spotcolor_counter_ & " " & ss) ; _local_specials_ := _local_specials_ & - "spotcolorhash["&decimal pp&"]["&decimal s&"]:=-1;" ; + "spotcolorhash["&decimal pp&"]["&decimal ps&"]:=-1;" ; fi ; - (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) + (_special_signal_/1000,2/1000,spotcolorhash[pp][ps]/1000) else : - (1-s,1-s,1-s) + .5white fi enddef ; @@ -459,6 +531,63 @@ 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 ; @@ -485,7 +614,9 @@ vardef transparent(expr n, t, c) = elseif is_spot : spotcolorpattern[bluepart cc] else : dddecimal cc fi ; % check if this one is already used - ss := "tr_" & s ; +% ss := "tr_" & s ; +% ss := cleanstring(ss) ; + ss := cleanstring("tr_" & s) ; % efficiency hack if expandafter unknown scantokens(ss) : ok := false ; % not yet defined @@ -496,7 +627,7 @@ vardef transparent(expr n, t, c) = fi ; if not ok : if is_spot : - flush_special(5, 6, s) ; + flush_special(5, 8, s) ; elseif is_cmyk : flush_special(4, 8, s) ; else : diff --git a/metapost/context/base/mp-text.mp b/metapost/context/base/mp-text.mp index cb6bb3895..2e061df09 100644 --- a/metapost/context/base/mp-text.mp +++ b/metapost/context/base/mp-text.mp @@ -2,165 +2,182 @@ %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 ; - -vardef textext@#(expr txt) = - interim labeloffset := textextoffset ; - noftexpictures := noftexpictures + 1 ; - if string txt : +% 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 ; if hobbiestextext : % the tex.mp method as fallback (see tex.mp) - write "btex " & txt & " etex" to "mptextmp.mp" ; +% write _s_ to "mptextmp.mp" ; + write _s_ & "btex " & txt & " etex" to "mptextmp.mp" ; write EOF to "mptextmp.mp" ; scantokens "input mptextmp" else : - write "% figure " & decimal charcode & " : " & - "texpictures[" & decimal noftexpictures & "] := btex " & - txt & " etex ;" to jobname & ".mpt" ; - if unknown texpictures[noftexpictures] : - thelabel@#("unknown",origin) +% 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) 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 ; @@ -169,82 +186,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