;+ ; NAME: ; PRINTWINDOW ; ; PURPOSE: ; The purpose of this program is to provide a quick-and-easy way to print ; the current IDL Direct Graphics window (!D.WINDOW) to the printer device ; centered on a 8.5" x 11" piece of paper with 1" margins (if needed). These ; margins will only be accurate if the unprintable area for the printer ; is set to zero. If the printer and/or its driver has margins (i.e. ; unprintable area) already specified this will offset the IDL output. ; This routine attempts to match the size of the print to the size of ; the graphics window on the monitor. ; ; CATEGORY: ; Visual ; ; CALLING SEQUENCE: ; PRINTWINDOW ; ; INPUT PARAMETERS: ; None. ; ; KEYWORD PARAMETERS: ; None. ; ; OUTPUTS: ; None. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None. ; ; DISCLAIMER: ; This procedure is provided "as is" and is not supported or ; maintained by Research Systems Inc. ; ; MODIFICATION HISTORY: ; Written by: Adam Bielecki, April 2000. ;- PRO PRINTWINDOW ;obtain current device: currdevice=!D.NAME ;error catching: !error_state.code=0 catch,error if error NE 0 then begin help,/last_message,output=traceback errarray=['Error Caught',traceback] dummy=dialog_message(errarray,/error,/cancel) if STRUPCASE(dummy) EQ 'CANCEL' then begin if !D.NAME EQ 'PRINTER' and size(scale,/type) NE 0 then device,scale_factor=scale set_plot,currdevice return endif endif ;obtain current device resolution: xppi=!D.X_PX_CM*2.22 yppi=!D.Y_PX_CM*2.22 ;Note: conversion factor of 2.22 is used instead of 2.54 in order to make ;sure output is at least as big as graphics window due to device dependant ;inaccuracies in the !D.X_PX_CM and !D.Y_PX_CM system variables ; ;check to make sure IDL graphics window is open: if !D.WINDOW EQ -1 then begin dummy=DIALOG_MESSAGE('No IDL graphics windows currently open !',/error) return endif ;query visual class and TVRD the current graphics window: if !D.N_COLORS GT 256 then begin image=TVRD(true=3) color_mode=24 endif else begin image=TVRD() color_mode=8 endelse ;change to the PRINTER device: SET_PLOT,'PRINTER' ;present the user with printer properties dialog: dummy=DIALOG_PRINTERSETUP() if (dummy EQ 0) then begin print,'// % PRINTCENTER WAS TERMINATED % \\' set_plot,currdevice return endif else begin ;obtain original scale factor: help,/dev,output=orig scalepos=STRPOS(STRUPCASE(orig),'SCALE FACTOR') scaleindex=WHERE(scalepos NE -1,count) if count EQ 0 then begin dummy=dialog_message('Indeterminable Scale Factor for PRINTER device',/error) set_plot,currdevice return endif scaleindex=scaleindex[0] scalepos=scalepos[scaleindex]+13 scale=STRMID(orig[scaleindex],scalepos) scale=float(scale) ;set scale factor equal to one: device,scale_factor=1 ;compute size of graphic in inches: ncols=(SIZE(image))[1] nrows=(SIZE(image))[2] xsize=ncols/xppi ysize=nrows/yppi if xsize LE 6.5 and ysize LE 9 then begin ;graphic does NOT have to be reduced in resolution: device,xoffset=0,yoffset=0,xsize=xsize,ysize=ysize,/inches xmarg=(8.5-xsize)/2 ymarg=(11-ysize)/2 if color_mode EQ 24 then TV,image,xmarg,ymarg,true=3,xsize=xsize,ysize=ysize,/inches if color_mode EQ 8 then TV,image,xmarg,ymarg,xsize=xsize,ysize=ysize,/inches DEVICE,/CLOSE endif else begin ;otherwise, find limiting dimension and reduce resolution accordingly: xfac=6.5/xsize yfac=9/ysize if yfac LT xfac then begin ;the Y dimension is the limiting factor: newxsize=xsize*yfac newysize=ysize*yfac device,xoffset=0,yoffset=0,xsize=newxsize,ysize=newysize,/inches xmarg=(8.5-newxsize)/2 ymarg=(11-newysize)/2 if color_mode EQ 24 then TV,image,xmarg,ymarg,true=3,xsize=newxsize,ysize=newysize,/inches if color_mode EQ 8 then TV,image,xmarg,ymarg,xsize=newxsize,ysize=newysize,/inches DEVICE,/CLOSE endif else begin ;the X dimension is the limiting factor: newxsize=xsize*xfac newysize=ysize*xfac device,xoffset=0,yoffset=0,xsize=newxsize,ysize=newysize,/inches xmarg=(8.5-newxsize)/2 ymarg=(11-newysize)/2 if color_mode EQ 24 then TV,image,xmarg,ymarg,true=3,xsize=newxsize,ysize=newysize,/inches if color_mode EQ 8 then TV,image,xmarg,ymarg,xsize=newxsize,ysize=newysize,/inches DEVICE,/CLOSE endelse endelse ;reset scale factor to original: device,scale_factor=scale endelse ;reset current device to original: SET_PLOT,currdevice END