TweetFollow Us on Twitter

December 92 - PRINT HINTS

PRINT HINTS

TOP 10 PRINTING MISDEMEANORS

PETE ("LUKE") ALEXANDER

[IMAGE 084-088_Luke's_column_re1.GIF]

In my last column (indevelop Issue 10), I talked about the "Top 10 Printing Crimes" that would cause you and your application serious headaches during print time. Here I'll list the "Top 10 Printing Misdemeanors." A printing misdemeanor will cause minor to major printing problems on different devices. Usually, you'll be able to get output onto a page, but it won't necessarily be what you want or where you want it.

Here's the list:
10. Using CopyMask and CopyDeepMask with the LaserWriter.
9. Using the obsolete spool-a-page, print-a-page method.
8. Not being very careful when using SetOrigin with the LaserWriter.
7. Creating pictures while the Printing Manager is open.
6. Not having all your data ready for the Printing Manager when you open it.
5. Making assumptions about the imageable area.
4. Using variables from Laser Prep (that is,md).
3. Checking wDev for the wrong reasons.
2. Accessing print record fields that are used internally.
1. Adding printing to your application four weeks before going final.

Most of these misdemeanors are easily avoided if you plan ahead. Let's take a look at the problems and the solution to each one.

SOLUTIONS TO THE MISDEMEANORS
10. Using CopyMask and CopyDeepMask with the LaserWriter.

It's not possible to directly print to a LaserWriter an image that was created with CopyMask or CopyDeepMask, because these calls aren't saved in pictures and they don't go through the stdBits QuickDraw bottleneck. The image's data must be recorded in the picture or go through the stdBits bottleneck in order for the LaserWriter driver to be able to image the data on the printer.

Solution: You can create your image in an off-screen world using CopyMask and CopyDeepMask to your heart's content. When you're ready to print your image, CopyBits it directly to the LaserWriter's grafPort using srcCopy.

9. Using the obsolete spool-a-page, print-a-page method.

There are still a few applications using the spool-a-page, print-a-page method of printing a document. This approach is no longer required unless you're printing from a Macintosh that doesn't have a hard drive. Otherwise, it's a bad idea; it has major drawbacks in the areas of speed and user happiness.

The idea of this method was to print each page of a document as a separate job. This was required in the early Macintosh days because disk space was at a premium. It prevented a document from filling up the entire disk and never printing a page. But in this age of hard disks, it's no longer needed.

Opening and closing the Printing Manager for each page could result in a serious speed penalty. And it could make your users very unhappy when printing to a shared printer; it's possible to have another user grab the printer before you do, thereby intermixing your pages with theirs.

Solution: Don't use the spool-a-page, print-a-page technique. Instead, use the method described in the Technical Note "A Printing Loop That Cares . . .".

8. Not being very careful when using SetOrigin with the LaserWriter.

If you're using SetOrigin to change the coordinate system when sending direct PostScriptTMcode to the LaserWriter, you'll run into trouble when printing in the foreground versus the background.

The PostScript LaserWriter drivers 4.0 through 5.2 handle SetOrigin differently when background printing is enabled.

  • When background printing is disabled and the application calls SetOrigin, QuickDraw responds by adjusting the portRect of the printer driver's grafPort. Since SetOrigin doesn't cause any grafProcs to run (because no drawing occurs), the printer driver doesn't see the effect of this call until the next QuickDraw call is made (for example, DrawString or LineTo). At this point, the driver notices the change in the portRect and updates its internal origin. From then on, all QuickDraw and PostScript graphics are localized to the new origin.
  • When background printing is enabled, QuickDraw is playing back a picture that was spooled earlier. When SetOrigin is encountered while DrawPicture is playing the picture, the grafPort's portRect isn't updated. Instead, QuickDraw keeps the current origin cached and offsets each graphic on the fly. Since the portRect wasn't modified, the printer driver doesn't see the SetOrigin call. Although all QuickDraw objects are still localized correctly (by QuickDraw), PostScript graphics don't move to the new origin.

In LaserWriter drivers 6.0 and later, the call to SetOrigin is a problem only on the first page that's spooled. After the first page, the driver looks at the grafPort's coordinates and then records the SetOrigin information correctly by inserting a picture comment into the spool file. This enables PrintMonitor to realize when the origin changes. Unfortunately, the driver never records the changes produced by a SetOrigin call when it's in the stdBits QuickDraw bottleneck.

Solution: In general, using SetOrigin doesn't buy you much, and it can get you in a lot of trouble. There are still a few printer drivers that don't handle the call correctly. Avoid using SetOrigin if possible.

If you use SetOrigin when sending direct PostScript code, use the techniques described in the Technical Note "Position-Independent PostScript" to ensure that all the PostScript code your application creates is position independent. To get the LaserWriter driver to realize as soon as possible that you've changed the coordinate system, you can send the following code:

PicComment (PostScriptBegin, 0, nil);
PicComment (PostScriptEnd, 0, nil);

This is a little weird, but it works because the two PicComment calls go through the stdBits QuickDraw bottleneck, which is where the driver checks and updates the coordinate system as required.

7. Creating pictures while the Printing Manager is open.

Some applications use a picture to collect all their QuickDraw objects before sending them on to the printer. This approach is OK unless the Printing Manager has already been opened by a call to PrOpen. The most noticeable problems are memory use and floating picture comments.

The memory problem can be very evident if you're printing to a printer driver that requires a lot of memory. Between your memory use and the printer driver's, there might not be enough memory available to meet everyone's appetite. Remember, there isn't a magical amount of memory that will guarantee that your application will print successfully.

The other significant problem you might encounter is floating picture comments. When this occurs, the picture comments sent by your application will be recorded out of order, which will usually cause your image to print its objects out of order.

Solution: Read the Technical Note "Pictures and the Printing Manager" before you start to use pictures at print time. Better yet, don't create a picture when the Printing Manager is open.

6. Not having all your data ready for the Printing Manager when you open it.

There aren't too many things you can do to speed up printing, but having data ready for the Printing Manager when you open it is one of them. If you open the Printing Manager and then go off to collect data you want to print, your printing time could increase dramatically. You also run the risk of timing out the print job because you don't send data to a networked printer fast enough or your print job takes too long to complete.

Solution: When you open the Printing Manager, have all your data collected and ready to send to the printer. Make sure the data is formatted for the current printer (see the next misdemeanor for additional details).

If your application needs to perform a lot of data collection or preparation (as would a database application), consider spooling all your information to disk as pictures. This is especially useful when you don't know how long it will take to gather the data for a particular page. To use this approach, you would open up a file and write out each page as a picture (as the Printing Manager does), spool everything to disk, and then send the pictures to the printer driver. Printing will be really fast! But be sure not to commit misdemeanor 7 above, and note that this should not be the only way your application prints; since you may not have enough disk space, you should make it an option in a Preferences or Print dialog.

Having your data ready to go when you open the Printing Manager ensures that you'll print as fast as possible and avoid timeout problems. And it will make your application a friendly networked printer user, compared to grabbing the printer on the network and hogging it while your application collects data.

5. Making assumptions about the imageable area.

Some applications make assumptions about the imageable area (the page rectangle) at print time. This can cause some serious speed and clipping problems. If any part of your image (which may contain text, QuickDraw objects, bitmaps, or pixMaps) falls outside the page rectangle, the printer driver will need to clip it. This will slow down the printing process and you won't get the output you want. The imageable area for each printer is slightly different; this is actually a good thing, since it allows the printer driver to take full advantage of the printer's capabilities.

About half of the printing game is reformatting your image to work for the currently selected printer. This problem is most noticeable when you print to a film recorder an image that was set up for a LaserWriter. If you don't reformat the image, you won't get the results you want; because of the higher resolution of the film recorder (1500 versus 300 dpi), you'll get a micro-image and you'll waste film. Also, most film recorders print only in landscape orientation.

Solution: Since each printer has a slightly different imageable area, you should format your image to this area. Before sending your data to the printer, you should format it to rPage, the page rectangle for the current printer. rPage lives in the TPrInfo record within the print record. However, becareful; as mentioned in the previous misdemeanor, you should have all your data ready to send (including all formatting) before opening the Printing Manager. Open the Printing Manager, get the dimension for rPage, close the Printing Manager, format your data, open the Printing Manager again, and print.

One approach for saving your data within your application to help you format it at print time is to specify the location of each object on the page as a percentage of distance (as opposed to pixels). For example, you could specify an object to be 10% from the top and left margins. You would then always be able to place the object in the correct position for all printers no matter what the resolution.

4. Using variables from Laser Prep (that is, md).

Using operators from the LaserWriter driver's dictionarymd is a classic way of causing your application compatibility problems when a new LaserWriter driver is released. Some developers do this to achieve additional PostScript functionality at print time. The problem is that when Apple releases a new LaserWriter driver it usually changes a few of the operators inmd. This will then break code that depends onmd. It's an even bigger problem if you save this information in pictures. When a new LaserWriter driver is released, none of these pictures created by your users will be able to be printed.

Solution: Don't use any of the operators defined withinmd in your printing code. This has been around for a long time as a compatibility issue; take a look at the Technical Note "Using Laser Prep Routines" for the historical data.

If you decide to jump off the cliff and use operators inmd, you owe it to your users to check the existence of an operator before you use it. This piece of PostScript code will do the trick:

userdict /md known 
{
	md /bu known {myBU} if
} if

In this example, we're checking for the existence ofbu before we replace it with our newly defined operator,myBU. If thebu operator didn't exist, we'd do the right thing (that is, we'd still be able to print).

3. Checking wDev for the wrong reasons.

The printer type (such as LaserWriter or StyleWriter) is stored as an unsigned char in the high byte of the print record's wDev field (in the TPrStl record). Each printer driver has a unique wDev, and there are now over 142 wDevs in the world. That's quite a few printers available for your application to print to.

If you're checking wDev to see which type of printer you're talking to, you could end up very disappointed. Relying on wDev to make decisions at print time makes your application completely device dependent. What do you do when you get a wDev you don't know about? You have to make assumptions about the printer, and if you make a bad decision, you won't get the output you expect. This isn't fair to your users; they should be able to print to any printer that's connected to the Macintosh.

When we were developing the StyleWriter printer, we had some serious compatibility problems with a few of the major applications. They assumed that any device with a resolution greater than 300 dpi must be a PostScript printer. They sent only PostScript code to the StyleWriter, which didn't work out too well, since of course the StyleWriter doesn't understand PostScript.

Solution: Don't check wDev, with a couple of exceptions. One exception is that you should check wDev and the printer driver version if you need to work around a bug in the printer driver. This is the only method available to determine whether you're dealing with a particular printer driver. Checking the driver version by calling PrDrvrVers is important, because when the bug is fixed, you can remove your fix and let the driver do the work. Another exception is that you can check wDev after you've created a valid print handle (by calling PrintDefault) to see if the user has changed the printer type (for example, a LaserWriter to a StyleWriter) via the Chooser. In any case, be sure that when you do check wDev, you check it as an unsigned char value.

2. Accessing print record fields that are used internally.

You may notice that this is similar to the number 2 printing crime in the Print Hints column in Issue 10. There I emphasized the crime of accessing private ("PT") fields that you may come across when prowling around in the print record. Also likely to cause inconsistent results is the misdemeanor of accessing other fields in the print record that are used internally (or unused). To make this even clearer, I'll tell you just what print record fields youcan read and write.

The print record is chock full of information. It's an application's playground during printing. It's also used by printer drivers to hold information about the current print job. Since each printer has slightly different needs, each one uses these fields differently. The public API documented inInside Macintosh is the same, but the rest of the print record is free domain for the printer driver to use as it sees fit.

Setting a field that the printer driver doesn't expect you to touch can cause big problems for your application. This is one of the reasons why printer drivers have compatibility problems when they're being developed, and why they take so long to create.

Solution: Don't set any fields in the print record besides iLstPage, iFstPage, pIdleProc, pFileName, and iFileVol. If you do, you're running a serious compatibility risk with new printer drivers and printers you don't have access to during your test cycle. See the Technical Note "A Printing Loop That Cares . . ." for details about setting and using iLstPage and iFstPage, and the Technical Note "Me and My pIdle Proc (or how to let users know what's going on during print time . . .)" for details about setting pIdleProc.

Don't read any fields in the print record besides the ones you can set and the fields rPage, rPaper, iCopies, iVRes, iHRes, bjDocLoop, and bFileVers. (You can also read the TPrStatus record returned by prPicFile.)

1. Adding printing to your application four weeks before going final.

This too is similar to a printing crime in Print Hints in Issue 10 -- but there has been a change, to four weeks instead of two. I can't emphasize this enough. Since my last column, a couple of developers have come to us with major printing problems and a shipping deadline only a few weeks away. They had just started to add printing to their applications.

Solution: Designing printing at the beginning -- not the end! -- of your application's development cycle is the solution to most of your printing headaches. Printing performance can make or break an application. You should convince the right people in your organization that printing is just as important as any other feature. There are a few pitfalls in the current printing architecture, but most of these problems can be avoided without a lot of work -- if you design printing into your application from the start.

So please, stay out of trouble and avoid the printing crimes and misdemeanors. You'll be a happy printing developer and your users will also be delighted.

REFERENCES

  • Inside Macintosh  Volume II (Addison-Wesley, 1985), Chapter 5, "The Printing Manager," pages 150-151.
  • "Print Hints: Top 10 Printing Crimes" by Pete ("Luke") Alexander, develop  Issue 10.
  • "Print Hints From Luke & Zz: CopyMask, CopyDeepMask, and LaserWriter Driver 7.0" by Pete ("Luke") Alexander, develop  Issue 8.
  • Macintosh Technical Notes "The Effect of Spool-a-page/Print-a-page on Shared Printers" (formerly #125), "Using Laser Prep Routines" (formerly #152), "A Printing Loop That Cares . . ." (formerly #161), "Position-Independent PostScript" (formerly #183), "Me and My pIdle Proc (or how to let users know what's going on during print time . . .)" (formerly #294), and "Pictures and the Printing Manager" (formerly #297).

PETE ("LUKE") ALEXANDERLuke's latest adventure was landing his sailplane close to the edge of the earth (there's an actual sign, near Gerlach, north of Reno, that reads "The Edge of the Earth, 8 miles -- Planet X"). Not only is this in the middle of nowhere, but rumor has it that Gerlach is the home of the best ravioli in Nevada. Luke and his friends didn't locate the ravioli, but as a consolation prize they stumbled onto Planet X instead (and Planets Y and Z, all art galleries, run by a slow-motion hippie who will reluctantly take MasterCard, if you have all year). The edge of the earth did deliver some great camping under the stars, and real cool satellite watching. *

Thanks to Hugo Ayala, Dave Hersey, and Scott ("Zz") Zimmerman for reviewing this column, and to Ana Wilczynski for the column idea.*

 
AAPL
$100.96
Apple Inc.
-0.83
MSFT
$47.52
Microsoft Corpora
+0.84
GOOG
$596.08
Google Inc.
+6.81

MacTech Search:
Community Search:

Software Updates via MacUpdate

Audio Hijack Pro 2.11.3 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Airfoil 4.8.9 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
WhatRoute 1.13.0 - Geographically trace...
WhatRoute is designed to find the names of all the routers an IP packet passes through on its way from your Mac to a destination host. It also measures the round-trip time from your Mac to the... Read more
Chromium 37.0.2062.122 - Fast and stable...
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. FreeSMUG-Free OpenSource Mac User Group build is... Read more
Attachment Tamer 3.1.14b9 - Take control...
Attachment Tamer gives you control over attachment handling in Apple Mail. It fixes the most annoying Apple Mail flaws, ensures compatibility with other email software, and allows you to set up how... Read more
Duplicate Annihilator 5.0 - Find and del...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator detects... Read more
jAlbum Pro 12.2 - Organize your digital...
jAlbum Pro has all the features you love in jAlbum, but comes with a commercial license. With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code!... Read more
jAlbum 12.2 - Create custom photo galler...
With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code! Beginner-friendly, with pro results Simply drag and drop photos into groups, choose a design... Read more
Quicken 2015 2.0.4 - Complete personal f...
Quicken 2015 helps you manage all your personal finances in one place, so you can see where you're spending and where you can save. Quicken automatically categorizes your financial transactions,... Read more
iMazing 1.0 - Complete iOS device manage...
iMazing (formerly DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and... Read more

Latest Forum Discussions

See All

View Source – HTML, JavaScript and CSS...
View Source – HTML, JavaScript and CSS 1.0 Device: iOS Universal Category: Utilities Price: $.99, Version: 1.0 (iTunes) Description: View Source is an app plus an iOS 8 Safari extension that makes it easy to do one key web developer... | Read more »
Avenged Sevenfold’s Hail To The King: De...
Avenged Sevenfold’s Hail To The King: Deathbat is Coming to iOS on October 16th Posted by Jessica Fisher on September 19th, 2014 [ permalink ] Just in time for Halloween, on October 16 Avenged Sevenfold will be launching | Read more »
Talisman Has Gone Universal – Can Now be...
Talisman Has Gone Universal – Can Now be Played on the iPhone Posted by Jessica Fisher on September 19th, 2014 [ permalink ] | Read more »
Tap Army Review
Tap Army Review By Jennifer Allen on September 19th, 2014 Our Rating: :: SHOOT EM ALLUniversal App - Designed for iPhone and iPad Mindless but fun, Tap Army is a lane-based shooter that should help you relieve some stress.   | Read more »
Monsters! Volcanoes! Loot! Epic Island f...
Monsters! Volcanoes! Loot! | Read more »
Plunder Pirates: Tips, Tricks, Strategie...
Ahoy There, Seadogs: Interested in knowing our thoughts on all this plundering and pirating? Check out our Plunder Pirates Review! Have you just downloaded the rather enjoyable pirate-em-up Plunder Pirates and are in need of some assistance? Never... | Read more »
Goat Simulator Review
Goat Simulator Review By Lee Hamlet on September 19th, 2014 Our Rating: :: THE GRUFFEST OF BILLY GOATSUniversal App - Designed for iPhone and iPad Unleash chaos as a grumpy goat in this humorous but short-lived casual game.   | Read more »
A New and Improved Wunderlist is Here fo...
A New and Improved Wunderlist is Here for iOS 8 Posted by Jessica Fisher on September 19th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Evernote Update for iOS 8 Adds Web Clipp...
Evernote Update for iOS 8 Adds Web Clipping, Quick Notes, and More Posted by Ellis Spice on September 19th, 2014 [ permalink ] | Read more »
Apple Names Ultimate Productivity Bundl...
Apple Names Ultimate Productivity Bundle by Readdle as the Essential Bundle on the App Store Posted by Jessica Fisher on September 19th, 2014 [ permalink | Read more »

Price Scanner via MacPrices.net

iFixIt Tears Down iPhone 6; Awards Respectabl...
iFixit notes that even the smaller 4.7″ iPhone 6 is a giant among iPhones; so big that Apple couldn’t fit it into the familiar iPhone form factor. In a welcome reversal of a recent trend to more or... Read more
Phone 6 Guide – Tips Book For Both iPhone 6...
iOS Guides has announced its latest eBook: iPhone 6 Guide. Brought to you by the expert team at iOS Guides, and written by best-selling technology author Tom Rudderham, iPhone 6 Guide is packed with... Read more
How to Upgrade iPhone iPad to iOS 8 without D...
PhoneClean, a iPhone cleaner utility offered by iMobie Inc., reveals a solution for upgrading iPhone and iPad to iOS 8 without deleting photos, apps, the new U2 album or anything. Thanks to more than... Read more
Inpaint 6 – Photo Retouching Tool Gets Faster...
TeoreX has announced Inpaint 6, a simple retouching tool for end users that helps remove scratches, watermarks, and timestamps as well as more complex objects like strangers, unwanted elements and... Read more
Worldwide PC Monitor Market Sees Growth in To...
Worldwide PC monitor shipments totaled 32.5 million units in the second quarter of 2014 (2Q14), a year-over-year decline of -2.9%, according to the International Data Corporation (IDC) Worldwide... Read more
Updated Price Trackers
We’ve updated our Mac Price Trackers with the latest information on prices, bundles, and availability on systems from Apple’s authorized internet/catalog resellers: - 15″ MacBook Pros - 13″ MacBook... Read more
Mac Pros available for up to $260 off MSRP
Adorama has Mac Pros on sale for up to $260 off MSRP. Shipping is free, and Adorama charges sales tax in NY & NJ only: - 4-core Mac Pro: $2839.99, $160 off MSRP - 6-core Mac Pro: $3739.99, $260... Read more
13-inch 2.6GHz/256GB Retina MacBook Pros avai...
B&H Photo has the 13″ 2.6GHz/256GB Retina MacBook Pro on sale for $1379 including free shipping plus NY sales tax only. Their price is $120 off MSRP. Read more
Previous-generation 15-inch 2.0GHz Retina Mac...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
21″ 2.7GHz iMac available for $1179, save $12...
Adorama has 21″ 2.7GHz Hawell iMacs on sale for $1179.99 including free shipping. Their price is $120 off MSRP. NY and NJ sales tax only. Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** The Apple Store is a retail environment like no other - uniquely focused on delivering amazing customer experiences. As an Expert, you introduce people Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As businesses discover the power of Apple computers and mobile devices, it's your job - as a Solutions Engineer - to show them how to introduce these Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.