%
% Proofs and pretty-printed source (book format) for Tsukurimashou
% Copyright (C) 2011, 2012, 2013  Matthew Skala
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, version 3.
%
% As a special exception, if you create a document which uses this font, and
% embed this font or unaltered portions of this font into the document, this
% font does not by itself cause the resulting document to be covered by the
% GNU General Public License. This exception does not however invalidate any
% other reasons why the document might be covered by the GNU General Public
% License. If you modify this font, you may extend this exception to your
% version of the font, but you are not obligated to do so. If you do not
% wish to do so, delete this exception statement from your version.
%
% This program 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 General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
% Matthew Skala
% http://ansuz.sooke.bc.ca/
% mskala@ansuz.sooke.bc.ca
%

% warning, this page layout must match proofs.tex (modulo bleed)

\input{version.tex}

\newif\iftsukudraft\tsukudraftfalse
\input{\jobname-draft.tex}

\usepackage[strict]{changepage}
\usepackage{fontspec}
\usepackage[margin=1.375in,top=0.975in,bottom=0.975in,headheight=18pt,%
  papersize={8.75in,11.25in}]{geometry}
\usepackage{tikz}
\usepackage[rm,medium,center,compact]{titlesec}
\usepackage{tocloft}
\usepackage{url}
\usepackage{xcolor}
\usepackage{xltxtra}

% work around a bug in tocloft
\renewcommand{\cftnodots}{5000}

% colors
\definecolor{darkgreen}{rgb}{0,0.35,0}
\definecolor{purplish}{rgb}{0.4,0,0.6}

\usetikzlibrary{arrows,calc,shapes.callouts,shapes.geometric}

\defaultfontfeatures{Path=../otf/}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\titlelabel{}
\newcommand{\sectionbreak}{\clearpage}

\setlength{\cftbeforesecskip}{0pt}
\setlength{\cftbeforesubsecskip}{0pt}

\makeatletter
\renewcommand{\@pnumwidth}{2em}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\hypertarget}[2]{#2}
\newcommand{\hyperref}[2][]{#2}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newfontface\kaku[Mapping=tex-text]{TsukurimashouKakuPS}
\newfontface\mincho[Mapping=tex-text]{TsukurimashouMinchoPS}

\newfontface\anbiruteki[WordSpace={1,0,0},PunctuationSpace=3]%
  {TsukurimashouAnbirutekiPS}
\newfontface\anbirutekimono[Mapping=tex-text,WordSpace={1,0,0},PunctuationSpace=3]{TsukurimashouAnbiruteki}

\newfontface\kakudemo[WordSpace={1,0,0},PunctuationSpace=3]{TsukurimashouKaku}
\newfontface\minchodemo[WordSpace={1,0,0},PunctuationSpace=3]{TsukurimashouMincho}
\newfontface\dodumdemo[WordSpace={1,0,0},PunctuationSpace=3,%
  RawFeature={+liga,+ljmo,+vjmo}]{JieubsidaDodum}
\newfontface\batangdemo[WordSpace={1,0,0},PunctuationSpace=3,%
  RawFeature={+liga,+ljmo,+vjmo}]{JieubsidaBatang}
\newfontface\atamademo[WordSpace={1,0,0},PunctuationSpace=3]{TsuItaAtama}
\newfontface\sokudemo[WordSpace={1,0,0},PunctuationSpace=3]{TsuItaSoku}
\newfontface\cosettedemo[WordSpace={1,0,0},PunctuationSpace=3]{BlackletterLolitaCosette}

\setmainfont[Mapping=tex-text,ItalicFont=TsukurimashouMinchoPS]{TsukurimashouKakuPS}
\setmonofont[Mapping=tex-text,WordSpace={1,0,0},PunctuationSpace=3]{TsukurimashouMincho}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\tsukuDemoFonts}{\let\KDF\kakudemo\let\MDF\minchodemo\relax}
\newcommand{\jieubDemoFonts}{\let\KDF\dodumdemo\let\MDF\batangdemo\relax}
\newcommand{\tsuitaDemoFonts}{\let\KDF\atamademo\let\MDF\sokudemo\relax}
\newcommand{\bllDemoFonts}{\let\KDF\cosettedemo\let\MDF\cosettedemo\relax}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter
\def\ps@tabbed{
  \def\@oddhead{\oddpagetrue\CurrentTab}%
  \def\@evenhead{\oddpagefalse\CurrentTab}%
  \def\@oddfoot{\hspace*{\fill}\thepage\hspace*{\fill}}%
  \def\@evenfoot{\hspace*{\fill}\thepage\hspace*{\fill}}%
}
\makeatother

\newcommand{\DrawOneTab}[4]{
  \clip (current page.south west) rectangle (current page.north east);
  \ifoddpage
    \fill[rounded corners=#4pt,color=black]
      ($(current page.north east)+(1.5*2.54,0)
         +{(-1.125-((#1-0.875)/#2)*9)*2.54}*(0,1)$)
      rectangle ++(${-2.5*2.54}*(1,0)+{(-0.75/#2)*9*2.54}*(0,1)$);
    \node[anchor=east,color=white]
      at ($(current page.north east)+(-0.625,0)
         +{(-1.125-((#1-0.5)/#2)*9)*2.54}*(0,1)$)
      {\anbiruteki #3};
  \else
    \fill[rounded corners=#4pt,color=black]
      ($(current page.north west)+(-1.5*2.54,0)
         +{(-1.125-((#1-0.875)/#2)*9)*2.54}*(0,1)$)
      rectangle ++(${2.5*2.54}*(1,0)+{(-0.75/#2)*9*2.54}*(0,1)$);
    \node[anchor=west,color=white]
      at ($(current page.north west)+(0.625,0)
        +{(-1.125-((#1-0.5)/#2)*9)*2.54}*(0,1)$)
      {\anbiruteki #3};
  \fi
}

\newcommand{\DrawOneLabel}[3]{
  \node[anchor=east]
    at ($(current page.north east)+(-1*2.54,0)
       +{(-1.125-((#1-0.5)/#2)*9)*2.54}*(0,1)$)
    {#3};
}

\newcommand{\OneTab}[4]{%
\begin{tikzpicture}[remember picture,overlay]
  \DrawOneTab{#1}{#2}{#3}{#4}
\end{tikzpicture}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\LabelFont}{\anbirutekimono\tiny}

\newcommand{\LineNumber}[1]{\makebox[0pt][r]{\scriptsize #1~}}

\newcommand{\CopyrightNotice}[2]%
  {\LineNumber{#1--#2}[Standard copyright notice]\par}

\def\FileGroup#1#2{}
\newcommand{\File}[1]{\clearpage\section*{#1}\pagestyle{tabbed}\StartTabSec}
\newcommand{\Subhead}[2]%
  {\subsection*{#1}}

% scaling factor 23.71 by measuring off PDF file
% x1.3 = 30.823

\newcommand{\Picture}[9]{
\hfill
\begin{tikzpicture}[scale=1.3,>=latex']
  \useasboundingbox (#6) rectangle (#7);
  \iftsukudraft
    \draw (#6) rectangle (#7);
    \node at ($(#6)!0.5!(#7)$) {DRAFT};
  \else
    \draw[color=black!50!white,xslant=#8] (#4,-1) grid (#5,9);
    \draw[color=black!50!white,ultra thick,->,xslant=#8] (#4,0) -- (#5,0);
    \draw[color=black!50!white,ultra thick,->,xslant=#8] (0,-1) -- (0,9);
    \fill[color=white] (0,0) circle(0.1);
    \draw[color=black!50!white] (0,0) circle(0.1);
    \draw[inner sep=0pt,anchor=base west,color=blue!30!white]
      (0,0) node{\scalebox{30.823}{\normalsize\KDF #3}};
    \draw[inner sep=0pt,anchor=base west,color=green!70!black,opacity=0.4]
      (0,0) node{\scalebox{30.823}{\normalsize\MDF #3}};
    #9
  \fi
\end{tikzpicture}%
\checkoddpage%
\begin{tikzpicture}[remember picture,overlay]
  \clip (current page.south west) rectangle (current page.north east);
  \ifoddpage
    \node[anchor=north east]
      at ($(current page.north east)+(-0.625*2.54,-0.625*2.54)$) {U+#2};
    \node[anchor=north east]
      at ($(current page.north east)+(-0.625*2.54,-0.775*2.54)$) {#1};
  \else
    \node[anchor=north west]
      at ($(current page.north west)+(0.625*2.54,-0.625*2.54)$) {U+#2};
    \node[anchor=north west]
      at ($(current page.north west)+(0.625*2.54,-0.775*2.54)$) {#1};
  \fi
\end{tikzpicture}%
\hspace*{\fill}\par
}

\newcommand{\PBx}[9]%
  {\draw[color=red!80!black,very thick]
    (#2,#3) -- (#4,#5) -- (#6,#7) -- (#8,#9) -- cycle;
   \node[shape=rectangle,color=red!50!black,thick,draw,inner sep=0.05cm,
         anchor=north west] at (#8,#9) {#1};}

\newcommand{\MPt}[2]%
  {\node[diamond,inner sep=0cm,fill,%
   color=green!50!black,text=white] at (#1) {\LabelFont #2};}
\newcommand{\KPt}[2]%
  {\node[diamond,inner sep=0cm,fill,%
   color=blue!50!black,text=white] at (#1) {\LabelFont #2};}
\newcommand{\BPt}[2]%
  {\node[diamond,inner sep=0cm,fill,text=white] at (#1) {\LabelFont #2};}

\newcommand{\MSg}[2]{\draw[very thick,color=green!30!black,->] %
  (#1)--($(#1)!0.52!(#2)$); %
  \draw[very thick,color=green!30!black] ($(#1)!0.48!(#2)$)--(#2);}
\newcommand{\KSg}[2]{\draw[very thick,color=blue!30!black,->] %
  (#1)--($(#1)!0.52!(#2)$); %
  \draw[very thick,color=blue!30!black] ($(#1)!0.48!(#2)$)--(#2);}
\newcommand{\BSg}[2]{\draw[very thick,->] %
  (#1)--($(#1)!0.52!(#2)$); %
  \draw[very thick] ($(#1)!0.48!(#2)$)--(#2);}

\newcommand{\MBl}[2]%
  {\node[star,star point height=0.2cm,inner sep=0cm,fill,%
   color=green!50!black,text=white] at (#1) {\LabelFont #2};}
\newcommand{\KBl}[2]%
  {\node[star,star point height=0.2cm,inner sep=0cm,fill,%
   color=blue!50!black,text=white] at (#1) {\LabelFont #2};}
\newcommand{\BBl}[2]%
  {\node[star,star point height=0.2cm,inner sep=0cm,fill,%
   text=white] at (#1) {\LabelFont #2};}

\newcommand{\Lkr}[2]{}
%  {\draw[densely dotted,very thick,color=red!80!black] (#1)--(#2);}

\newcommand{\Srf}[2]{%
  \node[shape=ellipse callout,color=green!50!black,text=white,fill,%
    callout absolute pointer={(#1)},inner sep=0.05cm] %
    at ($(#1)!0.5cm!180:(3,4)$) {\LabelFont Ｓ#2};
}

\newcommand{\MAn}[9]%
  {\draw[color=red!80!black,thick,->]
    (#2,#3) -- (#4,#5);
   \draw[color=red!80!black,thick,->]
    (#6,#7) -- (#8,#9);
   \node[shape=circle,color=red!50!black,draw,fill=white,
         thick,inner sep=0.01cm] at ($(#2,#3)!0.5!(#4,#5)$) {\LabelFont #1};}

\newcommand{\BAn}[9]%
  {\draw[color=red!80!black,thick,->]
    (#2,#3) -- (#4,#5);
   \draw[color=red!80!black,thick,->]
    (#6,#7) -- (#8,#9);
   \node[shape=circle,color=red!50!black,draw,fill,text=white,
         thick,inner sep=0.01cm] at ($(#2,#3)!0.5!(#4,#5)$) {\LabelFont #1};}

\newcommand{\BlankLine}[1]{\LineNumber{#1}\par}
\newcommand{\BlankLines}[2]{\LineNumber{#1--#2}\par}
\newcommand{\PercentLine}[1]{\LineNumber{#1}\rule[0.5ex]{\linewidth}{1.2pt}\par}
\newcommand{\Comment}[2]{\LineNumber{#1}\%#2\par}
\newcommand{\CodeLine}[2]{\LineNumber{#1}#2\par}
\newcommand{\IlR}[1]{\hfill[see page \pageref{#1}]}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\ProgressCLine{}

\makeatletter
\def\ProgressCheckpoint{\immediate\write18{./wdperl\space
  -CDS\space
  ./wdprogress\space
  count\space
  \jobname}%
  \write\@mainaux{\string\ProgressCLine}%
}
\makeatother

\immediate\write18{./wdperl\space
  -CDS\space
  ./wdprogress\space
  start\space
  \jobname\space
  \ProgressCount}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter\@input{cooked.aux}\makeatother

\begin{document}

\pagestyle{plain}\thispagestyle{empty}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\kaku
\begin{center}\LARGE

\vspace*{\fill}

{\Huge 作りましょう~\TsukurimashouVWide}\\
{\huge パラメタ方式フォントファミリ\\
校とプリティプリントのソース}

\vspace*{0.75in}

{\Huge Tsukurimashou~\TsukurimashouVersion}\\
{\huge Parametric Font Family\\
Proofs and pretty-printed\\source code}

\vspace*{1.5in}

Matthew Skala\\
mskala@ansuz.sooke.bc.ca\\
\TsukurimashouRDWide\qquad\TsukurimashouReleaseDate

\vspace*{\fill}

\end{center}
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\vspace*{\fill}

Proofs and pretty-printed source code for Tsukurimashou\\
Copyright © 2011, 2012, 2013~~Matthew Skala

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.

As a special exception, if you create a document which uses this font, and
embed this font or unaltered portions of this font into the document, this
font does not by itself cause the resulting document to be covered by the
GNU General Public License. This exception does not however invalidate any
other reasons why the document might be covered by the GNU General Public
License. If you modify this font, you may extend this exception to your
version of the font, but you are not obligated to do so. If you do not
wish to do so, delete this exception statement from your version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see \url{http://www.gnu.org/licenses/}.

\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% modified TOC code to display proofs's TOC instead of ours

\makeatletter
    \@cfttocstart
    \par
    \begingroup
      \parindent\z@ \parskip\cftparskip
      \@cftmaketoctitle
      \if@cfttocbibind
        \@cftdobibtoc
      \fi
  \begingroup
    \makeatletter
\def\contentsline#1#2#3#4{\csname l@#1\endcsname{#2}{#3}}%
    \@input{proofs.toc}%
    \if@filesw
      \expandafter\newwrite\csname tf@toc\endcsname
      \immediate\openout \csname tf@toc\endcsname \jobname.toc\relax
    \fi
    \@nobreakfalse
  \endgroup
    \endgroup
    \@cfttocfinish
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\clearpage

\setlength{\parskip}{0pt}
\small\kaku
