TweetFollow Us on Twitter

December 93 - PRINT HINTS

PRINT HINTS

LASERWRITER 8 FOR FUN AND PROFIT

MATT DEATHERAGE

[IMAGE 076-080_Print_Hints_rev1.GIF]

In May of this year, Apple and Adobe Systems released version 8.0 of the LaserWriter driver -- the biggest change to PostScript® printing on the Macintosh in eight years. This new driver was rewritten from the ground up by engineers at Adobe, working closely with Apple engineers who provided source code, guidance, and comprehensive testing. The resulting driver unleashes the power of PostScript Level 2 printing as much as possible under the limitations of the pre-QuickDraw GX printing architecture.

Since the driver has been in general release for quite some time, we won't go through feature lists or repeat things you've seen printed elsewhere. Instead we'll focus on how your application can compatibly take advantage of the new driver's power. We'll also note some programming practices that cause problems with LaserWriter 8 and that will continue to cause grief in the future with QuickDraw GX.

WHERE TO FIND INFORMATION
The best news for programmers about this driver is that there's more information available for this driver than for any printer driver before it. It follows the standard Printing Manager API documented inInside MacintoshVolumes II and V, which you should stop reading immediately when you can grab Inside Macintosh: Imaging With QuickDraw. The new book has vastly superior organization and information about printing, including what's covered in the older Macintosh Technical Notes, Q&As, and other sources of information Apple has refined through the years. Even if you don't yet have the new book, everything in the older volumes and in the Technical Notes is still valid, with few exceptions.

In addition, this issue's CD contains a 25-page document called "Developer Information," located in the LaserWriter 8 folder, that talks about differences between the old and new drivers. Since this driver was in open beta test from October 1992 through May 1993 as "PSWriter," the changes shouldn't surprise too many people. The "Developer Information" document has been available since October 1992 as well, so all kinds of great information have been at your fingertips for quite some time.

THE GROUND RULE
The new driver has several exciting new API calls to assist with PostScript printing and translation. However, before getting into them, we must state The Ground Rule: While you're encouraged to use new LaserWriter 8 features where appropriate, your application should not depend on them. Your handling of printing or key services should not fail if the features aren't available.

Some users may not have upgraded to LaserWriter 8, and some may be running specialized versions of the older driver and don't want to give it up. More important, however, is that the new API features provided through PrGeneral arenot present in QuickDraw GX. In its initial release, QuickDraw GX makes it easy for PostScript printer manufacturers to create their own drivers supporting all their printer-specific features; under the old architecture this was about as easy as removing your eyeballs from their sockets with your toes. This means there's a chance that a customer will have softwarebeyondLaserWriter 8 that doesn't support the new calls documented on the CD, so use them only if they're present.

For example, if you have an application that uses PostScript printer description (PPD) files to obtain information about a target printer, you can use the new driver's PSPrimaryPPDOp selector to PrGeneral to obtain an FSSpec referencing the PPD file the user chose for the current printer in the Chooser. However, if the driver isn't available, the new PrGeneral calls return the error opNotImpl (opcode not implemented) or resNotFound (the current driver doesn't support PrGeneral). In this case, you should ask the user to locate the PPD file just as you did before LaserWriter 8 was available. You shouldnot display an alert saying "You have the wrong printer driver chosen; go fix it."

Another example is in the powerful new functions that the driver provides for converting QuickDraw pictures to encapsulated PostScript (EPS) format. If using these functions allows you to export EPS data in a cross-platform document for higher fidelity on another system, that's great. If the driver isn't available, though, you need to create your own EPS data or provide some alternate representation of the data (perhaps a bitmap or a TIFF image).

Remember, these functions are there to use if they're available, but you can't require them. It's not fair to remove features from your application based on the printer driver version. Try to use them if you need to, but be prepared for when they're not present.

Sample code that helps explain the new features is also on the CD, in the same folder as the new driver.

NEW THINGS YOU CAN DO
With that caveat on the table, let's discuss how some of the new features might affect your program. There isn't room here to cover all the new APIs or their uses, so be sure to check out the documentation and sample code on the CD for the comprehensive scoop.

PostScript printer description files. In addition to using PPD files in applications, some people will need to create PPD files for custom in-house purposes, or because they're developing PostScript-compatible hardware. There's a trick that's undocumented (and unguaranteed, so don't write code that depends on this!) which lets the driver help you debug your PPD files: Normally, when the driver parses a PPD file (during Chooser selection), it puts up a simple error dialog saying "This PPD is invalid" if it finds a problem with the file. However, the driver has a resource of type 'PLRT' with ID 1 that contains a single byte, normally 0. If you change this byte to $01, the driver will display an alert during PPD parsing saying exactly what it didn't like and on what line it didn't like it. Since PPD files can get fairly complicated in short order, this feature can be extremely helpful.

This preference is stored in a PLRT resource only in versions 8.0 and 8.0.1 (shipping with Adobe Acrobat). In later releases, it will be combined with some other useful preferences in a PRFS resource. There's a resource editor TMPL template describing the bits in the PRFS resource. One of these bits tells the driver to write all Printer Access Protocol (PAP) transactions to a PAPToDisk file so that you can debug your printing code's output. This lets you see what the driver generates during normal printing (not what it generates in the special case of creating a PostScript file) and is quite handy. Have fun with the preferences, but remember not to ship code that relies on them -- don't modify them from your code.

Dealing with EPS files. The older LaserWriter driver had been creating PostScript files as a debugging aid for several years, and in version 7.0 this feature was finally added to the print job dialog so that users could visibly control it. In 8.0, the file creation mechanism has been further improved: it now provides user control over PostScript language level, font inclusion, and ASCII or binary protocol, and can create EPS files on request. Since so many applications understand EPS files, this feature gets a lot of exercise, and fosters some misunderstandings. The encapsulated PostScript file format version 3.0 is discussed in Appendix H of Adobe'sPostScript Language Reference Manual, Second Edition (the "red book"). The red book clearly states that an EPS file describes animage of a single page. That's why printing a range of pages to an EPS file gives you an image of only the first page -- you can't have an image of more than one page in an EPS file.

The main problem users are having with EPS files created by the driver, however, is with the EPS preview. This preview is an optional PICT resource of ID 256 which, if present, contains a QuickDraw picture resembling what a PostScript interpreter would produce after executing the EPS code.

LaserWriter 8 does previews in three ways: it creates a picture that's one giant bitmap or pixel map ("standard preview"); it creates a picture containing all the drawing commands used to draw the page ("enhanced preview"); or it doesn't create a preview at all. The choice is the user's, or at least it'ssupposed to be. Some applications don't like the word "optional" very much and refuse to import EPS files that don't contain the "optional" preview. Don't make the mistake of considering the preview to be required.

Since the information for the preview picture comes from the drawing your application does into the printing grafPort, there's trouble if your application doesn't draw things as the driver expects. For example, some applications still examine the high byte of the wDev field in the print record and, if they find the value 3, assume they're talking to a PostScript printer.

Such programs send all their data to be printed as custom PostScript code, not drawing anything into the printing grafPort. This makes for an extremely boring preview image -- your code didn't draw anything, so there's nothing in there to display.

If you create your own PostScript code,alwayssend dual QuickDraw and PostScript information when printing or exporting pictures. Never create PostScript code without making as faithful a QuickDraw representation as you can. Not only does this prevent EPS preview problems with LaserWriter 8, it prevents problems under QuickDraw GX, where users can redirect print files after you've finished your print loop but before they're imaged on a printer. If you sent only PostScript code and the user redirects the print job to a StyleWriter II because the PostScript printer is busy, the result will be a bunch of blank pages.

Some people have asked why EPS files created by the driver seem to be the size of a printed page when the real image is only a small part of the page. That happens when your application doesn't change the clipping rectangle for the image it's printing and when you send no QuickDraw code, but only PostScript code. The driver watches all drawing you perform in the printing grafPort to calculate the bounding rectangle for the EPS file; it has no way of knowing what that rectangle would be for any PostScript code you send, so it relies on the clipping rectangle when your PostScript code is sent through the printing grafPort. Use ClipRect to set the clipping rectangle of the printing grafPort to match the height and width of your image. The driver will accumulate all your clipping rectangles and make the bounding rectangle of the EPS file the smallest rectangle that encloses all of them plus the bounding rectangles of all QuickDraw drawing you performed. If you send both QuickDraw and PostScript code as recommended, you won't have this problem.

OLD THINGS THAT ARE DIFFERENT NOW
Some things are bound to change when you rewrite code from the ground up -- mostly implementation details that were never guaranteed. That doesn't stop enterprising programmers from finding such details and using them, though, and that's where a lot of compatibility problems occur. Here are some things that have changed in the new driver that shouldn't have affected your programs, but might have anyway.

Using private PostScript operators. Apple has advised programmers for a long time not to use "Laser Prep" or "md" dictionary operators -- private PostScript operators used by the LaserWriter driver to get its work done. Those operators were never documented or guaranteed to work, and as the driver changed over the years so did many of the procedures, breaking applications that relied on them. It's no big surprise that almost every one of those operators is either gone or changed in the new driver. There's been some confusion in the past about just what Apple was trying to warn against, so I'm pleased to take this opportunity to make it very clear:If it's not in the PostScript Language Reference Manual, including appropriate supplements for your printer, don't use it.

Don't use any PostScript procedures you didn't define unless they're part of the language. If you find a procedure defined in LaserWriter 8 that does something you want to do, don't call it! The PostScript system in QuickDraw GX is entirely different from the one in LaserWriter 8; if you just substitute one set of procedures that you shouldn't call for another, your application will break again in the near future.

I would even avoid using printer-specific features, because with EPS files you're never sure what the target printer will be. If you must use these features, wrap them in PostScript's "stop" mechanism so that the job will complete even if the feature creates an error.

Precision Bitmap Alignment. In version 8.0, the Page Setup option "Precision Bitmap Alignment" still says "(4% reduction)" at the end of the item in the Options dialog. That will change in versions after 8.0 because the code will change.

In 8.0 and earlier, the Precision Bitmap Alignment option simply reduces the coordinate system to 96% of the former value, turning 300-dpi printers into 288-dpi printers. Since 288 dpi is an even multiple of 72 dpi, the screen resolution, this prevents rounding errors in bitmaps where some bits would be slightly larger than others. Unfortunately, this only solves the problem on 300-dpi printers. On 400-dpi printers (such as are often found in Japan), it changes the resolution to 384 dpi, which doesn't help.

Sometime after 8.0, "Precision Bitmap Alignment" will start aligning to the nearest lower multiple of 72 dpi available on the target printer, calculated by the PostScript code when printing. On a 400-dpi printer, that's 360 dpi for a 10% reduction. On a 600-dpi printer, it's 576 dpi and is again a 4% reduction. The point is to get precisely aligned bitmaps, not to reduce by exactly 4%, and past 8.0 that's how it will work.

Font substitution. In the past, turning on fractional font widths with SetFractEnable(TRUE) disabled font substitution. With LaserWriter 8, you always get font substitution when you ask for it.

In LaserWriter 7.1.1 through LaserWriter 7.2, turning off font substitution would sometimes give you a TrueType version of a font if you had it -- even if the printer had a Type 1 version available -- depending on whether you'd turned off line layout or enabled fractional font widths, and on what day of the week it was. This inconsistent behavior is removed from LaserWriter 8: once again, Type 1 fonts are always picked over TrueType fonts if both are available to the printing system. This is largely for compatibility with pre-TrueType systems.

Older customization resources. The older drivers supported mechanisms for adding device- specific items to non-Apple printers, such as custom page sizes and code to enable sheet feeders. These resources, if present, are ignored by LaserWriter 8 -- printer manufacturers can control feeders, custom page sizes, and other device-specific features through PPD files. We later discovered that some enterprising developers were using the 'feed' resource to control things other than sheet feeders, since the mechanism gave them a chance to execute code on the Macintosh during the job dialog. That wasn't what it was designed for, so no one made any effort to make sure that would still work. That mechanism is now gone.

Color QuickDraw pixel patterns. Before LaserWriter 8, attempting to print with pixel patterns (as opposed to older black-and-white patterns) generally produced stunning black blobs on your page. With LaserWriter 8, printing with pixel patterns works just as you'd hope it would if the user chooses either "Color/Grayscale" or "Calibrated Color/Grayscale" (making the printing grafPort a cGrafPort) and if the printer supports PostScript Level 2 so the driver can use the Level 2 PostScript pattern mechanism. On Level 1 devices, pixel patterns are implemented using screens (color screens if available, halftone screens otherwise) and the patterns are clipped to their upper left eight-by-eight grid, matching the dimensions of a regular QuickDraw pattern. Even though the implementationisn't perfect on Level 1 devices, something much closer to your desired pattern than a black blob now appears.

Preferences file. The new driver keeps a preferences file in the Preferences folder (or in the System Folder under System 6). It's in this file that the driver stores the parsed PPD data, plus the recorded choices of which printers match which PPDs and some other driver-specific data that needs to stick around. If you ever update drivers manually, delete the old preferences file. Its contentswillchange from version to version. If you share one driver file among systems trying to isolate or reproduce a problem and you want to have the best chance of seeing the problem again, be sure to keep the preferences file with the driver as you bop between systems.

THE REST IS WAITING FOR YOU
If you have comments or bugs to report about the LaserWriter 8 driver, you can send them on AppleLink to the read-only address LWDRIVER.BUG. You won't get a response or an acknowledgment, but your feedback will get to the people responsible for making changes. Don't forget to look at the information on the CD for the complete story!

SUMMARY OF NEW API FEATURES IN LASERWRITER 8

These are new selectors to PrGeneral. Full details and sample code are located on the CD. Remember, don't even think about requiring these calls in your program.

  • PSPrimaryPPDOp: Returns an FSSpec record locating the PPD file chosen for this printer, along with a Boolean value indicating whether the file is the built-in "generic" PPD.
  • getPSInfoOp:Informs you if the target printer supports PostScript Level 2 and binary communications. Also tells you what kind of PostScript file the user chose to create, if any: EPS with no preview, EPS with standard preview, EPS with enhanced preview, or PostScript job file format.
  • PSIntentionsOp: Allows your code to tell the driver that you intend to use PostScript Level 2 or binary communications features, so that the driver can generate appropriate DSC (document structuring conventions) comments and return errors if the target printer doesn't support those features.
  • PSpict2eps: Converts a QuickDraw picture into an EPS stream. You can specify most of the parameters in the style and job dialogs, and you provide a callback routine that receives the EPS stream as it's created.
  • PSFontInfo: Provides a PostScript stream to make a given outline font available on a PostScript interpreter, including the TrueType scaler and TrueType conversions of fonts if necessary. You provide a callback routine to receive the font information from the driver. Bitmap fonts are not supported.

RECOMMENDED READING

  • Inside Macintosh Volume II (Addison-Wesley, 1985), Chapter 5, and Volume V (Addison-Wesley, 1988), Chapter 22.
  • Inside Macintosh: Imaging With QuickDraw (Addison-Wesley, forthcoming).
  • "Meet PrGeneral, the Trap That Makes the Most of the Printing Manager" by Pete ("Luke") Alexander,develop Issue 3.
  • "Print Hints: Top 10 Printing Crimes" by Pete ("Luke") Alexander, develop Issue 10.
  • "Print Hints: Top 10 Printing Misdemeanors" by Pete ("Luke") Alexander, develop Issue 12.
  • Macintosh Technical Note "Picture Comments -- the Real Deal" (QuickDraw 10).

While we refer to the driver here as "LaserWriter 8," Adobe distributes the same driver as "PSPrinter." Adobe also licenses the driver to printer manufacturers who license PostScript language software from Adobe, and those printermakers may call the driver by different names as well. Apple's initial release of the driver is named "LaserWriter 8.0," but later releases (which may happen by the time this is published) will be named "LaserWriter 8." No matter what the driver is called or how the icons appear, the internals are the same and all the information here applies. *

For more information on PrGeneral, see the article "Meet PrGeneral, the Trap That Makes the Most of the Printing Manager" in develop Issue 3.*

Information on PostScript printer description files and other items related to PostScript language development are available from the Adobe Systems Developers' Association, 1585 Charleston Road, P.O. Box 7900, Mountain View, CA, 94039-7900, telephone (415)961-4111.*

Document structuring conventions are discussed in Appendix G of thePostScript Language Reference Manual, second edition. *

MATT DEATHERAGE (AppleLink DEATHERAGE1) has been doing technical support for over five years. In addition to serving as the technical lead for the LaserWriter 8 driver in Apple's Developer Technical Support group, he's worked on several Apple printer projects when not focusing on fonts or typography or all the other fun imaging stuff there's never enough time for. He remains true to his background by running the Apple II Programmers and Developers roundtable on GEnie, but you can find him on-line in lots of other places, usually just where you're hoping he won't be. *

Thanks to Waymen Askey, Richard Blanchard, and Steve Winters for reviewing this column. *

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

How to evolve Eevee in Pokemon GO
By now, almost everyone should be hip to how to evolve Pokemon in Pokemon GO (and if not, there's a guide for that). Just gather enough candy of the appropriate type, feed them all to the Pokemon, and evolution happens. It's a miracle that would... | Read more »
CSR Racing 2: Guide to all game modes
It might not seem like there are all that many ways to go fast in a straight line, but CSR Racing 2 begs to differ. [Read more] | Read more »
Bulb Boy (Games)
Bulb Boy 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Multi-award winning 2D point & click horror adventure about a boy with a glowing head. | Read more »
5 top free emoji keyboard apps
If we're not at peak emoji yet as a society, it feels like we definitely should be. The emoji concept has gone far beyond what anyone in Japan could have envisioned when the people there unleashed it on an unsuspecting world, but the West has... | Read more »
How to unlock more characters in Disney...
One of the big charms of Disney Emoji Blitz is seeing a wide variety of beloved Disney and Pixar characters transformed into smiling emojis. Even someone like the sneaky Randall from Monsters Inc., who probably never cracked a smile on film, is... | Read more »
Cubway (Games)
Cubway 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Cubway is a journey with an abstract story of lifecycle of rebirth, called Samsara. Guide the cube through the long way full of dangers... | Read more »
Colorcube (Games)
Colorcube 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Turn pieces and blend colours in this minimal yet visually stunning puzzler.Over 200 handcrafted and challenging levels. Features... | Read more »
Doodle God Griddlers (Games)
Doodle God Griddlers 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: | Read more »
Crusader Kings: Chronicles (Games)
Crusader Kings: Chronicles 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: Crusader Kings: Chronicles is an interactive text based game that puts you in the shoes of Guy de Rose as you make... | Read more »
Roads of Rome: New Generation (Games)
Roads of Rome: New Generation 1.0 Device: iOS Universal Category: Games Price: $5.99, Version: 1.0 (iTunes) Description: | Read more »

Price Scanner via MacPrices.net

Apple price trackers, updated continuously
Scan our Apple Price Trackers for the latest information on sales, bundles, and availability on systems from Apple’s authorized internet/catalog resellers. We update the trackers continuously: - 15″... Read more
13-inch 2.5GHz MacBook Pro (Apple refurbished...
Apple has Certified Refurbished 13″ 2.5GHz MacBook Pros available for $829, or $270 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros... Read more
21-inch iMacs on sale for up to $120 off MSRP
B&H Photo has 21″ iMacs on sale for up to $120 off MSRP including free shipping plus NY sales tax only: - 21″ 3.1GHz iMac 4K: $1379 $120 off MSRP - 21″ 2.8GHz iMac: $1199.99 $100 off MSRP - 21″ 1... Read more
Charitybuzz Set to Auction Unique Apple-1 Com...
Offering an opportunity to own the computer that sparked a revolution, on Monday, July 25, leading online charity auction platform Charitybuzz will auction what is claimed to be the world’s most... Read more
MacBook Airs on sale for up to $150 off MSRP
Amazon has 11″ and 13″ MacBook Airs on sale for up to $150 off MSRP for a limited time. Shipping is free: - 13″ 1.6GHz/128GB MacBook Air (sku MMGF2LL/A): $899.99 $100 off MSRP - 13″ 1.6GHz/256GB... Read more
Apple refurbished 13-inch Retina MacBook Pros...
Apple has Certified Refurbished 13″ Retina MacBook Pros available for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and shipping is free: - 13″ 2.7GHz... Read more
Apple refurbished 11-inch MacBook Airs availa...
Apple has Certified Refurbished 11″ MacBook Airs (the latest models), available for up to $170 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is... Read more
Apple iPad Pro Sales Far Outpacing Microsoft...
A report on Appleinsider notes that despite Microsoft Surface tablet PC sales growing by 9 percent year over year, revenues remained below $1 billion, and are down sequentially from the $1.1 billion... Read more
DEVONthink 2.9 Features Ultra-fast, Robust, A...
DEVONthink 2.9 allows users to keep databases synchronized using many means of transport. It transmits them between Macs on the local network or stores them in a syncable form on removable hard... Read more
12-inch WiFi Apple iPad Pros on sale for up t...
B&H Photo has 12″ WiFi iPad Pros on sale for up to $100 off MSRP, each including free shipping. B&H charges sales tax in NY only: - 12″ Space Gray 32GB WiFi iPad Pro: $749 $50 off MSRP - 12″... Read more

Jobs Board

*Apple* Solutions Consultant - APPLE (United...
Job Summary As an Apple Solutions Consultant, you'll be the link between our future customers and our products. You'll showcase your entrepreneurial spirit as you Read more
*Apple* Professional Learning Specialist - A...
Job Summary The Apple Professional Learning Specialist is a full-time position for one year with Apple in the Phoenix, AZ area. This position requires a high Read more
*Apple* Picker - Apple Hill Orchard (United...
Apple Hill Orchard, Co. Rte. 21,Whitehall, NY 9/7/16-10/228/16. Pick fresh market or processing apples Productivity of 60 boxes and 80 boxes processing fruit per Read more
*Apple* Solutions Consultant - APPLE (United...
Job Summary As an Apple Solutions Consultant, you'll be the link between our future customers and our products. You'll showcase your entrepreneurial spirit as you Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.