%%
%% This is file `blowup.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% blowup.dtx  (with options: `package')
%% 
%%    Copyright (C) 2007, 2017-
%%    Rolf Niepraschk, Rolf.Niepraschk@gmx.de
%% 
%%    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 2003/12/01 or later.
%% 
%%    This work has the LPPL maintenance status "author-maintained".
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{blowup}[2018/01/02 1.0 Document Scaling (RN)]
\RequirePackage{atbegshi,keyval,graphics}
\@ifpackageloaded{typearea}{}{%
  \newcommand*\BL@save@dimen[1]{%
    \@ifundefined{BL@#1}{%
      \expandafter\newlength\csname BL@#1\endcsname}{}%
    \csname BL@#1\endcsname\csname #1\endcsname
    \g@addto@macro\BL@restore@dimens{%
      \csname #1\endcsname\csname BL@#1\endcsname}%
  }%
  \newcommand*\BL@restore@dimens{}%
  \BL@save@dimen{textwidth}%
  \BL@save@dimen{textheight}%
  \BL@save@dimen{evensidemargin}%
  \BL@save@dimen{oddsidemargin}%
  \BL@save@dimen{topmargin}%
  \BL@save@dimen{headheight}%
  \BL@save@dimen{headsep}%
  \BL@save@dimen{topskip}%
  \BL@save@dimen{footskip}%
  \BL@save@dimen{baselineskip}%
  \let\l@addto@macro=\relax
  \RequirePackage{typearea}%
  \BL@restore@dimens
  \let\BL@save@dimen=\relax
  \let\BL@restore@dimens=\relax
}
\providecommand*\vb@xt@{\vbox to}
\newlength\tPaperWidth  \tPaperWidth=\paperwidth
\newlength\tPaperHeight \tPaperHeight=\paperheight
\newlength\oPaperWidth  \oPaperWidth=\z@
\newlength\oPaperHeight \oPaperHeight=\z@
\newcommand*\BL@resize[1]{#1}
\newcommand*\BL@scalePage{%
  \setbox\AtBeginShipoutBox=\vbox{%
    \vskip1in\moveright1in\box\AtBeginShipoutBox}%
  \setbox\AtBeginShipoutBox=\hb@xt@\paperwidth{%
    \box\AtBeginShipoutBox\hss}%
  \setbox\AtBeginShipoutBox=\vb@xt@\paperheight{%
    \box\AtBeginShipoutBox\vss}%
  \ifBL@noscale\else
    \ifdim\oPaperWidth>\z@
      \setbox\AtBeginShipoutBox=\hbox{\resizebox{\oPaperWidth}{\oPaperHeight}%
        {\box\AtBeginShipoutBox}}%
    \else
      \def\BL@resize##1{\resizebox{\tPaperWidth}{!}{##1}}%
      \setbox\@tempboxa=\hbox{\BL@resize{\copy\AtBeginShipoutBox}}%
      \ifdim\ht\@tempboxa>\tPaperHeight
        \def\BL@resize##1{\resizebox{!}{\tPaperHeight}{##1}}%
      \fi
    \fi
  \fi
  \setbox\@tempboxa=\vb@xt@\tPaperHeight{%
    \kern\z@\BL@t
    \hb@xt@\tPaperWidth{\BL@l\BL@resize{\box\AtBeginShipoutBox}\BL@r}%
    \BL@b\kern\z@
  }%
  \setbox\AtBeginShipoutBox=\vbox{%
    \vskip-1in\moveright-1in\box\@tempboxa}%
}
\newcommand\BL@tempa{}
\newcommand\BL@tempb{}
\newcommand*\BL@strip@comma{}
\def\BL@strip@comma#1,{#1}
\newcommand*\BL@is@dimen@pair[1]{%
  \expandafter\BL@@is@dimen@pair#1,\@nil
}
\newcommand*\BL@@is@dimen@pair{}
\def\BL@@is@dimen@pair#1,#2\@nil{%
  \edef\BL@tempa{#1}\edef\BL@tempb{#2}%
  \@tempswafalse
  \ifx\BL@tempb\@empty\else
    \edef\BL@tempb{\expandafter\BL@strip@comma\BL@tempb}%
    \ifdimen{\BL@tempa}{%
      \ifdimen{\BL@tempb}{\@tempswatrue}{}%
    }{}%
  \fi
  \if@tempswa
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\newcommand*\BL@strip@x{}
\def\BL@strip@x#1x{#1}
\newcommand*\BL@is@factor[1]{%
  \expandafter\BL@@is@factor#1x\@nil
}
\newcommand*\BL@@is@factor{}
\def\BL@@is@factor#1x#2\@nil{%
  \edef\BL@tempa{#2}%
  \@tempswafalse
  \ifx\BL@tempa\@empty\else
    \edef\BL@tempa{\expandafter\BL@strip@x\BL@tempa}%
    \ifdimen{\BL@tempa pt}{\@tempswatrue}{}%
  \fi
  \if@tempswa
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\newcommand*\BL@getDimens[3]{%
  \BL@is@dimen@pair{#1}{%
    \global#2=\BL@tempa\relax
    \global#3=\BL@tempb\relax
  }{%
    \BL@is@factor{#1}{%
      \global#2=\BL@tempa\paperwidth
      \global#3=\BL@tempa\paperheight
    }{%
      \begingroup
        \KOMAoptions{paper=portrait,paper=#1}%
        \global#2=\paperwidth
        \global#3=\paperheight
      \endgroup
    }%
  }%
}
\define@key{BL@}{origin}{%
  \BL@getDimens{#1}{\oPaperWidth}{\oPaperHeight}%
}
\define@key{BL@}{target}{%
  \BL@getDimens{#1}{\tPaperWidth}{\tPaperHeight}%
}
\newif\ifBL@noscale \BL@noscalefalse
\define@key{BL@}{noscale}[true]{%
  \csname BL@noscale#1\endcsname
}
\newcommand*\BL@l{}
\newcommand*\BL@r{}
\newcommand*\BL@i{}
\newcommand*\BL@o{}
\newcommand*\BL@t{}
\newcommand*\BL@b{}
\newcommand\BL@setPos[1]{%
  \def\BL@l{\hss}\def\BL@r{\hss}%
  \def\BL@o{\hss}\def\BL@i{\hss}%
  \def\BL@t{\vss}\def\BL@b{\vss}%
  \BL@is@dimen@pair{#1}{%
    \edef\BL@b{\vskip\BL@tempb}%
    \if@twoside
      \edef\BL@l{\noexpand\ifodd\value{page}%
        \hskip\BL@tempa\noexpand\else\hss\noexpand\fi}%
      \edef\BL@r{\noexpand\ifodd\value{page}%
        \hss\noexpand\else\hskip\BL@tempa\noexpand\fi}%
    \else
      \edef\BL@l{\hskip\BL@tempa}%
    \if
  }{%
    \@for\BL@tempa:=#1\do{%
      \edef\BL@tempb{\expandafter\@car\BL@tempa\@nil}%
      \expandafter\let\csname BL@\BL@tempb \endcsname\relax
    }%
    \if@twoside
      \ifx\BL@i\relax
        \def\BL@r{\ifodd\value{page}\hss\else\relax\fi}%
        \def\BL@l{\ifodd\value{page}\relax\else\hss\fi}%
      \fi
      \ifx\BL@o\relax
        \def\BL@l{\ifodd\value{page}\hss\else\relax\fi}%
        \def\BL@r{\ifodd\value{page}\relax\else\hss\fi}%
      \fi
    \else
      \let\BL@l=\BL@o
      \let\BL@r=\BL@i
    \fi
  }%
}
\define@key{BL@}{pos}{%
  \BL@setPos{#1}%
}
\newif\ifBL@landscape \BL@landscapefalse
\define@key{BL@}{landscape}[true]{%
  \csname BL@landscape#1\endcsname
}
\newcommand*\BL@pageInit{}
\define@key{BL@}{onepage}[true]{%
  \csname if#1\endcsname
    \def\BL@pageInit{\gdef\shipout{\setbox\@tempboxa=}}%
  \fi
}
\newcommand*\blowUp[1]{%
  \setkeys{BL@}{#1}%
  \ifBL@landscape
    \@tempdima=\tPaperWidth
    \global\tPaperWidth=\tPaperHeight
    \global\tPaperHeight=\@tempdima
  \fi
  \AtBeginShipout{\BL@scalePage}%
  \gdef\blowUp##1{%
    \PackageWarning{blowup}{Only the first call of `\string\blowUp'
      \MessageBreak is effective}}%
}
\AtBeginShipout{\BL@pageInit}
\@onlypreamble\blowUp
\AtBeginDocument{%
  \BL@pagesize@specials{\tPaperWidth}{\tPaperHeight}%
}
\RequirePackage{ifxetex,ifluatex,ifpdf,ifvtex}
\newcommand*\BL@pagesize@specials[2]{}
\ifluatex
  \PackageInfo{blowup}{Generating code for LuaTeX}%
  \@ifundefined{pagewidth}{%
    \def\BL@pagesize@specials#1#2{\pdfpagewidth=#1 \pdfpageheight=#2}%
  }{%
    \def\BL@pagesize@specials#1#2{\pagewidth=#1 \pageheight=#2}%
  }
\else
  \ifxetex
    \PackageInfo{blowup}{Generating code for XeTeX}%
    \def\BL@pagesize@specials#1#2{\@tempdima=#1 \@tempdimb=#2 %
      \AtBeginDvi{\special{papersize=\the\@tempdima,\the\@tempdimb}}%
      \pdfpagewidth=#1 \pdfpageheight=#2}%
  \else
    \ifvtex
      \PackageInfo{blowup}{Generating code for VTeX}%
      \def\BL@pagesize@specials#1#2{\mediawidth=#1 \mediaheight=#2}%
    \else
      \ifpdf
        \PackageInfo{blowup}{Generating code for pdfTeX}%
        \def\BL@pagesize@specials#1#2{\pdfpagewidth=#1 \pdfpageheight=#2}%
      \else
        \PackageInfo{blowup}{Generating code for dvips}%
        \def\BL@pagesize@specials#1#2{\@tempdima=#1 \@tempdimb=#2 %
          \AtBeginDvi{\special{papersize=\the\@tempdima,\the\@tempdimb}}}%
      \fi
    \fi
  \fi
\fi
\endinput
%%
%% End of file `blowup.sty'.
