;+ ; NAME: ; set_page ; PURPOSE: ; Setup procedure for controlling output to plot device or graphics file ; The output procedure is completed by a call to href=get_page= ; CALLING SEQUENCE: PRO set_page, $ eps = eps , $ gif = gif , $ bmp = bmp , $ png = png , $ xysize = xysize , $ aspect = aspect , $ fullsize = fullsize , $ winaspect = winaspect , $ landscape = landscape , $ portrait = portrait , $ silent = silent , $ setup_only = setup_only, $ file = file , $ zbuffer = zbuffer , $ printer = printer , $ display = display , $ ctable = ctable , $ old_device = old_device, $ new = new , $ bigsize = bigsize , $ xoff = xoff , $ yoff = yoff , $ smallsize = smallsize , $ notwin = notwin , $ font = font ; OPTIONAL INPUT PARAMETERS: ; The following keywords control the size and orientation of the output page. ; They only affect EPS, PS, HP or PRINTER devices (as keywords in the 'device' ; call). EPS is selected with the /eps keyword. PS, HP and PRINTER is used ; depending on !ThePrinter (initialized during startup). ; ; /landscape plot in landscape mode ; /portrait plot in portrait mode ; If neither of these is set then /landscape is used ; Only used to set up PS, EPS or default PRINTER. ; xysize=xysize scalar, or array[2]; type: float ; horizontal and vertical size of page (in cm for printer, ; in pixel for display and z-buffer). If a scalar is ; specified it is assumed to be the horizontal size ; /fullsize overrides 'xysize' keyword. For the printer xysize is set ; to the full page size, for other devices [!d.x_size, ; !d.ysize] is used ; ; If xysize is not specified then default values are selected ; depending on whether /landscape of /portrait is used. ; If specified then aspect (or /winaspect) overrides either ; xsize of ysize to establish the proper aspect. ; ; aspect=aspect scalar; type: float ; aspect ratio (=ratio vertical/horizontal size ; /winaspect same as: aspect = !d.y_size/!d.x_size ; i.e. the aspect ratio of the active window is used ; /silent suppresses informational messages ; /setup_only the command 'set_page, /setup, /silent' is used during ; IDL_startup to set up the default printer. The plot ; device is NOT changed, and !ThePlotFile is NOT set (i.e. ; is set to the null string) ; ; /eps sets the plot device to PS and opens an EPS file ; !ThePlotFile is set to IDL.EPS or 'File' ; /gif sets the plot device to !TheTerminal ; !ThePlotFile is set to IDL.GIF or 'File' ; /png sets the plot device to !TheTerminal ; !ThePlotFile is set to IDL.PNG or 'File' ; /bmp sets the plot device to !TheTerminal ; !ThePlotFile is set to IDL.BMP or 'File' ; /zbuffer NOT WORKING YET ; OUTPUTS: ; xysize=xysize array[2]; type: integer ; [!d.x_size, !d.y_size] on return ; old_device=old_device ; scalar; type: string ; original graphics device (i.e. value of !d.name when ; this procedure is called) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, SetFileSpec, GetFileSpec, reset_colors, do_file ; destroyvar ; SEE ALSO: ; qset_page ; PROCEDURE: ; Pretty darn ugly. ; The plot device is set to !ThePrinter, or PS (if /eps is set) or ; !TheTerminal (if /gif or /bmp are set). ; !ThePlotFile is always set. Unless argument 'File' is used ; the file name will be IDL.EPS, IDL.GIF or IDL.BMP (if /eps, /gif or /bmp are ; set) or IDL.HP, IDL.PS or IDL.PRINTER (depending on the value of ; !ThePrinter). Note that in the last case (IDL.PRINTER) no plot file is used ; since the output goes directly to the printer. ; For HP and PS the graphics output is collected in the output file, which is ; then send to the printer using href=get_page= ; MODIFICATION HISTORY: ; MAR-1995, Paul Hick (UCSD/CASS) ; MAR-1998, Paul Hick (UCSD/CASS); added PRINTER device ; MAR-2000, Paul Hick (UCSD/CASS) ; added /gif and /bmp keywords, updated documentation ; ???-2002, Paul Hick (UCSD/CASS) ; added /png keyword ; AUG-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; added /color to device call for EPS ;- ; If argument 'file' is defined, use it to determine the type ; of output image. Otherwise use keywords /gif,/png,/bmp,/eps CASE IsType(file, /defined) OF 0: BEGIN InitVar, gif, /key InitVar, png, /key InitVar, bmp, /key InitVar, eps, /key END 1: BEGIN SetFileSpec, file type = strlowcase(GetFileSpec(part='type')) gif = type EQ '.gif' png = type EQ '.png' bmp = type EQ '.bmp' eps = type EQ '.eps' END ENDCASE ; The output device is either set explicitly or is implied by the ; type of output image, e.g. /eps implies printer device. InitVar, zbuffer , /key InitVar, display , /key InitVar, printer , /key InitVar, notwin , /key printer = printer OR eps display = display OR (1-zbuffer AND (gif OR png OR bmp)) OR (1-zbuffer AND 1-printer) InitVar, landscape , /key ; The default is landscape InitVar, portrait , /key InitVar, winaspect , /key InitVar, fullsize , /key InitVar, silent , /key InitVar, setup_only , /key CASE IsType(file, /defined) OF 0: BEGIN CASE 1 OF eps : printer = 1 ELSE: IF NOT zbuffer AND NOT printer THEN display = 1 ENDCASE CASE 1 OF gif : type = '.gif' png : type = '.png' bmp : type = '.bmp' eps : type = '.eps' printer : type = '.'+strlowcase(!ThePrinter ) zbuffer : type = '.z' display : type = '.'+strlowcase(!TheTerminal) ENDCASE !ThePlotFile = filepath(root=getenv('TUB'),'idl'+string(fix(10000*randomu(s)), format='(I5.5)')+strlowcase(type)) END 1: BEGIN printer = type EQ '.'+strlowcase(!ThePrinter ) !ThePlotFile = file END ENDCASE landscape = landscape or 1-portrait portrait = 1-landscape old_device = !d.name IF NOT silent THEN $ IF type NE '.z' AND type NE '.x' THEN $ message, /info, 'using '+type+' file '+!ThePlotFile ; Page size and margin offset for Laserjet III printer ; xoff=0.32, yoff=1.91 for LJ III (???) ; xoff=10,yoff=20 is for HP LJ1012 ; xoff= 6,yoff= 9 is for HP LJ4000 InitVar, bigsize , 24.75 ; Full page height for A4 form in cm (9900 pix) InitVar, smallsize, 18.10 ; Full page width for A4 form in cm (7240 pix) InitVar, xoff, 6.0 InitVar, yoff, 9.0 xspec = n_elements(xysize) GE 1 ; Explicit x-size specified yspec = n_elements(xysize) GE 2 ; Explicit y-size specified CASE fullsize OF 0: BEGIN IF xspec THEN xs = xysize[0] IF yspec THEN ys = xysize[1] CASE printer OF 0: BEGIN IF NOT xspec THEN xs = !d.x_size IF NOT yspec THEN BEGIN IF xspec THEN ys = xs ELSE ys = !d.y_size ENDIF END 1: BEGIN xspage = landscape*bigsize +portrait*smallsize yspage = landscape*smallsize+portrait*bigsize pageaspect = float(xspage)/float(yspage) CASE 1 OF xspec AND yspec: BEGIN aspect = float(ys)/float(xs) IF xs GT xspage THEN BEGIN xs = xspage ys = xs*aspect ENDIF IF ys GT yspage THEN BEGIN ys = yspage xs = ys/aspect ENDIF destroyvar, aspect END xspec: BEGIN xs = xs < xspage ys = xs*pageaspect END yspec: BEGIN ys = ys < yspage xs = ys/pageaspect END ELSE: BEGIN xs = !d.x_size ys = !d.y_size aspect = float(ys)/float(xs) IF xs GT xspage THEN BEGIN xs = xspage ys = xs*aspect ENDIF IF ys GT yspage THEN BEGIN ys = yspage xs = ys/aspect ENDIF destroyvar, aspect END ENDCASE END ENDCASE IF winaspect THEN aspect = float(!d.y_size)/!d.x_size IF IsType(aspect, /defined) THEN BEGIN defaspect = ys/xs IF aspect LT defaspect OR xspec THEN ys = aspect*xs IF aspect GT defaspect OR yspec THEN xs = ys/aspect ENDIF END 1: BEGIN CASE printer OF 0: BEGIN xs = !d.x_size ys = !d.y_size END 1: BEGIN xs = landscape*bigsize +portrait*smallsize ys = landscape*smallsize+portrait*bigsize END ENDCASE CASE 1 OF xspec AND yspec : aspect = float(xysize[1])/xysize[0] winaspect : aspect = float(!d.y_size)/!d.x_size ENDCASE IF IsType(aspect, /defined) THEN BEGIN defaspect = ys/xs IF aspect LT defaspect OR xspec THEN ys = aspect*xs IF aspect GT defaspect OR yspec THEN xs = ys/aspect ENDIF END ENDCASE ; !!! IDL puts the HP-GL2 command R90; (which rotates the coordinate system ; over 90 deg) at the beginning of the plot file. Effectively this changes ; landscape to portrait and v.v. Hence the next line: IF !ThePrinter EQ 'HP' THEN landscape = 1-landscape portrait = 1-landscape IF printer THEN IF NOT silent THEN message, /info, $ ; Show page layout (['LANDSCAPE','PORTRAIT'])[portrait]+' ('+strcompress(xs,/rem)+'x'+strcompress(ys,/rem)+' cm)' CASE 1 OF zbuffer OR display: BEGIN IF zbuffer THEN ch_size = [!d.x_ch_size, !d.y_ch_size] Terminal = ([!TheTerminal,'Z'])[zbuffer] IF !d.name NE Terminal THEN set_plot, Terminal ; Switch to terminal CASE zbuffer OF 0: IF NOT notwin THEN twin, xsize=xs, ysize=ys, new=new 1: device, z_buffering=0, set_character_size=ch_size, set_resolution=[xs,ys] ENDCASE reset_colors IF IsType(ctable,/defined) AND !d.n_colors EQ 256 THEN loadct, ctable, /silent END eps: BEGIN IF !d.name NE 'PS' THEN set_plot, 'PS' ; Switch to PostScript device IF IsType(font,/defined) THEN !p.font = font ELSE !p.font = 1 device, portrait=portrait, xsize=xs, ysize=ys, $ /encapsulated, file=!ThePlotFile, set_font='times', /color ;device, portrait=portrait, xsize=xs, ysize=ys, /encapsulated, file=!ThePlotFile END printer: BEGIN IF !d.name NE !ThePrinter THEN set_plot, !ThePrinter; Switch to plot device ; Just setting portrait=0 does NOT put the HP printer in landscape mode. ; As a safety we specify portrait AND landscape keyword. CASE !ThePrinter OF 'HP': device, portrait=portrait, landscape=landscape, xsize=xs, ysize=ys, xoffset=xoff, yoffset=yoff, file=!ThePlotFile, xon_xoff=0 'PS': device, portrait=portrait, xsize=xs, ysize=ys, xoffset=xoff, yoffset=yoff, file=!ThePlotFile 'PRINTER': BEGIN catch, ierr IF ierr EQ 0 THEN BEGIN ; Do NOT merge these two device statements !!!!! The page size is ; not always processed properly, if the orientation is changed and ; the size is set in a single device call. device, portrait=portrait device, xsize=xs, ysize=ys, xoffset=xoff, yoffset=yoff ENDIF catch, /cancel END ELSE: BEGIN message, /info, !ThePrinter+' device not implemented' !ThePlotFile = '' END ENDCASE END ENDCASE xysize = [!d.x_size,!d.y_size] IF NOT silent THEN message, /info, '!D.NAME='+!d.name IF setup_only THEN BEGIN ; The device command opens a new plot file. Close and delete it here when ; /setup_only is set. IF !d.name ne 'PRINTER' THEN BEGIN device, /close i = do_file(!ThePlotFile, /delete, silent=silent) ENDIF IF !d.name ne old_device THEN BEGIN set_plot, old_device reset_colors ENDIF !ThePlotFile = '' ENDIF RETURN & END