function scalefig(scalefactor_font, scalefactor_width, retain_axis)
%SCALEFIG Scales text and lines on the current figure.
%
%   SCALEFIG(SCALEFACTOR_FONT, SCALEFACTOR_WIDTH, RETAIN_AXIS)
%   The font size of all text in the current figure is multiplied by
%   SCALEFACTOR_FONT. Similarly, the linewidth of all lines in the current
%   figure is multiplied by SCALEFACTOR_WIDTH. These rescalings may cause the
%   axis limits to be automatically changed; a non-zero value of RETAIN_AXIS
%   will cause the axis limits to be retained.

%   written by Douglas M. Schwarz
%   schwarz@kodak.com
%   5 May 1998
%   extended by Jim Mansbridge

fig = gcf;
sh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on')
ax = findobj(fig,'Type','axes');
t = findobj(fig,'Type','text');
li = findobj(fig,'Type','line');
axis_val = axis;
for i = 1:length(ax)
    fs = get(ax(i),'FontSize');
    set(ax(i),'FontSize',fs*scalefactor_font)
    ls = get(ax(i),'LineWidth');
    set(ax(i),'LineWidth',ls*scalefactor_width)
end
for i = 1:length(t)
    fs = get(t(i),'FontSize');
    set(t(i),'FontSize',fs*scalefactor_font)
end
for i = 1:length(li)
    ls = get(li(i),'LineWidth');
    set(li(i),'LineWidth',ls*scalefactor_width)
end
set(0,'ShowHiddenHandles',sh)
if (nargin > 2) & retain_axis
  axis(axis_val);
end
