% ..............................................................................
% The main theme file for the fau-beamer template according to the FAU 
% corporate style guide 2021, see 
% https://www.intern.fau.de/kommunikation-marketing-und-corporate-identity/corporate-identity/
%
%
% for use with LaTeX.
%
% This template was written by Tim Roith.
%
% Copyright 2022 by Tim Roith <tim.roith@fau.de>
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.
%
% ------------------------------------------------------------------------------

\ProvidesPackage{styles/beamerthemefau}
% ..............................................................................
\RequirePackage{xifthen}
\RequirePackage{geometry}
% ..............................................................................
\newif\iffau@isfau\fau@isfautrue
\newif\iffau@isphil\fau@isphilfalse
\newif\iffau@isrewi\fau@isrewifalse
\newif\iffau@ismed\fau@ismedfalse
\newif\iffau@isnat\fau@isnatfalse
\newif\iffau@istech\fau@istechfalse

% ..............................................................................
% Institute
% -------
%
% Define which insitute template should be used.
% ------------------------------------------------------------------------------
\def\inst{FAU}
\DeclareOptionBeamer{institute}{%
  \PassOptionsToPackage{institute=#1}{styles/beamercolorthemefau}
  \ifthenelse{\equal{#1}{FAU}}{\fau@isfautrue\def\inst{FAU}}{\fau@isfaufalse}%
  \ifthenelse{\equal{#1}{Phil}}{\fau@isphiltrue\def\inst{Phil}}{\fau@isphilfalse}%
  \ifthenelse{\equal{#1}{RW}}{\fau@isrewitrue\def\inst{RW}}{\fau@isrewifalse}%
  \ifthenelse{\equal{#1}{Med}}{\fau@ismedtrue\def\inst{Med}}{\fau@ismedfalse}%
  \ifthenelse{\equal{#1}{Nat}}{\fau@isnattrue\def\inst{Nat}}{\fau@isnatfalse}%
  \ifthenelse{\equal{#1}{Tech}}{\fau@istechtrue\def\inst{Tech}}{\fau@istechfalse}%
}

% ..............................................................................
% Aspect ratio
% ------------------------------------------------------------------------------
\def\aspectratio{169}%
\DeclareOptionBeamer{aspectratio}{%
  \ifthenelse{\equal{#1}{169}}{\def\aspectratio{#1}}{}% 16:9
  \ifthenelse{\equal{#1}{43}}{\def\aspectratio{#1}}{}% 4:3
}%

% Define size scaling of the document
\def\scale{1}% default
\DeclareOptionBeamer{scale}{%
  \def\scale{#1}%
  \PassOptionsToPackage{scale=#1}{styles/beamerfontthemefau}
}%

% ..............................................................................
% FontSize
% ------------------------------------------------------------------------------
\DeclareOptionBeamer{fontsize}{%
  \PassOptionsToPackage{fontsize=#1}{styles/beamerfontthemefau}
}%

\DeclareOptionBeamer{fontbaselineskip}{%
  \PassOptionsToPackage{fontbaselineskip=#1}{styles/beamerfontthemefau}
}%

\DeclareOptionBeamer{fontscale}{%
  \PassOptionsToPackage{fontscale=#1}{styles/beamerfontthemefau}
}%
%
\DeclareOptionBeamer{BaseLineSkip}{%
  \PassOptionsToPackage{baselinescale=#1}{styles/beamerfontthemefau}
}%

% ..............................................................................
% File paths for template art
% -------
%
% We define the pathe to the logos and pictures taking into account the 
% institute.
% ------------------------------------------------------------------------------
% defaults

\def\WordMark{template-art/FAUWortmarkeBlau.pdf}
\def\WordMarkTitle{template-art/FAUWortmarkeWhite.pdf}

% The following are dependent on the institute
\def\WordMarkTitleLeft{template-art/\inst /\inst KennungWhite.pdf}
\def\TitleArt{template-art/\inst /\inst Title.jpg}

% Declare options for user specification
\DeclareOptionBeamer{WordMark}{\def\WordMark{#1}}%
\DeclareOptionBeamer{WordMarkTitle}{\def\WordMarkTitle{#1}}
\DeclareOptionBeamer{WordMarkTitleLeft}{\def\WordMarkTitleLeft{#1}}
\DeclareOptionBeamer{TitleArt}{\def\TitleArt{#1}}
\DeclareOptionBeamer{SecondLogo}{\PassOptionsToPackage{SecondLogo=#1}{styles/beamerouterthemefau}}
\DeclareOptionBeamer{ThirdLogo}{\PassOptionsToPackage{ThirdLogo=#1}{styles/beamerouterthemefau}}
% fall back to default image, if the images are not in the folder
\newcommand{\includegraphicsdefault}[2][width=\linewidth]{%
\IfFileExists{#2}%
{\includegraphics[#1]{#2}}%
{%\includegraphics[#1]{template-art/default-image}%
\PackageWarning{beamerthemefau}{Warning: File #2 not found in includegraphicsdefault.}%
}%
}%


% ..............................................................................
\ProcessOptionsBeamer
\selectcolormodel{rgb}
\mode<presentation>
% ------------------------------------------------------------------------------


% ..............................................................................
% Dimensions for outer theme
% -------
%
% We define the relevant dimensions for the outer theme.
% ------------------------------------------------------------------------------
% Aspect ratio: 16:9
\ifthenelse{\equal{\aspectratio }{169}}{%
	\PassOptionsToPackage{SideBarWidthLeft=14.4mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{HeaderHeight=5.mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{HeaderTitleHeight=4mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleHeight=33mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleLineHeight=10mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleTitleSkip=3.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleSkip=5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleSkipLeft=5.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{LineWidthThick=2mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{LineWidthThin=.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{FootHeight=9mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{FootLineSkip=3mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkHeight=17mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkWidth=34mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkTitleHeight=25.4mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkTitleWidth=50.2mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkLeftHeight=12mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkLeftWidth=74mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkBoxWidth=60mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkSkip=12mm}{styles/beamerouterthemefau}
	%
	\PassOptionsToPackage{XScale=\scale}{styles/beamerouterthemefau}
	\PassOptionsToPackage{YScale=\scale}{styles/beamerouterthemefau}
}{}%
% Aspect ratio: 4:3
\ifthenelse{\equal{\aspectratio }{43}}{%
	\gdef\fau@outer@XScale{\scale}
	\gdef\fau@outer@YScale{\scale}
	\PassOptionsToPackage{SideBarWidthLeft=10.8mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{HeaderHeight=5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{HeaderTitleHeight=4mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleHeight=30mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleLineHeight=10mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleTitleSkip=3.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleSkip=2.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{TitleSkipLeft=4.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{LineWidthThick=2mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{LineWidthThin=.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{FootHeight=9mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{FootLineSkip=3mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkHeight=12.6mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkWidth=24.5mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkTitleHeight=21.9mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkTitleWidth=40.0mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkLeftHeight=12mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkLeftWidth=50mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkBoxWidth=60mm}{styles/beamerouterthemefau}
	\PassOptionsToPackage{WordMarkSkip=12mm}{styles/beamerouterthemefau}
	%
	\PassOptionsToPackage{XScale=\scale}{styles/beamerouterthemefau}
	\PassOptionsToPackage{YScale=\scale}{styles/beamerouterthemefau}
}{}%
%
\PassOptionsToPackage{InsertTotalFoot}{styles/beamerouterthemefau}
\PassOptionsToPackage{WordMark=\WordMark}{styles/beamerouterthemefau}
\PassOptionsToPackage{WordMarkTitle=\WordMarkTitle}{styles/beamerouterthemefau}
\PassOptionsToPackage{WordMarkTitleLeft=\WordMarkTitleLeft}{styles/beamerouterthemefau}
% ------------------------------------------------------------------------------




% ..............................................................................
% Dimensions for inner theme
% -------
%
% We define the relevant dimensions for the inner theme in 16:9.
% ------------------------------------------------------------------------------
\ifthenelse{\equal{\aspectratio }{169}}{%
	\PassOptionsToPackage{TitleTitleSkip=3.5mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{WordMarkTitleHeight=21.9mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{WordMarkTitleWidth=55.2mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{HeaderHeight=5mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{TitleHeight=30mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{TitleLineHeight=10mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{RightMargin=3.5mm}{styles/beamerinnerthemefau}
	%
	\PassOptionsToPackage{XScale=\scale}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{YScale=\scale}{styles/beamerinnerthemefau}
}{}%

\ifthenelse{\equal{\aspectratio }{43}}{%
	\PassOptionsToPackage{TitleTitleSkip=3.5mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{WordMarkTitleHeight=25.4mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{WordMarkTitleWidth=46.0mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{HeaderHeight=5mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{TitleHeight=30mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{TitleLineHeight=10mm}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{RightMargin=3.5mm}{styles/beamerinnerthemefau}
	%
	\PassOptionsToPackage{XScale=\scale}{styles/beamerinnerthemefau}
	\PassOptionsToPackage{YScale=\scale}{styles/beamerinnerthemefau}
}{}%

\PassOptionsToPackage{WordMarkTitle=\WordMarkTitle}{styles/beamerinnerthemefau}

\PassOptionsToPackage{TitleArt=\TitleArt}{styles/beamerinnerthemefau}
% ------------------------------------------------------------------------------

% ..............................................................................
% Default options for frame
% -------------------------
\BeforeBeginEnvironment{frame}{%
  \setbeamertemplate{background}{}
  \setbeamertemplate{headline}[headline default]%
  \setbeamertemplate{frametitle}[frametitle default]%
  \setbeamertemplate{sidebar left}{}%
  \setbeamercolor{background canvas}{bg=white}%
  \setbeamertemplate{footline}[footline default]%
  \setbeamertemplate{footline}[footline default]
  \hypersetup{linkcolor=BaseColor}%
  \usebeamerfont{default}%
  \usebeamercolor[fg]{default}%
  \setbeamercolor{footnote}{fg=black}%
  \setbeamercolor{footnote mark}{fg=black}%
}

% ..............................................................................
% Geometry of the layout
% -------
\ifthenelse{\equal{\aspectratio }{169}}{%
	\geometry{paperwidth=\scale\dimexpr338.7mm,paperheight=\scale\dimexpr190.5mm}% for 16:9
}{}%
\ifthenelse{\equal{\aspectratio }{43}}{%
	\geometry{paperwidth=\scale\dimexpr720pt,paperheight=\scale\dimexpr540pt}% for 4:3
}{}%


\usepackage{styles/beamerfontthemefau}
\usepackage{styles/beamercolorthemefau}
\usepackage{styles/beamerinnerthemefau}
\usepackage{styles/beamerouterthemefau}

% ..............................................................................
% Patch for label alignment
% -------
\patchcmd{\beamer@inserttarget}
{\hbox{#1}}{\ifmmode#1\else\hbox{#1}\fi}{}{}
% ..............................................................................
\mode<all>
% ------------------------------------------------------------------------------