%-*- auto-fill -*-
% Note: All the stuff in this file duplicates and/or refines the
% parameters of raw TeX to facilitate the operation of the geometry
% manager. We will still need the raw TeX params for running the
% paginator (within our regions), hence the duplications.

\immediate\write16{Paper Utilities...}

\voffset=-1in \hoffset=-1in % zero out tools' builtin offsets
\newdimen\PageHeight\newdimen\PageWidth
\newdimen\ImageHeight\newdimen\ImageWidth

\def\defpaper#1#2{
 \edef\papername{\csname#1\endcsname}
 \expandafter\def\papername{#2}}

\def\paperDimensions height:#1 width:#2;{
 \PageHeight=#1 \PageWidth=#2
 \ImageHeight=\PageHeight \ImageWidth=\PageWidth
 \ifpdfTeX \pdfpageheight=\PageHeight \pdfpagewidth=\PageWidth \fi}

\defpaper{a4}{\paperDimensions height:297truemm width:210truemm;}
\defpaper{a4l}{\paperDimensions height:210truemm width:297truemm;}
\defpaper{USLetter}{\paperDimensions height:11truein width:8.5truein;}

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

\def\Margins top:#1 bottom:#2 left:#3 right:#4;{
 \global\advance\voffset by#1 \global\advance\ImageHeight by-#1
 \global\advance\ImageHeight by-#2
 \global\advance\hoffset by#3 \global\advance\ImageWidth by-#3
 \global\advance\ImageWidth by-#4
 \def\PageBoundaries{
  \Rectangle[region] %
   origin0pt,0pt %
   extent\the\ImageWidth,\the\ImageHeight;}}
