% Front page for Unified Process Methodology
%
% Copyright (c) 2006-2007 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.
%
% Creation date: 2006-04-11
% Modifications:
%   2007-07-05   Add people name formatting function.
%   2007-07-03   Force single spacing inside the title.
%   2007-03-19   Add localization.
%   2006-04-19   Add version number.
%

\global\edef\upm@package@fp@ver{2007/07/04}

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

%-----
% 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{xspace}
\RequirePackage{tabularx}
\RequirePackage{graphicx}
\RequirePackage{setspace}

\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}{%
    \begin{titlepage}%
	\begin{center}

		% Illustration picture
 		\ifx\upm@front@illustration\relax
 		\noindent\vfill\includegraphics[width=.4\linewidth]{\theupmdoclogo}
 		\else
 		\noindent\expandafter\includegraphics[width=\upm@front@illustration@size\expandafter\linewidth]{\upm@front@illustration}
 		\fi

		% 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} \\
		\upm@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
 		\ifx\upm@front@illustration\relax
		\noindent\raggedleft\upm@front@author@fmt{\upm@lang@front@authors:~\theauthorlist} \\
 		\else
 		\noindent\begin{tabularx}{\linewidth}{l>{\raggedleft}X}
			\includegraphics[width=.3\linewidth]{\theupmdoclogo} & 
			\upm@front@author@fmt{\upm@lang@front@authors:~\theauthorlist} \\
 		\end{tabularx}
 		\fi

	\end{center}
    \end{titlepage}
}


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

	% Document title
	\upm@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)
		\ifx\upm@front@illustration\relax
		\else
		\put(-110,-100){
			\includegraphics[width=\upm@front@illustration@size\expandafter\linewidth]{\upm@front@illustration}
		}
		\fi
		\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
		\put(\strip@pt\upm@front@tmpa,-50){
			\includegraphics[width=.3\linewidth]{\theupmdoclogo}%
		}
		\end{picture}

	}
    \end{titlepage}
}

%----
% Set the front page layout as the classic layout theme
%\setfrontlayout{layout_name}
\newcommand{\setfrontlayout}[1]{%
	\ifthenelse{\equal{#1}{classic}}{%
		\gdef\upm@front@illustration@size{.6}
		\global\let\upm@front@layout\upm@front@layout@classic%
	}{%
		\ifthenelse{\equal{#1}{modern}}{%
			\gdef\upm@front@illustration@size{1}
			\global\let\upm@front@layout\upm@front@layout@modern%
		}{%
			\errmessage{invalid front layout theme: #1}%
		}%
	}%
}

\setfrontlayout{classic}

\AtBeginDocument{%
	\renewcommand{\maketitle}{\upm@front@layout}%
}

\let\upm@front@illustration\relax

%----
% Set the illustration figure on the front page
%\setfrontillustration[size_factor]{filename}
\newcommand{\setfrontillustration}[2][1]{%
	\gdef\upm@front@illustration{#2}%
	\gdef\upm@front@illustration@size{#1}%
}

\endinput
