%HTML:�t���p�N���X�t�@�C��

\NeedsTeXFormat{pLaTeX2e}
\ProvidesClass{hagaki}

\def\@hagakiSizes{}

\DeclareOption*{%
  \ifx\@hagakiSizes\empty
    \xdef\@hagakiSizes{\CurrentOption}\relax
  \else
    \xdef\@hagakiSizes{\@hagakiSizes,\CurrentOption}\relax
  \fi
}

\ProcessOptions\relax
\LoadClass[12pt]{treport}

\pagestyle{empty}

\def\@hagakiHeight{height}
\newdimen\@hagakiVSize

\def\@hagakiTopMargin{topmargin}
\newdimen\@hagakiVMargin

\def\@hagakiWidth{width}
\newdimen\@hagakiHSize

\def\@hagakiLeftMargin{leftmargin}
\newdimen\@hagakiHMargin

\def\@hagakiSize#1=#2,{%
  \def\sizeitem{#1}\relax
  \ifx\sizeitem\@hagakiHeight
    \global\@hagakiVSize=#2\relax
  \else
    \ifx\sizeitem\@hagakiTopMargin
      \global\@hagakiVMargin=#2\relax
    \else
      \ifx\sizeitem\@hagakiWidth
	\global\@hagakiHSize=#2\relax
      \else
	\ifx\sizeitem\@hagakiLeftMargin
	  \global\@hagakiHMargin=#2\relax
	\fi
      \fi
    \fi
  \fi
}

\ifx\@hagakiSizes\empty
  \def\@hagakiSizes{height=14.8cm,topmargin=.58cm,width=10cm,leftmargin=.58cm}%
\fi

\@for\@item:=\@hagakiSizes\do{\expandafter\@hagakiSize\@item,}

\textwidth=\@hagakiVSize
\advance\textwidth by -\@hagakiVMargin

\topmargin=\@hagakiVMargin
\advance\topmargin by -1in

\paperwidth=\@hagakiVSize
\advance\paperwidth by \topmargin

\textheight=\@hagakiHSize
\advance\textheight by -\@hagakiHMargin

\oddsidemargin=\@hagakiHMargin
\advance\oddsidemargin by -1in
\evensidemargin=\oddsidemargin

\paperheight=\@hagakiHSize
\advance\paperheight by \oddsidemargin

\def\@hagakiZipSkipChar{x}

\def\@hagakiZipChar#1#2#3#4#5{%
  \def\char{#5}%
  \ifx\char\@hagakiZipSkipChar
    \def\char{\phantom{0}}\relax
  \fi
  \vbox to #1{\vbox to #2{\vss \hbox to #3{\hss \hbox{#4\relax\yoko \char}\hss}\vss}\vss}%
}

\def\@HagakiZipSmallCharStyle{\large}
\def\HagakiZipSmallCharStyle#1{\gdef\@HagakiZipSmallCharStyle{#1}}

\def\@HagakiZipLargeCharStyle{\Large}
\def\HagakiZipLargeCharStyle#1{\gdef\@HagakiZipLargeCharStyle{#1}}

\def\@hagakiZipSmallChar#1{\@hagakiZipChar{.68cm}{.6cm}{.84cm}{\@HagakiZipSmallCharStyle}{#1}}
\def\@hagakiZipLargeChar#1{\@hagakiZipChar{.7cm}{.62cm}{.86cm}{\@HagakiZipLargeCharStyle}{#1}}

\def\@hagakiZip#1#2#3-#4#5#6#7.{%
  \vbox{%
    \halign{%
      \hss ##\hss\cr
      \@hagakiZipSmallChar{#7}\cr
      \@hagakiZipSmallChar{#6}\cr
      \@hagakiZipSmallChar{#5}\cr
      \@hagakiZipSmallChar{#4}\cr
      \noalign{\vskip .05cm}%
      \@hagakiZipLargeChar{#3}\cr
      \@hagakiZipLargeChar{#2}\cr
      \@hagakiZipLargeChar{#1}\cr
    }%
  }%
}

\def\@onInterLineSkip#1{%
  \spaceskip=0pt
  \baselineskip=#1%
  \lineskiplimit=0pt
  \lineskip=0pt
  \parindent=0pt
}

\def\@hagakiAddress#1#2#3#4{%
  \parbox[t]{#2}{\@onInterLineSkip{#3}\relax #1\relax #4\hss}%
}

\def\@HagakiSirSkip{1zh plus 1zh}
\def\HagakiSirSkip#1{\gdef\@HagakiSirSkip{#1}}

\def\@hagakiSir#1{%
  \def\sir{#1}\relax
  \ifx\sir\empty\else
    \hskip \@HagakiSirSkip\relax \sir\relax
  \fi
}

\def\@HagakiNameSkip{0pt}
\def\HagakiNameSkip#1{\gdef\@HagakiNameSkip{#1}}

\def\@hagakiNameCharSkip#1{%
  {\spaceskip=\@HagakiNameSkip\relax \kanjiskip=\@HagakiNameSkip\relax \xkanjiskip=\@HagakiNameSkip\relax #1}%
}

\def\@HagakiNameGrue{\hskip 1zh plus 1zh minus 1zh}
\def\HagakiNameGrue#1{\gdef\@HagakiNameGrue{#1}}

\def\@HagakiFamilyNameSkip{1zh plus 1zh}
\def\HagakiFamilyNameSkip#1{\gdef\@HagakiFamilyNameSkip{#1}}

\def\@HagakiNameSep{.5zw}
\def\HagakiNameSep#1{\gdef\@HagakiNameSep{#1}}

\def\@hagakiNameSpread#1{%
  \edef\@char{#1}%
  \def\@charskip{}%
  \ifx\@char\empty\else
    \expandafter\@tfor\expandafter\@char\expandafter:\expandafter=#1%
      \do{\@charskip \@char \edef\@charskip{\@HagakiNameGrue}}%
  \fi
}

\def\@hagakiName#1#2#3{%
  \valign{%
    \@hagakiNameCharSkip{#1\relax ##}\vss\cr
    \hbox{\@hagakiNameSpread{#2}}\cr
    \noalign{#1\relax \hskip \@HagakiFamilyNameSkip}%
    \halign{%
      \vrule height0pt depth\@HagakiNameSep width0pt
      \@hagakiNameSpread{##}&\@hagakiNameCharSkip{\@hagakiSir{##}}\cr
      #3\cr
    }\cr
  }%
}

\def\@HagakiOurZipCharStyle{\small}
\def\HagakiOurZipCharStyle#1{\gdef\@HagakiOurZipCharStyle{#1}}

\def\@hagakiOurZipChar#1{\@hagakiZipChar{0.4cm}{0.4cm}{0.7cm}{\@HagakiOurZipCharStyle}{#1}}

\def\@hagakiOurZip#1#2#3-#4#5#6#7.{%
  \vbox{%
    \halign{%
      \hss ##\hss\cr
      \@hagakiOurZipChar{#7}\cr
      \@hagakiOurZipChar{#6}\cr
      \@hagakiOurZipChar{#5}\cr
      \@hagakiOurZipChar{#4}\cr
      \noalign{\vskip .1cm}%
      \@hagakiOurZipChar{#3}\cr
      \@hagakiOurZipChar{#2}\cr
      \@hagakiOurZipChar{#1}\cr
    }%
  }%
}

\def\@TheirAddressHeight{9.4cm}
\def\TheirAddressHeight#1{\gdef\@TheirAddressHeight{#1}}

\def\@TheirAddressBaselineSkip{3zw}
\def\TheirAddressBaselineSkip#1{\gdef\@TheirAddressBaselineSkip{#1}}

\def\@TheirAddressStyle{\Large}
\def\TheirAddressStyle#1{\gdef\@TheirAddressStyle{#1}}

\def\@TheirNameStyle{\Huge}
\def\TheirNameStyle#1{\gdef\@TheirNameStyle{#1}}

\def\@OurAddressBaselineSkip{1.5zw}
\def\OurAddressBaselineSkip#1{\gdef\@OurAddressBaselineSkip{#1}}

\def\@OurAddressHeight{6cm}
\def\OurAddressHeight#1{\gdef\@OurAddressHeight{#1}}

\def\@OurAddressTopMargin{0pt plus 1fill}
\def\OurAddressTopMargin#1{\gdef\@OurAddressTopMargin{#1}}

\def\@OurAddressBottomMargin{0pt}
\def\OurAddressBottomMargin#1{\gdef\@OurAddressBottomMargin{#1}}

\def\@OurAddressStyle{\large}
\def\OurAddressStyle#1{\gdef\@OurAddressStyle{#1}}

\def\@OurAddress{}
\long\def\OurAddress#1{\long\gdef\@OurAddress{#1}}

\def\@OurFamilyName{}
\def\OurFamilyName#1{\gdef\@OurFamilyName{#1}}

\def\@OurName{}
\def\OurName#1{\gdef\@OurName{#1}}

\def\@OurNameStyle{\Large}
\def\OurNameStyle#1{\gdef\@OurNameStyle{#1}}

\def\@OurNameSkip{0pt}
\def\OurNameSkip#1{\gdef\@OurNameSkip{#1}}

\def\@OurNameGrue{\hskip 1zh plus 1zh minus 1zh}
\def\OurNameGrue#1{\gdef\@OurNameGrue{#1}}

\def\@OurFamilyNameSkip{1zh plus 1zh}
\def\OurFamilyNameSkip#1{\gdef\@OurFamilyNameSkip{#1}}

\def\@OurNameSep{.3cm}
\def\OurNameSep#1{\gdef\@OurNameSep{#1}}

\def\@OurNameTopMargin{2zh plus 1fill}
\def\OurNameTopMargin#1{\gdef\@OurNameTopMargin{#1}}

\def\@OurNameBottomMargin{0pt}
\def\OurNameBottomMargin#1{\gdef\@OurNameBottomMargin{#1}}

\def\@ourAddressAndName{%
  \hskip \@OurAddressTopMargin\relax
  \@hagakiAddress{\@OurAddressStyle}{\@OurAddressHeight}{\@OurAddressBaselineSkip}{\@OurAddress}%
  \hskip \@OurAddressBottomMargin\cr
  \noalign{\vskip \@OurNameSep}%
  \hskip \@OurNameTopMargin\relax
  \bgroup
    \def\@HagakiNameSkip{\@OurNameSkip}%
    \def\@HagakiNameGrue{\@OurNameGrue}%
    \def\@HagakiFamilyNameSkip{\@OurFamilyNameSkip}%
    \@hagakiName{\@OurNameStyle}{\@OurFamilyName}{\@OurName}%
  \egroup
  \hskip \@OurNameBottomMargin\cr
}

\def\@OurZip{}
\def\OurZip#1{\gdef\@OurZip{#1}}

\def\@OmoteWidth{8.62cm}%=9.2cm-.58cm
\def\OmoteWidth#1{\gdef\@OmoteWidth{#1}}

\def\@OmoteHeight{10.3cm}%=12.4cm-1.24cm-.86cm
\def\OmoteHeight#1{\gdef\@OmoteHeight{#1}}

\def\@OmoteTopMargin{.66cm}%=1.24cm-.58cm
\def\OmoteTopMargin#1{\gdef\@OmoteTopMargin{#1}}

\def\@HagakiZipSep{1cm}
\def\HagakiZipSep#1{\gdef\@HagakiZipSep{#1}}

\def\@HagakiRightMargin{1cm}
\def\HagakiRightMargin#1{\gdef\@HagakiRightMargin{#1}}

\def\@KatagakiSep{.2zw}
\def\KatagakiSep#1{\gdef\@KatagakiSep{#1}}

\def\@HagakiNameTopMargin{.7cm plus .7cm minus .7cm}
\def\HagakiNameTopMargin#1{\gdef\@HagakiNameTopMargin{#1}}

\def\@HagakiNameBottomMargin{.7cm plus .7cm minus .7cm}
\def\HagakiNameBottomMargin#1{\gdef\@HagakiNameBottomMargin{#1}}

\newif\ifOmoteJusho
\OmoteJushofalse

\def\Jusho#1{\csname #1Jusho\endcsname}

\def\OmoteJusho{\OmoteJushotrue\relax}

\def\UraJusho{\OmoteJushofalse\relax}

\def\@OmoteJushoWidth{2.9cm}
\def\OmoteJushoWidth#1{\gdef\@OmoteJushoWidth{#1}}

\def\@OmoteJushoHeight{6.8cm}
\def\OmoteJushoHeight#1{\gdef\@OmoteJushoHeight{#1}}

\def\@OmoteJushoBottomMargin{.3cm}
\def\OmoteJushoBottomMargin#1{\gdef\@OmoteJushoBottomMargin{#1}}

\def\WithValues#1{%
  \bgroup
  \@for\@def:=#1\do{\expandafter\@withValue\@def;}%
}

\def\@withValue#1=#2;{%
  \expandafter\def\csname @#1\endcsname{#2}%
}

\def\endWithValues{\egroup}

\long\def\omote{\@ifnextchar<{\omote@}{\omote@<>}}
\long\def\omote@<#1>{\@ifnextchar[{\omote@@<#1>}{\omote@@<#1>[]}}

\long\def\omote@@<#1>[#2]#3#4#5#6{%
  \newpage
  \noindent
  \offinterlineskip
  \par
  \begin{WithValues}{#1}%
    \def\katagaki{#2}%
    \def\familyName{#3}%
    \def\name{#4}%
    \def\zip{#5}%
    \def\addr{#6}%
    \hbox{%
      \hskip \@OmoteTopMargin\relax
      \valign{%
	\vbox to \@OmoteWidth{##}\cr
	\expandafter\@hagakiZip\zip.\vss\cr
	\halign{%
	  \hbox to \@OmoteHeight{\hskip \@HagakiZipSep\relax ##}\cr
	  \vbox to 0pt{%
	    \vskip \@HagakiRightMargin\relax
	    \hbox{\@hagakiAddress{\@TheirAddressStyle}{\@TheirAddressHeight}{\@TheirAddressBaselineSkip}{\addr}}%
	    \vss
	  }\hss\cr
	  \noalign{\vss}%
	  \ifx\katagaki\empty\else
	    \vbox to 0pt{%
	      \vss
	      \hbox{%
		\@hagakiAddress{\@TheirAddressStyle}{\@TheirAddressHeight}{\@TheirAddressBaselineSkip}{\katagaki}%
	      }%
	      \vskip \@KatagakiSep
	    }\relax\hss\cr
	  \fi
	  \hskip \@HagakiNameTopMargin\relax
	  \@hagakiName{\@TheirNameStyle}{\familyName}{\name}%
	  \hskip \@HagakiNameBottomMargin\cr
	  \noalign{\vss}%
	  \ifOmoteJusho
	    \hss\vbox to .0pt{%
	      \vss
	      \vbox to \@OmoteJushoWidth{%
		\vss
		\halign{%
		  \hbox to \@OmoteJushoHeight{##\hskip \@OmoteJushoBottomMargin}\cr
		  \@ourAddressAndName
		}%
		\vss
	      }%
	    }\cr
	  \fi
	}\cr
	\ifOmoteJusho
	  \vss\expandafter\@hagakiOurZip\@OurZip.\cr
	\fi
      }%
    }%
  \end{WithValues}%
}

\long\def\UraParBox#1#2#3{\parbox[t]{#1}{\@onInterLineSkip{#2}\relax #3\hss}}

\def\@UraZipStyle{\small}
\def\UraZipStyle#1{\gdef\@UraZipStyle{#1}}

\def\@UraZipSep{1zh plus 1fil}
\def\UraZipSep#1{\gdef\@UraZipSep{#1}}

\def\@hagakiUraZip#1#2#3-#4#5#6#7.{%
  \halign{%
    \hss \hbox{\yoko \@UraZipStyle\relax ##}\hss\cr
    #7\cr
    #6\cr
    #5\cr
    #4\cr
    --\cr
    #3\cr
    #2\cr
    #1\cr
    ��\cr
  }%
}

\def\UraJusho#1{%
  \hbox to #1{%
    \valign{%
      \vss ##\vss\cr
      \expandafter\@hagakiUraZip\@OurZip.\cr
      \noalign{\hskip \@UraZipSep}%
      \halign{%
	##\cr
	\@ourAddressAndName
      }\cr
    }%
  }%
}

\def\@UraWidth{8.84cm}%=10cm-.58cm*2
\def\UraWidth#1{\gdef\@UraWidth{#1}}

\def\@UraHeight{13.64cm}%=14.8cm-.58cm*2
\def\UraHeight#1{\gdef\@UraHeight{#1}}

\long\def\ura#1{%
  \newpage
  \noindent
  \offinterlineskip
  \par
  \hbox{%
    \vbox to \@UraWidth{%
      \halign{%
	\hbox to \@UraHeight{##}\cr
	#1\cr
      }%
    }%
  }%
}

\def\@hagakiYokoZip#1#2#3-#4#5#6#7.{\hbox{\@UraZipStyle\relax ��#1#2#3--#4#5#6#7}}

\def\UraYokoJusho#1#2{%
  \vbox{%
    \halign{%
      \hbox to #1{##}\cr
      \valign{%
	##\vss\cr
	\expandafter\@hagakiYokoZip\@OurZip.\cr
	\noalign{\hskip \@UraZipSep}%
	\halign{%
	  ##\cr
	  \@ourAddressAndName
	}\cr
      }\cr
    }%
  }%
}

\long\def\uraYoko#1{%
  \newpage
  \noindent
  \offinterlineskip
  \par
  \hbox to \@UraHeight{%
    \valign{%
      \hbox to \@UraWidth{\yoko ##}\cr
      #1\cr
    }%
  }%
}
