% Macros for IC-UNICAMP letters with slanted IC abacus
% Created by Jorge Stolfi sometime in 1992--2007
{ 
  \def\lastedit{2007-11-23 21:48:24 by stolfi}
  \typeout{ic-letter-macros-2 \lastedit} 
  \typeout{Based on `letterunicamp.sty' by Pedro J. de Rezende <12 Feb 92>.}
}

\input{logo-ic-2}
\input{logo-unicamp-2}

\makeatletter
\advance\endlinechar by -256\relax

\newsavebox{\ICL@headbox}
\newsavebox{\ICL@footbox}

% Letter environment

  % Usage:
  %   \input{ic-letter-macros}
  %   \input{my-letter-data}
  %   \begin{letter}
  %     \english % or \portugues
  %     \myopinion % to get the disclaimer above the footer
  %     \placedate{St. Anford, \today}
  %     \sendto{Mr. Bean//Jellybean Corp.//Candytown, NM}
  %
  %     Dear Mr. Bean,
  %     ...
  %     Sincerely,
  %     \signed{C. Rice\\Site Coordinator\\CandyExpo 2001}
  %     \writtenby{CR/ms}
  %   \end{letter}

  \newenvironment{letter}
    {
      \bgroup
        \newpage
        \c@page\@ne
        \raggedbottom

        \def\ICL@disclaimer{} % Redefined by \myopinion

        \def\portugues{
          \let\sendertitle=\portsendertitle\relax
          \let\senderaddress=\portsenderaddress\relax
          \let\disclaimertext=\portdisclaimertext\relax
          \def\today{
            \number\day\space de \ifcase\month\or
            janeiro\or fevereiro\or {mar\c co}\or abril\or maio\or junho\or
            julho\or agosto\or setembro\or outubro\or novembro\or dezembro\fi
            \space de \number\year
          }
          \ICL@makeheadfoot
        }

        \def\english{
          \let\sendertitle=\englsendertitle\relax
          \let\senderaddress=\englsenderaddress\relax
          \let\disclaimertext=\engldisclaimertext\relax
          \def\today{
            \ifcase\month\or
            January\or February\or March\or April\or May\or June\or
            July\or August\or September\or October\or November\or December\fi
            \space\number\day, \number\year
          }
          \ICL@makeheadfoot
        }
        
        \def\myopinion{
          \def\ICL@disclaimer{
            \vspace{2pt}
            \begin{center}
              \tiny\rm \disclaimertext
            \end{center}
          }
          \ICL@makeheadfoot
        }

        \english % by default
        
        \pagestyle{plain}
        \thispagestyle{letterfirst} 

        \normalsize\rm
        \parskip=1.0ex
        \lineskip=1pt 
        \normallineskip=1pt
        \def\baselinestretch{1}
        \topsep=0.5ex \partopsep=0pt \itemsep=0.5ex
        \rightskip=0pt \leftskip=0pt
        \rightmargin=0pt \leftmargin=0pt
        \marginparwidth=0pt \marginparsep=0pt
        \parindent=2em
        \def\insertfoot{\usebox{\ICL@footbox}}
    }
    {
        \vfill
        \pagebreak
      \egroup
    }

  \newcommand{\placedate}[1]{%
    \begin{raggedleft}
      #1\par
    \end{raggedleft}
    \vspace{2\parskip}
  }

  \newcommand{\sendto}[1]{
    \begin{raggedright} 
      \noindent #1\par
    \end{raggedright}
    \nobreak
    \vspace{2\parskip}
  }

  % Usage: \signatureblock{SIGNATURE}{NAME\\TITLE}
  \newcommand{\signatureblock}[2]{
    \par\nobreak
    \begin{raggedleft}
      ${}$
      \hbox{
        \vrule height 1.75\baselineskip depth 0.25\baselineskip width 0pt
        #1
      }\\
      ${}$
      \hbox{
        \begin{tabular}{r}
        #2
        \end{tabular}
        \quad\quad\quad\quad
      }
      \par
    \end{raggedleft}
  }

  % Usage: \signed{NAME\\TITLE}
  \newcommand{\signed}[1]{
    \signatureblock{~}{#1}  
  }
  
  % Requires macros-epsbox
  % Usage: \epssigned{SIGFILE}{SCALE}{NAME\\TITLE}
  \newcommand{\epssigned}[3]{
    \signatureblock{\epsbox{#1}{#2}}{#3} 
  }
  
  \newcommand{\writtenby}[1]{
    \vfill
    \begin{raggedright}
      \normalsize\tt #1
    \end{raggedright}
    \vspace{0pt plus -1fill}
  }
  
  \newcommand{\disclaimer}{
    \vfill
    
    \hrule height 0pt depth 0pt
    \kern -5mm
    \hrule height 0pt depth 0pt
  }

% Page styles:

  % First page of letter
  %
  \def\ps@letterfirst{
    \setlength{\topmargin}{0.75in}
      \addtolength{\topmargin}{-\ht\ICL@headbox}
    \setlength{\headheight}{12pt}
      \addtolength{\headheight}{\ht\ICL@headbox}
    \headsep=20pt
    \footskip=5pt
      \addtolength{\footskip}{\ht\ICL@footbox}
    \textheight=\paperheight\relax
      \addtolength{\textheight}{-1.0in}
      \addtolength{\textheight}{-\topmargin}
      \addtolength{\textheight}{-\headheight}
      \addtolength{\textheight}{-\headsep}
      \addtolength{\textheight}{-\footskip}
    \vsize=\textheight
    \def\@oddhead{\usebox{\ICL@headbox}}
    \def\@evenhead{}
    \def\@oddfoot{\usebox{\ICL@footbox}}
    \def\@evenfoot{}
  }

% Letterhead/letterfoot elements:

  % These definitions are used to build the letter header 
  % and letter footer.  They should be redefined
  % by the user.

  \def\sendername{}
  \def\portsendertitle{}
  \def\englsendertitle{}
  \def\portsenderaddress{}
  \def\englsenderaddress{}
  \def\sendertel{}
  \def\senderfax{}
  \def\senderemail{}
  \def\senderwww{}
  \def\disclaimertext{}

  \def\logoheight{65pt}   % Nominal height of both logos
  
% Letterhead and letterfoot 

  \newcommand{\ICL@headfont}{
    \baselineskip 12pt
    \def\ss{\usefont{T1}{cmss}{m}{n}} 
    \let\rm=\ss\relax
    \def\tt{\usefont{T1}{cmtt}{m}{n}}
    \ss
  }

  \newcommand{\ICL@makeheadfoot}{
    \savebox{\ICL@headbox}{
      \vbox{
        \offinterlineskip
        \hrule height 0pt width 0pt
        \ICL@makeheadbox{6.0in}
        \hrule height 0pt width 0pt
      }
    }
    \savebox{\ICL@footbox}{
      \vbox{
        \offinterlineskip
        \hrule height 0pt width 0pt
        \ICL@makefootbox{\textwidth}
        \hrule height 0pt width 0pt
      }
    }
  }

  % Usage 
  \newcommand{\ICL@makeheadbox}[1]{
    \hbox to #1{
      \vrule width 0pt
      \kern -6.5mm
      % \vrule width 1pt
      \iclogobare
      % \vrule width 1pt
      \kern 2mm
      % \vrule width 1pt
      \vbox to \logoheight{
        \setlength{\textwidth}{0pt}
        \offinterlineskip
        \hrule height 0pt width 0pt
        \hbox{
          \begin{minipage}{4.0in}
            \begin{raggedright}
              \ICL@headfont
              {\Large\ss Instituto de Computa\c{c}\~ao\\}
              {\large\ss Universidade Estadual de Campinas\\[1mm]}
              {\small\ss \senderaddress}
            \end{raggedright}
          \end{minipage}
        }
        \vss
        \hrule height 0pt width 0pt
      }
      % \vrule width 1pt
      \hss
      % \vrule width 1pt
      \ueclogo
      % \vrule width 1pt
      \kern -6.5mm
      \vrule width 0pt
    }
  }

  \newcommand{\ICL@makefootbox}[1]{
    \hbox to #1{
      \vrule height 0pt width 0pt
      \hss
      \vtop to \footskip{
        \parindent 0pt
        \hrule height 0pt width 0pt
        \ICL@disclaimer
        \vspace{2pt}
        \hrule
        \vspace{5pt}
        \hbox to #1{
          \vbox{
            \parindent 0pt
            % \leftskip 0pt \rightskip 0pt
            \hbox{
              \begin{minipage}{2.6in}
                \begin{raggedright}
                  \parindent=0pt
                  \ICL@headfont\ss
                  \sendername\\
                  \sendertitle\\
                  \senderwww\par
                \end{raggedright}
              \end{minipage}
            }
            \hrule height 0pt width 0pt
          }
          \hss
          \lower 6mm \icabacus
          \hss
          \vbox{
            \parindent 0pt
            % \leftskip 0pt \rightskip 0pt
            \hbox{
              \begin{minipage}{2.6in}
                \begin{raggedleft}
                  \ICL@headfont\ss
                  \senderemail\\
                  \sendertel\\
                  \senderfax\par
                \end{raggedleft}
              \end{minipage}
            }
            \hrule height 0pt width 0pt
          }
        }
        \vss
        \hrule height 0pt width 0pt
      }
      \hss
    }
  }

\advance\endlinechar by 256
\makeatother 
