PREC Resource
Volume Number: 5
Issue Number: 8
Column Tag: Pascal Procedures
A Look At The PREC Resource 
By Dave Kelly, MacTutor Editorial Board
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
As we all know the Apple ImageWriter printer has taken a back seat over the past
several years to the LaserWriter. Most of us prefer Laser quality printing to that of
the ImageWriter. However, another reality is the extra cost of the LaserWriter.
A quick look back in history reminds us that there are some previsions in the
ImageWriter drivers which allow applications to “own” their own page sizes. This
facility is brought to use by way of the PREC resource. In particular, the driver itself
uses PREC resource ID=3 for the page size definitions as a default. If an application
contains a PREC resource with ID=4 these size definitions take precedence. This may
be old news to most of us, but it doesn’t seem to be well documented anywhere. The
only place I found information about this was in some old notes from April, 1985. The
Macintosh Technical notes don’t give any indication about this subject.
A sample RMaker source defining a PREC 4 resource that encodes the default
configuration of the Page Setup Dialog is:
Type PREC = GNRL
*Paper size info -- localizable, customizable.
,4
.I
*Number of paper-size buttons used (max is 6):
5
*6 paper sizes in 120ths (decimal!):
*1st number is vertical, 2nd is horizontal.
*First button: 8.5 X 11" ‘US letter’ paper
1320
1020
*Second button: 8.25 X 11.66" ‘A4 letter’
1400
990
*Third button: 8.5 X 14" ‘US legal’ paper
1680
1020
*4th button:8.25 X 12" ‘international fanfold’
1440
990
*Fifth button: 14 X 11" ‘computer paper’
1320
1680
*Sixth button: - not visible
0
0
.P
*Titles for six buttons.
US Letter
A4 Letter
US Legal
International Fanfold
Computer Paper
?
*The blank line just above this one is necessary!
One easy way of creating this type of resource is with RMaker. It may not be
very convenient for non-programmers to create the resource without help. The Pascal
application included here allows editing and creation of the PREC 4 resource. Handling
the resource is not too difficult although there are a couple of things you need to know
to manipulate the structure.
1. The type PREC is reserved for use by the Macintosh print driver. It should not
be used in any other way than described here and not with any other resource ID
other than 4. The PREC 3 resource in the printer driver itself could be modified
although is not recommended.
2. Exactly six buttons must be defined in the PREC 4 resource even if you are not
using all the buttons. One character titles should be used for unused buttons.
3. All PREC 4 numbers are in decimal.
4. The first item in the PREC resource is the number of buttons to be displayed, a
word-size integer. Whatever number is used here will be used by the printer
driver to determine the number of items in the Page Setup dialog. If you use a
number greater than six you are in big trouble.
5. The dimensions follow next as an array of six pairs of integers. Each pair of
numbers corresponds to the paper sizes with the first integer in each pair as the
height and the second integer as the width. These numbers are given in 120ths of
an inch.
6. The remainder of the data is presented as an array of variable length Pascal
strings. To get to each string, these strings need to be handled as a byte or char
array. The first byte is the length of the first string which is followed by the
first string, followed by the length of the second string, and so forth.
I credit my assistant, Prototyper for the shell of this program with the
necessary additions added for loading, saving and manipulating the PREC 4 resource.
The List Manager is used to display and select the 6 possible buttons.
With all this said and done, it is good to note that Apple has announced that with
System 7.0, spooling will be supported for all printers, not just the LaserWriter.
Personally, I use the AppleTalk ImageWriter driver with 2 Macs wishing that the
background printing was supported with the current system.
unit globals;
interface
var
MyWindow: WindowPtr; {Window pointer}
TitleFieldhndl: TEHandle; {Text Edit field handle}
WidthFieldhndl: TEHandle; {Text Edit field handle}
HeightFieldhndl: TEHandle; {Text Edit field handle}
reply: SFReply;
realprec = record
numberof buttons: signedbyte;
Size: array[1..6] of point;
title: packed array[0..255] of char;
end;
realprec4ptr = ^realprec;
realprec4hndl = ^realprec4ptr;
prec = record
numberof buttons: integer;
Size: array[1..6] of point;
Title: array[1..6] of str255;
end;
prec4ptr = ^prec;
prec4hndl = ^prec4ptr;
var
therealprec4: realprec;
therealprec4hndl: realprec4hndl;
prec4: prec;
theprec4hndl: prec4hndl;
implementation
end.
unit InitTheMenus;
{File name: InitTheMenus.p}
{Function: Pull in menu lists from a resource file.}
{ This procedure is called once at program start.}
{ AppleMenu is the handle to the Apple menu, it is also}
{ used in the procedure that handles menu events.}
{History: 6/10/89 Original by Prototyper. }
interface
procedure Init_My_Menus; {Initialize the menus}
var
AppleMenu:MenuHandle; {Menu handle}
M_File:MenuHandle; {Menu handle}
M_Edit:MenuHandle; {Menu handle}
implementation
procedure Init_My_Menus; {Initialize the menus}
const
Menu1 = 1001; {Menu resource ID}