% Define colours
\usepackage{xcolor}
\definecolor{xmosblue}{rgb}{0.0745, 0.6, 0.8588} 
\definecolor{xmosgreen}{rgb}{0.6, 0.8549, 0.02745} 
\definecolor{xmoslightgrey}{rgb}{0.8196, 0.82745, 0.83137} 
\definecolor{xmosdarkgrey}{rgb}{0.274, 0.278, 0.290} 
\def\xmosblue{\color{xmosblue}}
\def\xmosgreen{\color{xmosgreen}}
\def\xmoslightgrey{\color{xmoslightgrey}}
\def\xmosdarkgrey{\color{xmosdarkgrey}}

% titling provides things like \thetitle
\usepackage{titling}

% Add front page picture
\usepackage{eso-pic}
\AddToShipoutPicture*{
    \put(0,0){
        \parbox[b][\paperheight]{\paperwidth}{
            \vfill
            \centering
            \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{striking-image.jpg}
            \vfill
        }
    }
}

% Section header font colour
\usepackage{sectsty}
\chapterfont{\color{xmosblue}}      % sets colour of X chapters
\sectionfont{\color{xmosblue}}      % sets colour of X.X sections
\subsectionfont{\color{xmosblue}}   % sets colour of X.X.X subsections

% Chapter styles
\newcommand*{\tocchapterstyle}{
    % Bold blue
    \titleformat{\chapter}[display]{}{}{}{\LARGE\bfseries\color{xmosblue}}
    \titlespacing{\chapter}{0pt}{25pt}{10pt}
}
\newcommand*{\normalchapterstyle}{
    % $NUM $NAME with thick line beneath
    \titleformat{\chapter}[display]{}{}{-10ex}{\LARGE\thechapter\hspace{12pt}}[\vspace{-1.5ex}\rule{\textwidth}{3.5pt}]
    \titlespacing{\chapter}{0pt}{25pt}{10pt}
}

% % Tables
\usepackage{booktabs}   % provides top/mid/bottom rules
\protected\def\sphinxstyletheadfamily {\color{xmosblue}\bfseries}   % set table header fonts 

% % Figures
% % Remove spacing between in-text figures
% \setlength{\intextsep}{\baselineskip}
% \setlength{\textfloatsep}{3\baselineskip}


% Logos
\newlength{\xmoslogolength}       % whole logo
\def\xmoslogo{xmos-logo-2020}
\setlength{\xmoslogolength}{50mm}
\newlength{\xmoslogoXheight}      % Just a single X
\def\xmoslogoX{X}
\setlength{\xmoslogoXheight}{6.9mm}

% Header and Footers
% calculate lengths for title footer
\usepackage{calc}
\setlength{\headwidth}{\textwidth}
\newlength{\footernologolength}
\newlength{\footerpartlinelength}
\setlength{\footernologolength}{\headwidth}
\addtolength{\footernologolength}{-\xmoslogolength}
\setlength{\footerpartlinelength}{\footernologolength/2}

\makeatletter % I think it's like an escape for @
% set hdr/ftr hrules to grey
\renewcommand{\headrule}{
    \xmoslightgrey
    \hrule\@height\headrulewidth\@width\headwidth
    \vskip-\headrulewidth
}
\renewcommand{\footrule}{
    \xmoslightgrey
    \hrule\@width\headwidth\@height\footrulewidth
}
\fancypagestyle{titlestyle}{ % just on title page (called in maketitle)
    \renewcommand{\headrulewidth}{0pt} % no hrules
    \renewcommand{\footrulewidth}{0pt}
    \fancyhf{}
    % full logo with hrule on either side
    \fancyfoot[C]{{\xmosdarkgrey\rule[2.7mm]{\footerpartlinelength}{2pt}\includegraphics{\xmoslogo}\rule[2.7mm]{\footerpartlinelength}{2pt}}}
}
\fancypagestyle{plain}{ % chapter/contents pages
    \renewcommand{\headrulewidth}{0pt} % no hrule
    \renewcommand{\footrulewidth}{0.5pt}
    \fancyhf{}
    % page on left, X logo on right
    \fancyfoot[EO]{{\xmosdarkgrey \thepage} \hfill \raisebox{-2.5mm}{\includegraphics[height=\xmoslogoXheight]{\xmoslogoX}}}
}
\fancypagestyle{normal}{ % normal pages
    \renewcommand{\headrulewidth}{0.5pt}
    \renewcommand{\footrulewidth}{0.5pt}
    \fancyhf{}
    % doc title top right
    \fancyhead[EO]{\hfill {\xmosdarkgrey \thetitle}}
    % page on left, X logo on right
    \fancyfoot[EO]{{\xmosdarkgrey \thepage} \hfill \raisebox{-2.5mm}{\includegraphics[height=\xmoslogoXheight]{\xmoslogoX}}}
}
\makeatother % undoes makeatletter

% define the disclaimer/logo chunk
\newcommand{\makepubpage}{
    \Needspace{3.3cm}
    \vspace*{\fill}
    \includegraphics{\xmoslogo}\\[0.5em]
    Copyright \copyright\ \the\year{}, All Rights Reserved.

    {\xmoslightgrey\rule[1mm]{\linewidth}{0.5pt}}
    %licenseeTrademark defined in sphinx preamble
    \licenseeTrademark
    \vspace*{-1.5mm}
}

% set the last page disclaimer
\AtEndDocument{
    \clearpage
    \newpage   
    \makepubpage
}
