NEXTSTEP Printing Development Q&A

Creation Date: Jul 27, 1998
Keywords: NeXTSTEP

Disclaimer

This document pertains to the NeXTSTEP operating system, which is no longer a supported product of Apple Computer.  This information is provided only as a convenience to our customers who have not yet upgraded their systems, and may not apply to OPENSTEP, WebObjects, or any other product of Apple Enterprise Software.  Some questions in this Q&A document may not apply to version 3.3 or to any given specific version of NeXTSTEP.

Q: During printing, the view that is printing can't also write to the screen using a modal panel.  If I want to query the user for values to pass to the printing machinery while printing, such as adjusting the percentage of a view to be pushed to the next page, I can't use NXRunAlertPanel().

A: Yes, this is true.  During printing the active PostScript context is pointing at the printerÐthus all PostScript to draw your panel goes to the printer and not the screen. The solution is to temporarily divert the PostScript to the Window Server context with something like:

	{
		DPSContext oldContext;
		short oldStatus;
		
		oldContext = DPSGetCurrentContext();
		DPSSetContext([NXApp context]);	// talk to the server
		oldStatus = NXDrawingStatus;
		NXDrawingStatus = NX_DRAWING;

		// You can do drawing to the screen here; use
		// NXRunAlertPanel(), etc...

		NXDrawingStatus = oldStatus;
		DPSSetContext(oldContext);	// return to talking to printer
	}

Q:  I have implemented the setScalingFactor: method of PrintInfo in order to scale my printed output.  It does not seem to be having any effectÐmy printed output is always 100% of original size.  What could be wrong?
	
A:  Have you set your Window or View subclass to override knowsPagesFirst:last: to return YES and are you computing your own page rectangles with getRect:forPage:?  Then that View is claiming that it knows how to paginate itself and the setScalingFactor: method of PrintInfo has no effect.  

By not automatically scaling the printing, the AppKit allows you to decide how scaling affects pagination.  Scaling by 50%, for example, should always cause the view to be 50% smaller in both directions, so what was a full-sized page now only takes up a quarter of a page.  However you must decide whether each scaled page continues to be printed on a separate piece of paper or whether you group four of the scaled pages on each piece of paper.
 
In either case, the correct way to get your scaled view to print scaled is to override the View method addToPageSetup and use the PSscale() pswrap function to set your scaling factor appropriately:

	-addToPageSetup
	{
	    [super addToPageSetup];
	    PSscale(width_scale, height_scale);
	    return self;
	}