Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adityam
Created November 19, 2011 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityam/1379296 to your computer and use it in GitHub Desktop.
Save adityam/1379296 to your computer and use it in GitHub Desktop.
ConTeXt module for drawing hooked lines
\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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment