%% bescheinigung.cls
%% Copyright 2018 by K. Wittenburg <5wittenb@informatik.uni-hamburg.de>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% 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.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is K. Wittenburg.
%
% This work consists of the files bescheinigung.cls.


\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{bescheinigung}[2018/07/01 Bescheinigung]

\ProcessOptions\relax

\LoadClass[a4paper,12pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{etoolbox}
\usepackage[factor=1250]{microtype}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{svg}
\usepackage{eso-pic}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Fonts %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% We're using Latin Modern as a base font. However this font family is
% lacking some important fonts (most notably bold sans serif small
% capitals). For this reason we need to substitute some fonts.
\usepackage{lmodern}

% We're loading the Helvetica font in order to substitute the missing
% shapes from the helvetica font.
\sffamily
\usepackage{helvet}
\sffamily
\DeclareFontShape{T1}{lmss}{bx}{sc} { <-> ssub * phv/bx/sc }{}
\DeclareFontShape{T1}{lmss}{m}{sc} { <-> ssub * phv/m/sc }{}

% The helvet package overrides the default fonts so we need to set those
% back to Latin Modern.
\renewcommand{\rmdefault}{lmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}

%%%%%%%%% Font Sizes %%%%%%%%%
% We're only setting the font sizes required for the layout.
\renewcommand\normalsize{\@setfontsize\normalsize{13pt}{20pt}}
\renewcommand\large{\@setfontsize\large{16pt}{24}}
\renewcommand\Large{\@setfontsize\Large{18pt}{20}}
\renewcommand\small{\@setfontsize\small{11.5pt}{12}}
\renewcommand\scriptsize{\@setfontsize\scriptsize{10pt}{11}}

% Set the main font to a grayish sans serif font.
\renewcommand{\familydefault}{\sfdefault}
\newcommand{\globalcolor}[1]{%
  \color{#1}\global\let\default@color\current@color
}
\AtBeginDocument{\globalcolor{basecolor}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% New Commands %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The following commands can be used in the header along with the
% \title, \subtitle, \date etc.
\newcommand{\institution}[1]{\gdef\@institution{#1}}
\newcommand{\address}[1]{\gdef\@address{#1}}
\newcommand{\recipient}[1]{\gdef\@recipient{#1}\gdef\therecipient{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Configuration %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[
    paper=a4paper,
    top=1.5cm,
    left=2.45cm,
    right=2.45cm,
    bottom=1.27cm,
    includefoot]{geometry}
\setlength{\parindent}{0pt}
\setlength{\parskip}{9pt}
\definecolor{basecolor}{RGB}{89,75,59}
\definecolor{linecolor}{RGB}{172,165,157}

%%%%%%%%% Page Style %%%%%%%%%
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\lfoot{\scriptsize\@institution}
\rfoot{\scriptsize\@address}
\apptocmd{\maketitle}{\thispagestyle{fancy}}{}{}

%%%%%%%%%% Watermark %%%%%%%%%
\AddToShipoutPictureBG*{%
  \AtPageLowerLeft{%
    \makebox[\paperwidth][r]{%
        \includegraphics[scale=0.95]{Wasserzeichen.pdf}
    }
  }
}

%%%%%%%%%% Signature %%%%%%%%%
% Usage: \signature[<date>]{<name>}
% Sets a line along with an optional date and name where a signature may be placed.
\newcommand{\signature}[2][\@date]{
    \par
    \vfill\vfill
    \hfill
    \color{linecolor}
    \begin{minipage}[t]{0.5\textwidth}
        \textcolor{basecolor}{#1}
        \par
        \vspace{\dimexpr -\baselineskip + 5pt}
        \rule{\textwidth}{1pt}
        \par
        \hfill\scriptsize\textcolor{basecolor}{#2}
    \end{minipage}
    \vspace{1.25cm}
}


%%%%%%%%% Title %%%%%%%%%%%%%%
\renewcommand\@maketitle{
    % Header logos
    \begingroup
        \includegraphics[width=0.4\textwidth]{UHH-Logo.pdf}
        \hfill
        \includegraphics[width=0.4\textwidth]{Fachschaftslogo.pdf}
    \endgroup
    
    \vspace{0.4cm}
    
    % Title
    \begingroup
        \centering
        \color{linecolor}
        \hfill\rule{0.9\textwidth}{0.5pt}\hfill
        \vspace{0.32cm}
        \Large
        \rmfamily
        \lsstyle
        \bfseries
        \textcolor{basecolor!90!white}{\MakeUppercase{\@title}}\\
        \color{linecolor}
        \hfill\rule{0.9\textwidth}{2pt}\hfill
    \endgroup
    
    \vspace{-0.4cm}
    
    % Recipient
    \begin{center}
        \color{basecolor!90!white}
        \small
        \slshape
        \sffamily
        Für \@recipient
    \end{center}
    
    % Subtitle
    \begin{center}
        \begin{minipage}{0.75\textwidth}
            \color{black}
            \large
            \bfseries
            \scshape
            \sffamily
            \lsstyle
            \begin{center}
                \@subtitle
            \end{center}
        \end{minipage}
    \end{center}
    \vspace{0.25cm}
    
    \begingroup
    \endgroup
}

\endinput
