www.pudn.com > 精通Matlab综合辅导与指南-源程序.zip > mmpage.m
function mmpage(arg)
%MMPAGE GUI to Set Figure Paper Position.
% MMPAGE allows the user to set the current figure
% position on the printed page using a gui.
% MMPAGE(Hf) places the figure having handle Hf.
%
% Editable text boxes: Left Bottom Width Height
% sets the respective figure position on the page.
% Pushbuttons:
% Set Default makes the current position default for future figures.
% Get Factory changes the figure position to factory values.
% L/R Center centers the figure Left to Right.
% U/D Center centers the figure Up to Down.
% WYSIWYG makes the Width and Height identical to the Figure Window.
% Get Default sets the figure position to the Default values.
% Revert restores the figure position to that when MMPAGE was called.
% Done closes the MMPAGE GUI.
%
% Usage: create figure, call MMPAGE, then print.
% D.C. Hanselman, University of Maine, Orono, ME, 04469
% 4/25/95
% Copyright (c) 1996 by Prentice-Hall, Inc.
global Hf_2p Hf_gui Ha_gui Hp_gui Hu_l Hu_b Hu_w Hu_h
figrgb=[.5 .5 1]; % background figure color
boxrgb=[.65 .65 1]; % fill box color
axesrgb=[1 1 1]; % axes background color
xyrgb=[0 0 0]; % grid and label color
if nargin==0
arg=mmgcf;
if isempty(arg),error('No Figure to Place on Page.'),end
end
if length(arg)==1 & arg>0 % must be a Figure handle
Hf_2p=arg;
pu=get(Hf_2p,'PaperUnits');
if ~strcmp(pu,'inches')&~strcmp(pu,'centimeters')
set(Hf_2p,'PaperUnits','inches')
pu='inches';
end
if strcmp(pu,'inches'),
xyunits='inches'; TINC=1;
else % centimeters
xyunits='cm';TINC=2;
end
ps=get(Hf_2p,'PaperSize');
pp=get(Hf_2p,'PaperPosition');
pp=[max(pp(1:2),.028*ps) min(pp(3:4),.96*ps)]; % limit size
set(Hf_2p,'PaperPosition',pp)
Hf_gui=figure(... % create GUI figure
'BackingStore','on',...
'Color',figrgb,...
'Units','normalized',...
'Position',[0 .2 .75*ps./max(ps);],...
'NumberTitle','off',...
'Name','MMPAGE',...
'NextPlot','add',...
'Resize','off',...
'Userdata',pp);
Ha_gui=axes(... % create axes showing paper size
'AspectRatio',[ps(1)./ps(2) 1],...
'Box','on',...
'Color',axesrgb,...
'Drawmode','fast',...
'NextPlot','add',...
'View',[0 90],...
'Units','normalized',...
'Position',[0 .25 .8 .7],...
'XColor',xyrgb,...
'YColor',xyrgb,...
'Xgrid','on',...
'Ygrid','on',...
'Xlim',[0 ps(1)],...
'Ylim',[0 ps(2)],...
'XLimMode','manual',...
'YLimMode','manual',...
'Xtick',0:TINC:ps(1),...
'Ytick',0:TINC:ps(2));
Ht_x=text(0,0,['Paper Width, ' xyunits],'Color',xyrgb);
Ht_y=text(0,0,['Paper Height, ' xyunits],'Color',xyrgb);
Ht_t=text(0,0,['Paper Type: ' get(Hf_2p,'Papertype')],'Color',xyrgb);
set(Ha_gui,'XLabel',Ht_x,'Ylabel',Ht_y,'Title',Ht_t)
xpg=[pp(1) pp(1)+pp(3) pp(1)+pp(3) pp(1)];
ypg=[pp(2) pp(2) pp(2)+pp(4) pp(2)+pp(4)];
Hp_gui=fill(xpg,ypg,boxrgb); % draw box showing figure placement
Hu_l=uicontrol(... % left edit box
'Style','edit',...
'Units','normalized',...
'Position',[.01 .06 .18 .05],...
'String',sprintf('%.2f',pp(1)),...
'Callback','mmpage(-1)');
uicontrol(...
'Style','text',...
'BackGroundColor',figrgb,...
'Units','normalized',...
'Position',[.01 0 .18 .04],...
'HorizontalAlignment','left',...
'String','Left');
Hu_b=uicontrol(... % bottom edit box
'Style','edit',...
'Units','normalized',...
'Position',[.21 .06 .18 .05],...
'String',sprintf('%.2f',pp(2)),...
'Callback','mmpage(-1)');
uicontrol(...
'Style','text',...
'BackGroundColor',figrgb,...
'Units','normalized',...
'Position',[.21 0 .18 .04],...
'HorizontalAlignment','left',...
'String','Bottom');
Hu_w=uicontrol(... % width edit box
'Style','edit',...
'Units','normalized',...
'Position',[.41 .06 .18 .05],...
'String',sprintf('%.2f',pp(3)),...
'Callback','mmpage(-1)');
uicontrol(...
'Style','text',...
'BackGroundColor',figrgb,...
'Units','normalized',...
'Position',[.41 0 .18 .04],...
'HorizontalAlignment','left',...
'String','Width');
Hu_h=uicontrol(... % height edit box
'Style','edit',...
'Units','normalized',...
'Position',[.61 .06 .18 .05],...
'String',sprintf('%.2f',pp(4)),...
'Callback','mmpage(-1)');
uicontrol(...
'Style','text',...
'BackGroundColor',figrgb,...
'Units','normalized',...
'Position',[.61 0 .18 .04],...
'HorizontalAlignment','left',...
'String','Height');
uicontrol(... % DONE
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 0 .18 .05],...
'String','Done',...
'Callback','close' );
uicontrol(... % REVERT -2
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .06 .18 .05],...
'String','Revert',...
'Callback','mmpage(-2)');
uicontrol(... % Get DEFAULT -3
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .12 .18 .05],...
'String','Get Default',...
'Callback','mmpage(-3)');
uicontrol(... % WYSIWYG -4
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .18 .18 .05],...
'String','WYSIWYG',...
'Callback','mmpage(-4)');
uicontrol(... % U/D Center -5
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .24 .18 .05],...
'String','U/D Center',...
'Callback','mmpage(-5)');
uicontrol(... % L/R Center -6
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .30 .18 .05],...
'String','L/R Center',...
'Callback','mmpage(-6)');
uicontrol(... % Set Default -7
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .42 .18 .05],...
'String','Set Default',...
'Callback','mmpage(-7)');
uicontrol(... % Factory -8
'Style','pushbutton',...
'Units','normalized',...
'Position',[.81 .36 .18 .05],...
'String','Get Factory',...
'Callback','mmpage(-8)');
set(Hf_gui,'Visible','on')
elseif length(arg)==4 % update gui display
pp=arg;
set(Hu_l,'String',sprintf('%.2f',pp(1)))
set(Hu_b,'String',sprintf('%.2f',pp(2)))
set(Hu_w,'String',sprintf('%.2f',pp(3)))
set(Hu_h,'String',sprintf('%.2f',pp(4)))
set(Hf_2p,'PaperPosition',pp)
xpg=[pp(1) pp(1)+pp(3) pp(1)+pp(3) pp(1)];
ypg=[pp(2) pp(2) pp(2)+pp(4) pp(2)+pp(4)];
set(Hp_gui,'Xdata',xpg,'Ydata',ypg) % adjust figure patch
elseif arg==-1 % User-edited data
mps=0.96*get(Hf_2p,'PaperSize');
pp=zeros(1,4);
% prioritize width over left and height over bottom
pp(3)=min(abs(eval(get(Hu_w,'String'))),mps(1)); % width
pp(4)=min(abs(eval(get(Hu_h,'String'))),mps(2)); % height
pp(1)=min(abs(eval(get(Hu_l,'String'))),mps(1)-pp(3)); % left
pp(2)=min(abs(eval(get(Hu_b,'String'))),mps(2)-pp(2)); % bottom
mmpage(pp)
elseif arg==-2 % Revert
pp_rev=get(Hf_gui,'Userdata');
mmpage(pp_rev)
elseif arg==-3 % Get Default
set(Hf_2p,'PaperPosition','default')
pp=get(Hf_2p,'PaperPosition');
mmpage(pp)
elseif arg==-4 % WYSIWYG
f_units=get(Hf_2p,'Units');
set(Hf_2p,'Units',get(Hf_2p,'PaperUnits'))
fp=get(Hf_2p,'Position');
set(Hf_2p,'Units',f_units)
ps=get(Hf_2p,'PaperSize');
pp=zeros(1,4);
pp(3:4)=min(fp(3:4),0.96*ps); % limit width and height to paper size
pp(1)=(ps(1)-pp(3))/2; % left
pp(2)=(ps(2)-pp(4))/2; % bottom
mmpage(pp)
elseif arg==-5 % U/D Center
pp=get(Hf_2p,'PaperPosition');
ps=get(Hf_2p,'PaperSize');
pp(2)=(ps(2)-pp(4))/2; % bottom
mmpage(pp)
elseif arg==-6 % L/R Center
pp=get(Hf_2p,'PaperPosition');
ps=get(Hf_2p,'PaperSize');
pp(1)=(ps(1)-pp(3))/2; % left
mmpage(pp)
elseif arg==-7 % Set Default
pp=get(Hf_2p,'PaperPosition');
set(0,'DefaultFigurePaperPosition',pp)
elseif arg==-8 % Factory
set(Hf_2p,'PaperPosition','factory')
pp=get(Hf_2p,'PaperPosition');
mmpage(pp)
end