% SPDX-FileCopyrightText: 2022 Johannes Loher
%
% SPDX-License-Identifier: CC0-1.0

% !TeX root = ./fanwerk-template.tex

\setlength{\columnsep}{8.5mm}

\definecolor{colorfg}{HTML}{231F20}
\colorlet{colorbg}{white}
\definecolor{colorboxbg}{HTML}{E9E9E9}
\setnormalcolor{colorfg}

\newcommand*{\dstitle}[1]{
    \begin{center}
        \normalfont\woodstampfont\fontsize{100pt}{100pt}\selectfont
        \begin{tikzpicture}[anchor=base, baseline]
            \node at (0,0) {\textpdfrender{
                    TextRenderingMode=FillStrokeClip,
                    LineWidth=8pt,
                    FillColor=colorbg,
                    StrokeColor=colorfg,
                    MiterLimit=2
                }{\MakeUppercase{#1}}};
            \node at (0,0) {\color{colorbg}\MakeUppercase{#1}};
        \end{tikzpicture}
    \end{center}
}

\setkomafont{section}{\normalfont\woodstampfont\fontsize{28pt}{28pt}\selectfont}
\setkomafont{subsection}{\normalfont\woodstampfont\fontsize{28pt}{28pt}\selectfont}
\setkomafont{subsubsection}{\normalfont\woodstampfont\fontsize{24pt}{24pt}\selectfont}
\setkomafont{pagenumber}{\normalfont\woodstampfont\fontsize{36pt}{36pt}\selectfont}

\newlength{\sectionpadding}
\setlength{\sectionpadding}{1mm}
\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
    \Ifstr{#1}{section}{%
        \hspace*{#2}%
        \colorbox{colorfg}{%
            \parbox{\dimexpr\linewidth-2\fboxsep-#2}{%
                \vspace{\sectionpadding}%
                \centering
                \textcolor{colorbg}{\@hangfrom{#3}{#4}}%
                \vspace{\sectionpadding}%
            }%
        }%
    }{%
        \Ifstr{#1}{subsection}{%
            \centering\@hangfrom{\hskip #2#3}{#4}% chktex 21 chktex 41
        }{%
            \@hangfrom{\hskip #2#3}{#4}% chktex 41
        }%
    }%
}%
\makeatother

\RedeclareSectionCommand[afterindent=false, beforeskip=\baselineskip, afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[afterindent=false, beforeskip=\baselineskip, afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[runin=false, afterindent=false, beforeskip=\baselineskip, afterskip=0mm]{subsubsection}

\newcommand*{\dssection}[1]{
    \section*{\MakeUppercase{#1}}
}
\newcommand*{\dssubsection}[1]{
    \subsection*{\MakeUppercase{#1}}
}
\newcommand*{\dssubsubsection}[1]{
    \subsubsection*{\MakeUppercase{#1}}
}

\newcommand*{\dsbox}[1]{%
    \par\noindent\colorbox{colorboxbg}{%
        \parbox{\dimexpr\linewidth-2\fboxsep}{%
            \centering\relax#1%
        }%
    }%
}%

\newcommand*{\dsfbox}[1]{%
    \par\noindent\fcolorbox{colorfg}{colorboxbg}{%
        \parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{%
            \centering\relax#1%
        }%
    }%
}%

\newcommand{\dsminipage}[1]{%
    \par\noindent\colorbox{colorboxbg}{%
        \begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}%
            \centering\relax#1%
        \end{minipage}%
    }%
}

\newcommand{\dsfminipage}[1]{%
    \vspace{\baselineskip}\par\noindent\fcolorbox{colorfg}{colorboxbg}{%
        \begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}%
            \centering\relax#1%
        \end{minipage}%
    }%
}
