
\mainlanguage[de]

\setvariables[cover][
  issue={0},
  author={Autor Name},
  title={Toller Titel},
  subtitle={Aussagekräftiger Untertitel}
]

\definemeasure[Bleed][3mm]
\definemeasure[FrontOffset][210mm]

\definepapersize[Cover][% A3
  width=420mm,
  height=297mm]
\definepapersize[CoverPlus][
  width=430mm,
  height=307mm]
\setuppapersize[Cover][CoverPlus]

\definemeasure[MaxHeight][{\dimexpr\paperheight + 2\measure{Bleed}\relax}]
\definemeasure[MaxWidth][{\dimexpr\paperwidth + 2\measure{Bleed}\relax}]

\setuplayout[
  marking=on,
  location=middle,
  top=0mm,
  header=0mm,
]
\setupalign[flushleft,hanging]

\setupbodyfont[ss,24pt]

\setuppagenumbering[state=stop]

\definecolor[cmykblack][c=0,m=0,y=0,k=1]
\definecolor[LineColor][c=.9,m=.8,y=0,k=.3,t=1,a=2]
\setupcolors[
  pagecolormodel=auto,
  rgb=no,cmyk=yes,spot=no,
  state=start,
  overprint=yes,
  intent={Uncoated FOGRA29 (ISO 12647-2:2004)},
  textcolor=LineColor,
]
\setupbackend[
  format=PDF/X-4,
]
\definetransparency[tmultiply][a=2,t=1]
\definetransparency[tpaper][a=1,t=.05]

\definelayer[whole][
  width=\paperwidth,
  height=\paperheight
]

\startuniqueMPgraphic{fuzzylines}
  input mp-sketch; % by Aditya Mahajan

  pen pillpen ; pillpen := makepen ((-1.5bp,-0.5bp)--(1.5bp,-0.5bp)..(1.5bp,0.5bp)--(-1.5bp,0.5bp)..cycle) ;
  pickup pillpen xyscaled 3bp ;

  sketchypaths; % Make draw and fill sketchy
  sketch_amount := 4bp;
  sketch_passes := 5;
  sketch_segments := 10;

  path one   ; one   := (25.5mm,300mm) -- (25.5mm,249mm) -- (210mm,249mm) -- (395mm,249mm) -- (395mm,300mm) ; % links-oben
  % split horizontal and vertical parts to adapt settings:
  path one_h ; one_h := (25.5mm,249mm) -- (210mm,249mm) -- (395mm,249mm) ;
  path one_v ; one_v := (25.5mm,300mm) -- (25.5mm,249mm) ;
  path two   ; two   := (25.5mm+210mm,-3mm) -- (25.5mm+210mm,130mm) -- (213mm+210mm,130mm) ; % unten-rechts
  path three ; three := (-3mm,130mm) -- (210mm-25.5mm,130mm) -- (210mm-25.5mm,-3mm); % links-unten

  draw one withcolor "LineColor" withtransparency ("multiply", 0.2);
  draw two withcolor "LineColor" withtransparency ("multiply", 0.2);
  draw three withcolor "LineColor" withtransparency ("multiply", 0.2);

  picture NoisePattern;
  NoisePattern := image(
    pickup pencircle xyscaled 0.5bp;
    numeric pmax ; pmax := 7 ;
    numeric x ; numeric y ;
  	for i = 1 upto pmax:
  		for j = 1 upto pmax:
        % try to get more dots in the center
        x := (i - (pmax/2)) * (uniformdeviate 2.5); % we use a wide pen
        y := (j - (pmax/2)) * (uniformdeviate 1.25);
        draw (x, y) withcolor "LineColor" withtransparency ("normal", (uniformdeviate 0.33));
  		endfor
  	endfor
  );

  numeric noise_steps ; noise_steps := 100;

  def noisify(expr p) =
    for i = 0 step 1/noise_steps until length p:
    	draw NoisePattern randomized 1 shifted point i of p ;
    endfor
  enddef;

  noisify(one_h);
  noisify(two);
  noisify(three);
  noise_steps := 30;
  noisify(one_v);
  noisify(one_v shifted (369.5mm,0));

  naturalizepaths;
\stopuniqueMPgraphic

\defineoverlay[fuzzylines][\uniqueMPgraphic{fuzzylines}]

\setupbackgrounds[page][background={fuzzylines,whole},state=start]


\starttext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startlayout [page]

\definemeasure[FrontTextstart][{\dimexpr\measure{FrontOffset}+36mm\relax}]

\setlayerframed[whole][
  hoffset=-\measure{Bleed},
  voffset=-\measure{Bleed}-8mm,
  offset=overlay,
  frame=off,
  width=\measure{MaxWidth},
  height=\measure{MaxHeight},
]{\starttransparent[tpaper]% funktioniert nicht!
%\externalfigure[paper][width=\measure{MaxWidth},height=\measure{MaxHeight},rotation=90]%
\stoptransparent}

\setlayerframed[whole][
  x=\measure{FrontTextstart},
  y=60mm,
  width=150mm,
  align=flushleft,
  frame=off,
  offset=overlay,
]{\getvariable{cover}{author}}

\setlayerframed[whole][
  x=\measure{FrontTextstart}-2mm,
  y=77mm,
  height=65mm,
  width=150mm,
  align={flushleft,hanging,lohi},
  frame=off,
  offset=overlay,
]{\definedfont[SansItalic*default at 96bp]\getvariable{cover}{title}}

\setlayerframed[whole][
  x=\measure{FrontTextstart},
  y=144mm,
  width=150mm,
  align=flushleft,
  frame=off,
  offset=overlay,
]{\getvariable{cover}{subtitle}}

\setlayerframed[whole][
  x=\measure{FrontTextstart}+20mm,
  y=264.5mm,
  width=150mm,
  align=flushleft,
  frame=off,
  offset=overlay,
]{\definedfont[SansItalic*default at 24bp]Workbook \getvariable{cover}{issue}}

\setlayerframed[whole][
  x=\measure{FrontTextstart},
  y=258mm,
  offset=overlay,
  %frame=off,
  width=16mm,
  height=16mm,
]{\startMPcode
  %input img/dvhlogo.mp;
  %draw DVHlogo_sw xysized (16mm,16mm);
  %redraw currentpicture withpen pencircle scaled 0.5bp withcolor "LineColor";
\stopMPcode}

\flushlayer[whole]

TEST

\stoplayout

\stoptext
