Skip to content

Instantly share code, notes, and snippets.

@mpfusion
Created January 25, 2013 15:44
Show Gist options
  • Save mpfusion/4635387 to your computer and use it in GitHub Desktop.
Save mpfusion/4635387 to your computer and use it in GitHub Desktop.
\setupbodyfont
[sans, 10pt]
\definecolor
[paper] [c=0, m=0, y=.1, k=0]
\definecolor
[mylightgray] [s=.6]
\starttext
\startreusableMPgraphic{pagelayout}
u:=.5cm;
w:=21u; h:=29.7u;
% layout
backspace :=7u; topspace :=5u;
header :=1u; headerdistance :=2u;
textheight :=13u; footerdistance :=u;
footer :=u; leftmargin :=3u;
textwidth :=7u; leftmargindistance :=.4u;
rightmargin :=3.1u; rightmargindistance :=.4u;
topheight :=1.5u; topdistance :=u;
bottom :=1.5u; bottomdistance :=u;
margin :=2.9u; margindistance :=.7u;
edge :=2.6u; edgedistance :=.5u;
% page
fill unitsquare
xyscaled (w,h)
shifted (0,-h)
withcolor \MPcolor{paper};
% text
drawoptions(withcolor \MPcolor{mylightgray});
% text text
fill unitsquare
xyscaled (textwidth,-textheight)
shifted (backspace,- (topspace+header+headerdistance) );
% text header
fill unitsquare
xyscaled (textwidth,-header)
shifted (backspace,-topspace);
% text footer
fill unitsquare
xyscaled (textwidth,-footer)
shifted (backspace,
-(topspace+header+headerdistance+textheight+footerdistance) );
% text top
fill unitsquare
xyscaled (textwidth,-topheight)
shifted (backspace,-topspace+topdistance+topheight);
% text bottom
fill unitsquare
xyscaled (textwidth,-bottom)
shifted (backspace,
-(topspace+header+headerdistance+textheight
+footerdistance+footer+bottomdistance) );
% left margin
% left margin text
fill unitsquare
xyscaled (margin,-textheight)
shifted (backspace-margin-margindistance,
- (topspace+header+headerdistance) );
% left margin header
fill unitsquare
xyscaled (margin,-header)
shifted (backspace-margin-margindistance,-topspace);
% left margin footer
fill unitsquare
xyscaled (margin,-footer)
shifted (backspace-margin-margindistance,
-(topspace+header+headerdistance+textheight+footerdistance) );
% left margin top
fill unitsquare
xyscaled (margin,-topheight)
shifted (backspace-margin-margindistance,-topspace+topdistance+topheight);
% left margin bottom
fill unitsquare
xyscaled (margin,-bottom)
shifted (backspace-margin-margindistance,
-(topspace+header+headerdistance+textheight
+footerdistance+footer+bottomdistance) );
% right margin
% right margin text
fill unitsquare
xyscaled (margin,-textheight)
shifted (backspace+textwidth+margindistance,
- (topspace+header+headerdistance) );
% right margin header
fill unitsquare
xyscaled (margin,-header)
shifted (backspace+textwidth+margindistance,-topspace);
% right margin footer
fill unitsquare
xyscaled (margin,-footer)
shifted (backspace+textwidth+margindistance,
-(topspace+header+headerdistance+textheight+footerdistance) );
% right margin top
fill unitsquare
xyscaled (margin,-topheight)
shifted (backspace+textwidth+margindistance,
-topspace+topdistance+topheight);
% right margin bottom
fill unitsquare
xyscaled (margin,-bottom)
shifted (backspace+textwidth+margindistance,
-(topspace+header+headerdistance+textheight
+footerdistance+footer+bottomdistance) );
% left edge
% left edge text
fill unitsquare
xyscaled (edge,-textheight)
shifted (backspace-edge-edgedistance-margin-margindistance,
- (topspace+header+headerdistance) );
% left edge header
fill unitsquare
xyscaled (edge,-header)
shifted (backspace-edge-edgedistance-margin-margindistance,-topspace);
% left edge footer
fill unitsquare
xyscaled (edge,-footer)
shifted (backspace-edge-edgedistance-margin-margindistance,
-(topspace+header+headerdistance+textheight+footerdistance) );
% left edge top
fill unitsquare
xyscaled (edge,-topheight)
shifted (backspace-edge-edgedistance-margin-margindistance,
-topspace+topdistance+topheight);
% left edge bottom
fill unitsquare
xyscaled (edge,-bottom)
shifted (backspace-edge-edgedistance-margin-margindistance,
-(topspace+header+headerdistance+textheight
+footerdistance+footer+bottomdistance) );
% right edge
% right edge text
fill unitsquare
xyscaled (edge,-textheight)
shifted (backspace+textwidth+edgedistance+margin+margindistance,
- (topspace+header+headerdistance) );
% right edge header
fill unitsquare
xyscaled (edge,-header)
shifted (backspace+textwidth+edgedistance+margin+margindistance,
-topspace);
% right edge footer
fill unitsquare
xyscaled (edge,-footer)
shifted (backspace+textwidth+edgedistance+margin+margindistance,
-(topspace+header+headerdistance+textheight+footerdistance) );
% right edge top
fill unitsquare
xyscaled (edge,-topheight)
shifted (backspace+textwidth+edgedistance+margin+margindistance,
-topspace+topdistance+topheight);
% right edge bottom
fill unitsquare
xyscaled (edge,-bottom)
shifted (backspace+textwidth+edgedistance+margin+margindistance,
-(topspace+header+headerdistance+textheight
+footerdistance+footer+bottomdistance) );
% labels
drawoptions(withcolor black);
pickup pencircle scaled 1pt;
% top
label.top(\sometxt{text}, (backspace+.5textwidth,u));
label.top(\sometxt{left},
(backspace-margindistance-.5margin,u));
label.bot(\sometxt{margin},
(backspace-margindistance-.5margin,u));
label.top(\sometxt{left},
(backspace-margindistance-margin-edgedistance-.5edge,u));
label.bot(\sometxt{edge},
(backspace-margindistance-margin-edgedistance-.5edge,u));
label.top(\sometxt{right},
(backspace+textwidth+margindistance+.5margin,u));
label.bot(\sometxt{margin},
(backspace+textwidth+margindistance+.5margin,u));
label.top(\sometxt{right},
(backspace+textwidth+margindistance+margin+edgedistance+.5edge,u));
label.bot(\sometxt{edge},
(backspace+textwidth+margindistance+margin+edgedistance+.5edge,u));
% left
label.lft(\sometxt{text}, (0,-topspace-header-headerdistance-.5textheight));
label.lft(\sometxt{header}, (0,-topspace-.5header));
label.lft(\sometxt{top}, (0,-topspace+topdistance+.5topheight));
label.lft(\sometxt{footer}, (0,
-topspace-header-headerdistance-textheight-footerdistance-.5footer));
label.lft(\sometxt{bottom}, (0,
-topspace-header-headerdistance-textheight-footerdistance-footer
-bottomdistance-.5bottom));
drawoptions(withcolor white);
% textheight
drawdblarrow
(.5w,-topspace-header-headerdistance)--
(.5w,-topspace-header-headerdistance-textheight);
label.rt(\sometxt{\color[white]{\tfx textheight}}, (.5w,-topspace-header-headerdistance-.5textheight));
% height
drawdblarrow
(backspace+.3textwidth, -topspace)--
(backspace+.3textwidth,
-topspace-header-headerdistance-textheight-footerdistance-footer)
withcolor black;
label.lft(\sometxt{\tfx height},(backspace+.3textwidth,
-topspace-header-header-.5textheight))
withcolor black;
% header
drawdblarrow
(.5w,-topspace)--
(.5w,-topspace-header);
label.rt(\sometxt{\color[white]{\tfx header}}, (.5w,-topspace-.5header));
% footer
drawdblarrow
(.5w,-topspace-header-headerdistance-textheight-footerdistance)--
(.5w,-topspace-header-headerdistance-textheight-footerdistance-footer);
label.rt(\sometxt{\color[white]{\tfx footer}},
(.5w,-topspace-header-headerdistance-textheight-footerdistance-.5footer));
% top
drawdblarrow
(.5w,-topspace+topdistance)--
(.5w,-topspace+topdistance+topheight);
label.rt(\sometxt{\color[white]{\tfx top}}, (.5w,-topspace+topdistance+.5topheight));
% bottom
drawdblarrow
(.5w,-topspace-header-headerdistance-textheight
-footerdistance-footer-bottomdistance)--
(.5w,-topspace-header-headerdistance-textheight
-footerdistance-footer-bottomdistance-bottom);
label.rt(\sometxt{\color[white]{\tfx bottom}},
(.5w,-topspace-header-headerdistance-textheight
-footerdistance-footer-bottomdistance-.5bottom));
% textwidth
drawdblarrow
(backspace,-.4h)--
(backspace+textwidth,-.4h);
label.top(\sometxt{\color[white]{\tfx textwidth,}}, (backspace+1.6u+.5textwidth,-.4h));
label.bot(\sometxt{\color[white]{\tfx width}}, (backspace+1.6u+.5textwidth,-.4h));
% leftmargin
drawdblarrow
(backspace-margindistance-margin,-.4h)--
(backspace-margindistance,-.4h);
label.top(\sometxt{\color[white]{\tfx leftmargin,}}, (backspace-margindistance-.5margin,-.4h));
label.bot(\sometxt{\color[white]{\tfx margin}}, (backspace-margindistance-.5margin,-.4h));
% rightmargin
drawdblarrow
(backspace+textwidth+margindistance,-.4h)--
(backspace+textwidth+margindistance+margin,-.4h);
label.top(\sometxt{\color[white]{\tfx rightmargin,}},
(backspace+textwidth+margindistance+.5margin,-.4h));
label.bot(\sometxt{\color[white]{\tfx margin}},
(backspace+textwidth+margindistance+.5margin,-.4h));
% leftedge
drawdblarrow
(backspace-margindistance-margin-edgedistance,-.4h)--
(backspace-margindistance-margin-edgedistance-edge,-.4h);
label.top(\sometxt{\color[white]{\tfx leftedge,}},
(backspace-margindistance-margin-edgedistance-.5edge,-.4h));
label.bot(\sometxt{\color[white]{\tfx edge}},
(backspace-margindistance-margin-edgedistance-.5edge,-.4h));
% rightedge
drawdblarrow
(backspace+textwidth+margindistance+margin+edgedistance,-.4h)--
(backspace+textwidth+margindistance+margin+edgedistance+edge,-.4h);
label.top(\sometxt{\color[white]{\tfx rightedge,}},
(backspace+textwidth+margindistance+margin+edgedistance+.5edge,-.4h));
label.bot(\sometxt{\color[white]{\tfx edge}},
(backspace+textwidth+margindistance+margin+edgedistance+.5edge,-.4h));
% inbetween
drawoptions(withcolor black);
% topspace
drawdblarrow
(backspace-margindistance-margin-.5edgedistance,0)--
(backspace-margindistance-margin-.5edgedistance,-topspace);
label.rt(\sometxt{\tfx topspace},
(backspace-margindistance-margin-.5edgedistance,
(-topspace+topdistance+topheight)/2));
% topdistance
drawdblarrow
(backspace-.5margindistance,-topspace+topdistance)--
(backspace-.5margindistance,-topspace);
label.rt(\sometxt{\tfx topdistance},
(backspace-.5margindistance, -topspace+topdistance/2));
% headerdistance
drawdblarrow
(backspace+textwidth+.5margindistance,-topspace-header)--
(backspace+textwidth+.5margindistance,-topspace-header-headerdistance);
label.rt(\sometxt{\tfx headerdistance},
(backspace+textwidth+.5margindistance,
-topspace-header-headerdistance/2));
% footerdistance
drawdblarrow
(backspace+textwidth+.5margindistance,
-topspace-header-headerdistance-textheight)--
(backspace+textwidth+.5margindistance,
-topspace-header-headerdistance-textheight-footerdistance);
label.rt(\sometxt{\tfx footerdistance},
(backspace+textwidth+.5margindistance,
-topspace-header-headerdistance-textheight-footerdistance/2));
% bottomdistance
drawdblarrow
(backspace-.5margindistance,
-topspace-header-headerdistance-textheight-footerdistance-footer)--
(backspace-.5margindistance,
-topspace-header-headerdistance
-textheight-footerdistance-footer-bottomdistance);
label.rt(\sometxt{\tfx bottomdistance},
(backspace-.5margindistance,
-topspace-header-headerdistance
-textheight-footerdistance-footer-bottomdistance/2));
% helper
low := -topspace-header-headerdistance-textheight
-footerdistance-footer-bottomdistance-bottom;
% leftedgedistance
drawdblarrow
(backspace-margindistance-margin, low)--
(backspace-margindistance-margin-edgedistance, low);
label.bot(\sometxt{\tfx leftedgedistance,},
(backspace-margindistance-margin-edgedistance/2,low));
label.bot(\sometxt{\tfx edgedistance},
(backspace-margindistance-margin-edgedistance/2,low-.7u));
% leftmargindistance
drawdblarrow
(backspace, low)--
(backspace-margindistance, low);
label.bot(\sometxt{\tfx leftmargindistance,},
(backspace-margindistance/2, low-1.4u));
label.bot(\sometxt{\tfx margindistance},
(backspace-margindistance/2, low-2.1u));
% rightedgedistance
drawdblarrow
(backspace+textwidth+margindistance+margin, low)--
(backspace+textwidth+margindistance+margin+edgedistance, low);
label.bot(\sometxt{\tfx rightedgedistance,},
(backspace+textwidth+margindistance+margin+edgedistance/2,low));
label.bot(\sometxt{\tfx edgedistance},
(backspace+textwidth+margindistance+margin+edgedistance/2,low-.7u));
% rightmargindistance
drawdblarrow
(backspace+textwidth, low)--
(backspace+textwidth+margindistance, low);
label.bot(\sometxt{\tfx rightmargindistance,},
(backspace+textwidth+margindistance/2, low-1.4u));
label.bot(\sometxt{\tfx margindistance},
(backspace+textwidth+margindistance/2, low-2.1u));
% backspace
drawdblarrow
(0, -topspace-header-.5headerdistance)--
(backspace, -topspace-header-.5headerdistance);
label.top(\sometxt{\tfx backspace},(backspace/2, -topspace-header-.5headerdistance));
\stopreusableMPgraphic
\reuseMPgraphic{pagelayout}
\stoptext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment