Re: Window Contents Directly to Printer [message #11230] |
Thu, 19 March 1998 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Hi Folks,
For some inexplicable reason I wrote a piece of code
like this in my earlier PRINT_IT program this morning:
> ; Print it.
>
> Device, Portrait=(NOT landscape), Scale_Factor=scalefactor
The only thing I can think is that my brain was addled by
shovelling 16 inches of snow off my rather large driveway
without the help of my supposedly strong and able sons.
This should, of course, look like this:
Device, Landscape=landscape, Scale_Factor=scalefactor
Sorry for the confusion. :-)
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Window Contents Directly to Printer [message #11236 is a reply to message #11230] |
Thu, 19 March 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Hi Folks,
If anyone is following along or thinks this program is the
least bit useful, here is the final PRINT_IT program that
Armand and I have come up with. I got some help from the
usual anonymous lurkers, as well. :-)
I'll put this on my web page later today.
Cheers,
David
;----------------------------------------------------------
PRO Print_It, wid, Landscape=landscape, NoScale=noscale, $
NoCenter=nocenter
; This program sends the contents of the specified
; window to the default printer. The current window
; is used if a window index number is not provided.
; This program was originally written by David Fanning
; using advice from RSI. It was extensively modified and
; improved by Armand J.L. Jongen and others on the IDL newsgroup.
; KEYWORD PARAMETERS:
;
; LANDSCAPE If this keyword is set, the output is in Landscape
; mode. Otherwise, Portrait mode is used.
;
; NOSCALE If this keyword is set, the output is not scaled
; to fill the page, but is left in its actual
; device coordinate size.
;
; NOCENTER If this keyword is set, the output is positioned
; in the lower-left corner of the display. Otherwise,
; the output is centered on the page.
; Check parameters.
IF N_Params() EQ 0 THEN wid = !D.Window
landscape = Keyword_Set(landscape)
noscale = Keyword_Set(noscale)
nocenter = Keyword_Set(nocenter)
; Make the window current. Get contents.
WSet, wid
contents = TVRD()
; Get the sizes of the window.
xsize = !D.X_Size
ysize = !D.Y_Size
; Change the current device to PRINTER. Copy color table.
thisDevice = !D.Name
Set_Plot, 'PRINTER', /Copy
; Reset the PRINTER for proper calculations.
Device, Scale_Factor=1, Portrait=1
; Get the sizes for the PRINTER device.
; If the Landscape keyword is set, swap PRINTER sizes.
IF landscape THEN BEGIN
pxsize = !D.Y_Size
pysize = !D.X_Size
ENDIF ELSE BEGIN
pxsize = !D.X_Size
pysize = !D.Y_Size
ENDELSE
; Calculate a scale factor for the printer.
IF noscale THEN scalefactor = 1 ELSE $
scalefactor = 1.0 / ((Float(xsize)/pxsize) > (Float(ysize)/pysize))
; Do you want the output centered?
IF nocenter THEN BEGIN
xoffset = 0
yoffset = 0
ENDIF ELSE BEGIN
; Calculate offsets to center ouput. The offsets
; will be scaled later by the device so be sure to
; divide by the scale factor.
xoffset = Fix((Float(pxsize)/scalefactor - xsize)/2.0)
yoffset = Fix((Float(pysize)/scalefactor - ysize)/2.0)
ENDELSE
; Print it.
Device, Portrait=(NOT landscape), Scale_Factor=scalefactor
TV, contents, xoffset, yoffset, /Device
Device, /Close_Document
; Clean up.
Set_Plot, thisDevice
END
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Window Contents Directly to Printer [message #11237 is a reply to message #11230] |
Thu, 19 March 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Armand J.L.Jongen (a.j.jongen@amc.uva.nl) writes:
> I hope I stand a change with my version of Print_It. It works on my
> printer :-)) Looking forward to your comments.
Well, all right, Armand. Nice job! I think this meets the
criteria for a prize winner. Your book is on its way and
I'll put your entry prominently on display on my web page.
But first I'm going to change your Scale keyword to NoScale,
so that filling up the page is the default behaviour. I
think this is more in keeping with what the PRINTER device
does otherwise. It's my only quibble with what you have
done.
I think it is just a *little* bit unfair, though, that
you have so much time to work on this. Now, PLEASE quit
procrastinating and finish up that research article! :-)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Window Contents Directly to Printer [message #11241 is a reply to message #11230] |
Thu, 19 March 1998 00:00  |
Armand J. L. Jongen
Messages: 9 Registered: April 1997
|
Junior Member |
|
|
David Fanning wrote:
> I leave it as an exercise for the reader to figure out
> how to print in landscape mode. And if someone can figure
> out how to center the window contents on the page, I'll
> send them my favorite Barry Lopez book, *Desert Notes/
> River Notes*. :-)
>
> Cheers,
>
> David
>
I hope I stand a change with my version of Print_It. It works on my
printer :-)) Looking forward to your comments.
Cheers,
Armand
--
************************************************************ ************
Armand J.L. Jongen Academic Medical Centre
Laser Centre
Phone +31-20-5667418 \\||||// Meibergdreef 9
Fax +31-20-6975594 | ~ ~ | 1105 AZ Amsterdam
E-mail a.j.jongen@amc.uva.nl [| o o |] The Netherlands
*****************************o00o***(__)***o00o************* ************
**********************************************************
PRO Print_It, wid, Landscape=Landscape, Scale=Scale,
NotCentered=NotCentered
; This program sends the contents of the specified
; window to the default printer. The current window
; is used if a window index number is not provided.
; KEYWORD PARAMETERS:
; LANDSCAPE = If set it prints in Landscape mode.
; Portrait is default.
; SCALE = If set the Window-contents is scaled
; to fill the page. Default is no scaling
; NotCentered = If set the Window-contents is not centered
; on the page. By default the contents
; will be centered.
IF N_Params() EQ 0 THEN wid = !D.Window
IF Keyword_set(Landscape) Then Portrait=0 ELSE Portrait=1
IF Keyword_set(Scale) Then Scale=1 ELSE Scale=0
IF Keyword_set(NotCentered) Then Center=0 ELSE Center=1
; Make the window current. Get contents.
WSet, wid
contents = TVRD()
; Get the sizes of the window.
xsize = !D.X_Size
ysize = !D.Y_Size
; Change the current device to printer
thisDevice = !D.Name
Set_Plot, 'PRINTER'
; Always set the scaling back to one first and
; also set back to portrait for proper calculations
Device, Scale_Factor=1
Device, /Portrait
; Get the sizes of the PRINTER device.
; If the Landscape keyword was set, swap px and py sizes
If (Portrait) Then Begin
pxsize = !D.X_Size
pysize = !D.Y_Size
EndIf Else Begin
pxsize = !D.Y_Size
pysize = !D.X_Size
EndElse
; Calculate a scale factor for the printer
; if the keyword Scale is set.
If Scale Then Begin
scalefactor = 1.0/((Float(xsize) / pxsize) > (Float(ysize) / pysize))
EndIf ELSE scalefactor=1
If Center Then Begin
; Calculate the offsets to center the thing
; The will also be scaled later by the device so
; devide by scalefactor
xoffset=FIX((Float(pxsize)/scalefactor - xsize)/2.0)
yoffset=FIX((Float(pysize)/scalefactor - ysize)/2.0)
Endif Else Begin
; No centering so no offset
xoffset=0
yoffset=0
Endelse
; Print it.
Device, Portrait=Portrait
Device, Scale_Factor=scalefactor
TV, contents, xoffset, yoffset,/Device
Device, /Close_Document
; Clean up.
Set_Plot, thisDevice
END
**********************************************************
|
|
|