\startenvironment env_test
\project tests

\setuppapersize[A6]

\startmode[print]
\newdimen\Bleed
\Bleed=3mm
\setupbleeding[offset=\Bleed]

\setuppapersize[A6][A6,oversized]
\setuplayout[
  marking=on,
  location=middle,
  cropoffset=-5mm,
	bleedoffset=\Bleed,
	trimoffset=-5mm,
]
\stopmode

\startmode[grid]
\setuplayout[
  grid=yes,
]
\stopmode
\showgrid

\setupbodyfont[ss,8pt]
\setupindenting[yes,next,medium]

\setupcolors[state=start]
\setupinteraction[state=start]
\placebookmarks[chapter,section]

\startmode[oldcolumns]
\usemodule[old-columns]
\usemodule[old-columnsets]
\usemodule[old-multicolumns]
\stopmode
\definecolumnset[TwoColumns][n=2]

\useMPlibrary[dum]
\usemodule[visual]
\definecolor[fakerulecolor][c=.3,m=0,y=0,k=.2,t=.5]
\definecolor[fakebaselinecolor][c=1,m=0,y=0,k=0,t=.5]
\definecolor[fakeparindentcolor][c=.05,m=0,y=0,k=0,t=.5]

\startsetups captionsetups
  \definecolor[fakerulecolor][c=0,m=.3,y=0,k=.2,t=.5]
\stopsetups

\setuphead[
  page=no,
  number=no,
  before={\placefloats},
  after={\testpage{5}},
]

\setupheadertexts[\doifmodeelse{*grid}{grid}{no grid}][\doifmodeelse{oldcolumns}{old columns}{new columns}]

\setupfloats[grid=tolerant]
\setupcaptions[
  setups=captionsetups,
  style={\bfx},
]

\startmode[*grid]
\setuphead[
  before={\startlinecorrection},
  after={\stoplinecorrection\testpage{5}},
]
\setupcaptions[
  before={\startlinecorrection},
  after={\stoplinecorrection},
]
\stopmode

\definelayer[WholePage][
  x=0mm,
  y=0mm,
  width=\paperwidth,
  height=\paperheight,
]
\definelayer[TypeArea][
  x=0mm,
  y=0mm,
  width=\textwidth,
  height=\textheight,
]
\setupbackgrounds[page][background={WholePage},state=start]
\setupbackgrounds[text][background={TypeArea},state=start]

\startluacode

local locations = {
  'top',
  'bottom',
  'left',
  'right',
  'here',
}

local locmods = {
  '',
  'high',
  'low',
  'fit',
}

function RandomLocation()
  context(locations[math.random(1,#locations)] .. "," .. locmods[math.random(1,#locmods)])
end

function NumLocation(p)
  context(locations[p])
end

function NumMod(m)
  context(locmods[m])
end

\stopluacode

\define[1]\Blindbild{
\edef\PicLocation{#1}%
\getrandomnumber\imgH{1}{6}%
\getrandomnumber\imgW{3}{10}%
\startplacefigure[
  location={\PicLocation},
  title={\PicLocation \fakewords{3}{20}}]%
%\placefigure[\PicLocation]{\PicLocation \fakewords{3}{20}}{%
\doifmode{*grid}{\startlinecorrection}%
\externalfigure[testbild][
  width=\dimexpr\textwidth * \imgW / 10 \relax,
  height=\dimexpr\textheight * \imgH / 10 \relax,
]%
\doifmode{*grid}{\stoplinecorrection}%
\stopplacefigure%
}

\def\Blindtext{%
  \dorecurse{5}{%
    \edef\Loc{\ctxlua{NumLocation(\recurselevel)}}%
    \chapter{\Loc}
    \dorecurse{4}{%
      \edef\Mod{\ctxlua{NumMod(\recurselevel)}}%
      \section{\Loc, \Mod}
      \dorecurse{2}{%
        \dorecurse{2}{\fakewords{50}{100}\endgraf}
        \Blindbild{\Loc,\Mod}
        \dorecurse{2}{\fakewords{50}{100}\endgraf}
}}}}

\def\BlindtextOhneBilder{%
  \dorecurse{5}{%
    \chapter{\fakewords{2}{5}}
    \dorecurse{4}{%
      \section{\fakewords{2}{6}}
      \dorecurse{4}{%
        \fakewords{50}{100}\endgraf}
}}}

\stopenvironment
