function pgsetup(command,subcommand,comnum); %PGSETUP Open the printer setup window % %Creates a dialog box which allows the user %to customize the printing options for the %current figure. Most of the items should %be self explanatory. A picture is drawn at %the bottom of the figure showing the page %and the positioning of the figure's contents %on it. Click and drag on the edges of the %inner rectangle to resize, and in the center %to reposition. % %Keith Rogers 12/94 %Copyright (c) 1995 by Keith Rogers %This function has been modified by Claudio Rivetti %to be well adapted to ALEX. 7 Oct. 1995 global Device Handlefig PrinterList Printer savepath if(nargin<1) PrinterList=[ ' 1) PostScript BW|',... ' 2) PostScript Color|',... ' 3) EPSF BW|',... ' 4) EPSF BW preview|',... ' 5) EPSF Color|',... ' 6) EPSF Color preview|',... ' 7) HPGL|',... ' 8) Adobe Illustrator|',... ' 9) HP LaserJet|',... '10) HP LaserJet+|',... '11) HP LaserJet IIP|',... '12) HP LaserJet III|',... '13) HP DeskJet+|',... '14) HP DeskJet 500C BW|',... '15) DeskJet 500C 1 bit|',... '16) DeskJet 500C 24 bit|',... '17) HP PaintJet Color|',... '18) Canon BJ10e|',... '19) DEC LN03|',... '20) Epson dot matrix']; Printer=[ '-dps ';... '-dpsc ';... '-deps ';... '-deps -epsi ';... '-depsc ';... '-depsc -epsi';... '-dhpgl ';... '-dill ';... '-dlaserjet ';... '-dljetplus ';... '-dljet2p ';... '-dljet3 ';... '-ddeskjet ';... '-dcdjmono ';... '-dcdeskjet ';... '-dcdjcolor ';... '-dpaintjet ';... '-dbj10e ';... '-dln03 ';... '-deps9high ']; ff=findobj('Name','Printer Setup'); if ~isempty(ff) figure(ff); return; end ShrinkFactor = 3.7; Background = [0.701961 0.701961 0.701961]; Bg=[0.55 0.55 0.55]; Bgimage=[0 0.1529 0.6235]; Txtcolor=[0.2784 0.2784 0.2784]; Foreground = 'black'; fig = gcf; PSFigure = figure('Name','Printer Setup',... 'Position',[100 40 430 580],... 'NextPlot','Add',... 'NumberTitle', 'off',... 'Resize', 'off',... 'Color',Bg); PaperPosition = get(fig,'PaperPosition'); PaperSize = get(fig,'PaperSize'); %set(gca,'Visible','Off'); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Margins',... 'Position',[25 540 70 20]); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Bottom',... 'HorizontalAlignment','Right',... 'Position',[5 520 60 20]); uicontrol(PSFigure,'Style','Edit',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String',num2str(PaperPosition(2)),... 'Position',[70 520 60 20],... 'Tag','Bottom',... 'Callback','pgsetup(''Margins'',''Bottom'')'); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Left',... 'HorizontalAlignment','Right',... 'Position',[5 488 60 20]); uicontrol(PSFigure,'Style','Edit',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String',num2str(PaperPosition(1)),... 'Position',[70 488 60 20],... 'Tag','Left',... 'Callback','pgsetup(''Margins'',''Left'')'); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Top',... 'HorizontalAlignment','Right',... 'Position',[5 457 60 20]); uicontrol(PSFigure,'Style','Edit',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String',num2str(PaperSize(2)-PaperPosition(2)-PaperPosition(4)),... 'Position',[70 457 60 20],... 'Tag','Top',... 'Callback','pgsetup(''Margins'',''Top'')'); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Right',... 'HorizontalAlignment','Right',... 'Position',[5 425 60 20]); uicontrol(PSFigure,'Style','Edit',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String',num2str(PaperSize(1)-PaperPosition(1)-PaperPosition(3)),... 'Position',[70 425 60 20],... 'Tag','Right',... 'Callback','pgsetup(''Margins'',''Right'')'); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Paper Type',... 'HorizontalAlignment','Left',... 'Position',[150 540 100 20]); PaperType = get(fig,'PaperType'); if(strcmp(PaperType,'usletter')) val = 1; elseif(strcmp(PaperType,'uslegal')) val = 2; elseif(strcmp(PaperType,'a3')) val = 3; elseif(strcmp(PaperType,'a4letter')) val = 4; elseif(strcmp(PaperType,'a5')) val = 5; elseif(strcmp(PaperType,'b4')) val = 6; else val = 7; end uicontrol(PSFigure,'Style','popupmenu',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String','usletter|uslegal|a3|a4letter|a5|b4|tabloid',... 'Value',val,... 'Tag','PaperType',... 'Callback','pgsetup(''PaperType'')',... 'Position',[150 520 140 20]); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'HorizontalAlignment','left',... 'String','Paper Orient.',... 'Position',[150 495 120 20]); Orient = get(fig,'PaperOrientation'); if(strcmp(Orient,'portrait')) val = 1; elseif(strcmp(Orient,'landscape')) val = 2; else val = 3; end uicontrol(PSFigure,'Style','popupmenu',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String','Portrait|Landscape|Tall',... 'Tag','Orient',... 'Value',val,... 'Callback','pgsetup(''Orient'')',... 'Position',[150 475 140 20]); uicontrol(PSFigure,'Style','checkbox',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'Horiz', 'left',... 'String','White bg',... 'Tag','Invert',... 'Value',strcmp(get(fig,'InvertHardCopy'),'on'),... 'Callback','pgsetup(''Invert'')',... 'Position',[300 490 120 22]); uicontrol(PSFigure,'Style','checkbox',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String','To File...',... 'Tag','Tofile',... 'Horiz', 'left',... 'Value', get(findobj('tag', 'PRINTITEM'), 'Userdata'),... 'Callback','set(findobj(''tag'', ''PRINTITEM''), ''Userdata'', get(gco, ''value''))',... 'Position',[300 460 120 22]); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'String','Paper Units',... 'HorizontalAlignment','Left',... 'Position',[300 540 100 20]); PaperUnits = get(fig,'PaperUnits'); if(strcmp(PaperUnits,'inches')) val = 1; elseif(strcmp(PaperUnits,'centimeters')) val = 2; elseif(strcmp(PaperUnits,'normalized')) val = 3; else val = 4; end uicontrol(PSFigure,'Style','popupmenu',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'String','inches|centimeters|normalized|points',... 'Tag','PaperUnits',... 'Value',val,... 'Callback','pgsetup(''PaperUnits'')',... 'Position',[300 520 120 20]); uicontrol(PSFigure,'Style','pushbutton',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'Inter', 'yes',... 'String','Print',... 'Tag','OK',... 'Callback','pgsetup(''Print'')',... 'Position',[320 375 100 25]); uicontrol(PSFigure,'Style','pushbutton',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'Inter', 'yes',... 'String','Cancel',... 'Tag','Cancel',... 'Callback','pgsetup(''Cancel'')',... 'Position',[320 335 100 25]); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'HorizontalAlignment','left',... 'String','Printer',... 'Position',[150 445 140 20]); uicontrol(PSFigure,'Style','popupmenu',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'HorizontalAlignment', 'left',... 'String', PrinterList,... 'Tag','Printer',... 'Value',Device,... 'Callback','pgsetup(''Printer'')',... 'Position',[150 425 270 20]); uicontrol(PSFigure,'Style','Text',... 'BackgroundColor',Bg,... 'ForegroundColor',Txtcolor,... 'HorizontalAlignment','left',... 'String','Window',... 'Position',[70 395 140 20]); uicontrol(PSFigure,'Style','popupmenu',... 'BackgroundColor',Background,... 'ForegroundColor',Foreground,... 'HorizontalAlignment', 'left',... 'String', '',... 'Tag','WINMENU',... 'Value', 1,... 'CallBack', 'pgsetup(''Window'')',... 'Userdata', '',... 'Position',[70 375 220 20]); pgsetup('Window'); axes('Units',PaperUnits,... 'Position',[.7 .25 PaperSize(1)/ShrinkFactor PaperSize(2)/ShrinkFactor],... 'box','on') axis('equal'); axis([0 PaperSize(1) 0 PaperSize(2)]); if(get(findobj(gcf,'Tag','Invert'),'Value')) set(gca, 'color', 'white'); else set(gca, 'color', 'black'); end PlotRect = [PaperPosition(1) PaperPosition(2); PaperPosition(1)+PaperPosition(3) PaperPosition(2); PaperPosition(1)+PaperPosition(3) PaperPosition(2)+PaperPosition(4); PaperPosition(1) PaperPosition(2)+PaperPosition(4)]; PatchObj = patch('XData',PlotRect(:,1),... 'YData',PlotRect(:,2),... 'EdgeColor','w',... 'FaceColor',Bgimage); set(PatchObj,'ButtonDownFcn','pgsetup(''Resize'')'); UserData = [fig;PatchObj;ShrinkFactor]; set(gcf,'UserData',UserData); set(gcf,'PaperPosition',PaperPosition,... 'PaperType',PaperType,... 'PaperOrientation',Orient,... 'PaperUnits',PaperUnits); axis(axis); hold on; elseif(strcmp(command,'DrawPage')) UserData = get(gcf,'UserData'); PatchObj = UserData(2); ShrinkFactor = UserData(3); PaperPosition = get(gcf,'PaperPosition'); PaperUnits = get(gcf,'PaperUnits'); if(strcmp(get(gca,'Units'),'normalized')) set(gca,'units',PaperUnits); else set(gcf,'PaperUnits',get(gca,'Units')); end PaperSize = get(gcf,'PaperSize'); set(gcf,'PaperUnits',PaperUnits); AxPos = get(gca,'Position'); set(gca,'Position',[AxPos(1) AxPos(2) PaperSize(1)/ShrinkFactor PaperSize(2)/ShrinkFactor]); set(gca,'Units',PaperUnits); if(strcmp(PaperUnits,'normalized')) axis('normal'); axis([0 1 0 1]); else axis('equal'); PaperSize = get(gcf,'PaperSize'); axis([0 PaperSize(1) 0 PaperSize(2)]); end PlotRect = [PaperPosition(1) PaperPosition(2); PaperPosition(1)+PaperPosition(3) PaperPosition(2); PaperPosition(1)+PaperPosition(3) PaperPosition(2)+PaperPosition(4); PaperPosition(1) PaperPosition(2)+PaperPosition(4)]; set(PatchObj,'EraseMode','Xor',... 'XData',PlotRect(:,1),... 'YData',PlotRect(:,2)); set(PatchObj,'EraseMode','Normal'); axis(axis); hold on; elseif(strcmp(command,'Resize')) UserData = get(gcf,'UserData'); PatchObj = UserData(2); if(nargin<2) cp = get(gca,'CurrentPoint'); XData = get(PatchObj,'XData'); YData = get(PatchObj,'YData'); minx = min(XData); miny = min(YData); ext = [minx miny max(XData)-minx max(YData)-miny]; set(PatchObj,'UserData',ext); if(cp(1,1)ext(2)+.8*ext(4)) % Upper Left Corner set(gcf,'WindowButtonMotionFcn','pgsetup(''Resize'',''Corner'',2)'); else % Left Side set(gcf,'WindowButtonMotionFcn','pgsetup(''Resize'',''Side'',1)'); end elseif(cp(1,1)>ext(1)+.8*ext(3)) if(cp(1,2)ext(2)+.8*ext(4)) % Upper Right Corner set(gcf,'WindowButtonMotionFcn','pgsetup(''Resize'',''Corner'',3)'); else % Right Side set(gcf,'WindowButtonMotionFcn','pgsetup(''Resize'',''Side'',3)'); end elseif(cp(1,2)>ext(2)+.8*ext(4)) % Top Side set(gcf,'WindowButtonMotionFcn','pgsetup(''Resize'',''Side'',2)') elseif(cp(1,2) 0 & Device < 3 Fext='*.ps'; end if Device > 2 & Device < 7 Fext='*.eps'; end if Device == 7 Fext='*.hpgl'; end if Device == 8 Fext='*.adb'; end output=get(findobj('tag', 'PRINTITEM'), 'userdata'); if output==1 % FILE [name, path] = uiputfile([savepath Fext]); if isempty(name) | name == 0 return end PTRname = [path name]; pmsg=PTRname; else PTRname=''; pmsg=printopt; end wm=findobj('tag', 'WINMENU'); spf=findobj('name', 'Printer Setup'); hfigs=get(wm, 'Userdata'); n=get(wm, 'value'); pu=get(spf,'PaperUnits'); pt=get(spf,'PaperType'); po=get(spf,'PaperOrientation'); pp=get(spf,'PaperPosition'); pi=get(spf,'InvertHardCopy'); delete(findobj('name', 'Printer Setup')); set(Handlefig,'Pointer','watch'); if hfigs(n)==0 hfigs=hfigs(2:length(hfigs)); else hfigs=hfigs(n); end for i=1:length(hfigs) if i==1 cprint=['print ' Printer(Device,:) ' ' PTRname]; else cprint=['print ' Printer(Device,:) ' -append ' PTRname]; end if isobj(hfigs(i)) set(hfigs(i),'PaperUnits',pu); set(hfigs(i),'PaperType',pt); set(hfigs(i),'PaperOrientation',po); set(hfigs(i),'PaperPosition',pp); set(hfigs(i),'InvertHardCopy',pi); fcolor=get(hfigs(i),'color'); if onoff(pi) & ~any(fcolor==[0 0 0]) set(hfigs(i), 'color', [0 0 0]); end figname=get(hfigs(i), 'name'); if isempty(figname) figname=['Figure No. ' num2str(hfigs(i))]; end statusbar(['Printing ' figname ' to ' pmsg]); figure(hfigs(i)); eval(cprint); set(hfigs(i), 'color', fcolor); end end set(Handlefig,'Pointer','arrow'); clearstatusbar; elseif(strcmp(command,'Window')) FigureListLab='All Windows'; FigureList=[0]; figs=findobj(0, 'type', 'figure'); for i=1:length(figs) figname=get(figs(i), 'name'); if isempty(figname) figname=['Figure No. ' num2str(figs(i))]; end if ~strcmp(figname, 'Printer Setup') FigureListLab=[FigureListLab '|' figname]; FigureList=[FigureList figs(i)]; end end wm=findobj('tag', 'WINMENU'); if isobj(wm) set(wm, 'string', FigureListLab, 'Userdata', FigureList); end end return