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
$105.22
Apple Inc.
+0.39
MSFT
$46.13
Microsoft Corpora
+1.11
GOOG
$539.78
Google Inc.
-4.20

MacTech Search:
Community Search:

Software Updates via MacUpdate

f.lux 34.0 - Adjusts the color of your d...
f.lux makes the color of your computer's display adapt to the time of day, warm at night and like sunlight during the day. Ever notice how people texting at night have that eerie blue glow? Or wake... Read more
Ember 1.8.2 - Versatile digital scrapboo...
Ember (formerly LittleSnapper) is your digital scrapbook of things that inspire you: websites, photos, apps or other things. Just drag in images that you want to keep, organize them into relevant... Read more
Tonality Pro 1.1.2 - Professional-grade...
Tonality Pro gives you the power to create stunning and dramatic black & white images. This is a complete monochrome image editor with more than 150 one-click style presets, totally unique... Read more
VueScan 9.4.49 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
OS X Server 4.0 - For OS X 10.10 Yosemit...
Designed for OS X and iOS devices, OS X Server makes it easy to share files, schedule meetings, synchronize contacts, develop software, host your own website, publish wikis, configure Mac, iPhone,... Read more
TotalFinder 1.6.12 - Adds tabs, hotkeys,...
TotalFinder is a universally acclaimed navigational companion for your Mac. Enhance your Mac's Finder with features so smart and convenient, you won't believe you ever lived without them. Tab-based... Read more
BusyCal 2.6.3 - Powerful calendar app wi...
BusyCal is an award-winning desktop calendar that combines personal productivity features for individuals with powerful calendar sharing capabilities for families and workgroups. BusyCal's unique... Read more
calibre 2.7 - Complete e-library managem...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Skitch 2.7.3 - Take screenshots, annotat...
With Skitch, taking, annotating, and sharing screenshots or images is as fun as it is simple.Communicate and collaborate with images using Skitch and its intuitive, engaging drawing and annotating... Read more
Delicious Library 3.3.2 - Import, browse...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more

Latest Forum Discussions

See All

Rami Ismail Opens Up distribute​() for D...
Rami Ismail Opens Up distribute​() for Developers Posted by Jessica Fisher on October 24th, 2014 [ permalink ] Rami Ismail, Chief Executive of Business and Development at indie game studio | Read more »
Great Hitman GO Goes on Sale and Gets Ne...
Great Hitman GO Goes on Sale and Gets New Update – Say That Three Times Fast Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
Rival Stars Basketball Review
Rival Stars Basketball Review By Jennifer Allen on October 24th, 2014 Our Rating: :: RESTRICTIVE BUT FUNUniversal App - Designed for iPhone and iPad Rival Stars Basketball is a fun mixture of basketball and card collecting but its... | Read more »
Rubicon Development Makes Over a Dozen o...
Rubicon Development Makes Over a Dozen of Their Games Free For This Weekend Only Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
I Am Dolphin Review
I Am Dolphin Review By Jennifer Allen on October 24th, 2014 Our Rating: :: NEARLY FIN-TASTICUniversal App - Designed for iPhone and iPad Swim around and eat nearly everything that moves in I Am Dolphin, a fun Ecco-ish kind of game... | Read more »
nPlayer looks to be the ultimate choice...
Developed by Newin Inc, nPlayer may seem like your standard video player – but is aiming to be the best in its field by providing high quality video play performance and support for a huge number of video formats and codecs. User reviews include... | Read more »
Fighting Fantasy: Caverns of the Snow Wi...
Fighting Fantasy: Caverns of the Snow Witch Review By Jennifer Allen on October 24th, 2014 Our Rating: :: CLASSY STORYTELLINGUniversal App - Designed for iPhone and iPad Fighting Fantasy: Caverns of the Snow Witch is a sterling... | Read more »
A Few Days Left (Games)
A Few Days Left 1.01 Device: iOS Universal Category: Games Price: $3.99, Version: 1.01 (iTunes) Description: Screenshots are in compliance to App Store's 4+ age rating! Please see App Preview for real game play! **Important: Make... | Read more »
Toca Boo (Education)
Toca Boo 1.0.2 Device: iOS Universal Category: Education Price: $2.99, Version: 1.0.2 (iTunes) Description: BOO! Did I scare you!? My name is Bonnie and my family loves to spook! Do you want to scare them back? Follow me and I'll... | Read more »
Intuon (Games)
Intuon 1.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.1 (iTunes) Description: Join the battle with your intuition in a new hardcore game Intuon! How well do you trust your intuition? Can you find a needle in a... | Read more »

Price Scanner via MacPrices.net

Weekend sale: 13-inch 128GB MacBook Air for $...
Best Buy has the 2014 13-inch 1.4GHz 128GB MacBook Air on sale for $849.99, or $150 off MSRP, on their online store. Choose free home shipping or free local store pickup (if available). Price valid... Read more
Nimbus Note Cross=Platform Notes Utility
Nimbus Note will make sure you never forget or lose your valuable data again. Create and edit notes, save web pages, screenshots and any other type of data – and share it all with your friends and... Read more
NewerTech’s Snuglet Makes MagSafe 2 Power Con...
NewerTech has introduced the Snuglet, a precision-manufactured ring designed to sit inside your MagSafe 2 connector port, providing a more snug fit to prevent your power cable from unintentional... Read more
Apple Planning To Sacrifice Gross Margins To...
Digitimes Research’s Jim Hsiao says its analysts believe Apple is planning to sacrifice its gross margins to save its tablet business, which has recently fallen into decline. They project that Apple’... Read more
Who’s On Now? – First Instant-Connect Search...
It’s nighttime and your car has broken down on the side of the highway. You need a tow truck right away, so you open an app on your iPhone, search for the closest tow truck and send an instant... Read more
13-inch 2.5GHz MacBook Pro on sale for $949,...
Best Buy has the 13″ 2.5GHz MacBook Pro available for $949.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $150 off MSRP. Price is... Read more
Save up to $125 on Retina MacBook Pros
B&H Photo has the new 2014 13″ and 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels... Read more
Apple refurbished Time Capsules available sta...
The Apple Store has certified refurbished Time Capsules available for up to $60 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $255... Read more
Textilus New Word, Notes and PDF Processor fo...
Textilus is new word-crunching, notes, and PDF processor designed exclusively for the iPad. I haven’t had time to thoroughly check it out yet, but it looks great and early reviews are positive.... Read more
WD My Passport Pro Bus-Powered Thunderbolt RA...
WD’s My Passport Pro RAID solution is powered by an integrated Thunderbolt cable for true portability and speeds as high as 233 MB/s. HighlightsOverviewSpecifications Transfer, Back Up And Edit In... Read more

Jobs Board

*Apple* Solutions Consultant - Apple Inc. (U...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions Read more
*Apple* Solutions Consultant - Apple Inc. (U...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.