%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% uminho/uminho-defaults.clo
%% NOVA thesis configuration file
%%
%% Customization for UNIVERSIDADE DO MINHO (strings and cover)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\typeout{NT FILE uminho/uminho-defaults.clo}%


%%=======================================================================
%% METADATA & GLOBAL PROPERTIES
%%=======================================================================

% UMINHO
\NTOptNewChoice{uminho/copyrightmodifier}{by-nc-sa, by-sa, by, by-nc, by-nd, by-nc-nd}{by-nc-sa}
\NTOptNewToggle{uminho/skipblankcovers}{false}
\NTOptNewToggle{uminho/signatureline}{true}
\NTOptNewValue{uminho/signatureplace}{}

% Do not accept pdfLaTex
\AddValidProcessor{uminho}{lua,xe}

% novathesis customization
\ntsetup{lang/cover=pt}
\ntsetup{print/frontpage=true}
\ntsetup{print/statement=true}
\ntsetup{style/font=newsgott}
\ntsetup{numbering/floats=sequential}

\ntaddfile{statement}{uminho/uminho-statement}

\ifdocprovisional{\ntsetup{docstatus=final}}{}
\ifmaindoc{\ifdocfinal{\ntaddfile{cover}[1]{\DIRSCHOOLS/uminho/cover-final.tex}}{}}{}
\ntsetup{spine/layout=false}

% memoir customization
\setmemoirfontsize{12}   % A4paper with main text at 12pt
\openany         % Two print single paged


%%=======================================================================
%% COLORS
%%=======================================================================

% Colorscheme as viewed in PDF Reader
\definecolor{uminhoGREY}{RGB}{151, 153, 155}
\definecolor{uminhoRED}{RGB}{164, 52, 58}


%%=======================================================================
%% STRINGS (UNIVERSITY & SCHOOL)
%%=======================================================================

% University
\SetUniversity*(pt)={Universidade do Minho}
\SetUniversity*(en)={Universidade do Minho}
\SetUniversity*(fr)={Universidade do Minho}
\SetUniversity*(it)={Universidade do Minho}
\SetUniversity*(logo,RGB)={uminho-insignia-color}
\SetUniversity*(logo,GRAY)={uminho-insignia-mono}

\NewMemStore{OfStr}
\SetOfStr*(pt)={ de }
\SetOfStr*(en)={, }

\NewMemStore{UmDoctype}
\SetUmDoctype*(pt,phd)={Tese de Doutoramento}
\SetUmDoctype*(pt,phdprop)={Proposta de Tese de Doutoramento}
\SetUmDoctype*(pt,phdplan)={Plano de Tese de Doutoramento}
\SetUmDoctype*(en,phd)={Doctorate Thesis}
\SetUmDoctype*(en,phdprop)={Doctorate Thesis Proposal}
\SetUmDoctype*(en,phdplan)={Doctorate Thesis Plan}

\SetUmDoctype*(pt,msc)={Dissertação de Mestrado}
\SetUmDoctype*(pt,mscplan)={Plano de Dissertação de Mestrado}
\SetUmDoctype*(en,msc)={Master Thesis}
\SetUmDoctype*(en,mscplan)={Master Thesis Plan}

\NewMemStore{AdviserSrt}
\SetAdviserSrt*(pt)={Trabalho efetuado sob a orientação de:}
\SetAdviserSrt*(en)={Work developed under the supervision of:}

\NewMemStore{PlaceStr}
\SetPlaceStr*(pt)={Local}
\SetPlaceStr*(en)={Place}

\NewMemStore{DateStr}
\SetDateStr*(pt)={Data}
\SetDateStr*(en)={Date}

\SetAbstractOrder*(pt)={pt,en}
\SetAbstractOrder*(en)={pt,en}
\SetAbstractOrder*(fr)={pt,fr}
\SetAbstractOrder*(it)={pt,it}
\SetAbstractOrder*(es)={pt,es}
\SetAbstractOrder*(de)={pt,de}

\SetCommaString*(pt)={\\}
\SetCommaString*(en)={\\}
\SetCommaString*(fr)={\\}
\SetCommaString*(it)={\\}
\SetCommaString*(es)={\\}
\SetCommaString*(de)={\\}

\SetAndString*(pt)={\\}
\SetAndString*(en)={\\}
\SetAndString*(fr)={\\}
\SetAndString*(it)={\\}
\SetAndString*(es)={\\}
\SetAndString*(de)={\\}


%%=======================================================================
%% COMMITTEE
%%=======================================================================

\SetCommitteeOrder*()={c,r,m}%


%%=======================================================================
%% LAYOUT (MARGINS)
%%=======================================================================

% Set margins for "normal" pages
\SetMargin*(screen,top)={3.5cm}
\SetMargin*(screen,bottom)={2.5cm}
\SetMargin*(screen,left)={2.5cm}
\SetMargin*(screen,right)={2.5cm}
\SetMargin*(paper,top)={3.5cm}
\SetMargin*(paper,bottom)={2.5cm}
\SetMargin*(paper,left)={2.5cm}
\SetMargin*(paper,right)={2.5cm}

% Set margins for cover pages
% \margin(cover,phd,top):={3.67cm}
\SetMargin*(cover,top)={0cm}
\SetMargin*(cover,bottom)={1.0cm}
\SetMargin*(cover,left)={7.87cm}
\SetMargin*(cover,right)={2.0cm}


%%=======================================================================
%% SPINE
%%=======================================================================

\SetSpine(logo,university)={\GetUniversity(logo,RGB)}
\SetSpine(logo,school)={\GetSchool(logo,RGB)}
\SetSpine(author)={\GetDocAuthor(name,short)}
\SetSpine(title)={\GetDocTitle(\@LANG@COVER,main,plain)}
\SetSpine(year)={\GetDocDate(submission,year)}
% \spine(top)={116pt}
\SetSpine(top)={9cm}
\SetSpine(margin)={3mm}
\SetSpine(font)={}


%%=======================================================================
%% COVER PAGE SETUP (BACKGROUNDS)
%%=======================================================================

\SetThesisCover*(phd,1-1,textcolor)={white}
\SetThesisCover*(phd,1-1,bgcolor)={uminhoGREY}
\SetThesisCover*(phd,1-2,bgcolor)={uminhoRED}
\SetThesisCover*(phd,2-1,textcolor)={uminhoGREY}
\SetThesisCover*(phd,N-1,bgcolor)={uminhoRED}
\SetThesisCover*(phd,N-2,bgcolor)={uminhoGREY}

\SetThesisCover*(msc,1-1,textcolor)={uminhoGREY}
\SetThesisCover*(msc,1-1,bgcolor)={white}
\SetThesisCover*(msc,1-2,bgcolor)={uminhoGREY}
\SetThesisCover*(msc,2-1,textcolor)={uminhoGREY}
\SetThesisCover*(msc,N-1,bgcolor)={uminhoGREY}
\SetThesisCover*(msc,N-2,bgcolor)={white}


%%=======================================================================
%% COPYRIGHT & LICENSING
%%=======================================================================

\AtEndPreamble{
  \usepackage[
      type={CC},
      lang=\@LANG@COPYRIGHT,
      modifier=\option{/novathesis/uminho/copyrightmodifier},
      version={4.0},
  ]{doclicense}
}

\newcommand{\licenseThis}{%
  \normalsize%
  \textbf{\emph{\GetUmCopyrightLabel(\@LANG@COVER)}}\\
  \doclicenseImage\\[0.5mm]%
  \textbf{\doclicenseLongName}\\[0.5mm]
  \textbf{\doclicenseName}\\[2ex]
  {\small\url{\doclicenseURL}}
}

\NewMemStore{UmCopyrightLabel}
\SetUmCopyrightLabel*(pt)={Licença concedida aos utilizadores deste trabalho}
\SetUmCopyrightLabel*(en)={License granted to the users of this work}

\NewMemStore{UmCopyrightText}
\SetUmCopyrightText(pt)={%
  \begin{center}%
    \textbf{DIREITOS DE AUTOR E CONDIÇÕES DE UTILIZAÇÃO DO TRABALHO POR TERCEIROS}%
  \end{center}%
  \indent Este é um trabalho académico que pode ser utilizado por terceiros desde que respeitadas as regras e boas práticas internacionalmente aceites, no que concerne aos direitos de autor e direitos conexos.\\[1ex]
  \indent Assim, o presente trabalho pode ser utilizado nos termos previstos na licença abaixo
indicada.\\[1ex]
  \indent Caso o utilizador necessite de permissão para poder fazer um uso do trabalho em condições não previstas no licenciamento indicado, deverá contactar o autor, através do RepositoriUM da \GetUniversity(\@LANG@COVER).\\[1cm]
  \licenseThis%
}

\SetUmCopyrightText(en)={%
  \begin{center}
    \textbf{COPYRIGHT AND TERMS OF USE OF THIS WORK BY A THIRD PARTY}%
  \end{center}%
  \indent This is academic work that can be used by third parties as long as internationally accepted rules and good practices regarding copyright and related rights are respected.\\[1ex]
  \indent Accordingly, this work may be used under the license provided below.\\[1ex]
  \indent If the user needs permission to make use of the work under conditions not provided for in the indicated licensing, they should contact the author through the RepositoriUM of \GetUniversity(\@LANG@COVER).\\[1cm]
  \licenseThis%
}


%%=======================================================================
%% UTILITIES & HOOKS
%%=======================================================================

\NTAddToHook{abstract/pre}{%
  \let\oldchapterheadstart=\chapterheadstart%
  \preto{\chapterheadstart}{\vspace*{-2cm}}
}

\ntsetup{abstract/title=after}

\NTAddToHook{abstract/title/after}{%
  {{\noindent\bfseries\Large\GetDocTitle(\@LSHORT,main,plain)}\\[1ex]}%
}
\NTAddToHook{abstract/post}{%
  \let\chapterheadstart=\oldchapterheadstart%
}

\NTAddToHook{dedication/pre}{%
  \thispagestyle{plain}%
}

\NTAddToHook{quote/pre}{%
  \thispagestyle{plain}%
}


%%=======================================================================
%% FRONT MATTER CONFIGURATION
%%=======================================================================

\@nt@printorder@set{frontmatter_final}{%
    copyright,       % (*) The copyright page
    acknowledgements,% (*) Print the acknowledgments
    statement,       % The statement page
    quote,           % (*) Print the quote
    abstracts,       % Print abstracts in multiple languages.
    alllistof,       % Print all the listof defined in “7_list_of.tex”
    myprintglossaries, % Print the Glossary, Acronyms, Symbols, etc…
}

\@nt@printorder@set{frontmatter_provisional}{%
    copyright,       % (*) The copyright page
    acknowledgements,% (*) Print the acknowledgments
    statement,       % The statement page
    quote,           % (*) Print the quote
    abstracts,       % Print abstracts in multiple languages.
    alllistof,       % Print all the listof defined in “7_list_of.tex”
    myprintglossaries, % Print the Glossary, Acronyms, Symbols, etc…
}

\@nt@printorder@set{frontmatter_working}{%
    copyright,       % (*) The copyright page
    acknowledgements,% (*) Print the acknowledgments
    quote,           % (*) Print the quote
    abstracts,       % Print abstracts in multiple languages.
    alllistof,       % Print all the listof defined in “7_list_of.tex”
    myprintglossaries, % Print the Glossary, Acronyms, Symbols, etc…
}


%%=======================================================================
%% COVER 1 & 2 ELEMENTS
%%=======================================================================

\ntaddtocover{1-2}{}
\ntaddtocover{N-1}{}

% University and School logos
\ntaddtocover[vspace=-0.6mm,halign=l,height=2.6cm]{1-1}{%
  \includegraphics[height=2.5cm]{\GetUniversity(logo,RGB)}%
  \includegraphics[height=2.5cm]{\GetSchool(logo,RGB)}%
}

% University and School logos
\ntaddtocover[vspace=-0.6mm,,halign=l,height=2.6cm]{2-1}{%
  \hspace*{-0.5pt}%
  \includegraphics[height=2.5cm]{\GetUniversity(logo,GRAY)}%
  \hspace{1pt}%
  \includegraphics[height=2.5cm]{\GetSchool(logo,GRAY)}%
}

% University and School names
\ntaddtocover[vspace=1cm,halign=l,height=5.25cm,valign=t]{1-1,2-1}{%
  \fontsize{14}{14}\selectfont%
  \addfontfeature{LetterSpace=2.5}%
  \textbf{\GetUniversity(pt)}%
  \\%
  \addfontfeature{LetterSpace=1.2}%
  \GetSchool(pt)%
}

% Author name
\ntaddtocover[vspace=0mm,halign=l]{1-1,2-1}{%
  \fontsize{17pt}{20.4bp}\selectfont%
  \addfontfeature{LetterSpace=2.9}%
  \GetDocAuthor(name)%
}

% Title of Dissertation
\ntaddtocover[vspace=0.8cm,halign=l,height=5.5cm,valign=t]{1-1,2-1}{%
  \fontsize{17pt}{20.4bp}\selectfont%
  \addfontfeature{LetterSpace=2.9}%
  \textbf{\GetDocTitle(\@LANG@MAIN,main)}
}

% Degree info (Cover 2 only)
\ntaddtocover[vspace=0mm,halign=l,height=3.9cm,valign=t]{2-1}{%
  \vfill
  \fontsize{14}{16.8bp}\selectfont%
  \GetUmDoctype(\@LANG@COVER,\option{/novathesis/doctype})%
  \\%
  \GetDegreeName(\@LANG@COVER)%
  \IfMemVoidF{Specialization}{\@LANG@COVER}{%
    \\%
    \GetSpecialization(\@LANG@COVER)%
  }{}%
}

% Advisers (Cover 2 only)
\ntaddtocover[vspace=0.75cm,halign=l]{2-1}{%
  \fontsize{14}{16.8bp}\selectfont%
  \GetAdviserSrt(\@LANG@COVER)\\%[\dimexpr-\baselineskip+0.5ex]%
  \bigskip
  \textbf{\ntprintpersons{0.9}{0}{adviser}{a,c}}%
}

% Date
\ntaddtocover[vfill=1,halign=l]{1-1,2-1}{%
  \fontsize{10}{10}\selectfont%
  \PrintDateISO[~\GetOfStr(\@LANG@COVER)~]{\GetDocDate(submission,year)-\GetDocDate(submission,month)}
}


%%=======================================================================
%% BACK COVER ELEMENTS
%%=======================================================================

% Print sponsor logos
\ntaddtocover[vfill=1, halign=l]{N-2}{%
  \foreach \myi in {1, ..., 9} {%
    \IfMemVoidF{Sponsor}{\@LANG@COVER,\myi,logo}{%
      \GetSponsor(\@LANG@COVER,\myi,logo)\qquad%
    }{}%
  }%
}
