%D \module
%D   [      file=x-e-1008,
%D        version=2002.xx.xx,
%D          title=\EXAMPLE\ GUI Files,
%D       subtitle=Script Practicing,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This is experimental code. Don't change it, don't rely on
%D this interface remaining the same, don't use tricks used
%D here but not described in manuals, so: asume that this
%D file does not exists.

% evt per regel doen, dan geen probleem met 'onderste regel'

\setupoutput
  [pdftex]

\usemodule[e-0000]

\setEXAvariable {tex:sample-1:n}{3}
\setEXAvariable {tex:sample-1:size}{30pt}
\setEXAvariable {tex:sample-1:content}{}

\setEXAvariable {tex:sample-2:n}{8}
\setEXAvariable {tex:sample-2:size}{20pt}
\setEXAvariable {tex:sample-2:content}{}

\setEXAvariable {tex:sample-3:n}{5}
\setEXAvariable {tex:sample-3:size}{15pt}
\setEXAvariable {tex:sample-3:content}{}

\setEXAvariable {tex:footer:content}{sample}
\setEXAvariable {tex:paper:size}{A4}
\setEXAvariable {tex:paper:orientation}{portrait}

\setEXAvariable {tex:layout:interlinespace}{1.50}

\startnotmode[demo]

  \loadEXArequest{\inputfilename}
  \loadEXAmodes  {examodes.tex}

\stopnotmode

\setuppapersize
  [\getEXAvariable{tex:paper:size},
   \getEXAvariable{tex:paper:orientation}]
  [\getEXAvariable{tex:paper:size},
   \getEXAvariable{tex:paper:orientation}]

\setuplayout
  [width=middle,
   height=middle,
   header=0pt,
   topspace=1.5cm,
   backspace=1.5cm]

\setupheadertexts
  []

\setupfootertexts
  [\getEXAvariableXML{tex:footer:content}]

\startnotmode[atpragma]
    \usetypescript[calligraphy][chancery][texnansi,name]
    \usetypescript[map][chancery][texnansi]
    \definefontsynonym[MainFont][Calligraphy]
\stopnotmode

\startmode[atpragma]

    \usetypescriptfile[type-buy]
    \usetypescriptfile[type-ghz]

    \startmode[font-chancery]
        \usetypescript[calligraphy][chancery][texnansi,name]
        \usetypescript[map][chancery][texnansi]
        \definefontsynonym[MainFont][Calligraphy]
    \stopmode

    \startmode[font-zapfino]
        \usetypescript[handwriting][zapfino][texnansi]
        \usetypescript[map][zapfino][texnansi]
        \definefontsynonym[MainFont][ZapfinoTwo]
    \stopmode

    \startmode[font-lucida-hw]
        \usetypescript[handwriting][lucida][texnansi,name]
        \usetypescript[map][lucida][texnansi]
        \definefontsynonym[MainFont][Handwriting]
    \stopmode

    \startmode[font-lucida-cg]
        \usetypescript[calligraphy][lucida][texnansi,name]
        \usetypescript[map][lucida][texnansi]
        \definefontsynonym[MainFont][Calligraphy]
    \stopmode

    \startmode[font-informal]
        \usetypescript[casual][informal][default,name]
        \usetypescript[map][informal][texnansi]
        \definefontsynonym[MainFont][Serif]
    \stopmode

\stopmode

\setupfooter
  [style=type]

\setupcolors
  [state=start]

\dorecurse{3}
  {\expanded
     {\definetextbackground
        [test-\recurselevel]
        [mp=mpos:par:columnset:\recurselevel,
         location=paragraph,
         state=start,
         frame=off,
         before=,
         after=,
         backgroundcolor=white]}}

\startuseMPgraphic{mpos:par:columnset:1} my_draw_multi_pars(1) ; \stopuseMPgraphic
\startuseMPgraphic{mpos:par:columnset:2} my_draw_multi_pars(2) ; \stopuseMPgraphic
\startuseMPgraphic{mpos:par:columnset:3} my_draw_multi_pars(3) ; \stopuseMPgraphic

\setupalign
  [nothyphenated,right]

\setuptolerance
  [verytolerant]

\startMPinclusions
    numeric CharDepths[], CharHeights[], CharExHeights[] ;
    def my_draw_multi_pars(expr n)  =
        for i=1 upto nofmultipars :
            pair up_down ; up_down := if multilocs[i] = 3 : up else : down fi ;
            drawoptions(withpen pencircle scaled .4pt withcolor .25white) ;
            draw baseline_grid(multipars[i],up_down,true) ;
            path p ; p := boundingbox currentpicture ;
            draw baseline_grid(multipars[i],up_down,true) shifted (0, CharExHeights[n]) ;
            drawoptions(withpen pencircle scaled .2pt withcolor .25white) ;
            draw baseline_grid(multipars[i],up_down,true) shifted (0, CharHeights  [n]) ;
            draw baseline_grid(multipars[i],up_down,true) shifted (0,-CharDepths   [n]) ;
            setbounds currentpicture to p ;
        endfor ;
    enddef ;
\stopMPinclusions

\def\MakeSample#1#2#3#4%
  {\start
   \definefont[MyFont][MainFont at #3]
   \MyFont
   \bgroup
     \setcharstrut{(ghfq)}% needed for zapfino
     \scratchdimen=\dimexpr(\strutheight+\strutdepth)
     \scratchdimen=\getEXAvariable{tex:layout:interlinespace}\scratchdimen
     \xdef\GlobalDimen{\the\scratchdimen}%
   \egroup
   \expanded{\definebodyfontenvironment[#3][interlinespace=\GlobalDimen]}
   \switchtobodyfont[#3]
   \MyFont
   \bgroup
     \setcharstrut{gh}%
     \expanded {\startMPinitializations
       CharDepths   [#1] := \the\dimexpr(\strutdepth)  ;
       CharHeights  [#1] := \the\dimexpr(\strutheight) ;
     \stopMPinitializations}%
     \setcharstrut{o}%
     \expanded {\startMPinitializations
       CharExHeights[#1] := \the\dimexpr(\strutheight) ;
     \stopMPinitializations}%
   \egroup
   \starttextbackground[test-#1]
     \dorecurse{#2}
       {#4\space
        \ifnum\recurselevel=1
          \color[darkgray]  {#4}\space
          \color[middlegray]{#4}\space
          \color[lightgray] {#4}\space
        \fi
        \endgraf}
   \stoptextbackground
   \vskip.5\lineheight
   \stop}

\starttext

\startmode   [demo] \let\getEXAvariableHERE \getEXAvariable    \stopmode
\startnotmode[demo] \let\getEXAvariableHERE \getEXAvariableXML \stopnotmode

\dorecurse{3}
  {\let\CurrentSample\recurselevel
   \ifnum0\getEXAvariable{tex:sample-\CurrentSample:n}>0
     \MakeSample
       {\CurrentSample}
       {\getEXAvariable    {tex:sample-\CurrentSample:n}}
       {\getEXAvariable    {tex:sample-\CurrentSample:size}}
       {\getEXAvariableHERE{tex:sample-\CurrentSample:content}}
     \blank[line]
   \fi}

\stoptext
