%%
%% This is file `projlib-titlepage.sty',
%% generated with the docstrip utility.

%% Copyright (C) 2021-2022 by Jinwen XU
%% 
%% This is part of the ProjLib Toolkit.
%% 
%% This work may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License, either version 1.3c 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.3c or later is part of all distributions of LaTeX version
%% 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
\RequirePackage{l3keys2e}
\ProvidesExplPackage
  {projlib-titlepage}
  {2022/04/24} {}
  {Commands for rendering the title page}

\keys_define:nn { projlib-titlepage }
  {
    , unknown           .code:n             = {}
  }
\ProcessKeysOptions { projlib-titlepage }

\RequirePackage { projlib-paper }

\RequirePackage { tikz }
\ExplSyntaxOff
\usetikzlibrary { calc }
\ExplSyntaxOn

\tl_new:N \l_projlib_titlepage_logo_tl
\tl_new:N \l_projlib_titlepage_title_tl
\tl_new:N \l_projlib_titlepage_subtitle_tl
\tl_new:N \l_projlib_titlepage_author_tl
\tl_new:N \l_projlib_titlepage_date_tl
\tl_new:N \l_projlib_titlepage_style_tl

\NewDocumentCommand \ProjLibTitlePage { O{} m }
  {
    \keys_set:nn { projlib-titlepage-config } { #1 }
    \projlib_titlepage_render:n { #2 }
  }
\ProvideDocumentCommand \TitlePage { O{} m }
  {
    \ProjLibTitlePage [ #1 ] { #2 }
  }

\cs_new_protected:Nn \projlib_titlepage_set_color:nn
  {
    \colorlet { titlepage- #1 } { #2 }
  }

\keys_define:nn { projlib-titlepage-config }
  {
    , logo              .tl_set:N           = \l_projlib_titlepage_logo_tl
    , logo              .initial:n          = { \scalebox { 2 } { \ProjLib } }
    , title             .tl_set:N           = \l_projlib_titlepage_title_tl
    , subtitle          .tl_set:N           = \l_projlib_titlepage_subtitle_tl
    , author            .tl_set:N           = \l_projlib_titlepage_author_tl
    , date              .tl_set:N           = \l_projlib_titlepage_date_tl
    , style             .tl_set:N           = \l_projlib_titlepage_style_tl
    , style             .initial:n          = { default }
    , color             .code:n             = {
                                                \keyval_parse:nnn
                                                  { \use_none:n }
                                                  { \projlib_titlepage_set_color:nn }
                                                  { #1 }
                                              }
    , unknown           .code:n             = {}
  }

\colorlet { titlepage-main } { blue!50!cyan!50!black }
\colorlet { titlepage-back } { blue!50!cyan!10!yellow!30 }

\cs_new_protected:Nn \projlib_titlepage_render:n
  {
    \keys_set:nn { projlib-titlepage-config } { #1 }
    \begin { titlepage }
      \cs_if_exist_use:c { projlib_titlepage_render_with_style_ \l_projlib_titlepage_style_tl : }
    \end   { titlepage }
    \setcounter { page } { 0 }
  }

\cs_new_protected:Nn \projlib_titlepage_render_with_style_default:
  {
    \begin{tikzpicture}[overlay,remember~picture]
      \fill [color=titlepage-main] ($(current~page.south~west)$) rectangle ($(current~page.north~east)+(0,-.3\paperheight)$);
      \fill [color=titlepage-back] ($(current~page.south~west)$) rectangle ($(current~page.north~west)+(.125\paperwidth,-.3\paperheight)$);
      \fill [color=titlepage-main] ($(current~page.north~west)$) rectangle ($(current~page.north~west)+(.125\paperwidth,-.3\paperheight)$);
      \fill [color=titlepage-back] ($(current~page.north~east)$) rectangle ($(current~page.north~west)+(.125\paperwidth,-.3\paperheight)$);
      \node[text~width=.3\paperwidth,text~height=.2\paperheight] at ($(current~page.north~west)+(.32\paperwidth,-.17\paperheight)$) { \l_projlib_titlepage_logo_tl };
      \node[text~width=.8\paperwidth,text~height=.4\paperheight] at ($(current~page.north~west)+(.57\paperwidth,-.33\paperheight)$) {\textcolor{titlepage-back}{\fontsize{24pt}{28pt}\selectfont\sffamily\textsc{ \l_projlib_titlepage_title_tl }\\[1.5em]\fontsize{18pt}{22pt}\selectfont{ \l_projlib_titlepage_subtitle_tl }}};
      \node[text~width=.3\paperwidth,text~height=.3\paperheight] at ($(current~page.south)+(.2\paperwidth,.3\paperheight)$) {\color{titlepage-back}\begin{flushright}\fontsize{16pt}{18pt}\selectfont\textsc{ \l_projlib_titlepage_author_tl }\\[1em]\fontsize{12pt}{14pt}\selectfont \l_projlib_titlepage_date_tl \end{flushright} };
    \end{tikzpicture}
  }

\cs_new_protected:Nn \projlib_titlepage_render_with_style_simple:
  {
    \begin{tikzpicture}[overlay,remember~picture]
      \fill[color=titlepage-main] ($(current~page.south~west)$) rectangle ($(current~page.north~east)+(0,-.3\paperheight)$);
      \node[text~width=.3\paperwidth,text~height=.2\paperheight] at ($(current~page.north~west)+(.27\paperwidth,-.15\paperheight)$) { \l_projlib_titlepage_logo_tl };
      \node[text~width=.8\paperwidth,text~height=.4\paperheight] at ($(current~page.north~west)+(.52\paperwidth,-.33\paperheight)$) {\textcolor{paper}{\fontsize{24pt}{28pt}\selectfont\sffamily\textsc{ \l_projlib_titlepage_title_tl }\\[1.5em]\fontsize{18pt}{22pt}\selectfont{ \l_projlib_titlepage_subtitle_tl }}};
      \node[text~width=.3\paperwidth,text~height=.3\paperheight] at ($(current~page.south)+(.2\paperwidth,.3\paperheight)$) {\color{paper}\begin{flushright}\fontsize{16pt}{18pt}\selectfont\textsc{ \l_projlib_titlepage_author_tl }\\[1em]\fontsize{12pt}{14pt}\selectfont \l_projlib_titlepage_date_tl \end{flushright} };
    \end{tikzpicture}
  }

\endinput
%%
%% End of file `projlib-titlepage.sty'.
