% ======================================================================
% variables-tikz.tex
% Copyright (c) Markus Kohm, 2005-2022
%
% This file is part of the LaTeX2e KOMA-Script bundle.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX 
% version 2005/12/01 or later and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of all files listed in MANIFEST.md.
% ======================================================================
%
% Generation of plength figures at scrlttr2 chapter of the KOMA-Script
% guide
%
% Maintained by Markus Kohm
% Original metapost source by Stephan Hennig
% Original TikZ source by Marei Peischl
%
% ======================================================================

\KOMAProvidesFile{variables-tikz.tex}%
                 [$Date: 2022-06-05 12:40:11 +0200 (So, 05. Jun 2022) $
                  KOMA-Script guide (figure in scrlttr2.tex)]
                 
\ExplSyntaxOn
\prop_if_exist:NF \l_this_plength_description_prop {
  \prop_new:N \l_this_plength_description_prop
}
\prop_set_from_keyval:Nn \l_this_plength_description_prop {
  firsthead=\Multi{\DescRef{scrlttr2.variable.firsthead}\\
    \DescRef{scrlttr2.variable.fromname}\and
    \DescRef{scrlttr2.variable.fromaddress}\and
    \DescRef{scrlttr2.variable.fromphone}\and
    \DescRef{scrlttr2.variable.fromfax}\and
    \DescRef{scrlttr2.variable.fromemail}\and
    \DescRef{scrlttr2.variable.fromurl}},
  firstfoot=\DescRef{scrlttr2.variable.firstfoot},
  backaddress =\DescRef{scrlttr2.variable.backaddress},
  specialmail=\DescRef{scrlttr2.variable.specialmail},
  refline=\Multi{\DescRef{scrlttr2.variable.yourref}\and
    \DescRef{scrlttr2.variable.yourmail}\and
    \DescRef{scrlttr2.variable.myref}\and
    \DescRef{scrlttr2.variable.customer}\and
    \DescRef{scrlttr2.variable.invoice}\and
    \DescRef{scrlttr2.variable.place}\and
    \DescRef{scrlttr2.variable.date}},
  title=\DescRef{scrlttr2.variable.title},
  subject=\DescRef{scrlttr2.variable.subject},
  signature=\DescRef{scrlttr2.variable.signature},
  location= \DescRef{scrlttr2.variable.location},
  toaddr=\Macro{begin}\PParameter{\DescRef{scrlttr2.env.letter}}\Parameter{\toaddrname},
  opening=\DescRef{scrlttr2.cmd.opening}\Parameter{\openingargumentname},
  body=\desc\letterbodyname,
  closing=\DescRef{scrlttr2.cmd.closing}\Parameter{\closingargumentname},
}

\prop_if_exist:NF \l_this_plength_var_prop {
  \prop_new:N \l_this_plength_var_prop
}

\prop_set_from_keyval:Nn \l_this_plength_var_prop {
  ticksize=1,
  textwidth= 147,
  textheight= 209.4,
  evensidemargin= 6.1,
  oddsidemargin = 6.1,
  paperwidth = 210,
  paperheight = 297,
  baselineskip = .9\baselineskip, %3.86607,
  headheight     =  6,
  headsep        =7.2,
  footskip       =16.73,
  foldmarkhpos = 3.5,
  tfoldmarkvpos = 105,
  bfoldmarkvpos = 210,
  tfoldmarklength = 2,
  pfoldmarklength = 4,
  bfoldmarklength = 2,
  toaddrvpos = 45,
  refvpos = 98.5,
  refaftervskip = \UseVar{baselineskip},
  toaddrhpos = 20,
  toaddrwidth = 85,
  toaddrheight = 40,
  toaddrindent = 6,
  specialmailwidth = 50,
  specialmailrightindent = 4,
  specialmailheight = \UseVar{baselineskip},
  locwidth = 37.5,
  backaddrheight = 5,
  firstheadvpos = 8,
  firstheadwidth = \UseVar{paperwidth} - 2 * \UseVar{toaddrhpos},
  firstfootwidth = \UseVar{firstheadwidth},
  firstfootvpos =  16.58 + \UseVar{headheight} + \UseVar{headsep} + \UseVar{textheight} + \UseVar{footskip},
  refwidth = 0,
  sigindent = 0,
  toaddrindent =0,
  sigbeforevskip = 2*\UseVar{baselineskip},
  firstheadhpos = 0.5* \UseVar{paperwidth}-.5*\UseVar{firstheadwidth},
  firstheadheight = 5*\UseVar{baselineskip},
  firstfoothpos = 0.5*(\UseVar{paperwidth}-\UseVar{firstfootwidth}),
  firstfootheight = 3*\UseVar{baselineskip},
  fromrulewidth = 0.5 * \UseVar{firstheadwidth},
  lochpos = \UseVar{paperwidth}-\UseVar{toaddrhpos}-\UseVar{locwidth},
  refhpos = 25.40+\UseVar{oddsidemargin},
  text = \UseVar{refhpos},
  textcenter = \UseVar{refhpos}+0.5*\UseVar{textwidth},
  refheight = 2*\UseVar{baselineskip},
  refwidth = \UseVar{textwidth},
  titlevpos = \UseVar{refvpos}+\UseVar{refheight}+\UseVar{refaftervskip},
  titlewidth = 90,
  titleheight = 1.2*\UseVar{baselineskip},
  subjectvpos = \UseVar{titlevpos}+\UseVar{titleheight}+1*\UseVar{baselineskip},
  subjectwidth = 80,
  subjectheight = \UseVar{baselineskip},
  openingvpos = \UseVar{subjectvpos}+\UseVar{subjectheight}+2*\UseVar{baselineskip},
  openingwidth = 60,
  openingheight = \UseVar{baselineskip},
  bodyvpos = \UseVar{openingvpos}+\UseVar{openingheight}+\UseVar{baselineskip},
  bodywidth = \UseVar{textwidth},
  bodyheight = 6*\UseVar{baselineskip},
  typeareabottom = \UseVar{firstfootvpos}-\UseVar{footskip},
  sigvpos = \UseVar{bodyvpos}+\UseVar{bodyheight}+\UseVar{baselineskip},
  sigwidth = 50,
  sigheight = \UseVar{baselineskip},
  locvpos = \UseVar{toaddrvpos},
  locheight = \UseVar{toaddrheight},
}
\def\UseVar#1{
  \fp_eval:n {\prop_item:Nn \l_this_plength_var_prop {#1}}
}

\def\UseDesc#1{
  \prop_item:Nn \l_this_plength_description_prop {#1}
}

\ExplSyntaxOff

\def\desc{\itshape}

\providecommand*{\Multi}[1]{%
  {\def\and{, }%
    \begin{tabular}{@{}l@{}}
      #1
    \end{tabular}
  }%
}

\begin{tikzpicture}[fill=black!20]
  \draw (0,0)rectangle (\UseVar{paperwidth},\UseVar{paperheight});
  
  \filldraw(\UseVar{firstheadhpos},\UseVar{firstheadvpos})rectangle node{\UseDesc{firsthead}}+(\UseVar{firstheadwidth},\UseVar{firstheadheight});
  
  \filldraw(\UseVar{toaddrhpos},\UseVar{toaddrvpos}) rectangle
  node {\UseDesc{backaddress}}
  +(\UseVar{toaddrwidth},\UseVar{backaddrheight});
  
  \filldraw(\UseVar{toaddrhpos}+.5*\UseVar{toaddrwidth}-\UseVar{specialmailrightindent},\UseVar{toaddrvpos}+\UseVar{backaddrheight}) rectangle
  node {\UseDesc{specialmail}}
  +(.5*\UseVar{toaddrwidth},\UseVar{specialmailheight});
  
  \filldraw(\UseVar{toaddrhpos}+\UseVar{toaddrindent},\UseVar{toaddrvpos}+\UseVar{backaddrheight}+\UseVar{specialmailheight})
  rectangle node {\UseDesc{toaddr}}
  +(\UseVar{toaddrwidth}-2*\UseVar{toaddrindent},\UseVar{toaddrheight}-\UseVar{backaddrheight}-\UseVar{specialmailheight});
  
  \draw(\UseVar{toaddrhpos},\UseVar{toaddrvpos})rectangle+(\UseVar{toaddrwidth},\UseVar{toaddrheight});
  
  \filldraw (\UseVar{refhpos},\UseVar{refvpos})rectangle node{\UseDesc{refline}}
  +(\UseVar{refwidth},\UseVar{refheight});
  
  \filldraw (\UseVar{textcenter}-.5*\UseVar{titlewidth},\UseVar{titlevpos})rectangle node{\UseDesc{title}}
  +(\UseVar{titlewidth},\UseVar{titleheight});
  
  \filldraw (\UseVar{text},\UseVar{subjectvpos})rectangle node{\UseDesc{subject}}
  +(\UseVar{subjectwidth},\UseVar{subjectheight});
  
  \filldraw (\UseVar{text},\UseVar{openingvpos})rectangle node{\UseDesc{opening}}
  +(\UseVar{openingwidth},\UseVar{openingheight});
  
  \filldraw (\UseVar{text},\UseVar{bodyvpos})rectangle node{\UseDesc{body}}
  +(\UseVar{bodywidth},\UseVar{bodyheight});
  
  \filldraw (\UseVar{text}+\UseVar{sigindent},\UseVar{sigvpos})rectangle node{\UseDesc{closing}}
  +(\UseVar{sigwidth},\UseVar{sigheight});
  
  \filldraw (\UseVar{text}+\UseVar{sigindent}+.1*\UseVar{sigwidth},\UseVar{sigvpos}+\UseVar{sigheight}+\UseVar{sigbeforevskip})rectangle node{\UseDesc{signature}}
  +(.8*\UseVar{sigwidth},\UseVar{sigheight});
  
  \filldraw (\UseVar{lochpos},\UseVar{locvpos}) rectangle node{\UseDesc{location}}+(\UseVar{locwidth},\UseVar{locheight});
  
  \filldraw (\UseVar{firstfoothpos},\UseVar{firstfootvpos}) rectangle node{\UseDesc{firstfoot}} +(\UseVar{firstfootwidth},\UseVar{firstfootheight});
  
  \draw[thick] (\UseVar{foldmarkhpos},\UseVar{tfoldmarkvpos}) --+(\UseVar{tfoldmarklength},0);
  \draw[thick] (\UseVar{foldmarkhpos},.5*\UseVar{paperheight}) --+(\UseVar{pfoldmarklength},0);
  \draw[thick] (\UseVar{foldmarkhpos},\UseVar{bfoldmarkvpos}) --+(\UseVar{bfoldmarklength},0);
\end{tikzpicture}

\endinput

%%% Local Variables: 
%%% mode: latex
%%% coding: utf-8
%%% End: 
