From 75be509021abdcd01f7d5caf35d026647042322a Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 4 Jun 2021 18:35:45 +0200 Subject: 2021-06-04 17:23:00 --- metapost/context/base/mpiv/mp-page.mpiv | 4 + metapost/context/base/mpxl/mp-lmtx.mpxl | 133 ++++++++++++++++++++++++++++++++ metapost/context/base/mpxl/mp-luas.mpxl | 60 ++++++++++---- metapost/context/base/mpxl/mp-page.mpxl | 7 ++ 4 files changed, 187 insertions(+), 17 deletions(-) (limited to 'metapost') diff --git a/metapost/context/base/mpiv/mp-page.mpiv b/metapost/context/base/mpiv/mp-page.mpiv index 7bc7c127c..6aed73868 100644 --- a/metapost/context/base/mpiv/mp-page.mpiv +++ b/metapost/context/base/mpiv/mp-page.mpiv @@ -504,6 +504,10 @@ def OverlayBox = (unitsquare xyscaled (OverlayWidth,OverlayHeight)) enddef ; +def BoundToOverlayBox = + setbounds currentpicture to OverlayBox; +enddef ; + % handy def innerenlarged = diff --git a/metapost/context/base/mpxl/mp-lmtx.mpxl b/metapost/context/base/mpxl/mp-lmtx.mpxl index 204986df3..f06bb6991 100644 --- a/metapost/context/base/mpxl/mp-lmtx.mpxl +++ b/metapost/context/base/mpxl/mp-lmtx.mpxl @@ -2412,3 +2412,136 @@ vardef lmt_do_labtorgb = ) enddef ; +% For now we collect all lmt namespace extensions here, so also this one: + +presetparameters "matrix" [ + % cell = (1, 1), + % from = (1, 1), + % to = (1, 1), + % shape = { "circle", "square" }, + connect = { "center", "center" }, + % text = "", +] ; + +def lmt_matrix = applyparameters "matrix" "lmt_do_matrix" enddef ; + +vardef mfun_lmt_matrix_cell (expr p) = + % anchorbox ("matrix", xpart p, ypart p) ("matrix", xpart p + 1, ypart p) + matrixcell (xpart p, ypart p) +enddef ; + +% todo: lft rt etc but then we need to push/pop the linewidth too + +def mfun_lmt_matrix_connect (expr h, p, r, l, u, d, gap) = + if h == "right" : center rightboundary (p enlarged gap) { r } + elseif h == "left" : center leftboundary (p enlarged gap) { l } + elseif h == "top" : center topboundary (p enlarged gap) { u } + elseif h == "bottom" : center bottomboundary (p enlarged gap) { d } + else : center (p enlarged gap) + fi +enddef ; + +def mfun_lmt_matrix_source (expr p, h, gap) = + mfun_lmt_matrix_connect(h, p, right, left, up, down, gap) +enddef ; + +def mfun_lmt_matrix_target (expr p, h, gap) = + mfun_lmt_matrix_connect(h, p, left, right, down, up, gap) +enddef ; + +vardef mfun_lmt_matrix_enhance (expr p, h) = + if h = "circle" : + fullcircle xysized (bbwidth p, bbheight p) shifted center p + elseif h = "round" : + (p smoothed getparameterdefault "radius" ExHeight) xysized (bbwidth p, bbheight p) + elseif h = "path" : + (getparameterpath "path") shifted center p + elseif h = "scaledpath" : + (getparameterpath "path") xysized (bbwidth p, bbheight p) shifted center p + else : + p + fi +enddef ; + +vardef lmt_do_matrix = + image ( + pushparameters "matrix" ; + draw image ( + save a, b, c, o, g ; path a, b, c ; numeric o, g ; + if (hasparameter "arrowoffset") : + g := getparameter "arrowoffset" ; + elseif (hasparameter "linewidth") : + g := getparameter "linewidth" ; + else : + g := 0; + fi ; + if (hasparameter "from") and (hasparameter "to") : + a := mfun_lmt_matrix_cell(getparameter "from") ; + b := mfun_lmt_matrix_cell(getparameter "to") ; + if hasparameter "offset" : + o := getparameter "offset" ; + a := a enlarged o ; + b := b enlarged o ; + fi ; + if hasparameter "shapes" : + a := mfun_lmt_matrix_enhance(a, getparameter "shapes" 1) ; + b := mfun_lmt_matrix_enhance(b, getparameter "shapes" 2) ; + fi ; + draw a + if (hasparameter "colors") : + withcolor (getparameter "colors" 1) + elseif (hasparameter "color") : + withcolor (getparameter "color") + fi + ; + draw b + if (hasparameter "colors") : + withcolor (getparameter "colors" 2) + elseif (hasparameter "color") : + withcolor (getparameter "color") + fi + ; + c := + mfun_lmt_matrix_source(a, getparameter "connect" 1, g) .. + mfun_lmt_matrix_target(b, getparameter "connect" 2, g) ; + drawarrow c + if (hasparameter "arrowcolor") : + withcolor (getparameter "arrowcolor") + elseif (hasparameter "color") : + withcolor (getparameter "color") + fi + ; + if hasparameter "label" : + pushparameters "label" ; + draw lmt_text [ + text = getparameter "text", + position = point (getparameterdefault "fraction" 1/2) of c, + offset = if hasparameter "offset" : getparameter "offset" fi, + color = if hasparameter "color" : getparameter "color" fi, + anchor = if hasparameter "anchor" : getparameter "anchor" fi, + % strut style format background backgroundcolor + ] ; + popparameters ; + fi ; + elseif (hasparameter "cell") : + a := mfun_lmt_matrix_cell(getparameter "cell") ; + if hasparameter "offset" : + o := getparameter "offset" ; + a := a enlarged o ; + fi ; + if hasparameter "shape" : + a := mfun_lmt_matrix_enhance(a, getparameter "shape") ; + fi ; + draw a + if (hasparameter "color") : + withcolor (getparameter "color") + fi + ; + fi; + ) + if (hasparameter "linewidth") : + withpen pencircle scaled (getparameter "linewidth") + fi + popparameters + ) +enddef ; diff --git a/metapost/context/base/mpxl/mp-luas.mpxl b/metapost/context/base/mpxl/mp-luas.mpxl index 4b92bb423..0fea462ff 100644 --- a/metapost/context/base/mpxl/mp-luas.mpxl +++ b/metapost/context/base/mpxl/mp-luas.mpxl @@ -318,24 +318,50 @@ enddef ; permanent textextanchor ; -newscriptindex mfid_anchorxy ; mfid_anchorxy := scriptindex "anchorxy" ; def anchorxy (expr name, x, y) = runscript mfid_anchorxy name x y enddef ; -newscriptindex mfid_anchorx ; mfid_anchorx := scriptindex "anchorx" ; def anchorx (expr name, x, y) = runscript mfid_anchorx name x y enddef ; -newscriptindex mfid_anchory ; mfid_anchory := scriptindex "anchory" ; def anchory (expr name, x, y) = runscript mfid_anchory name x y enddef ; -newscriptindex mfid_anchorht ; mfid_anchorht := scriptindex "anchorht" ; def anchorht (expr name, x, y) = runscript mfid_anchorht name x y enddef ; -newscriptindex mfid_anchordp ; mfid_anchordp := scriptindex "anchordp" ; def anchordp (expr name, x, y) = runscript mfid_anchordp name x y enddef ; -newscriptindex mfid_anchorll ; mfid_anchorll := scriptindex "anchorll" ; def anchorll (expr name, x, y) = runscript mfid_anchorll name x y enddef ; -newscriptindex mfid_anchorur ; mfid_anchorur := scriptindex "anchorur" ; def anchorur (expr name, x, y) = runscript mfid_anchorur name x y enddef ; -newscriptindex mfid_anchorbox ; mfid_anchorbox := scriptindex "anchorbox" ; - -vardef anchorbox(expr lname, lx, ly, rname, rx, ry) = - (runscript mfid_anchorbox lname lx ly rname rx ry) -enddef ; - -vardef matrixbox (expr fx, fy, tx, ty) = - anchorbox ("matrix", fx, fy) ("matrix", tx + 1, ty) -enddef ; +newscriptindex mfid_anchorxy ; mfid_anchorxy := scriptindex "anchorxy" ; +newscriptindex mfid_anchorx ; mfid_anchorx := scriptindex "anchorx" ; +newscriptindex mfid_anchory ; mfid_anchory := scriptindex "anchory" ; +newscriptindex mfid_anchorht ; mfid_anchorht := scriptindex "anchorht" ; +newscriptindex mfid_anchordp ; mfid_anchordp := scriptindex "anchordp" ; +newscriptindex mfid_anchorul ; mfid_anchorul := scriptindex "anchorul" ; +newscriptindex mfid_anchorll ; mfid_anchorll := scriptindex "anchorll" ; +newscriptindex mfid_anchorlr ; mfid_anchorlr := scriptindex "anchorlr" ; +newscriptindex mfid_anchorur ; mfid_anchorur := scriptindex "anchorur" ; +newscriptindex mfid_anchorbox ; mfid_anchorbox := scriptindex "anchorbox" ; +newscriptindex mfid_anchorspan ; mfid_anchorspan := scriptindex "anchorspan" ; + +def anchorxy (expr name, x, y) = runscript mfid_anchorxy name x y enddef ; +def anchorx (expr name, x, y) = runscript mfid_anchorx name x y enddef ; +def anchory (expr name, x, y) = runscript mfid_anchory name x y enddef ; +def anchorht (expr name, x, y) = runscript mfid_anchorht name x y enddef ; +def anchordp (expr name, x, y) = runscript mfid_anchordp name x y enddef ; +def anchorul (expr name, x, y) = runscript mfid_anchorul name x y enddef ; +def anchorll (expr name, x, y) = runscript mfid_anchorll name x y enddef ; +def anchorlr (expr name, x, y) = runscript mfid_anchorlr name x y enddef ; +def anchorur (expr name, x, y) = runscript mfid_anchorur name x y enddef ; + +% todo: matrix = + +string mfun_local_anchor_tag ; mfun_local_anchor_tag := "matrix" ; % todo: push pop + + +vardef localanchorbox (expr lname, fx, fy, rname, tx, ty) = (runscript mfid_anchorbox lname fx fy rname tx ty) enddef ; +vardef localanchorspan(expr lname, fx, fy, rname, tx, ty) = (runscript mfid_anchorspan lname fx fy rname tx ty) enddef ; +vardef localanchorcell(expr name, x, y ) = (runscript mfid_anchorspan name x y name x y) enddef ; + +vardef anchorbox (expr fx, fy, tx, ty) = (runscript mfid_anchorbox mfun_local_anchor_tag fx fy mfun_local_anchor_tag tx ty) enddef ; +vardef anchorspan(expr fx, fy, tx, ty) = (runscript mfid_anchorspan mfun_local_anchor_tag fx fy mfun_local_anchor_tag tx ty) enddef ; +vardef anchorcell(expr x, y ) = (runscript mfid_anchorspan mfun_local_anchor_tag x y mfun_local_anchor_tag x y) enddef ; + +vardef matrixbox (expr fx, fy, tx, ty) = (runscript mfid_anchorbox mfun_local_anchor_tag fx fy mfun_local_anchor_tag (tx+1) ty) enddef ; +vardef matrixspan(expr fx, fy, tx, ty) = (runscript mfid_anchorspan mfun_local_anchor_tag fx fy mfun_local_anchor_tag (tx+1) ty) enddef ; +vardef matrixcell(expr x, y ) = (runscript mfid_anchorbox mfun_local_anchor_tag x y mfun_local_anchor_tag ( x+1) y) enddef ; permanent anchorxy, anchorx, anchory, anchorht, anchordp, - anchorll, anchorur, anchorbox ; + anchorul, anchorll, anchorlr, anchorur, anchorbox, + anchorspan ; + +permanent + matrixbox, matrixspan, matrixcell diff --git a/metapost/context/base/mpxl/mp-page.mpxl b/metapost/context/base/mpxl/mp-page.mpxl index 72831e927..525a5b157 100644 --- a/metapost/context/base/mpxl/mp-page.mpxl +++ b/metapost/context/base/mpxl/mp-page.mpxl @@ -222,9 +222,16 @@ def OverlayBox = (unitsquare xyscaled (OverlayWidth,OverlayHeight)) enddef ; +def BoundToOverlayBox = + setbounds currentpicture to OverlayBox; +enddef ; + immutable % permanent OverlayBox ; +permanent + BoundToOverlayBox ; + % handy def innerenlarged = -- cgit v1.2.3