public
Created

ConTeXt module for drawing hooked lines

  • Download Gist
meta-imp-hooks.mkiv
TeX
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
\unprotect
 
% Override default value in pack-fen.mkiv
\def\setinstalledframedimensions
{\edef\overlaywidth {\the\frameddimenwd\space}%
\edef\overlayheight{\the\dimexpr\frameddimenht+\frameddimendp\relax\space}%
\edef\overlaydepth {\the\frameddimendp\space}%
\edef\overlaycolor {\framedparameter\c!backgroundcolor}%
\edef\overlaylinecolor{\framedparameter\c!framecolor}%
\edef\overlaylinewidth{\the\ruledlinewidth}}
 
% Hooked fences: lefthook, righthook, tophook, and bottomhook.
% The parameter \type{radius} determine the radius of the hook.
% The parameter \type{hook} determines the length of the hook.
 
\startMPextensions
vardef BasicHook (expr size, radius, hook) =
((0,0) --- (size - radius, 0){right} .. {up}(size, radius) --- (size, hook))
enddef;
\stopMPextensions
 
\startuseMPgraphic{bottom_right_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayWidth, radius, hook)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{bottom_left_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayWidth, radius, hook)
reflectedabout ((0.5OverlayWidth, 0), (0.5OverlayWidth, OverlayHeight))
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{top_right_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayWidth, radius, hook)
reflectedabout ((0,0),(OverlayWidth,0))
shifted (0,OverlayHeight)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{left_top_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayWidth, radius, hook)
reflectedabout ((0.5OverlayWidth, 0), (0.5OverlayWidth, OverlayHeight))
reflectedabout ((0,0),(OverlayWidth,0))
shifted (0,OverlayHeight)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{left_bottom_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayHeight, radius, hook)
rotated -90
shifted (0,OverlayHeight)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{left_top_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayHeight, radius, hook)
reflectedabout ((0,0),(OverlayWidth,0))
rotated 90
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{right_top_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayHeight, radius, hook)
rotated 90
shifted (OverlayWidth,0)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\startuseMPgraphic{right_bottom_hook}
save radius, hook ;
radius := \the\dimexpr\framedparameter\c!frameradius\relax;
hook := \the\dimexpr\framedparameter{hook}\relax;
draw BasicHook(OverlayHeight, radius, hook)
reflectedabout ((0,0),(OverlayWidth,0))
rotated -90
shifted (OverlayWidth,OverlayHeight)
withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor;
 
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
 
\installtopframerenderer {righthook}{\useMPgraphic{top_right_hook}}
\installtopframerenderer {lefthook}{\useMPgraphic{top_left_hook}}
 
\installbottomframerenderer {righthook}{\useMPgraphic{bottom_right_hook}}
\installbottomframerenderer {lefthook}{\useMPgraphic{bottom_left_hook}}
 
\installleftframerenderer {bottomhook}{\useMPgraphic{left_bottom_hook}}
\installleftframerenderer {tophook}{\useMPgraphic{left_top_hook}}
 
\installrightframerenderer {bottomhook}{\useMPgraphic{right_bottom_hook}}
\installrightframerenderer {tophook}{\useMPgraphic{right_top_hook}}
 
\setupframed
[hook=\framedparameter\c!radius]
 
\protect
 
\continueifinputfile{meta-imp-hooks.mkiv}
 
\setupcolors[state=start]
% \setupframed[offset=none]
\starttext
\framed[frame=off,bottomframe=righthook]{Bottom right hook}
 
\framed[frame=off,bottomframe=lefthook,rulethickness=2bp]{Bottom left hook}
 
\blank
 
\framed[frame=off,topframe=righthook,rulethickness=2bp]{Top right hook}
 
\blank
 
\framed[frame=off,topframe=lefthook,rulethickness=2bp]{Top left hook}
 
\framed[frame=off,bottomframe=righthook,framecolor=green,rulethickness=2bp]{Changing colors}
 
\framed[align=normal,frame=off, hook=1cm, leftframe=bottomhook]{\input zapf \endgraf}
 
\blank
\framed[align=normal,frame=off, hook=1cm, leftframe=tophook]{\input zapf \endgraf}
 
\blank
\framed[align=normal,frame=off, hook=1cm, rightframe=tophook]{\input zapf \endgraf}
 
\blank
\framed[align=normal,frame=off, hook=1cm, rightframe=bottomhook]{\input zapf \endgraf}
\stoptext

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.