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
$106.79
Apple Inc.
-0.55
MSFT
$45.98
Microsoft Corpora
-0.65
GOOG
$544.32
Google Inc.
-5.01

MacTech Search:
Community Search:

Software Updates via MacUpdate

OneNote 15.3.2 - Free digital notebook f...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Audio Hijack Pro 2.11.4 - 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
Iridient Developer 3.0.0 beta 3 - Powerf...
Iridient Developer (was RAW Developer) is a powerful image conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more
TextWrangler 4.5.11 - Free general purpo...
TextWrangler is the powerful general purpose text editor, and Unix and server administrator's tool. Oh, and also, like the best things in life, it's free. TextWrangler is the "little brother" to... Read more
NeoFinder 6.6 - Catalog your external me...
NeoFinder (formerly CDFinder) rapidly organizes your data, either on external or internal disks, or any other volumes. It catalogs all your data, so you stay in control of your data archive or disk... Read more
Chromium 38.0.2125.111 - 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
Default Folder X 4.6.11 - Enhances Open...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click... Read more
Mariner Write 3.9.3 - Light-weight and s...
Mariner Write is your Mac OS go-to word processing tool! Professional writer, educator or student, Write has all the functionality you need for that important letter, technical paper or research... Read more
DesktopLyrics 2.6.5 - Displays current i...
DesktopLyrics is an application that displays the lyrics of the song currently playing in "iTunes" right on your desktop. The lyrics for the song have to be set in iTunes; DesktopLyrics does nothing... Read more
DiskMaker X 4.0b4 - Make a bootable OS X...
DiskMaker X (formerly Lion DiskMaker) is an application built with AppleScript that you can use with many versions of OS X to build a bootable drive from OS X OS X 10.8 Mountain Lion up to OS X 10.10... Read more

Latest Forum Discussions

See All

Any.DO 2.0 Hopes to Help Manage Producti...
Any.DO 2.0 Hopes to Help Manage Productivity Posted by Ellis Spice on October 30th, 2014 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »
Base Busters Review
Base Busters Review By Jennifer Allen on October 30th, 2014 Our Rating: :: FUN BUT RESTRICTED MIXUniversal App - Designed for iPhone and iPad Mixing up two forms of tower defense gaming and collectible cards, Base Busters is a fun... | Read more »
Medford Asylum: Paranormal Case - Hidden...
Medford Asylum: Paranormal Case - Hidden Object Adventure (Full) 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: Uncover the mystery of Medford City asylum! | Read more »
Secret Files Sam Peters (Games)
Secret Files Sam Peters 1.0.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.0 (iTunes) Description: [ After the successful iOS release of Secret Files Tunguska, the acclaimed point and click adventure Secret Files... | Read more »
Woah Dave! (Games)
Woah Dave! 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: ***SPECIAL LAUNCH PRICE! IT DOESN'T COST A LOT OF MONEY!*** Optimized for iPhone 6+! A huge hit at E3, PAX, PAX East, IndieCade... | Read more »
Drift'n'Drive (Games)
Drift'n'Drive 1.0.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.0 (iTunes) Description: Follow your destiny to become the ultimate racing driver! | Read more »
Twisty Hollow (Games)
Twisty Hollow 1.0.1 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.1 (iTunes) Description: A self-appointed mayor is spinning the town of Twisty Hollow out of order with nonsensical rulings. His cryptic instructions... | Read more »
Omnistat (Utilities)
Omnistat 1.0 Device: iOS Universal Category: Utilities Price: $1.99, Version: 1.0 (iTunes) Description: Omnistat is an application for tech lovers, it's the easiest way to consult your device stats. With Omnistat you don't need to... | Read more »
South Park Pinball Review
South Park Pinball Review By Blake Grundman on October 29th, 2014 Our Rating: :: FAN SERVICE GALOREUniversal App - Designed for iPhone and iPad It is hard to go wrong when tables are obviously being designed by fans of a specific... | Read more »
Mmm Fingers Review
Mmm Fingers Review By Jennifer Allen on October 29th, 2014 Our Rating: :: SIMPLE PLEASURESUniversal App - Designed for iPhone and iPad Chasing high scores with just one finger works well for Mmm Fingers.   | Read more »

Price Scanner via MacPrices.net

Sale! 3.7GHz Quad Core Mac Pro available for...
 B&H Photo has the 3.7GHz Quad Core Mac Pro on sale for $2649 including free shipping plus NY sales tax only. Their price is $350 off MSRP, and it’s the lowest price for this model from any... Read more
Mujjo Steps Up The Game With Refined Touchscr...
Netherlands based Mujjo have just launched their Refined Touchscreen Gloves, stepping up their game. The gloves feature a updated elegant design that takes these knitted gloves to the next level. A... Read more
Sale! Preorder the new 27-inch 5K iMac for $2...
 Abt Electronics has the new 27″ 3.5GHz 5K iMac on sale and available for preorder for $2374.05 including free shipping. Their price is $125 off MSRP, and it’s the lowest price available for this... Read more
Simplex Solutions Inc. Brings Secure Web Surf...
New York based Simplex Solutions Inc. has announced the release and immediate availability of Private Browser 1.0, its revolutionary new secure web browser developed for iPhone, iPad and iPod touch... Read more
Save up to $180 off MSRP with an Apple refurb...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available for up to $180 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
Apple refurbished 2013 MacBook Pros available...
The Apple Store has Apple Certified Refurbished 13″ and 15″ MacBook Pros available starting at $929. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros (4GB RAM/... Read more
What Post PC Era? – The Mac Bounces Back, Big...
Apple’s fiscal Q4 2014 was an all-time record quarter for Mac sales, with 5.5 million units shipped, representing nearly one million more sales (+21 percent, + 25 percent sequentially) than Apple... Read more
Unpacking The Big Changes At Microsoft – iPad...
The days of product keys and email attachments are nearing an end and Microsoft, though late to the game, is making big strides to keep up, says tech expert Karl Volkman of SRV Network, Inc. Under... Read more
Apple refurbished iPad Airs and minis availab...
Apple dropped prices recently on Apple Certified Refurbished iPad Airs and iPad mini 2s, with models now available starting at $209. Apple’s one-year warranty is included with each model, and... Read more
Practice Fusion Launches New Electronic Healt...
Practice Fusion, claimed to be the nation’s largest cloud-based electronic health records (EHR) platform, has launched a new EHR for Practice Fusion’s community of more than 112,000 medical... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple I...
…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 (ASC) - Apple I...
…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 (ASC) - Apple I...
…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
*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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.