\ProvidesPackage{zwpagelayout}[2008/12/26 ZW Page Layout]
\PackageInfo{zwpagelayout}{$Id: zwpagelayout.sty 290 2008-12-26 17:43:49Z zw $\@gobble}

%% Copyright 2008 Z. Wagner, http://icebearsoft.euweb.cz
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% 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.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Z. Wagner.
%
% This work consists of the files: zwpagelayout.sty and
% the documentation files zwpagelayout.tex, zwpagelayout.pdf.

\RequirePackage{kvoptions,ifpdf}
\SetupKeyvalOptions{family=zwpl,prefix=zwpl@}

% Landscape/Portrait

\DeclareBoolOption{Landscape}
\DeclareComplementaryOption{Portrait}{Landscape}
\DeclareBoolOption{AllowWidthHeightSwitching}

% Generic paper size, default=A4

\DeclareStringOption[210mm,297mm]{papersize}[] % empty means to calculate

% Normalized paper sizes
\errorcontextlines 999

\DeclareVoidOption{a0}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={841mm,1189mm}}}
\DeclareVoidOption{a1}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={594mm,841mm}}}
\DeclareVoidOption{a2}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={420mm,594mm}}}
\DeclareVoidOption{a3}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={297mm,420mm}}}
\DeclareVoidOption{a4}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={210mm,297mm}}}
\DeclareVoidOption{a5}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={148mm,210mm}}}
\DeclareVoidOption{a6}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={105mm,148mm}}}
\DeclareVoidOption{a7}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={74mm,105mm}}}
\DeclareVoidOption{a8}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={52mm,74mm}}}
\DeclareVoidOption{a9}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={37mm,52mm}}}
\DeclareVoidOption{a10}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={26mm,37mm}}}
\DeclareVoidOption{b0}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={1000mm,1414mm}}}
\DeclareVoidOption{b1}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={707mm,1000mm}}}
\DeclareVoidOption{b2}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={500mm,707mm}}}
\DeclareVoidOption{b3}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={353mm,500mm}}}
\DeclareVoidOption{b4}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={250mm,353mm}}}
\DeclareVoidOption{b5}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={176mm,250mm}}}
\DeclareVoidOption{b6}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={125mm,176mm}}}
\DeclareVoidOption{b7}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={88mm,125mm}}}
\DeclareVoidOption{b8}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={62mm,88mm}}}
\DeclareVoidOption{b9}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={44mm,62mm}}}
\DeclareVoidOption{b10}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={31mm,44mm}}}
\DeclareVoidOption{c0}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={917mm,1279mm}}}
\DeclareVoidOption{c1}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={648mm,917mm}}}
\DeclareVoidOption{c2}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={458mm,648mm}}}
\DeclareVoidOption{c3}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={324mm,458mm}}}
\DeclareVoidOption{c4}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={229mm,324mm}}}
\DeclareVoidOption{c5}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={162mm,229mm}}}
\DeclareVoidOption{c6}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={114mm,162mm}}}
\DeclareVoidOption{c7}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={81mm,114mm}}}
\DeclareVoidOption{c8}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={57mm,81mm}}}
\DeclareVoidOption{c9}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={40mm,57mm}}}
\DeclareVoidOption{c10}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={28mm,40mm}}}
\DeclareVoidOption{letter}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={8.5in,11in}}}
\DeclareVoidOption{legal}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={8.5in,14in}}}
\DeclareVoidOption{executive}{\setkeys{zwpl}{AllowWidthHeightSwitching,papersize={7.25in,10.5in}}}

% Layout (for the odd page, even page is mirrored)

\DeclareStringOption{margins}[0mm]
\DeclareStringOption[1in]{topmargin}
\DeclareStringOption[-1in]{leftmargin}
\DeclareStringOption[-1in]{rightmargin}
\DeclareStringOption[-1in]{textwidth}
\DeclareStringOption[-1in]{textheight} % height including a header, headsep, and footskip
\DeclareStringOption[0mm]{headheight}
\DeclareStringOption[0mm]{headsep}
\DeclareStringOption[0mm]{footskip}
\DeclareStringOption{topskip}
\DeclareStringOption{botmargin}[\zwpl@topmargin]
\DeclareBoolOption{strictheight}
\DeclareBoolOption[true]{adjustfootskip}
\DeclareComplementaryOption{adjustheadsep}{adjustfootskip}

% Options for cropmarks

\DeclareBoolOption{onlycropmarks}% Page layout is already set in a compatible way
\DeclareBoolOption{cropmarks}
\DeclareComplementaryOption{nocropmarks}{cropmarks}
\DeclareStringOption[5mm]{croplength}
\DeclareStringOption[5mm]{cropgap}
\DeclareStringOption{spine}
\DeclareStringOption{xspine}
\DeclareStringOption{flap}
\DeclareStringOption{xtrim}
\DeclareStringOption{ytrim}
\DeclareStringOption{trim}
\DeclareBoolOption{cropframe}
\DeclareComplementaryOption{nocropframe}{cropframe}
\DeclareStringOption[default]{cropmarkstyle}
\DeclareStringOption{croptitle}
\DeclareStringOption[:\quad]{cropseparator}
\DeclareBoolOption{pagenumberfirst}
\DeclareComplementaryOption{pagenumberlast}{pagenumberfirst}
\DeclareBoolOption[true]{usepagenumbers}
\DeclareComplementaryOption{nopagenumbers}{usepagenumbers}
%%%\DeclareStringOption[\fontsize{10}{10}]{cropfontsize}
%%%\DeclareStringOption[\normalfont]{cropfont}
\DeclareBoolOption{nobleedclip}

% Color support for cropmarks
\DeclareBoolOption{color}
\DeclareStringOption[cmyk]{colormodel}
\DeclareStringOption[1,1,1,1]{cropcolor}
\DeclareStringOption[{CYAN:1,0,0,0},{MAGENTA:0,1,0,0},{YELLOW:0,0,1,0},{BLACK:0,0,0,1}]{colors}

% Reflect, works with pdftex and dvips

\def\zwpl@makeHreflect{\AtBeginDocument{\ifpdf
         \let\zwpl@Hship\shipout
         \def\shipout{\zwpl@Hreflect\zwpl@Hship}\zwpl@Hreflect
    \else\zwpl@psHreflect\fi}}

\def\zwpl@makeVreflect{\AtBeginDocument{\ifpdf
          \let\zwpl@Vship\shipout
          \def\shipout{\zwpl@Vreflect\zwpl@Vship}\zwpl@Vreflect
     \else\zwpl@psVreflect\fi}}

\DeclareVoidOption{ReflectHorizontally}{\zwpl@makeHreflect}
\DeclareVoidOption{ReflectVertically}{\zwpl@makeVreflect}

\ProcessKeyvalOptions*

% Other packages

\ifzwpl@onlycropmarks
  \setkeys{zwpl}{cropmarks}
\else

% Set the paper size

\def\zwpl@setpapersize#1,#2\zw@{\paperwidth\z@ \paperheight\z@
  \ifcat$#1$\else \paperwidth#1 \fi
  \ifcat$#2$\else \paperheight#2 \fi}

\ifcat$\zwpl@papersize$
  \zwpl@setpapersize,\zw@
\else
  \expandafter\zwpl@setpapersize\zwpl@papersize\zw@
\fi

\def\zwpl@switchpapdims{\@tempdima=\paperheight \paperheight=\paperwidth \paperwidth=\@tempdima}

\ifzwpl@AllowWidthHeightSwitching
  \ifzwpl@Landscape
    \ifdim\paperheight>\paperwidth \zwpl@switchpapdims\fi
  \else
    \ifdim\paperheight<\paperwidth \zwpl@switchpapdims\fi
  \fi
\fi

\AtBeginDocument{\ifpdf
   \pdfpagewidth\paperwidth \pdfpageheight\paperheight
\else
   \special{papersize=\the\paperwidth,\the\paperheight}\fi}

\ifcat$\zwpl@margins$ \else
  \setkeys{zwpl}{topmargin=\zwpl@margins,botmargin,
                 leftmargin=\zwpl@margins,rightmargin=\zwpl@margins}
\fi
\topmargin\zwpl@topmargin
\oddsidemargin\zwpl@leftmargin
\evensidemargin\zwpl@rightmargin
\textwidth\zwpl@textwidth
\textheight\zwpl@textheight
\headheight\zwpl@headheight
\headsep\zwpl@headsep
\footskip\zwpl@footskip
\ifcat$\zwpl@topskip$\else
  \topskip\zwpl@topskip
\fi

\ifcat$\zwpl@trim$ \else
  \setkeys{zwpl}{xtrim=\zwpl@trim,ytrim=\zwpl@trim}
\fi

% Paper width
\ifdim\paperwidth>\z@

\ifdim\textwidth>\z@
  \ifdim\oddsidemargin<\z@\else
  \ifdim\evensidemargin<\z@\else
    \textwidth -1in
\fi \fi \fi

\ifdim\textwidth>\z@
  \ifdim\oddsidemargin<\z@
    \ifdim\evensidemargin<\z@
      \oddsidemargin\paperwidth
      \advance\oddsidemargin-\textwidth
      \divide\oddsidemargin 2
      \evensidemargin\oddsidemargin
    \else
      \oddsidemargin\paperwidth
      \advance\oddsidemargin -\textwidth
      \advance\oddsidemargin -\evensidemargin
    \fi
  \else
    \evensidemargin\paperwidth
    \advance\evensidemargin -\textwidth
    \advance\evensidemargin -\oddsidemargin
  \fi
\else
  \ifdim\oddsidemargin<\z@
    \ifdim\evensidemargin<\z@
      \oddsidemargin\topmargin
      \evensidemargin\topmargin
    \else
      \oddsidemargin\evensidemargin
    \fi
  \else
    \ifdim\evensidemargin<\z@
      \evensidemargin\oddsidemargin
    \fi
  \fi
  \textwidth\paperwidth
  \advance\textwidth -\oddsidemargin
  \advance\textwidth -\evensidemargin
\fi

\else % calculate \paperwidth
  % \textwidth is the page body text without a spine, xspine, flaps, trim
  \ifcat$\zwpl@flap$\else \advance\textwidth\zwpl@flap \fi
  \ifcat$\zwpl@spine$\else
    % xspine ignored without spine
    \ifcat$\zwpl@xspine$\else
      \advance\textwidth\zwpl@xspine
    \fi
    \multiply\textwidth 2
    \advance\textwidth\zwpl@spine
  \fi
  \ifcat$\zwpl@xtrim$\else
    \@tempdima\zwpl@xtrim
    \advance\textwidth 2\@tempdima
  \fi
  \ifdim\oddsidemargin<\z@
    \ifdim\evensidemargin<\z@
      \oddsidemargin\topmargin
      \evensidemargin\topmargin
    \else
      \oddsidemargin\evensidemargin
    \fi
  \else
    \ifdim\evensidemargin<\z@
      \evensidemargin\oddsidemargin
    \fi
  \fi
  \paperwidth\textwidth
  \advance\paperwidth\oddsidemargin
  \advance\paperwidth\evensidemargin
\fi

% Paper height
\ifdim\paperheight>\z@

\ifdim\textheight>\z@ \else
  \ifcat$\zwpl@botmargin$
    \setkeys{zwpl}{botmargin}
  \fi
\fi

\ifcat$\zwpl@botmargin$\else
  \textheight\paperheight
  \advance\textheight -\topmargin
  \advance\textheight -\zwpl@botmargin
\fi

\else % calculate \paperheight
  \paperheight\topmargin
  \ifcat$\zwpl@ytrim$\else
    % add 2*ytrim to textheight
    \@tempdima\zwpl@ytrim
    \advance\textheight 2\@tempdima
  \fi
  \advance\paperheight\textheight
  \ifcat$\zwpl@botmargin$ \else
    \advance\paperheight\zwpl@botmargin
  \fi
\fi

\small\normalsize

\parskip\z@

% Set \textheight
\advance\textheight -\footskip
\advance\textheight -\headheight
\advance\textheight -\headsep
\ifzwpl@strictheight\else
  \ifzwpl@adjustfootskip
    \advance\footskip \textheight
  \else
    \advance\headsep \textheight
  \fi
  \advance\textheight -\topskip
  \divide\textheight by \baselineskip
  \count@ \textheight
  \textheight \count@\baselineskip
  \advance\textheight \topskip
  \ifzwpl@adjustfootskip
    \advance\footskip -\textheight
  \else
    \advance\headsep -\textheight
  \fi
\fi
\advance\topskip 100sp minus 500sp 

\advance\topmargin -1in
\advance\oddsidemargin -1in
\advance\evensidemargin -1in


% \vskip multiple baselines hacked for emTeX

\DeclareRobustCommand\vb{\begingroup \catcode`\-12 \catcode`\.12 \ZW@vb}
\newcommand*\ZW@vb[1][1]{\endgroup\vspace{#1\ZW@baselineskip}}

\newskip\ZW@baselineskip
\def\set@ZW@baselineskip{\ZW@baselineskip \baselineskip
  \advance\ZW@baselineskip 10sp minus 50sp }

\AtBeginDocument{\set@ZW@baselineskip}

% Correction \vskip

\newcommand*\Vcorr{\vskip 10sp minus 50sp}

% New odd/even page leaving an empty page of a specific style

\def\NewOddPage{\@ifstar{\ZW@s@oddpage}{\ZW@oddpage}}
\def\ZW@s@oddpage{\def\ZW@maybewarning{\PackageWarningNoLine{zwpagelayout}}\ZW@oddpage}
\newcommand*\ZW@oddpage[1][empty]{\clearpage
  \ifodd\c@page \else \thispagestyle{#1}\null\ZW@maybewarning{\ZW@oddwarning}\clearpage
    \let\ZW@maybewarning\@gobble
  \fi}

\def\NewEvenPage{\@ifstar{\ZW@s@evenpage}{\ZW@evenpage}}
\def\ZW@s@evenpage{\def\ZW@maybewarning{\PackageWarningNoLine{zwpagelayout}}\ZW@evenpage}
\newcommand*\ZW@evenpage[1][empty]{\clearpage
  \ifodd\c@page \thispagestyle{#1}\null\ZW@maybewarning{\ZW@evenwarning}\clearpage
    \let\ZW@maybewarning\@gobble
  \fi}

\let\ZW@maybewarning\@gobble
\def\SetOddPageMessage#{\gdef\ZW@oddwarning}
\def\SetEvenPageMessage#{\gdef\Z@@evenwarning}
\def\ZW@oddwarning{Empty page inserted}\let\ZW@evenwarning\ZW@oddwarning

% End of page layout setting

\fi % \ifzwpl@onlycropmarks ... \else ... \fi


% User defined dimensions

\def\CropFlap{\zwpl@flap}
\def\CropSpine{\zwpl@spine}
\def\CropXSpine{\zwpl@xspine}
\def\CropXtrim{\zwpl@xtrim}
\def\CropYtrim{\zwpl@ytrim}
\def\UserWidth{\zwpl@textwidth}
\def\UserLeftMargin{\zwpl@leftmargin}
\def\UserRightMargin{\zwpl@rightmargin}
\def\UserTopMargin{\zwpl@topmargin}
\def\UserBotMargin{\zwpl@botmargin}

% Handle cropmarks

\newdimen\zwpl@low \zwpl@low 1in
\advance\zwpl@low\topmargin
\advance\zwpl@low \headheight
\advance\zwpl@low \headsep
\advance\zwpl@low \textheight
\advance\zwpl@low \footskip
\advance\zwpl@low -\paperheight

\ifzwpl@cropmarks
  \ifzwpl@color
    \RequirePackage{color}
  \else \ifzwpl@nobleedclip \else
    \RequirePackage{color}
  \fi \fi
  \let\zwpl@pagestyle\pagestyle
  \let\zwpl@thispagestyle\thispagestyle
  \def\pagestyle{\let\zwpl@next\zwpl@pagestyle \zwpl@testps}
  \def\thispagestyle{\let\zwpl@next\zwpl@thispagestyle \zwpl@testps}
\fi

\def\zwpl@testps#1{\@ifundefined{zwpl@ps@#1}{\zwpl@patchps{#1}}{}\zwpl@next{#1}}

\def\zwpl@patchps#1{\expandafter\let\csname zwpl@ps@#1\expandafter\endcsname\csname ps@#1\endcsname
  \expandafter\def\csname ps@#1\endcsname{\csname zwpl@ps@#1\endcsname \zwpl@patchfoot}}

\def\zwpl@patchfoot{\let\zwpl@oddfoot\@oddfoot \let\zwpl@evenfoot\@evenfoot
  \def\@oddfoot{\zwpl@cropbox\zwpl@oddfoot}%
  \def\@evenfoot{\zwpl@cropbox\zwpl@evenfoot}}

\def\zwpl@cropbox{\rlap{% Some parameters may be changed within the document
  \raisebox{\zwpl@low}[\z@][\z@]{\everyvbox{}\offinterlineskip\boxmaxdepth\z@
    \hskip -\hoffset \hskip -1in \hskip -
    \ifodd\c@page \oddsidemargin \else \evensidemargin \fi
    \vbox to \paperheight{\hsize\paperwidth \parindent\z@
       \ifzwpl@nobleedclip\else
         \begingroup \vbox to \z@{\color{white}\noindent
           \rlap{\vbox to \paperheight{\hsize \paperwidth
                 \hrule width \hsize height \zwpl@croplength \vfill
                 \hrule width \hsize height \zwpl@croplength}}%
           \rlap{\vbox to \paperheight{\hsize\paperwidth
                 \vrule width \zwpl@croplength height \paperheight
                 \hfill \vrule width \zwpl@croplength}}%
         \vss}%
         \endgroup
       \fi
       \ifzwpl@color
         \edef\zwpl@temp{\noexpand\color[\zwpl@colormodel]{\zwpl@cropcolor}}\zwpl@temp
       \fi
       %%%\zwpl@cropfont \zwpl@cropfontsize \selectfont
       \normalfont \fontsize{10}{10}\selectfont
       \csname cropmarkstyle@\zwpl@cropmarkstyle\endcsname
    }%
}}}

\ifzwpl@cropmarks \zwpl@patchfoot \fi

\newdimen\zwpl@len  \zwpl@len\zwpl@croplength
\newdimen\zwpl@gap  \zwpl@gap\zwpl@cropgap
\newdimen\zwpl@plus \newdimen\zwpl@minus
\zwpl@plus \zwpl@croplength
\zwpl@plus .5\zwpl@plus
\zwpl@minus -\zwpl@plus
\advance\zwpl@plus .2pt
\advance\zwpl@minus .2pt

\newdimen\zwpl@frame \zwpl@frame\paperheight

\ifzwpl@cropmarks
  \hoffset \zwpl@croplength
  \advance\hoffset \zwpl@gap
  \voffset\hoffset
  \advance\paperheight 2\voffset
  \advance\paperwidth 2\hoffset
\fi
\advance\zwpl@low -\voffset

\newdimen\zwpl@vsize
\zwpl@vsize\paperheight
\advance\zwpl@vsize -2\zwpl@croplength

\def\clap#1{\hbox to \z@{\hss #1\hss}}
\def\zwpl@cbox#1{\rlap{\hbox to \zwpl@croplength{\hss #1\hss}}}

\def\zwpl@vert{\vrule height \zwpl@croplength depth \z@ width .4pt }
\def\zwpl@horiz{\vrule height .2pt depth .2pt width \zwpl@croplength}
\def\zwpl@choriz{\vrule height \zwpl@plus depth \zwpl@minus width \zwpl@croplength}
\def\zwpl@cross{\zwpl@cbox{\zwpl@vert}\zwpl@choriz}
\def\zwpl@frm{\clap{\vrule height \zwpl@frame depth \z@ width .4pt}}
\def\zwpl@hh{\hbox to \hsize}
\def\zwpl@hline{\zwpl@hh{\zwpl@horiz \hskip\zwpl@gap
    \ifzwpl@cropframe
      \leaders \vrule height .2pt depth .2pt \hfill
    \else
      \hfill
    \fi
    \hskip\zwpl@gap \zwpl@horiz}}

\newcommand*\zwpl@vline[1][]{%
  \zwpl@hh{\zwpl@cross \hskip\zwpl@gap \clap{\zwpl@vert}%
    \ifcat$\zwpl@xtrim$\else
      \hskip\zwpl@xtrim \clap{\zwpl@vert}%
    \fi
    \ifcat$\zwpl@flap$\else
      \hskip\zwpl@flap \clap{\zwpl@vert}%
    \fi
    \rlap{\hskip\zwpl@gap #1}%
    \hss
    \ifcat$\zwpl@spine$\else
      \ifcat$\zwpl@xspine$\else
        \clap{\zwpl@vert}\hskip\zwpl@xspine
      \fi
      \clap{\zwpl@vert}\hskip\zwpl@spine \clap{\zwpl@vert}%
      \ifcat$\zwpl@xspine$\else
        \hskip\zwpl@xspine \clap{\zwpl@vert}%
      \fi
      \hss
      \ifcat$\zwpl@flap$\else
        \clap{\zwpl@vert}\hskip\zwpl@flap
      \fi
    \fi
    \ifcat$\zwpl@xtrim$\else
      \clap{\zwpl@vert}\hskip\zwpl@xtrim
    \fi
    \clap{\zwpl@vert}\hskip\zwpl@gap \zwpl@cross}}

\def\cropmarkstyle@default{%
  \expandafter\zwpl@vline\ifzwpl@color[\zwpl@showallcolors]\fi
  \vskip\zwpl@gap \zwpl@hline
  \ifcat$\zwpl@ytrim$\else
    \vskip\zwpl@ytrim \zwpl@hline
  \fi
  \vss
  \ifzwpl@cropframe
    \zwpl@hh{\hskip \hoffset \zwpl@frm
    \ifcat$\zwpl@xtrim$\else
      \hskip\zwpl@xtrim \zwpl@frm
    \fi
    \ifcat$\zwpl@flap$\else
      \hskip\zwpl@flap \zwpl@frm
    \fi
    \hss
    \ifcat$\zwpl@spine$\else
      \ifcat$\zwpl@xspine$\else
        \zwpl@frm \hskip\zwpl@xspine
      \fi
      \zwpl@frm \hskip\zwpl@spine \zwpl@frm
      \ifcat$\zwpl@xspine$\else
        \hskip\zwpl@xspine \zwpl@frm
      \fi
      \hss 
      \ifcat$\zwpl@flap$\else
        \zwpl@frm \hskip\zwpl@flap
      \fi
    \fi
    \ifcat$\zwpl@xtrim$\else
      \zwpl@frm \hskip\zwpl@xtrim
    \fi
    \zwpl@frm \hskip \hoffset}\vss
  \fi
  \ifcat$\zwpl@ytrim$\else
    \zwpl@hline \vskip\zwpl@ytrim
  \fi
  \zwpl@hline \vskip\zwpl@gap \zwpl@vline[\zwpl@printcroptitle]}

\def\zwpl@printcroptitle{\raisebox{.8ex}[\z@][\z@]{\ifzwpl@usepagenumbers
  \ifzwpl@pagenumberfirst
    \thePageNumber 
    \ifcat$\zwpl@croptitle$\else
      \zwpl@cropseparator \zwpl@croptitle
    \fi
  \else
    \ifcat$\zwpl@croptitle$\else
      \zwpl@croptitle \zwpl@cropseparator
    \fi
    \thePageNumber
  \fi
\else
  \ifcat$zwpl@croptitle$\else
    \zwpl@croptitle
  \fi
\fi}}

\def\thePageNumber{\#\,\arabic{page}}

\def\zwpl@printcolor#1:#2:{\edef\zwpl@temp{\noexpand\textcolor[\zwpl@colormodel]{#2}{#1}}\zwpl@temp\space}

\def\zwpl@showcolors#1,#2*{\zwpl@printcolor#1:%
    \ifcat$#2$\let\zwpl@next\relax
    \else\def\zwpl@next{\zwpl@showcolors#2*}\fi \zwpl@next}

\def\zwpl@showallcolors{\raisebox{.2ex}[\z@][\z@]{\expandafter\zwpl@showcolors\zwpl@colors,*}}

% Reflect (should be at the end of the package)

\newcount\zwpl@Hshift
\newcount\zwpl@Vshift

% shift calculation
\def\zwpl@calcshift#1#2{#1#2
    \divide #1 8
    \multiply #1 5
    \divide #1 8
    \multiply #1 5
    \divide #1 25696 }

% pdftex version
\def\zwpl@Hreflect{\zwpl@calcshift\zwpl@Hshift\hsize
    \pdfliteral{-1 0 0 1 \the\zwpl@Hshift\space 0 cm}}

\def\zwpl@Vreflect{\zwpl@calcshift\zwpl@Vshift\vsize
    \pdfliteral{1 0 0 -1 0 -\the\zwpl@Vshift\space cm}}

% dvips version (modifies bop-hook)
\def\zwpl@psreflect#1#2#3#4{\zwpl@calcshift#3#4
    \special{! userdict begin
               userdict /bop-hook known {bop-hook load cvx /ZW#1-hook exch def} if
               /bop-hook {
                   [#2] concat
                   userdict /ZW#1-hook known {ZW#1-hook} if
               } def end}}

\def\zwpl@psHreflect{\zwpl@psreflect H{-1 0 0 1 \the\zwpl@Hshift\space 0}\zwpl@Hshift\paperwidth}
\def\zwpl@psVreflect{\zwpl@psreflect V{1 0 0 -1 0 \the\zwpl@Vshift}\zwpl@Vshift\paperheight}
