diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-02-17 10:31:56 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-02-17 10:31:56 +0100 |
commit | b14f992ef5f4e868c9959b174278c86516d60dbc (patch) | |
tree | 28587bb46c025ea7b0d27ba93f09c93dcf53c73a /tex/context/base/mkiv/mlib-lua.lua | |
parent | 95a1799032dc61dbca4a11e495be34b4397c8fec (diff) | |
download | context-b14f992ef5f4e868c9959b174278c86516d60dbc.tar.gz |
2017-02-17 10:23:00
Diffstat (limited to 'tex/context/base/mkiv/mlib-lua.lua')
-rw-r--r-- | tex/context/base/mkiv/mlib-lua.lua | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/mlib-lua.lua b/tex/context/base/mkiv/mlib-lua.lua index 8f24124b9..4198a7339 100644 --- a/tex/context/base/mkiv/mlib-lua.lua +++ b/tex/context/base/mkiv/mlib-lua.lua @@ -202,7 +202,7 @@ end local replacer = lpeg.replacer("@","%%") -function mp.format(fmt,...) +function mp.fprint(fmt,...) n = n + 1 if not find(fmt,"%%") then fmt = lpegmatch(replacer,fmt) @@ -539,3 +539,95 @@ mp._get_toks_ = mp.gettoks mp._set_dimen_ = mp.setdimen mp._set_count_ = mp.setcount mp._set_toks_ = mp.settoks + +-- position fun + +do + + local mprint = mp.print + local fprint = mp.fprint + local qprint = mp.quoted + local getwhd = job.positions.whd + local getxy = job.positions.xy + local getposition = job.positions.position + local getpage = job.positions.page + local getregion = job.positions.region + local getmacro = tokens.getters.macro + + function mp.positionpath(name) + local w, h, d = getwhd(name) + if w then + fprint("((%p,%p)--(%p,%p)--(%p,%p)--(%p,%p)--cycle)",0,-d,w,-d,w,h,0,h) + else + mprint("(origin--cycle)") + end + end + + function mp.positioncurve(name) + local w, h, d = getwhd(name) + if w then + fprint("((%p,%p)..(%p,%p)..(%p,%p)..(%p,%p)..cycle)",0,-d,w,-d,w,h,0,h) + else + mprint("(origin--cycle)") + end + end + + function mp.positionbox(name) + local p, x, y, w, h, d = getposition(name) + if p then + fprint("((%p,%p)--(%p,%p)--(%p,%p)--(%p,%p)--cycle)",x,y-d,x+w,y-d,x+w,y+h,x,y+h) + else + mprint("(%p,%p)",x,y) + end + end + + function mp.positionxy(name) + local x, y = getxy(name) + if x then + fprint("(%p,%p)",x,y) + else + mprint("origin") + end + end + + function mp.positionpage(name) + local p = getpage(name) + if p then + fprint("%p",p) + else + mprint("0") + end + end + + function mp.positionregion(name) + local r = getregion(name) + if r then + qprint(r) + else + qprint("unknown") + end + end + + function mp.positionwhd(name) + local w, h, d = getwhd(name) + if w then + fprint("(%p,%p,%p)",w,h,d) + else + mprint("(0,0,0)") + end + end + + function mp.positionpxy(name) + local p, x, y = getposition(name) + if p then + fprint("(%p,%p,%p)",p,x,y) + else + mprint("(0,0,0)") + end + end + + function mp.positionanchor() + qprint(getmacro("MPanchorid")) + end + +end |