%% This is file `tudamecheng.cfg' version 4.02 (2025-02-25),
%% it is part of
%% TUDa-CI -- Corporate Design for TU Darmstadt
%% ----------------------------------------------------------------------------
%%
%%  Copyright (C) 2018--2025 by Marei Peischl <marei@peitex.de>
%%
%% ============================================================================
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% 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 2008/05/04 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is
%%   Marei Peischl <tuda-ci@peitex.de>
%%
%% The development respository can be found at
%% https://github.com/tudace/tuda_latex_templates
%% Please use the issue tracker for feedback!
%%
%% ============================================================================
%%
\RequirePackage{expl3}
\ProvidesExplFile{tudamecheng.cfg}{2025-02-25}{4.02}{Special Features the department of mechanical engineering of Darmstadt's Corporate Design (tuda-ci)}

\RequirePackage{pgf}

\keys_set:nn {ptxcd/colors}{accent=TUDa-2d,identbar=TUDa-6b}

\cs_new:Nn \ptxcd_mecheng_arrow:N {
	\begin{pgfpicture}
		\pgfsetbaseline{0}
		\pgfsetcolor{TUDa-Arrow}
		\pgfsetrectcap
		\str_if_eq:VnTF \c__ptxcd_base_str {leaflet}
			{\pgfsetlinewidth{2\g_ptxcd_titlerule_dim}}
			{\pgfsetlinewidth{2\c_ptxcd_smallrule_dim}}
		\pgfpathmoveto{\pgfpointorigin}
		\pgfpathlineto{\pgfpointpolar{174}{.05#1}}
		\pgfpathlineto{\pgfpointpolar{186}{.05#1}}
		\pgfpathclose
		\pgfusepath{fill}
		\pgfpathmoveto{\pgfpoint{-#1+.5\pgflinewidth}{0}}
		\pgfpathlineto{\pgfpoint{-.04#1-.5\pgflinewidth}{0}}
		\pgfusepath{stroke}
	\end{pgfpicture}
}

\NewDocumentCommand{\MechEngArrow}{sm}{
	\IfBooleanT{#1}{\begingroup\colorlet{TUDa-Arrow}{.}}
	\dim_set:Nn \l_tmpa_dim {#2}\ptxcd_mecheng_arrow:N \l_tmpa_dim
	\IfBooleanT{#1}{\endgroup}
}

\box_new:N \g_ptxcd_footline_box
\hbox_gset:Nn \g_ptxcd_footline_box {\MechEngArrow{\textwidth}}


\RenewDocumentCommand{\ptxcd_makefootrule}{som}{
	\keys_set:nn {ptxcd/rules} {
		width= \textwidth
	}
	\IfNoValueF {#2} {\keys_set:nn {ptxcd/rules}{#2}}
	\IfBooleanF {#1} {\box_new:c {#3_box}}
	\IfBooleanTF {#1} \use_none:n \hbox_gset:cn {#3_box} {
		\raisebox{-\height}{\MechEngArrow{\l_ptxcd_headrule_width_dim}}
	}
	\IfBooleanF{#1} {\cs_new:cpn {#3} {\box_use:c {#3_box}}}
}


\str_if_eq:VnT \c__ptxcd_base_str {pub} {
	\cs_set:Nn \ptxcd_setup_sponsor_box: {
		\hbox_gset:Nn \g_ptxcd_sponsor_box {
			\edef\height{\noexpand\dimexpr\dim_eval:n {\__ptxcd_logosep: + .5\c_ptxcd_logoheight_dim}}
			\parbox[t]{\textwidth}{
				\bool_if:nF {\seq_if_empty_p:N \g_ptxcd_sponsors_seq &&  \tl_if_empty_p:N \@sponsors} {
					\rule{\linewidth}{\g_ptxcd_titlerule_dim}\par\nointerlineskip
					\vspace{\dimexpr.1\c_ptxcd_logoheight_dim-\c_ptxcd_smallrule_dim}
				}
				\seq_use:Nn \g_ptxcd_sponsors_seq {\hfill}
				\ifhmode
					\par
					\nointerlineskip
					\addvspace{.1\c_ptxcd_logoheight_dim}
				\fi
				\ifx\@sponsors\@empty
				\else
				\@sponsors\par
					\nointerlineskip\addvspace{.1\c_ptxcd_logoheight_dim}
				\fi

				\smash{\MechEngArrow{\linewidth}}
				\\[\c_ptxcd_rulesep_dim]
				\usekomafont{pagefoot}\includegraphics[width=\c_ptxcd_logoheight_dim]{\g_ptxcd_departmentlogo_tl}
			}
		}
	}

	\renewcommand*{\sectionformat}{\color{TUDa-Primary2}\thesection\autodot\enskip}

	\if@titlepage
		\titlehead{\rule{0pt}{\c_ptxcd_logoheight_dim}}
	\fi
}

\str_case:VnT \c__ptxcd_base_str {
	{pub} {}
	{exercise} {}
} {

	\addtokomafont{footsepline}{\color{accentcolor}}
	\box_new:N \g_ptxcd_departmentlogo_box
	\newpairofpagestyles[TUDa.\c__ptxcd_base_str]{TUDa.mecheng}{
		\KOMAoptions{plainfootsepline,footsepline=5pt}
		\ptxcd_makeheadrule[color=TUDa-Primary1, width=\sls@headwidth]{ptxcd_headrule}
		\ModifyLayer[
			contents={
				\dim_compare:nF {\box_wd:N \ptxcd_headrule_box=\layerwidth} {
					\ptxcd_makeheadrule[color=TUDa-Primary1, width=\sls@headwidth]{ptxcd_headrule}
				}
				\smash{\ptxcd_headrule}
			}
		]{TUDa.mecheng.head.above.line}
		\ModifyLayer[
			contents={
				\dim_compare:nF {\box_wd:N \ptxcd_headrule_box=\layerwidth} {
					\ptxcd_makeheadrule[color=TUDa-Primary1, width=\sls@headwidth]{ptxcd_headrule}
				}
				\smash{\ptxcd_headrule}
			}
			]{plain.TUDa.mecheng.head.above.line}
		\ModifyLayer[
		contents={
			\dim_compare:nF {\box_wd:N \g_ptxcd_footline_box=\layerwidth} {
				\hbox_gset:Nn \g_ptxcd_footline_box {\MechEngArrow{\layerwidth}}
			}
			\smash{\box_use:N \g_ptxcd_footline_box}
		}
		]{TUDa.mecheng.foot.above.line}

		\ModifyLayer[
		contents={
			\dim_compare:nF {\box_wd:N \g_ptxcd_footline_box=\layerwidth} {
				\hbox_gset:Nn \g_ptxcd_footline_box {\MechEngArrow{\layerwidth}}
			}
			\smash{\box_use:N \g_ptxcd_footline_box}%
		}
		]{plain.TUDa.mecheng.foot.above.line}

		\clearpairofpagestyles
		\cfoot[\pagemark]{\pagemark}
		\hbox_gset:Nn \g_ptxcd_departmentlogo_box {
			\raisebox{-\height}{
				\tl_if_empty:NTF \g_ptxcd_departmentlogo_tl
					{\strut} {\includegraphics[width=\c_ptxcd_logoheight_dim]{\g_ptxcd_departmentlogo_tl}}
			}
		}
		\setlength{\footheight}{\dim_eval:n {\box_ht:N \g_ptxcd_departmentlogo_box+\box_dp:N \g_ptxcd_departmentlogo_box+\ht\strutbox}}

		\lefoot[\box_use:N \g_ptxcd_departmentlogo_box]{\box_use:N \g_ptxcd_departmentlogo_box}
		\lofoot[\box_use:N \g_ptxcd_departmentlogo_box]{\box_use:N \g_ptxcd_departmentlogo_box}
	}
	\DeclarePageStyleAlias{TUDa}{TUDa.mecheng}
	\DeclarePageStyleAlias{plain.TUDa}{plain.TUDa.mecheng}
	\pagestyle{TUDa}
}


\str_if_eq:VnT \c__ptxcd_base_str {sciposter} {
	\cs_set:Nn \__ptxcd_typeset_footer: {
		\coordinate(lastpos) at (bottomright);
		\tl_if_empty:NF \g_ptxcd_poster_qrcode_tl
		{
			\node[anchor=south~east, inner~sep=\z@] (qrcode)at (lastpos)
			{
				\exp_args:NnV \use:n {\qrcode[height=\dim_use:N \g_ptxcd_footheight_dim]}\g_ptxcd_poster_qrcode_tl
			};
			\coordinate (lastpos) at (qrcode.south~west);
		}
		\box_if_empty:NF \g_ptxcd_footergraphics_box {
			\node[anchor=south~east, inner~sep=\z@] at (lastpos) {
				\accentfont
				\box_use:N \g_ptxcd_footergraphics_box
			};
		}
		\node[anchor=south~west,inner~sep=\z@] (footerarrow) at ([yshift=\g_ptxcd_footheight_dim]bottomleft) {\MechEngArrow{\contentwidth}};
		\node[anchor=north~west,inner~sep=\z@] (departmentlogo) at ([yshift=\g_ptxcd_footheight_dim]bottomleft)
			{\includegraphics[width=\dimexpr2\linewidth/7]{\g_ptxcd_departmentlogo_tl}};
		\node[anchor=south~west,inner~sep=\z@] (infofooter) at (footerarrow.north~west) {
				\parbox{\contentwidth}{
					\accentfont\small\g_ptxcd_poster_foot_tl
					\par\medskip
					\let\footnotetext\ptxcd_title@footnote
					\g_ptxcd_thanks_tl}
		};
	}
}

\str_if_eq:VnT \c__ptxcd_base_str {poster} {
		\ModifyLayer[
		clone=TUDa.poster.qrcode,
		align=bl,
		hoffset=\g_ptxcd_margin_dim,
		width=\paperwidth-2\g_ptxcd_margin_dim,
		height=\g_ptxcd_footheight_dim,
		contents={
			\usekomafont{pagefoot}
			\bool_if:NTF \g_ptxcd_poster_foot_bool {
			\put(0,\LenToUnit{\g_ptxcd_qrcode_dim+\g_ptxcd_footheight_dim}){\rlap{\rule{\dimexpr\paperwidth-2\g_ptxcd_margin_dim}{.5\c_ptxcd_smallrule_dim}}}
			\put(0,\LenToUnit{\g_ptxcd_qrcode_dim+.5\g_ptxcd_footheight_dim}) {
				\parbox[c][\g_ptxcd_footheight_dim][c]{\layerwidth}{\strut\g_ptxcd_poster_foot_tl\strut}}
			\put(0,\LenToUnit{1.2\g_ptxcd_qrcode_dim}){\rlap{\ptxcd_makefootrule*[width=\dimexpr\paperwidth-2\g_ptxcd_margin_dim, color=identbarcolor]{TUDa@footrule}}}
			\putLL{
				\includegraphics[width=\dimexpr2\linewidth/7]{\g_ptxcd_departmentlogo_tl}
			}
			}{
					\put(0,\LenToUnit{1.2\g_ptxcd_qrcode_dim}){\rlap{\ptxcd_makefootrule*[width=\dimexpr\paperwidth-2\g_ptxcd_margin_dim, color=identbarcolor]{TUDa@footrule}}}
			\putLL{
				\includegraphics[width=\dimexpr2\linewidth/7]{\g_ptxcd_departmentlogo_tl}
			}
			}
		}
		]{TUDa.poster.footer}

	\dim_set:Nn \g_ptxcd_footheight_dim {\dim_max:nn {2\g_ptxcd_footheight_dim} {1.5\baselineskip}}
	\geometry{bottom=\dim_eval:n {\g_ptxcd_footheight_dim+\footskip+\g_ptxcd_margin_dim}}
}

\str_if_eq:VnT \c__ptxcd_base_str {letter} {
	\setkomavar{nextfoot}{
		\raisebox{-\height}[0pt][0pt]{
		\parbox{\useplength{firstfootwidth}}{
			\usekomafont{pagefoot}
			\includegraphics[width=\dim_eval:n {.5\__ptxcd_logowidth: + \__ptxcd_logosep:}]{\g_ptxcd_departmentlogo_tl}\\
			\MechEngArrow{\l_ptxcd_headrule_width_dim}
		}
		}
	}

	\setkomavar{nexthead}{}
	\newpairofpagestyles[TUDaLetter]{TUDaLetter.mecheng}{
		\KOMAoptions{footsepline=false,pagenumber=topright}
		\clearpairofpagestyles
		\lehead{\usekomavar{nexthead}}%
		\lohead{\usekomavar{nexthead}}%
		\lefoot{\usekomavar{nextfoot}}%
		\lofoot{\usekomavar{nextfoot}}%
		\rehead[\pagemark]{\pagemark}
		\rohead[\pagemark]{\pagemark}
	}

	\DeclarePageStyleByLayers{TUDaLetter.mecheng.first}{TUDaLetter.mecheng.foot.even,TUDaLetter.mecheng.foot.odd,TUDaLetter.mecheng.foot.oneside,TUDaLetter.mecheng.foot.above.line}
	\DeclarePageStyleAlias{letter.first}{TUDaLetter.mecheng.first}

	\def\letterpagestyle{TUDaLetter.mecheng}
	\geometry{bottom=\dimexpr\c_ptxcd_BottomMargin_dim+10mm}
}

\str_if_eq:VnT \c__ptxcd_base_str {leaflet} {
	\ModifyLayer[
		contents={\raisebox{-\height}[0pt][0pt]{\parbox{\layerwidth}{
				\leavevmode\box_use:N \ptxcd_footrule_box\\[\c_ptxcd_rulesep_dim]
				\includegraphics[width=\c_ptxcd_logoheight_dim]{\g_ptxcd_departmentlogo_tl}
		}}}
	]{TUDa.flyer.footline}
}

\endinput