diff options
author | Hans Hagen <pragma@wxs.nl> | 2019-09-27 20:24:34 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2019-09-27 20:24:34 +0200 |
commit | 0a5f59a9aa25b3de7e9659b39ad201aaf7eb5a67 (patch) | |
tree | a652bb083d6bc6a9b6309908dd5d09a539ac3859 /metapost | |
parent | 58c7c9288160407c874930aac789ef6ef3faa6b5 (diff) | |
download | context-0a5f59a9aa25b3de7e9659b39ad201aaf7eb5a67.tar.gz |
2019-09-27 18:10:00
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/mp-blob.mpiv | 11 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-lmtx.mpxl | 157 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-luas.mpxl | 2 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-mlib.mpiv | 20 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-tool.mpiv | 37 |
5 files changed, 163 insertions, 64 deletions
diff --git a/metapost/context/base/mpiv/mp-blob.mpiv b/metapost/context/base/mpiv/mp-blob.mpiv index d1fc7357b..dd147bede 100644 --- a/metapost/context/base/mpiv/mp-blob.mpiv +++ b/metapost/context/base/mpiv/mp-blob.mpiv @@ -51,8 +51,8 @@ vardef followtext(expr pth, txt) = image ( mfun_blob_n := mfun_blob_n + 1 ; lua.mp.mf_inject_blob(mfun_blob_n,txt); - save pat, al, at, pl, pc, wid, pos, ap, ad, pic, len, n, sc ; - path pat ; pat := pth ; + save pat, al, at, pl, pc, wid, pos, ap, ad, pic, len, n, b, sc ; + path pat, b ; pat := pth ; numeric al, at, pl, pc, wid, pos, len[], n, sc ; pair ap, ad ; picture pic[] ; @@ -98,15 +98,16 @@ vardef followtext(expr pth, txt) = draw ap withpen pencircle scaled .50pt withcolor green ; fi ; endfor ; - if ((autoscaleupfollowtext = 2) or (autoscaledownfollowtext = 2)) and - (sc <> 0) and (sc <> 1): + if ((autoscaleupfollowtext = 2) or (autoscaledownfollowtext = 2)) and (sc <> 0) and (sc <> 1): currentpicture := currentpicture scaled (1/sc) ; fi ; + b := boundingbox currentpicture ; if tracingfollowtext = 1 : - draw boundingbox currentpicture withpen pencircle scaled .25pt withcolor blue ; + draw b withpen pencircle scaled .25pt withcolor blue ; fi ; draw fullcircle scaled 100bp withprescript "mf_object=followtext" withprescript "ft_category=" & decimal mfun_blob_n ; + setbounds currentpicture to b ; ) enddef ; diff --git a/metapost/context/base/mpiv/mp-lmtx.mpxl b/metapost/context/base/mpiv/mp-lmtx.mpxl index fe511b74f..359c60921 100644 --- a/metapost/context/base/mpiv/mp-lmtx.mpxl +++ b/metapost/context/base/mpiv/mp-lmtx.mpxl @@ -247,7 +247,7 @@ vardef lmt_do_axis = enddef ; presetparameters "outline" [ - content = "", + text = "", kind = "draw", fillcolor = "", drawcolor = "", @@ -273,22 +273,24 @@ vardef lmt_do_outline = kind := "b" ; elseif kind = "reverse" : kind := "r" ; + elseif kind = "fillup" : + kind := "u" ; fi ; currentoutlinetext := currentoutlinetext + 1 ; lua.mp.mf_outline_text( currentoutlinetext, if align = "" : - getparameter "outline" "content", + getparameter "outline" "text", else : "\framed[align={" & align & "}" if width > 0 : & ",width=" & decimal width & "bp" fi if style <> "" : - & ",foregroundstyle=" & style + & ",foregroundstyle={" & style & "}" fi & ",offset=none,frame=off]{" - & (getparameter "outline" "content") + & (getparameter "outline" "text") & "}", fi, kind @@ -310,7 +312,7 @@ vardef lmt_do_outline = withcolor getparameter "outline" "drawcolor" ); elseif kind = "u" : - mfun_do_outline_text_set_f ( + mfun_do_outline_text_set_u ( withcolor getparameter "outline" "fillcolor" ); elseif kind = "r" : @@ -331,7 +333,7 @@ vardef lmt_do_outline = enddef ; presetparameters "followtext" [ - content = "", + text = "", spread = true, trace = false, reverse = false, @@ -344,24 +346,28 @@ def lmt_followtext = applyparameters "followtext" "lmt_do_followtext" enddef ; vardef lmt_do_followtext = image ( - save s_u ; string s_u ; s_u := getparameter "followtext" "autoscaleup" ; - save s_d ; string s_d ; s_d := getparameter "followtext" "autoscaledown" ; - save followtextalternative ; followtextalternative := if getparameter "followtext" "spread" : 1 else : 0 fi ; - save tracingfollowtext ; tracingfollowtext := if getparameter "followtext" "trace" : 1 else : 0 fi ; + pushparameters "followtext" ; + save s_u ; string s_u ; s_u := getparameter "autoscaleup" ; + save s_d ; string s_d ; s_d := getparameter "autoscaledown" ; + save followtextalternative ; followtextalternative := if getparameter "spread" : 1 else : 0 fi ; + save tracingfollowtext ; tracingfollowtext := if getparameter "trace" : 1 else : 0 fi ; save autoscaleupfollowtext ; autoscaleupfollowtext := if s_u = "yes" : 1 elseif s_u = "max" : 2 else : 0 fi ; save autoscaledownfollowtext ; autoscaledownfollowtext := if s_d = "yes" : 1 elseif s_d = "max" : 2 else : 0 fi ; draw followtext ( - if (getparameter "followtext" "reverse") : reverse fi getparameter "followtext" "path", - getparameter "followtext" "content" + if (getparameter "reverse") : reverse fi (getparameter "path"), + getparameter "text" ) ; + popparameters ; ) enddef ; presetparameters "arrow" [ path = origin, + % pen = ..., kind = "fill", dimple = 1/5, scale = 3/4, + penscale = 3, length = 4, angle = 45, location = "end", % middle both @@ -374,23 +380,32 @@ def lmt_arrow = applyparameters "arrow" "lmt_do_arrow" enddef ; vardef lmt_do_arrow = image ( - save a ; string a ; a := getparameter "arrow" "alternative" ; - save l ; string l ; l := getparameter "arrow" "location" ; - save k ; string k ; k := getparameter "arrow" "kind" ; - save p ; path p ; p := getparameter "arrow" "path" ; + pushparameters "arrow" ; + save a ; string a ; a := getparameter "alternative" ; + save l ; string l ; l := getparameter "location" ; + save k ; string k ; k := getparameter "kind" ; + save p ; path p ; p := getparameter "path" ; save ahvariant ; ahvariant := if a = "dimpled" : 1 elseif a = "curved" : 2 else : 0 fi ; - save ahdimple ; ahdimple := getparameter "arrow" "dimple" ; - save ahscale ; ahscale := getparameter "arrow" "scale" ; - save ahangle ; ahangle := getparameter "arrow" "angle" ; - save ahlength ; ahlength := getparameter "arrow" "length" ; - if not getparameter "arrow" "headonly" : + save ahdimple ; ahdimple := getparameter "dimple" ; + save ahscale ; ahscale := getparameter "scale" ; + save ahangle ; ahangle := getparameter "angle" ; + save ahlength ; ahlength := getparameter "length" ; + if not getparameter "headonly" : draw p ; fi ; + if hasparameter "pen" : + % a cheat: we should have a type check in lua + if hasoption "pen" "auto" : + ahlength := (getparameter "penscale") * boundingradius(currentpen) ; + else : + ahlength := (getparameter "penscale") * boundingradius(getparameterpen "pen") ; + fi ; + fi ; if k = "draw" : draw elseif k = "both" : filldraw else : fill fi if l = "middle" : midarrowhead p ; elseif l = "percentage" : - arrowheadonpath (p, (getparameter "arrow" "percentage")/100) ; + arrowheadonpath (p, (getparameter "percentage")/100) ; elseif l = "both" : arrowhead p ; if k = "draw" : draw elseif k = "both" : filldraw else : fill fi @@ -398,6 +413,7 @@ vardef lmt_do_arrow = else : arrowhead p ; fi ; + popparameters ; ) enddef ; @@ -415,13 +431,14 @@ def lmt_placeholder = applyparameters "placeholder" "lmt_do_placeholder" enddef def lmt_do_placeholder = begingroup ; + pushparameters "placeholder" ; save w, h, d, r, p, c, b, s, q, a ; numeric w, h, d, r ; path p ; string s, a ; - s := getparameter "placeholder" "color" ; - w := getparameter "placeholder" "width" ; - h := getparameter "placeholder" "height" ; - r := getparameter "placeholder" "reduction" ; - a := getparameter "placeholder" "alternative" ; + s := getparameter "color" ; + w := getparameter "width" ; + h := getparameter "height" ; + r := getparameter "reduction" ; + a := getparameter "alternative" ; d := max(w,h) ; if cmykcolor resolvedcolor(s) : cmykcolor c, b ; b := (0,0,0,0) @@ -445,6 +462,7 @@ def lmt_do_placeholder = withcolor r[c randomized(.3,.9),b] ; endfor ; clip currentpicture to p ; + popparameters ; endgroup ; enddef ; @@ -1239,7 +1257,8 @@ vardef lmt_do_chart_bar = ) enddef ; -% more complex than needed but i want to trace so i need the vars +%D This one is more complex than needed but I want to trace so I need all those +%D variables. presetparameters "shade" [ alternative = "circular", @@ -1258,6 +1277,8 @@ presetparameters "shade" [ ] ; +% TODO: pass colors as strings + def lmt_shade = applyparameters "shade" "lmt_do_shade" enddef ; vardef lmt_do_shade = @@ -1318,27 +1339,10 @@ vardef lmt_do_shade = 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) ; @@ -1369,6 +1373,26 @@ vardef lmt_do_shade = center_b := point p_b of bb ; fi fi ; + if hasparameter "center" : + save cx, cy ; + if numeric getparameter "center" : + cx := getparameter "center" ; + cx := cy ; + % elseif pair getparameter "center" : + % cx := xpart getparameter "center" ; + % cy := ypart getparameter "center" ; + else : + cx := getparameter "center" 1 ; + cy := getparameter "center" 2 ; + fi + center_a := center mfun_shade_path shifted ( + cx * bbwidth (mfun_shade_path)/2, + cy * bbheight(mfun_shade_path)/2 + ) ; + elseif hasparameter "vector" : + center_a := point (getparameter "vector" 1) of mfun_shade_path ; + center_b := point (getparameter "vector" 2) of mfun_shade_path ; + fi fill mfun_shade_path withprescript "sh_domain=" & decimal domain_min & " " & decimal domain_max withprescript "sh_transform=yes" @@ -1380,12 +1404,14 @@ vardef lmt_do_shade = withprescript "sh_set_y=" & ddecimal (mfun_shade_ny,mfun_shade_ly) % if alternative = "linear" : withprescript "sh_type=linear" - withprescript "sh_factor=1" + % withprescript "sh_factor=1" + withprescript "sh_factor=" & decimal factor 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_factor=1.2" + withprescript "sh_factor=" & decimal factor withprescript "sh_center_a=" & ddecimal center_a withprescript "sh_center_b=" & ddecimal center_b withprescript "sh_radius_a=" & decimal radius_a @@ -1394,11 +1420,13 @@ vardef lmt_do_shade = 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) ; + draw textext.top("\strut\ttx center a") ysized LineHeight shifted center_a shifted (0, 2mm) ; + draw textext.bot("\strut\ttx center b") ysized LineHeight 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 ; +% draw fullcircle scaled ( radius_a * 2) shifted center_a dashed evenly ; +% draw fullcircle scaled (factor * radius_b * 2) shifted -center_b dashed evenly ; + draw fullcircle scaled ( radius_a) shifted center_a dashed evenly ; + draw fullcircle scaled (factor * radius_b) shifted -center_b dashed evenly ; fi fi popparameters ; @@ -1473,12 +1501,15 @@ boolean lmx_contour_loaded ; lmx_contour_loaded := false ; def mfun_only_draw = addto currentpicture doublepath enddef ; def mfun_only_fill = addto currentpicture contour enddef ; def mfun_only_nodraw text t = addto currentpicture doublepath t withpostscript "collect" enddef ; -def mfun_only_nofill text t = addto currentpicture contour t withpostscript "collect" enddef ; +def mfun_only_nofill text t = addto currentpicture contour t withpostscript "evenodd" enddef ; +def mfun_only_eofill text t = addto currentpicture contour t withpostscript "collect" enddef ; def lmt_do_contour_shortcuts = save D ; let D = mfun_only_draw ; + save E ; let E = mfun_only_eofill ; save F ; let F = mfun_only_fill ; save d ; let d = mfun_only_nodraw ; + save e ; let f = mfun_only_eofill ; save f ; let f = mfun_only_nofill ; save C ; let C = cycle ; enddef ; @@ -1975,3 +2006,25 @@ vardef lmt_do_contour = ) enddef ; +presetparameters "svg" [ + filename = "", + width = 0, + height = 0, +] ; + +def lmt_svg = applyparameters "svg" "lmt_do_svg" enddef ; + +vardef lmt_do_svg = + save w, h ; + w := getparameter "svg" "width" ; + h := getparameter "svg" "height" ; + image ( + lua.mp.lmt_svg_include() + ) + if w > 0 : + if h > 0 : xysized(w,h) else : xsized(w) fi + else : + if h > 0 : ysized(h) fi + fi +enddef ; + diff --git a/metapost/context/base/mpiv/mp-luas.mpxl b/metapost/context/base/mpiv/mp-luas.mpxl index cd6733f84..1cd5efe7f 100644 --- a/metapost/context/base/mpiv/mp-luas.mpxl +++ b/metapost/context/base/mpiv/mp-luas.mpxl @@ -209,6 +209,7 @@ newinternal mfid_getparameterdefault ; mfid_getparameterdefault := scriptindex newinternal mfid_getparametercount ; mfid_getparametercount := scriptindex "getparametercount" ; newinternal mfid_getmaxparametercount ; mfid_getmaxparametercount := scriptindex "getmaxparametercount" ; newinternal mfid_getparameterpath ; mfid_getparameterpath := scriptindex "getparameterpath" ; +newinternal mfid_getparameterpen ; mfid_getparameterpen := scriptindex "getparameterpen" ; newinternal mfid_getparametertext ; mfid_getparametertext := scriptindex "getparametertext" ; %%%%%%%%%%% mfid_getparameteroption ; mfid_getparameteroption := scriptindex "getparameteroption" ; newinternal mfid_applyparameters ; mfid_applyparameters := scriptindex "applyparameters" ; @@ -224,6 +225,7 @@ 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 getparameterpen = runscript mfid_getparameterpen enddef ; def getparametertext = runscript mfid_getparametertext enddef ; %%% getparameteroption = runscript mfid_getparameteroption enddef ; def applyparameters = runscript mfid_applyparameters enddef ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 7d20da104..286e4e495 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -704,6 +704,15 @@ vardef mfun_max_radius(expr p) = ) enddef ; +vardef mfun_min_radius(expr p) = + min ( + (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 @@ -1149,6 +1158,10 @@ vardef mfun_do_outline_text_set_f (text f) text r = def mfun_do_outline_options_r = r enddef ; enddef ; +vardef mfun_do_outline_text_set_u (text f) text r = + def mfun_do_outline_options_f = f enddef ; +enddef ; + vardef mfun_do_outline_text_set_d (text d) text r = def mfun_do_outline_options_d = d enddef ; def mfun_do_outline_options_r = r enddef ; @@ -1682,7 +1695,12 @@ def nofill text t = fill t withpostscript "collect" enddef ; def nodraw text t = draw t withpostscript "collect" enddef ; def dodraw text t = draw t withpostscript "flush" enddef ; def dofill text t = fill t withpostscript "flush" enddef ; -%%% eoclip text t = clip t withpostscript "evenodd" enddef ; % no postscripts yet + +if contextlmtxmode : + def eoclip text t = clip t withpostscript "evenodd" enddef ; +else : + def eoclip text t = clip t enddef ; % no postscripts yet +fi ; % def withrule expr r = % if (t = "even-odd") or (t = "evenodd") : withpostscript "evenodd" fi diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index 3bae73aad..b05adcc8b 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -886,6 +886,13 @@ vardef roundedsquare (expr width, height, offset) = (0,height-offset) -- (0,offset) {down} .. cycle enddef ; +vardef roundedsquarexy (expr width, height, dx, dy) = + (dx,0) -- (width-dx,0) {right} .. + (width,dy) -- (width,height-dy) {up} .. + (width-dx,height) -- (dx,height) {left} .. + (0,height-dy) -- (0,dy) {down} .. cycle +enddef ; + %D Some colors. def resolvedcolor(expr s) = @@ -3641,11 +3648,29 @@ 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 ; + xxpart t = xx ; yypart t = yy ; + xypart t = xy ; yxpart t = yx ; + xpart t = x ; ypart t = y ; + t +enddef ; + +vardef bymatrix(expr rx, sx, sy, ry, tx, ty) = + save t ; transform t ; + xxpart t = rx ; yypart t = ry ; + xypart t = sx ; yxpart t = sy ; + xpart t = tx ; ypart t = ty ; t enddef ; + +let xslanted = slanted ; + +def yslanted primary s = + transformed + begingroup + save t ; transform t ; + xxpart t = 1 ; yypart t = 1 ; + xypart t = 0 ; yxpart t = s ; + xpart t = 0 ; ypart t = 0 ; + t + endgroup +enddef ; |