From b14f992ef5f4e868c9959b174278c86516d60dbc Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 17 Feb 2017 10:31:56 +0100 Subject: 2017-02-17 10:23:00 --- metapost/context/base/mpiv/mp-abck.mpiv | 5 ++ metapost/context/base/mpiv/mp-core.mpiv | 8 +-- metapost/context/base/mpiv/mp-grap.mpiv | 1 - metapost/context/base/mpiv/mp-luas.mpiv | 23 ++++++++ metapost/context/base/mpiv/mp-step.mpiv | 96 ++++++++++++++++++++------------- metapost/context/base/mpiv/mp-tool.mpiv | 68 +++++++++++------------ 6 files changed, 124 insertions(+), 77 deletions(-) (limited to 'metapost') diff --git a/metapost/context/base/mpiv/mp-abck.mpiv b/metapost/context/base/mpiv/mp-abck.mpiv index 8b5f0a534..57c8f226b 100644 --- a/metapost/context/base/mpiv/mp-abck.mpiv +++ b/metapost/context/base/mpiv/mp-abck.mpiv @@ -257,6 +257,11 @@ def anchor_box (expr n,x,y,w,h,d) = currentpicture := currentpicture shifted (-x,-y) ; enddef ; +def draw_box = % for old times sake + draw pxy boxlineoptions withpen pencircle scaled boxlinewidth ; + draw lxy -- rxy boxlineoptions withpen pencircle scaled boxgridwidth ; +enddef ; + def draw_free_region(expr width, height, depth, loffset, roffset, toffset, boffset) = begingroup ; save b, o, l ; path b, o, l[] ; save d ; diff --git a/metapost/context/base/mpiv/mp-core.mpiv b/metapost/context/base/mpiv/mp-core.mpiv index e826e837c..0ef24e57e 100644 --- a/metapost/context/base/mpiv/mp-core.mpiv +++ b/metapost/context/base/mpiv/mp-core.mpiv @@ -1184,10 +1184,10 @@ numeric boxfilloffset ; boxfilloffset := 0pt ; numeric boxgriddistance ; boxgriddistance := .5cm ; numeric boxgridshift ; boxgridshift := 0pt ; -def draw_box = - draw pxy boxlineoptions withpen pencircle scaled boxlinewidth ; - draw lxy -- rxy boxlineoptions withpen pencircle scaled boxgridwidth ; -enddef ; +% def draw_box = +% draw pxy boxlineoptions withpen pencircle scaled boxlinewidth ; +% draw lxy -- rxy boxlineoptions withpen pencircle scaled boxgridwidth ; +% enddef ; def draw_par = % 1 2 3 11 12 do_draw_par(pxy) ; do_draw_par(txy) ; do_draw_par(bxy) ; diff --git a/metapost/context/base/mpiv/mp-grap.mpiv b/metapost/context/base/mpiv/mp-grap.mpiv index 5f102fe1c..3a1d7742a 100644 --- a/metapost/context/base/mpiv/mp-grap.mpiv +++ b/metapost/context/base/mpiv/mp-grap.mpiv @@ -1260,7 +1260,6 @@ def plotsymbol(expr n, f) text t = fg := if known graph_foreground : graph_foreground else : black fi ; save p ; path p ; p = graph_shape[n] scaled graph_shapesize ; draw p withcolor bg withpen currentpen scaled 2 ; % halo - currentpen := currentpen scaled .5 ; if cycle p : fill p withcolor if known f : diff --git a/metapost/context/base/mpiv/mp-luas.mpiv b/metapost/context/base/mpiv/mp-luas.mpiv index 7dd569321..52351753e 100644 --- a/metapost/context/base/mpiv/mp-luas.mpiv +++ b/metapost/context/base/mpiv/mp-luas.mpiv @@ -137,3 +137,26 @@ def settoks (expr k, v) = lua.mp._set_toks_ (k,v) enddef ; % vardef setdimen(expr k,v) = save setdimen ; lua.mp.setdimen(k,v) enddef ; % vardef setcount(expr k,v) = save setcount ; lua.mp.setcount(k,v) enddef ; % vardef settoks (expr k,v) = save settoks ; lua.mp.settoks (k,v) enddef ; + +vardef positionpath (expr name) = lua.mp.positionpath (name) enddef ; +vardef positioncurve (expr name) = lua.mp.positioncurve (name) enddef ; +vardef positionxy (expr name) = lua.mp.positionxy (name) enddef ; +vardef positionpxy (expr name) = lua.mp.positionpxy (name) enddef ; +vardef positionwhd (expr name) = lua.mp.positionwhd (name) enddef ; +vardef positionpage (expr name) = lua.mp.positionpage (name) enddef ; +vardef positionregion(expr name) = lua.mp.positionregion(name) enddef ; +vardef positionbox (expr name) = lua.mp.positionbox (name) enddef ; +vardef positionanchor = lua.mp.positionanchor() enddef ; + +let wdpart = redpart ; +let htpart = greenpart ; +let dppart = bluepart ; + +vardef positioninregion = + currentpicture := currentpicture shifted - positionxy(positionanchor) ; +enddef ; + +vardef positionatanchor(expr name) = + currentpicture := currentpicture shifted - positionxy(name) ; +enddef ; + diff --git a/metapost/context/base/mpiv/mp-step.mpiv b/metapost/context/base/mpiv/mp-step.mpiv index cc5194af7..16d6be3a7 100644 --- a/metapost/context/base/mpiv/mp-step.mpiv +++ b/metapost/context/base/mpiv/mp-step.mpiv @@ -425,24 +425,36 @@ def step_end_chart = if bbwidth(text_t) > 0 : if bbwidth(cell_t) > 0 : alternative := if known line_top_shapes[i] : line_top_shapes[i] else : 1 fi ; - if (alternative = 1) or (alternative = 2) : drawarrow else : draw fi - midtopboundary cell_t - shifted (if i > 1 : line_offset else : 0 fi, cell_line_width) {up} .. - midbottomboundary text_t - shifted (0,-line_distance) .. - {down} midtopboundary next_t - shifted (if i < nofcells - 1 : -line_offset else : 0 fi,cell_line_width) - if (alternative = 2) or (alternative = 4) : - dashed evenly scaled ( - if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi - ) - fi - withpen pencircle scaled - if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi - withcolor - if known line_top_colors[i] : line_top_colors[i] else : line_line_color fi - ; - else : + if alternative <> 0 : + if (alternative = 1) or (alternative = 2) or (alternative = 5) or (alternative = 6) : + drawarrow + elseif (alternative = 3) or (alternative = 7): + drawdblarrow + else : + draw + fi + if (alternative = 2) or (alternative = 6) : + reverse + fi + ( + midtopboundary cell_t + shifted (if i > 1 : line_offset else : 0 fi, cell_line_width) {up} .. + midbottomboundary text_t + shifted (0,-line_distance) .. + {down} midtopboundary next_t + shifted (if i < nofcells - 1 : -line_offset else : 0 fi,cell_line_width) + ) + withpen pencircle scaled + if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi + withcolor + if known line_top_colors[i] : line_top_colors[i] else : line_line_color fi + if (alternative >= 5) and (alternative <= 8) : + dashed evenly scaled ( + if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi + ) + fi + ; + fi ; fi ; fi ; if bbwidth(text_b) > 0 : @@ -452,24 +464,36 @@ def step_end_chart = fi ; if bbwidth(cell_b) > 0 : alternative := if known line_bot_shapes[i] : line_bot_shapes[i] else : 1 fi ; - if (alternative = 1) or (alternative = 2) : drawarrow else : draw fi - midbottomboundary cell_b - shifted (if i > 1 : line_offset else : 0 fi, -cell_line_width) {down} .. - midtopboundary text_b - shifted (0, line_distance) .. - {up} midbottomboundary next_b - shifted (if i < nofcells - 1 : -line_offset else : 0 fi,-cell_line_width) - if (alternative = 2) or (alternative = 4) : - dashed evenly scaled ( - if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi - ) - fi - withpen pencircle scaled - if known line_bot_lines [i] : line_bot_lines [i] else : line_line_width fi - withcolor - if known line_bot_colors[i] : line_bot_colors[i] else : line_line_color fi - ; - else : + if alternative <> 0 : + if (alternative = 1) or (alternative = 2) or (alternative = 5) or (alternative = 6) : + drawarrow + elseif (alternative = 3) or (alternative = 7): + drawdblarrow + else : + draw + fi + if (alternative = 2) or (alternative = 6) : + reverse + fi + ( + midbottomboundary cell_b + shifted (if i > 1 : line_offset else : 0 fi, -cell_line_width) {down} .. + midtopboundary text_b + shifted (0, line_distance) .. + {up} midbottomboundary next_b + shifted (if i < nofcells - 1 : -line_offset else : 0 fi,-cell_line_width) + ) + withpen pencircle scaled + if known line_bot_lines [i] : line_bot_lines [i] else : line_line_width fi + withcolor + if known line_bot_colors[i] : line_bot_colors[i] else : line_line_color fi + if (alternative >= 5) and (alternative <= 8) : + dashed evenly scaled ( + if known line_top_lines [i] : line_top_lines [i] else : line_line_width fi + ) + fi + ; + fi ; fi ; fi ; endfor ; diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index 3a0b7b5d3..be35b9795 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -1327,7 +1327,7 @@ enddef ; def resetarrows = hide ( - ahlength := 4 ; + ahlength := 4 ; ahangle := 45 ; ahvariant := 0 ; ahdimple := 1/5 ; @@ -1558,21 +1558,17 @@ extra_beginfig := extra_beginfig & " linecap := rounded ; " ; % restores boolean autoarrows ; autoarrows := false ; numeric ahfactor ; ahfactor := 2.5 ; -def set_ahlength (text t) = +def set_ahlength (text t) = % called to often % ahlength := (ahfactor*pen_size(_op_ t)) ; % _op_ added % problem: _op_ can contain color so a no-go, we could apply the transform % but i need to figure out the best way (fakepicture and take components). ahlength := (ahfactor*pen_size(t)) ; enddef ; -% vardef pen_size (text t) = -% save p ; picture p ; p := nullpicture ; -% addto p doublepath (top origin -- bot origin) t ; -% (ypart urcorner p - ypart lrcorner p) -% enddef ; - vardef pen_size (text t) = - (ypart top origin - ypart bot origin) + save p ; picture p ; p := nullpicture ; + addto p doublepath (top origin -- bot origin) t ; + (ypart urcorner p - ypart lrcorner p) enddef ; %D The next two macros are adapted versions of plain @@ -1661,18 +1657,34 @@ enddef ; def mfun_draw_arrow_nothing text t = enddef ; -def mfun_with_arrow_path (text t) = +% The path is shortened so that the arrow head extends it to the original +% length. In case of a double arrow the path gets shortened twice. + +def mfun_draw_arrow_path text t = if autoarrows : set_ahlength(t) ; fi - t + draw arrowpath mfun_arrow_path t ; + fillup arrowhead mfun_arrow_path t ; endgroup ; enddef ; -def mfun_with_arrow_picture (text t) = +def mfun_draw_arrow_path_double text t = if autoarrows : set_ahlength(t) ; fi + draw arrowpath (reverse arrowpath mfun_arrow_path) t ; + fillup arrowhead mfun_arrow_path t ; + fillup arrowhead reverse mfun_arrow_path t ; + endgroup ; +enddef ; + +% The picture variant is not treating each path but only the first and +% last path. This can be somewhat counterintuitive but is needed for Alan's +% macros. So here the last and in case of a double path first paths in a +% picture get the shortening. + +def mfun_with_arrow_picture (text t) = mfun_arrow_count := 0 ; mfun_arrow_snippets := stroked_paths(mfun_arrow_picture) ; for i within mfun_arrow_picture : @@ -1682,33 +1694,12 @@ def mfun_with_arrow_picture (text t) = t fi ; endfor ; - endgroup ; -enddef ; - -% The path is shortened so that the arrow head extends it to the original -% length. In case of a double arrow the path gets shortened twice. - -def mfun_draw_arrow_path text t = - mfun_with_arrow_path ( - draw arrowpath mfun_arrow_path t ; - fillup arrowhead mfun_arrow_path t ; - ) ; -enddef ; - -def mfun_draw_arrow_path_double text t = - mfun_with_arrow_path ( - draw arrowpath (reverse arrowpath mfun_arrow_path) t ; - fillup arrowhead mfun_arrow_path t ; - fillup arrowhead reverse mfun_arrow_path t ; - ) ; enddef ; -% The picture variant is not treating each path but only the first and -% last path. This can be somewhat counterintuitive but is needed for Alan's -% macros. So here the last and in case of a double path first paths in a -% picture get the shortening. - def mfun_draw_arrow_picture text t = + if autoarrows : + set_ahlength(t) ; + fi mfun_with_arrow_picture ( if mfun_arrow_count = mfun_arrow_snippets : draw arrowpath mfun_arrow_path mfun_decoration_i i t ; @@ -1717,9 +1708,13 @@ def mfun_draw_arrow_picture text t = draw mfun_arrow_path mfun_decoration_i i t ; fi ; ) + endgroup ; enddef ; def mfun_draw_arrow_picture_double text t = + if autoarrows : + set_ahlength(t) ; + fi mfun_with_arrow_picture ( draw if mfun_arrow_count = 1 : @@ -1736,6 +1731,7 @@ def mfun_draw_arrow_picture_double text t = fillup arrowhead mfun_arrow_path mfun_decoration_i i t ; fi ) + endgroup ; enddef ; %D Handy too ...... -- cgit v1.2.3