diff options
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/mp-lmtx.mpxl | 521 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-luas.mpxl | 30 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-mlib.mpiv | 87 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-tool.mpiv | 11 |
4 files changed, 599 insertions, 50 deletions
diff --git a/metapost/context/base/mpiv/mp-lmtx.mpxl b/metapost/context/base/mpiv/mp-lmtx.mpxl index 45e216eef..9026255b3 100644 --- a/metapost/context/base/mpiv/mp-lmtx.mpxl +++ b/metapost/context/base/mpiv/mp-lmtx.mpxl @@ -18,6 +18,51 @@ if known context_lmtx : endinput ; fi ; boolean context_lmtx ; context_lmtx := true ; +presetparameters "text" [ + offset = 0, + strut = "auto", + style = "", + color = "", + text = "", + anchor = "", + format = "", + position = origin, +] ; + +def lmt_text = applyparameters "text" "lmt_do_text" enddef ; + +vardef lmt_do_text = + image ( + pushparameters "text" ; + save style, anchor, txt, fmt, strt ; + string style, anchor, txt, fmt, strt ; + interim textextoffset := getparameter "offset" ; + style := getparameter "style" ; + anchor := getparameter "anchor" ; + strt := getparameter "strut" ; + fmt := getparameter "format" ; + txt := getparameter "text" ; + if fmt <> "" : + txt := "\formatone{" & fmt & "}{" & txt & "}" + fi ; + if strt == "yes" : + txt := "\strut " & txt ; + elseif strt == "auto" : + txt := "\setstrut\strut " & txt ; + fi ; + if style <> "" : + txt := "\style[" & style & "]{" & txt & "}" ; + fi ; + draw + if anchor == "" : thetextext else : scantokens("thetextext." & anchor) fi ( + txt, + getparameter "position" + ) + withcolor getparameter "color" ; + popparameters ; + ) +enddef ; + presetparameters "grid" [ nx = 1, dx = 1, ny = 1, dy = 1, @@ -841,3 +886,479 @@ enddef ; vardef OverlayMesh(expr p, s) = lmt_mesh [ paths = { meshed(p,OverlayBox,s) } ] enddef ; + +% charts + +presetparameters "chart" [ + originsize = 1mm, + trace = false, + showlabels = true, + center = false, + + samples = { }, + + cumulative = false, + percentage = false, + maximum = 0, + distance = 1mm, + + % labels = { }, + labelstyle = "", + labelformat = "", + % labelstrut = "auto", + % labelanchor = "", + % labeloffset = 0, + labelfraction = 0.8, + labelcolor = "", + + backgroundcolor = "", + drawcolor = "white", + fillcolors = { % use color palet + "darkred", "darkgreen", "darkblue", + "darkyellow", "darkmagenta", "darkcyan", + "darkgray" + }, + colormode = "global", + + linewidth = .25mm, + + legendcolor = "", + legendstyle = "", + legend = { }, +] ; + +presetparameters "chart:circle" "chart" [ + height = 5cm, + width = 5mm, + labelanchor = "", + labeloffset = 0, + labelstrut = "no", +] ; + +presetparameters "chart:histogram" "chart" [ + height = 5cm, + width = 5mm, + labelanchor = "bot", + labeloffset = 1mm, + labelstrut = "auto", +] ; + +presetparameters "chart:bar" "chart" [ + height = 5mm, + width = 5cm, + labelanchor = "lft", + labeloffset = 1mm, + labelstrut = "no", +] ; + +def lmt_chart_circle = applyparameters "chart:circle" "lmt_do_chart_circle" enddef ; +def lmt_chart_histogram = applyparameters "chart:histogram" "lmt_do_chart_histogram" enddef ; +def lmt_chart_bar = applyparameters "chart:bar" "lmt_do_chart_bar" enddef ; + +def lmt_do_chart_start (expr what) = + pushparameters what ; + save width, height, distance, linewidth, labelgap, labelfraction, value, nofsamples, nofsamplesets ; + save fillcolor, drawcolor, labelcolor, labelstyle, labelformat, labelstrut, labelanchor, colormode ; + string fillcolor, drawcolor, labelcolor, labelstyle, labelformat, labelstrut, labelanchor, colormode ; + height := getparameter "height" ; + width := getparameter "width" ; + distance := getparameter "distance" ; + linewidth := getparameter "linewidth" ; + drawcolor := getparameter "drawcolor" ; + colormode := getparameter "colormode" ; + labelcolor := getparameter "labelcolor" ; + labelgap := getparameter "labeloffset" ; + labelstyle := getparameter "labelstyle" ; + labelformat := getparameter "labelformat" ; + labelstrut := getparameter "labelstrut" ; + labelanchor := getparameter "labelanchor" ; + labelfraction := getparameter "labelfraction" ; + nofsamplesets := getparametercount "samples" ; + nofsamples := getmaxparametercount "samples" ; +enddef ; + +def lmt_do_chart_stop = + if getparameter "center" : + currentpicture := currentpicture shifted - center currentpicture ; + fi + if (getparameter "backgroundcolor") <> "" : + addbackground withcolor getparameter "backgroundcolor" ; + fi + if getparameter "trace" : + save b ; path b ; b := boundingbox currentpicture ; + draw image ( + draw fullcircle scaled 1mm ; + draw b + ) + dashed evenly scaled 1/4 + withpen pencircle scaled .125mm + withcolor "darkgray" ; + fi + popparameters ; +enddef ; + +vardef lmt_do_chart_text(expr s, i, value) = + lmt_text [ + style = labelstyle, + format = labelformat, + strut = labelstrut, + anchor = labelanchor, + offset = labelgap, + color = labelcolor, + text = (getparameterdefault "labels" s i (decimal value)) + ] +enddef ; + +def lmt_do_chart_legend = + n := getparametercount "legend" ; + if n > 0 : + save dx, dy, p, l, w, o, d, ddy ; picture l ; + dx := xpart urcorner currentpicture + EmWidth ; + dy := ypart urcorner currentpicture ; + labelcolor := getparameter "legendcolor" ; + labelstyle := getparameter "legendstyle" ; + w := 2EmWidth ; + o := .25EmWidth ; + d := ExHeight ; + ddy := .8LineHeight ; + for i=1 upto n : + dy := dy - ddy ; + l := lmt_text [ + text = getparameter "legend" i, + anchor = "rt" + style = labelstyle, + color = labelcolor, + ] ; + fill leftboundary l rightenlarged w + shifted (dx,dy+d) + withcolor getparameter "fillcolors" i ; + draw l + shifted (dx+w+o,dy+d) ; + endfor ; + fi ; +enddef ; + +vardef lmt_do_chart_circle = + image ( + lmt_do_chart_start("chart:circle") ; + if (nofsamplesets > 0) and (nofsamples > 0) : + nofsamplesets := 1 ; + save p, r, s, first, last, total, factor, n, percentage ; + path p, r, s[] ; boolean percentage ; + percentage := getparameter "percentage" ; + total := 0 ; + for i = 1 upto nofsamples : + total := total + getparameter "samples" (1) i ; % () is needed else 1i + endfor ; + factor := 100/total ; + first := 0 ; + p := fullcircle ysized (height) ; + r := origin -- (2*height,0) ; + for i = 1 upto nofsamples : + fillcolor := getparameter "fillcolors" i ; + value := (getparameter "samples" (1) i) * factor ; + last := first + (360 / 100) * value ; + s[i] := ((p cutbefore (r rotated first)) cutafter (r rotated last)) ; + fill origin -- s[i] -- cycle withcolor fillcolor ; + first := last ; + endfor ; + if linewidth > 0 : + if drawcolor == "" : + drawcolor := backgroundcolor ; + fi ; + for i = 1 upto nofsamples : + interim linecap := butt ; + draw origin -- (point 0 of s[i]) withpen pencircle scaled linewidth withcolor drawcolor ; + draw origin -- (point length(s[i]) of s[i]) withpen pencircle scaled linewidth withcolor drawcolor ; + endfor ; + fi ; + if getparameter "showlabels" : + first := 0 ; + for i = 1 upto nofsamples : + value := getparameter "samples" (1) i ; + last := first + (360/100) * value * factor ; + draw lmt_do_chart_text (s,i,value) + shifted ((labelfraction*(height/2),0) rotated ((first+last)/2)) ; + first := last ; + endfor ; + fi ; + lmt_do_chart_legend ; + n := getparameter "originsize" ; + if n > 0 : + fill fullcircle scaled n withcolor "white" ; + fi ; + fi ; + lmt_do_chart_stop ; + ) +enddef ; + +vardef lmt_do_chart_histogram = + image ( + lmt_do_chart_start("chart:histogram") ; + if (nofsamplesets > 0) and (nofsamples > 0) : + save value, maximum, cumulative, maxwidth ; boolean cumulative ; + maximum := getparameter "maximum" ; + cumulative := getparameter "cumulative" ; + if labelanchor = "center" : + labelanchor := "vcenter" ; + fi ; + if maximum = 0 : + for s = 1 upto nofsamplesets : + for i = 1 upto nofsamples : + value := getparameter "samples" s i ; + maximum := if cumulative : + maximum + value ; + else : + max(maximum,value) ; + fi ; + endfor ; + endfor ; + fi ; + if nofsamplesets = 1 : + distance := 0 ; + fi ; + maxwidth := nofsamplesets * nofsamples * width + (nofsamples - 1)* distance ; + value := 0 ; + for s = 1 upto nofsamplesets : + for i = 1 upto nofsamples : + value := if cumulative : value + fi (getparameter "samples" s i) * height / maximum ; + fill unitsquare xyscaled (width,value) + if linewidth > 0 : + if i > 1 : leftenlarged (-linewidth/2) fi + if i < nofsamples : rightenlarged (-linewidth/2) fi + fi + shifted (nofsamplesets*(i-1)*width+(s-1)*width+(i-1)*distance,0) + withcolor getparameter "fillcolors" if colormode = "local" : s else : i fi ; + endfor ; + endfor ; + setbounds currentpicture to unitsquare xyscaled (maxwidth,height) ; + for s = 1 upto nofsamplesets : + if getparameter "showlabels" : + for i = 1 upto nofsamples : + draw lmt_do_chart_text (s,i,getparameter "samples" s i) + shifted (nofsamplesets*((i-1)*width)+width/2+(s-1)*width+(i-1)*distance,0) ; + endfor ; + fi ; + endfor ; + lmt_do_chart_legend ; + fi ; + lmt_do_chart_stop ; + ) +enddef ; + +vardef lmt_do_chart_bar = + + image ( + lmt_do_chart_start("chart:bar") ; + if (nofsamplesets > 0) and (nofsamples > 0) : + save value, maximum, cumulative, maxheight ; boolean cumulative ; + maximum := getparameter "maximum" ; + cumulative := getparameter "cumulative" ; + if labelanchor = "center" : + labelanchor := "hcenter" ; + fi ; + if maximum = 0 : + for s = 1 upto nofsamplesets : + for i = 1 upto nofsamples : + value := getparameter "samples" s i ; + maximum := if cumulative : maximum + value else : max(maximum,value) fi ; + endfor ; + endfor ; + fi ; + if nofsamplesets = 1 : + distance := 0 ; + fi ; + maxheight := nofsamplesets * nofsamples * height + (nofsamples - 1)* distance ; + for s = 1 upto nofsamplesets : + value := 0 ; + for i = 1 upto nofsamples : + value := if cumulative : value + fi (getparameter "samples" s i) * width / maximum ; + fill unitsquare xyscaled (value,height) + if linewidth > 0 : + if i > 1 : topenlarged (-linewidth/2) fi + if i < nofsamples : bottomenlarged (-linewidth/2) fi + fi + shifted (0,maxheight-nofsamplesets*i*height+(s-1)*height-(i-1)*distance) + withcolor getparameter "fillcolors" if colormode = "local" : s else : i fi ; + endfor ; + endfor ; + setbounds currentpicture to unitsquare xyscaled (width,maxheight) ; + if getparameter "showlabels" : + for s = 1 upto nofsamplesets : + for i = 1 upto nofsamples : + draw lmt_do_chart_text (s,i,getparameter "samples" s i) + shifted (0,maxheight-nofsamplesets*(i*height)+height/2+(s-1)*height-(i-1)*distance) ; + endfor ; + endfor ; + fi ; + lmt_do_chart_legend ; + fi ; + lmt_do_chart_stop ; + ) +enddef ; + +% more complex than needed but i want to trace so i need the vars + +presetparameters "shade" [ + alternative = "circular", + path = origin -- cycle, + trace = false + + % alternative = "circular" | "linear" + % domain = { a, b } + % radius = a | { a, b } + % factor = a + % origin = (a,b) | { (a,b), {c, d) } + % vector = { a, b } + % colors = { a, b } + % center = a | { a, b } + % direction = "up" | "down" | "left" | "right" | { a, b } + +] ; + +def lmt_shade = applyparameters "shade" "lmt_do_shade" enddef ; + +vardef lmt_do_shade = + image ( + pushparameters "shade" ; + + save domain_min, domain_max, radius_a, radius_b, factor ; + save color_a, color_b, center_a, center_b, alternative, s ; + string color_a, color_b, alternative, s ; pair center_a, center_b ; + + alternative := getparameter "alternative" ; + + mfun_with_shade_method_analyze(getparameter "path") ; + + domain_min := 0 ; + domain_max := 1 ; + + color_a := "white" ; + color_b := "black" ; + + if alternative = "circular" : + center_a := center mfun_shade_path ; + center_b := center_a ; + radius_a := 0 ; + radius_b := mfun_max_radius(mfun_shade_path) ; + factor := 1.2 ; + else : + center_a := llcorner mfun_shade_path ; + center_b := urcorner mfun_shade_path ; + radius_a := 0 ; + radius_b := 0 ; + factor := 0; + fi ; + + if hasparameter "domain" : + domain_min := getparameter "domain" 1 ; + domain_max := getparameter "domain" 2 ; + fi + if hasparameter "radius" : + if numeric getparameter "radius" : + radius_a := 0 ; + radius_b := getparameter "radius" ; + else : + radius_a := getparameter "radius" 1 ; + radius_b := getparameter "radius" 2 ; + fi ; + factor := 1 ; + fi + if hasparameter "factor" : + factor := getparameter "factor" ; + fi + if hasparameter "origin" : + if pair getparameter "origin" : + center_a := getparameter "origin" ; + center_b := center_b ; + else : + center_a := getparameter "origin" 1 ; + center_b := getparameter "origin" 2 ; + fi ; + fi + if hasparameter "vector" : + center_a := point (getparameter "vector" 1) of mfun_shade_path ; + center_b := point (getparameter "vector" 2) of mfun_shade_path ; + fi + if hasparameter "colors" : + color_a := getparameter "colors" 1 ; + color_b := getparameter "colors" 2 ; + fi + if hasparameter "center" : + if numeric getparameter "center" : + center_a := center mfun_shade_path shifted ( + (getparameter "center") * bbwidth (mfun_shade_path)/2, + (getparameter "center") * bbheight(mfun_shade_path)/2 + ) ; + else : + center_a := center mfun_shade_path shifted ( + (getparameter "center" 1) * bbwidth (mfun_shade_path)/2, + (getparameter "center" 2) * bbheight(mfun_shade_path)/2 + ) ; + fi + fi + if hasparameter "direction" : + save a, b, bb ; path bb ; + bb := boundingbox(mfun_shade_path) ; + a := b := -1 ; + if string getparameter "direction" : + s := getparameter "direction" ; + if s = "up" : + p_a := xpart shadedup ; + p_b := ypart shadedup ; + elseif s = "down" : + p_a := xpart shadeddown ; + p_b := ypart shadeddown ; + elseif s = "left" : + p_a := xpart shadedleft ; + p_b := ypart shadedleft ; + elseif s = "right" : + p_a := xpart shadedright ; + p_b := ypart shadedright ; + fi + else : + p_a := getparameter "direction" 1 ; + p_a := getparameter "direction" 2 ; + fi + if p_a >= 0 : + center_a := point p_a of bb ; + fi + if p_b >= 0 : + center_b := point p_b of bb ; + fi + fi ; + fill mfun_shade_path + withprescript "sh_domain=" & decimal domain_min & " " & decimal domain_max + withprescript "sh_transform=yes" + withprescript "sh_color=into" + withprescript "sh_color_a=" & colordecimals color_a + withprescript "sh_color_b=" & colordecimals color_b + withprescript "sh_first=" & ddecimal point 0 of mfun_shade_path % used for support scaling + withprescript "sh_set_x=" & ddecimal (mfun_shade_nx,mfun_shade_lx) % + withprescript "sh_set_y=" & ddecimal (mfun_shade_ny,mfun_shade_ly) % + if alternative = "linear" : + withprescript "sh_type=linear" + withprescript "sh_factor=1" + withprescript "sh_center_a=" & ddecimal center_a + withprescript "sh_center_b=" & ddecimal center_b + else : + withprescript "sh_type=circular" + withprescript "sh_factor=1.2" + withprescript "sh_center_a=" & ddecimal center_a + withprescript "sh_center_b=" & ddecimal center_b + withprescript "sh_radius_a=" & decimal radius_a + withprescript "sh_radius_b=" & decimal radius_b + fi ; + if getparameter "trace" : + draw fullcircle scaled 1mm shifted center_a ; + draw fullsquare scaled 2mm shifted center_b ; + draw textext.top("\strut\ttx center a") scaled .2 shifted center_a shifted (0, 2mm) ; + draw textext.bot("\strut\ttx center b") scaled .2 shifted center_b shifted (0,-2mm) ; + if alternative = "circular" : + draw fullcircle scaled ( radius_a * 2) shifted center_a dashed evenly ; + draw fullcircle scaled (factor * radius_b * 2) shifted -center_b dashed evenly ; + fi + fi + popparameters ; + ) +enddef ; diff --git a/metapost/context/base/mpiv/mp-luas.mpxl b/metapost/context/base/mpiv/mp-luas.mpxl index 0fcac55e6..23c76ab40 100644 --- a/metapost/context/base/mpiv/mp-luas.mpxl +++ b/metapost/context/base/mpiv/mp-luas.mpxl @@ -200,18 +200,19 @@ extra_endfig := extra_endfig & " runscript mfid_path_reset ; " ; vardef utflen(expr s) = lua.mp.utflen(s) enddef ; vardef utfsub(expr s,f,t) = lua.mp.utfsub(s,f,t) enddef ; -newinternal mfid_getparameters ; mfid_getparameters := scriptindex "getparameters" ; -newinternal mfid_presetparameters ; mfid_presetparameters := scriptindex "presetparameters" ; -newinternal mfid_hasparameter ; mfid_hasparameter := scriptindex "hasparameter" ; -newinternal mfid_getparameter ; mfid_getparameter := scriptindex "getparameter" ; -newinternal mfid_getparameterdefault ; mfid_getparameterdefault := scriptindex "getparameterdefault" ; -newinternal mfid_getparametercount ; mfid_getparametercount := scriptindex "getparametercount" ; -newinternal mfid_getparameterpath ; mfid_getparameterpath := scriptindex "getparameterpath" ; -newinternal mfid_getparametertext ; mfid_getparametertext := scriptindex "getparametertext" ; -newinternal mfid_getparameteroption ; mfid_getparameteroption := scriptindex "getparameteroption" ; -newinternal mfid_applyparameters ; mfid_applyparameters := scriptindex "applyparameters" ; -newinternal mfid_pushparameters ; mfid_pushparameters := scriptindex "pushparameters" ; -newinternal mfid_popparameters ; mfid_popparameters := scriptindex "popparameters" ; +newinternal mfid_getparameters ; mfid_getparameters := scriptindex "getparameters" ; +newinternal mfid_presetparameters ; mfid_presetparameters := scriptindex "presetparameters" ; +newinternal mfid_hasparameter ; mfid_hasparameter := scriptindex "hasparameter" ; +newinternal mfid_getparameter ; mfid_getparameter := scriptindex "getparameter" ; +newinternal mfid_getparameterdefault ; mfid_getparameterdefault := scriptindex "getparameterdefault" ; +newinternal mfid_getparametercount ; mfid_getparametercount := scriptindex "getparametercount" ; +newinternal mfid_getmaxparametercount ; mfid_getmaxparametercount := scriptindex "getmaxparametercount" ; +newinternal mfid_getparameterpath ; mfid_getparameterpath := scriptindex "getparameterpath" ; +newinternal mfid_getparametertext ; mfid_getparametertext := scriptindex "getparametertext" ; +newinternal mfid_getparameteroption ; mfid_getparameteroption := scriptindex "getparameteroption" ; +newinternal mfid_applyparameters ; mfid_applyparameters := scriptindex "applyparameters" ; +newinternal mfid_pushparameters ; mfid_pushparameters := scriptindex "pushparameters" ; +newinternal mfid_popparameters ; mfid_popparameters := scriptindex "popparameters" ; def getparameters = runscript mfid_getparameters enddef ; def presetparameters = runscript mfid_presetparameters enddef ; @@ -219,6 +220,7 @@ def hasparameter = runscript mfid_hasparameter enddef ; def getparameter = runscript mfid_getparameter enddef ; def getparameterdefault = runscript mfid_getparameterdefault enddef ; def getparametercount = runscript mfid_getparametercount enddef ; +def getmaxparametercount = runscript mfid_getmaxparametercount enddef ; def getparameterpath = runscript mfid_getparameterpath enddef ; def getparametertext = runscript mfid_getparametertext enddef ; def getparameteroption = runscript mfid_getparameteroption enddef ; @@ -234,3 +236,7 @@ newinternal mfid_day ; mfid_day := scriptindex "day" ; vardef day = newinternal mfid_hour ; mfid_hour := scriptindex "hour" ; vardef hour = runscript mfid_hour enddef ; newinternal mfid_minute ; mfid_minute := scriptindex "minute" ; vardef minute = runscript mfid_minute enddef ; newinternal mfid_second ; mfid_second := scriptindex "second" ; vardef second = runscript mfid_second enddef ; + +newinternal mfid_definecolor ; mfid_definecolor := scriptindex "definecolor" ; + +def definecolor = runscript mfid_definecolor ; enddef ; % the semicolon prevents lookahead diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 61ffba24c..8ccb6a695 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -280,21 +280,21 @@ vardef fontsize expr name = fi enddef ; -pair mfun_laboff ; mfun_laboff := (0,0) ; -pair mfun_laboff.lft ; mfun_laboff.lft := (-1,0) ; -pair mfun_laboff.rt ; mfun_laboff.rt := (1,0) ; -pair mfun_laboff.bot ; mfun_laboff.bot := (0,-1) ; -pair mfun_laboff.top ; mfun_laboff.top := (0,1) ; -pair mfun_laboff.ulft ; mfun_laboff.ulft := (-.7,.7) ; -pair mfun_laboff.urt ; mfun_laboff.urt := (.7,.7) ; -pair mfun_laboff.llft ; mfun_laboff.llft := -(.7,.7) ; -pair mfun_laboff.lrt ; mfun_laboff.lrt := (.7,-.7) ; - -pair mfun_laboff.d ; mfun_laboff.d := mfun_laboff ; -pair mfun_laboff.dlft ; mfun_laboff.dlft := mfun_laboff.lft ; -pair mfun_laboff.drt ; mfun_laboff.drt := mfun_laboff.rt ; -pair mfun_laboff.origin ; mfun_laboff.origin := origin ; -pair mfun_laboff.raw ; mfun_laboff.raw := origin ; +pair mfun_laboff ; mfun_laboff := origin ; +pair mfun_laboff.lft ; mfun_laboff.lft := (-1,0) ; +pair mfun_laboff.rt ; mfun_laboff.rt := (1,0) ; +pair mfun_laboff.bot ; mfun_laboff.bot := (0,-1) ; +pair mfun_laboff.top ; mfun_laboff.top := (0,1) ; +pair mfun_laboff.ulft ; mfun_laboff.ulft := (-.7,.7) ; +pair mfun_laboff.urt ; mfun_laboff.urt := (.7,.7) ; +pair mfun_laboff.llft ; mfun_laboff.llft := -(.7,.7) ; +pair mfun_laboff.lrt ; mfun_laboff.lrt := (.7,-.7) ; + +pair mfun_laboff.d ; mfun_laboff.d := mfun_laboff ; +pair mfun_laboff.dflt ; mfun_laboff.dflt := mfun_laboff.lft ; +pair mfun_laboff.drt ; mfun_laboff.drt := mfun_laboff.rt ; +pair mfun_laboff.origin ; mfun_laboff.origin := mfun_laboff ; +pair mfun_laboff.raw ; mfun_laboff.raw := mfun_laboff ; pair mfun_laboff.l ; mfun_laboff.l := mfun_laboff.lft ; pair mfun_laboff.r ; mfun_laboff.r := mfun_laboff.rt ; @@ -319,11 +319,11 @@ mfun_labxf.urt := mfun_labxf.r_t := mfun_labxf.t_r := 0 ; mfun_labxf.llft := mfun_labxf.l_b := mfun_labxf.b_l := 1 ; mfun_labxf.lrt := mfun_labxf.r_b := mfun_labxf.b_r := 0 ; -mfun_labxf.d := mfun_labxf ; -mfun_labxf.dlft := mfun_labxf.lft ; -mfun_labxf.drt := mfun_labxf.rt ; -mfun_labxf.origin := 0 ; -mfun_labxf.raw := 0 ; +mfun_labxf.d := mfun_labxf ; +mfun_labxf.dflt := mfun_labxf.lft ; +mfun_labxf.drt := mfun_labxf.rt ; +mfun_labxf.origin := 0 ; +mfun_labxf.raw := 0 ; mfun_labyf := 0.5 ; mfun_labyf.lft := mfun_labyf.l := 0.5 ; @@ -335,11 +335,11 @@ mfun_labyf.urt := mfun_labyf.r_t := mfun_labyf.t_r := 0 ; mfun_labyf.llft := mfun_labyf.l_b := mfun_labyf.b_l := 1 ; mfun_labyf.lrt := mfun_labyf.r_b := mfun_labyf.b_r := 1 ; -mfun_labyf.d := mfun_labyf ; -mfun_labyf.dlft := mfun_labyf.lft ; -mfun_labyf.drt := mfun_labyf.rt ; -mfun_labyf.origin := 0 ; -mfun_labyf.raw := 0 ; +mfun_labyf.d := mfun_labyf ; +mfun_labyf.dflt := mfun_labyf.lft ; +mfun_labyf.drt := mfun_labyf.rt ; +mfun_labyf.origin := 0 ; +mfun_labyf.raw := 0 ; mfun_labtype := 0 ; mfun_labtype.lft := mfun_labtype.l := 1 ; @@ -351,20 +351,27 @@ mfun_labtype.urt := mfun_labtype.r_t := mfun_labtype.t_r := 6 ; mfun_labtype.llft := mfun_labtype.l_b := mfun_labtype.b_l := 7 ; mfun_labtype.lrt := mfun_labtype.r_b := mfun_labtype.b_r := 8 ; mfun_labtype.d := 10 ; -mfun_labtype.dlft := 11 ; +mfun_labtype.dflt := 11 ; mfun_labtype.drt := 12 ; mfun_labtype.origin := 0 ; mfun_labtype.raw := 0 ; -% installlabel.foo ( 0, 1, 1, (.5,-1) ) ; - vardef installlabel@# (expr type, x, y, offset) = - numeric labtype@# ; labtype@# := type ; - pair laboff @# ; laboff @# := offset ; - numeric labxf @# ; labxf @# := x ; - numeric labyf @# ; labyf @# := y ; + numeric mfun_labtype@# ; mfun_labtype@# := type ; + pair mfun_laboff @# ; mfun_laboff @# := offset ; + numeric mfun_labxf @# ; mfun_labxf @# := x ; + numeric mfun_labyf @# ; mfun_labyf @# := y ; enddef ; +installlabel.center (0, 0.5, 0.5, (0,0)) ; +installlabel.c (0, 0.5, 0.5, (0,0)) ; + +installlabel.hcenter(0, 0.5, 0.5, (1,0)) ; +installlabel.h (0, 0.5, 0.5, (1,0)) ; + +installlabel.vcenter(0, 0.5, 0.5, (0,1)) ; +installlabel.v (0, 0.5, 0.5, (0,1)) ; + vardef mfun_labshift@#(expr p) = (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + @@ -688,6 +695,15 @@ def mfun_with_shade_method_analyze(expr p) = endfor ; enddef ; +vardef mfun_max_radius(expr p) = + 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) + ) +enddef ; + primarydef p withshademethod m = hide(mfun_with_shade_method_analyze(p)) p @@ -710,12 +726,7 @@ primarydef p withshademethod m = 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) - ) ) + withprescript "sh_radius_b=" & decimal mfun_max_radius(p) fi enddef ; diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index 2442beb1c..3bae73aad 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -3638,3 +3638,14 @@ vardef mfun_timestamp = if ((time-(time div 60)*60) < 10) : "0" & fi decimal (time-(time div 60)*60) enddef ; + +vardef totransform(expr x, y, xx, xy, yx, yy) = + save t ; transform t ; + xpart t = x ; + ypart t = y ; + xxpart t = xx ; + xypart t = xy ; + yxpart t = yx ; + yypart t = yy ; + t +enddef ; |