\ProvidesPackage{wrapft}[2001/09/27 ver.0.30]
\RequirePackage{wrapfig}[1999/10/12]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\WF@hsep %horizontal separation between fig and text
\newdimen\WF@vsep %vspace on the top and the bottom of the figure
\WF@hsep=1.6\columnsep 
\WF@vsep=\intextsep
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\WF@rapt[#1]#2{% final two args: #1 = overhang,  #2 = width,
 \ifnum `c=\WF@place % fig in the center
    \@tempdima\hsize \advance\@tempdima-#2 \divide\@tempdima\tw@
    \vskip\WF@vsep
    \noindent \hspace*{\@tempdima}\begin{minipage}[t]{#2}%
 \else
  \gdef\WF@ovh{#1}% hold overhang for later, when \width is known
  \global\setbox\WF@box\vtop\bgroup \setlength\hsize{#2}%
  \ifdim\hsize>\z@ \@parboxrestore \else 
  \setbox\z@\hbox\bgroup \let\wf@@caption\caption \let\caption\wf@caption 
  \ignorespaces \fi
 \fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\endwrapfigure{%
 \ifnum `c=\WF@place % fig in the center
    \end{minipage} \vskip\WF@vsep
 \else
%%%
  \ifdim\hsize>\z@ \par\hrule\@width\hsize\@height\z@ % force width
  \else \unskip \egroup \box\z@ \fi % or end hbox
  \egroup % end the \vtop; width is known so now is "later"
  \def\width{\wd\WF@box}\setlength\wrapoverhang{\WF@ovh}%
  \xdef\WF@ovh{\the\wrapoverhang}% save until wrapping
  \ifdim\ht\WF@box>\topskip \ht\WF@box\z@ \fi % too much height, set flag.
  \ifdim\ht\WF@box<.5\p@ % too tall (starts with \vbox) or too short
   \global\setbox\WF@box\vtop{\vskip-1.4ex\unvbox\WF@box}\fi
  \global\WF@size\dp\WF@box % box is guaranteed to have little height.
% \global\advance\WF@size1.5\baselineskip \global\advance\WF@size\tw@\intextsep
  \global\advance\WF@size1.1\baselineskip \global\advance\WF@size\tw@\WF@vsep
  \aftergroup\WF@startfloating % even when not really floating!
  \ifWF@float\else \ifhmode
     {\unskip \parfillskip\z@skip \par \vskip-\parskip}\aftergroup\noindent
  \fi\fi \global\@ignoretrue
 \fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\WF@@putfigmaybe\WF@putfigmaybe
\def\WF@putfigmaybe{%
 \columnsep \WF@hsep   \intextsep \WF@vsep
 \WF@@putfigmaybe}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\WF@startwrapping{%
 \ifx\WF@wli\@empty
% {\advance\WF@size1.1\baselineskip
  {\advance\WF@size1.5\baselineskip
  \divide\WF@size\baselineskip \global\c@WF@wrappedlines\WF@size}%
 \else
  \setcounter{WF@wrappedlines}{\WF@wli}\global\advance\c@WF@wrappedlines\@ne
 \fi
 \ifnum\c@WF@wrappedlines>\@ne
  \let\parshape\WF@fudgeparshape \let\WF@pspars\@empty \let\WF@@par\par
  \def\@setpar##1{\def\WF@@par{##1}}\def\par{\@par}\let\@par\WF@mypar
  \xdef\WF@restoretol{\tolerance\the\tolerance}\tolerance9999
 \fi}
