% Front page for Unified Process Methodology
%
% Copyright (c) 2006-2025 Stephane GALLAND <galland@arakhne.org>
% 
% This program is free library; you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as
% published by the Free Software Foundation; either version 3 of the
% License, or any later version.
%
% This library is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library; see the file COPYING.  If not,
% write to the Free Software Foundation, Inc., 59 Temple Place - Suite
% 330, Boston, MA 02111-1307, USA.
%

\global\edef\upm@package@fp@ver{2025/03/15}

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{upmethodology-frontpage}[\upm@package@fp@ver]

\RequirePackage{upmethodology-p-common}

%----------------------------------------
% Locales
%----------------------------------------
\def\upm@front@lang@english{
  \gdef\upm@lang@@{\message{**** upmethodology-frontpage is using English language ****}}%
  \gdef\upm@lang@front@authors{\upm@lang@document@authors}
}
\def\upm@front@lang@french{
  \gdef\upm@lang@@{\message{**** upmethodology-frontpage is using French language ****}}%
  \gdef\upm@lang@front@authors{\upm@lang@document@authors}
}

%----------------------------------------
% OPTIONS
%----------------------------------------
\DeclareOption{french}{%
  \upm@front@lang@french
}
\DeclareOption{francais}{%
  \upm@front@lang@french
}
\DeclareOption{english}{%
  \upm@front@lang@english
}
\ExecuteOptions{english}
\ProcessOptions
\upm@lang@@

\RequirePackage{upmethodology-extension}
\RequirePackage{upmethodology-document}

% Declare the temporary dimensions
\newdimen\upm@front@tmpa
\newdimen\upm@front@tmpb

%----------------------------------------
% String format
%----------------------------------------
\def\upm@front@force@single@spacing#1{{\begin{singlespace}#1\end{singlespace}}}
\def\upm@front@maintitle@fmt#1{\Huge \scshape #1}
\def\upm@front@project@fmt#1{\textbf{\Large #1}}
\def\upm@front@subproject@fmt#1{\textbf{\large #1}}
\def\upm@front@document@fmt#1{\textbf{\normalsize #1}}
\def\upm@front@info@fmt#1{{\normalsize #1}}
\def\upm@front@author@fmt#1{%
	\begin{upmfontsize}{\small}#1\end{upmfontsize}%
	}

%----------------------------------------
% Define the command to put the title with a classic layout
%----------------------------------------
\newcommand{\upm@front@layout@classic}{%
    \message{************ USE CLASSIC FRONT COVER}
    \begin{titlepage}%
	\begin{center}

		% Illustration picture
 		\Ifelsedefined{frontillustration}{%
			\noindent\expandafter\includegraphics[width=\Get{frontillustrationsize}\expandafter\linewidth]{\Get{frontillustration}}
		}{%
			\Ifdefined{logo}{\noindent\vfill\expandafter\includegraphics[width=.4\linewidth]{\Get{logo}}}%
		}%

		% Project name
		\vspace{1cm}
		\upm@front@force@single@spacing{\upm@front@maintitle@fmt{\theupmproject}}
		\vspace{1cm}

		% Document title
		\noindent\rule{\linewidth}{1mm} \\
		\noindent\raggedleft\upm@front@project@fmt{\theupmproject} \\
		\Ifnotempty{\theupmsubproject}{\noindent\raggedleft\upm@front@subproject@fmt{\theupmsubproject}\\}
		\vspace{.5cm}
		\noindent\raggedleft\upm@front@document@fmt{\theupmdocname} \\
		\noindent\rule{\linewidth}{1mm} \\

		\vspace{1cm}

		% Document information
 		\noindent\raggedleft\begin{tabular}{rr}
			\upm@front@info@fmt{\upm@lang@docref:} & \upm@front@info@fmt{\theupmdocref} \\
			\upm@front@info@fmt{\upm@lang@version:} & \upm@front@info@fmt{\theupmversion} \\
			\upm@front@info@fmt{\upm@lang@lastupdate@short:} & \upm@front@info@fmt{\theupmdate} \\
			\upm@front@info@fmt{\upm@lang@status:} & \upm@front@info@fmt{\theupmstatus} \\
 		\end{tabular}

		\vfill
 		\Ifelsedefined{frontillustration}{%
			\Ifelsedefined{logo}{%
		 		\noindent\begin{tabularx}{\linewidth}{l>{\raggedleft}X}%
					\expandafter\includegraphics[width=.3\linewidth]{\Get{logo}} & %
					\upm@front@author@fmt{\upm@lang@front@authors:~\theauthorlist} \\%
		 		\end{tabularx}%
			}{%
				\noindent\raggedleft\upm@front@author@fmt{\upm@lang@front@authors:~\theauthorlist} \\%
			}%
		}{%
			\noindent\raggedleft\upm@front@author@fmt{\upm@lang@front@authors:~\theauthorlist} \\%
		}%

	\end{center}
    \end{titlepage}
}


%----------------------------------------
% Define the command to put the title with a modern layout
%----------------------------------------
\newcommand{\upm@front@layout@modern}{%
    \message{************ USE MODERN FRONT COVER}
    \begin{titlepage}%
	% Project name
	\upm@front@maintitle@fmt{\theupmproject} \\
	\noindent\rule{\linewidth}{.5mm} \\

	% Document title
	\Ifnotempty{\theupmsubproject}{\noindent\raggedright\upm@front@subproject@fmt{\theupmsubproject}\\}
	\vspace{.5cm}
	\noindent\raggedright\upm@front@force@single@spacing{\upm@front@document@fmt{\theupmdocname}}

	\vfill

	\vbox{
		\begin{picture}(0,0)
		\Ifelsedefined{frontillustration}{%
			\put(-110,-100){%
				\includegraphics[width=\Get{frontillustrationsize}\expandafter\linewidth]{\Get{frontillustration}}%
			}%
		}{%
		}
		\upm@front@tmpa=\linewidth
		\advance\upm@front@tmpa-.4\linewidth
		\put(\strip@pt\upm@front@tmpa,75){
			\begin{tabular*}{.4\linewidth}{lr}
			\upm@front@info@fmt{\upm@lang@docref:} & \upm@front@info@fmt{\theupmdocref} \\
			\upm@front@info@fmt{\upm@lang@version:} & \upm@front@info@fmt{\theupmversion} \\
			\upm@front@info@fmt{\upm@lang@lastupdate@short:} & \upm@front@info@fmt{\theupmdate} \\
			\upm@front@info@fmt{\upm@lang@status:} & \upm@front@info@fmt{\theupmstatus} \\
			\end{tabular*}
		}
		\upm@front@tmpa=\linewidth
		\advance\upm@front@tmpa-.3\linewidth
		\Ifdefined{logo}{
			\put(\strip@pt\upm@front@tmpa,-50){
				\expandafter\includegraphics[width=.3\linewidth]{\Get{logo}}%
			}
		}
		\end{picture}

	}
    \end{titlepage}
}

\newcommand{\upm@front@setfrontlayout}[2]{%
	\ifthenelse{\equal{#1}{classic}}{%
		\Set{frontillustrationsize}{.6}%
		\global\let\upm@front@layout\upm@front@layout@classic%
	}{%
		\ifthenelse{\equal{#1}{modern}}{%
			\Set{frontillustrationsize}{1}
			\global\let\upm@front@layout\upm@front@layout@modern%
		}{%
			\ifthenelse{\equal{#1}{custom}}{#2}{\errmessage{invalid front layout theme: #1}}%
		}%
	}%
}

%----------------------------------------
% Set the front page layout as the classic layout theme
%----------------------------------------
%\setfrontcover{layout_name}
\newcommand{\setfrontcover}[1]{%
	\upm@front@setfrontlayout{#1}{\errmessage{invalid front layout theme: #1}}%
}
\newcommand{\setfrontlayout}[1]{\errmessage{"\string\setfrontlayout" is deprecated. Use "\string\setfrontcover" instead}}

\setfrontcover{classic}

\renewcommand{\maketitle}{%
	\Ifdefined{frontpage}{
		\upm@front@setfrontlayout{\Get{frontpage}}{%
    			\message{************ USE CUSTOM FRONT COVER}
			\gdef\upm@front@layout{%
				\begin{titlepage}%
				\Get{frontpage@custom}%
				\end{titlepage}%
			}%
		}%
	}%
	\upm@front@layout}%
\newcommand{\makefrontcover}{\maketitle}

%----------------------------------------
% Set the illustration figure on the front page
%----------------------------------------
%\setfrontillustration[size_factor]{filename}
\newcommand{\setfrontillustration}[2][1]{%
	\Set{frontillustrationsize}{#1}%
	\Set{frontillustration}{#2}%
}

%----------------------------------------
% Clear the illustration figure on the front page
%----------------------------------------
%\clearfrontillustration
\newcommand{\clearfrontillustration}{%
	\Set{frontillustrationsize}{1}%
	\Unset{frontillustration}%
}

%----------------------------------------
% SUPPORT FOR TIKZEXTERNAL
%----------------------------------------
% See issue #25
\AtBeginDocument{
	\@ifundefined{tikzexternalrealjob}{}{%
		\message{*** Overriding the document specification for TikZ externalizer.}%
		\ifthenelse{\equal{\jobname}{\tikzexternalrealjob}}{}{%
			\gdef\maketitle{}%
		}%
	}%
}

\endinput