Category : Dbase (Clipper, FoxBase, etc) Languages Source Code
Archive   : TN9101.ZIP
Filename : MASTERHP.TXT
Output of file : MASTERHP.TXT contained in archive : TN9101.ZIP
This article is reprinted from the January 1991 edition of
TechNotes/dBASE IV. Due to the limitations of this media, certain
graphic elements such as screen shots, illustrations and some tables
have been omitted. Where possible, reference to such items has been
deleted. As a result, continuity may be compromised.
TechNotes is a monthly publication from the Ashton-Tate Software
Support Center. For subscription information, call 800-545-9364.
Mastering Your HP Printer
Martin Leon
The Hewlett Packard laser printer family affords you a lot of options
in printing out your reports and labels from dBASE IV. You can change
the page orientation, print a variety of typestyles, character pitches
and symbol sets, and print on a variety of forms. In order to be able
to unleash this power in your favor, you need to understand a little
bit about how these printers work and how dBASE IV communicates with
them.
The first thing to know about laser printers is that they are page
printers. Unlike most dot matrix printers, they do not begin to
advance the page until a full page of text has been received or until
a command has been issued to tell it to release the page. From the
dot prompt in dBASE IV, the command to do this is EJECT. If the Form
Feed light on the printer remains on after you've sent a report or
some other output to the printer, that indicates that a portion of the
information you sent is still in the memory of the printer, which you
can print out by issuing an EJECT command or by taking the printer
off-line and pressing the Form Feed button.
Buffer, Buffer, What's In the Buffer?
To prevent this "page hanging" from occurring, an option has been put
on the Print: Control of printer menu that instructs dBASE IV to
automatically send an EJECT command to the printer before, after, or
before AND after your report has been printed (or not at all).
Setting it to AFTER is good enough if you use this option consistently
on all your output to the printer.
The HP laser printers have a very extensive set of control codes.
Look in the appendices in your user manual for a complete listing of
those that work with your printer; special combinations of characters
that talk directly to the printer and are not printed on the document
that you are printing. Almost all of the control codes that the HP
printers use begin with the Escape character ({ESC}, {27} or CHR(27)
in dBASE IV) and end with an alphabetic character. The HP manuals
indicate the Escape character as ec. Also, in most cases where the
control codes end with an alphabetic character, that character can be
either lower case or upper case. If it is upper case, that indicates
to the printer the end of the control codes and any new instructions
would need to be prefixed with the Escape character. It is sometimes
possible to put several commands together. To do so, you would leave
the ending alphabetic character lower case and piece several commands
together without having to resend the Escape character. The combining
of separate instructions is dependent on what common character
sequences they have. For example, you could send either of the two
escape sequences below and they will perform the same function.
{ESC}&l3E{ESC}&l54F
{ESC}&l3e54F
When Do I Use What?
There are sometimes three ways of expressing a control character. The
Escape character, for example, can be expressed using the CHR()
function. Curly braces allow you to express Escape as {27} or {Esc}.
This is the most commonly used non-printable character as most
printers use it as a cue for instructions rather than output to
print. If the curly brace means of expressing ASCII characters is
used in a program statement or at the dot prompt, it is also enclosed
in quotes along with the other literals. Or you can concatenate a
CHR(27) with a plus sign to a string expression.
The exception is that the CHR() function is not applicable to use in
Starting and Ending control code expression areas when designing
reports and forms. You use the curly brace method of expressing
characters like Escape and you do not use quotation marks. Got that?
Okay, let's go on.
Controlling Control Codes
In dBASE IV there are several ways to get control codes to the
printer. In a report you can specify control codes that you want to
be sent at the beginning and at the end of each print job. These are
stored in a print form file (not to be confused with a report form)
which has an extension of .PRF. In fact, all of the settings that you
put in to the Print menu can be saved in the print form: the
destination (file or printer), driver to use, page dimensions, and
several other settings. Printer escape codes are stored to the print
form via the Print: Control of printer: Starting/Ending control codes
options. Starting control codes are sent at the beginning of each
print job (such as a report or label run), directly after the control
codes that are sent by the driver you have selected. The driver
initializes the printer to certain settings, but since your starting
control codes come after the drivers control codes, you get the final
say in how the printer is set up to print.
Using Print Forms
The print form settings are only invoked automatically when you print
from the Control Center or from the Report Generator. In a program,
an Applications Generator application, or from the Dot Prompt, you
would have to explicitly tell dBASE IV which print form to use. You
do this by changing a system memory variable called _pform. To change
or assign a value to this variable, you enter, at the dot prompt or in
a program:
_pform = "
using your print form name in quotes. This must be done prior to
printing the report or label for which you set up this print form. If
you don't run this command, the print settings will be at their
default values and the report may not look the same as when you
printed from the Control Center. The codes you enter here will be
sent as if they were prefaced with the ??? command and surrounded by
quotes. For example if you entered {ESC}E as the ending code, picture
it as being sent by the command:
??? "{ESC}E"
The ??? command bypasses the current printer driver and sends
characters directly to the printer without adding a carriage return.
Combined with the ability of dBASE IV to refer to any ASCII character
by its decimal value in curly braces (such as {9} represents a TAB
character), this is an ideal way to send printer control sequences.
SET PRINT ON is not necessary with the ??? command.
Laser Printer Attributes
A very handy feature of the laser printer comes in being able to
change the orientation of the print so that it prints sideways on the
paper, which is referred to as landscape printing. This obviously
lets you squeeze more information across the page. Whenever you send
escape codes to an HP laser printer, the orientation codes should be
sent first. In dBASE IV, the way to change the orientation is by
sending the following characters to the printer: {ESC}&l1O for
landscape, {ESC}&l0O for portrait. Note that the last character is a
capital O and not a zero.
HP Laser printers have the ability to print using different fonts.
Fonts are defined as being a combination of symbol set, spacing,
pitch, point size, style, stroke weight, and typeface. A complete
printer instruction (escape sequence) may set each attribute mentioned
here but none are necessarily required. Your instruction may change
only the point size or typeface and not disturb the settings of other
attributes. Also, two distinct fonts can be defined in printer memory
that can be interchanged via printer control sequence.
A symbol set is the set of characters that the printer uses to
represent each of up to 256 characters in the ASCII character table.
The reason for these different symbol sets is that there are
potentially more than 256 different characters that could be
represented by an ASCII code (depending on what language you are using
and how many additional characters you want to be able to print, such
as math symbols and box and line symbols) but there are only 256 ASCII
character codes available (numbered 0 - 255).
Initially, there were only 128 ASCII codes (called a 7 bit set where
0111 1111 in binary = 127) which was expanded to 256 (called an 8 bit
set where 1111 1111 in binary = 255). Some of the Hewlett Packard
symbol sets are 7 bit sets and some are 8 bit sets, so if you were
using a 7 bit symbol set and asked the printer to print ASCII
character 145 you would get a blank character. The various symbol
sets can represent the ASCII codes with different characters. For
example, with the Roman 8 symbol set, ASCII character 209 (referred to
in dBASE IV as CHR(209) or sometimes {209}) is represented with a
character, but in the PC 8 symbol set it is a character. The dBASE
IV symbol set you see on your screen corresponds to the PC 8 symbol
set.
This symbol set will allow you to print any of the control characters
(the first 32 characters in the ASCII setÄthese characters have
special significance: they are characters such as the Escape
character, the line feed character, the form feed character, the end
of file character, and others). This set will also print any of the
box and line characters. As you can see from the list below, not all
8 bit symbol sets give you the ability to print box and line
characters. If you want to be able to print boxes and lines you must
use the PC 8 symbol set. The sequence to select a symbol set is:
{ESC}(# , where # is replaced by a symbol number. The "(" character
tells the printer that we are configuring the primary font. You can
define two fonts. To configure the secondary font, you would use the
")" character instead.
ymbol Set Sym Num 7/8 Bit Boxes/Lines Control Characters
ISO 6:ASCII 0U 7 N N
HP Roman8 8U 8 N N
PC-8 10U 8 Y Y
PC-8 (D/N) 11U 8 Y Y
PC 850 12U 8 N Y
HP Math-8 8M 8 N Y
HP Math 0A 8 N N
HP Line Draw 0B 8 N N
Proportional Printing
After deciding on a symbol set, you can select several aspects of how
the letters are printed out. You can select proportional or fixed
spacing. Fixed spacing means every character takes up the same amount
of space no matter how wide the character actually is; proportional
spacing means that the characters only take up as much space as they
need. In the PC world, we are used to seeing all characters take up
the same amount of space. For example, the letter m takes up just as
much space as the letter i. If you look at the letters on this page
you'll notice that an m takes up nearly 3 times the space of an i.
This is called proportional spacing which results in very
aesthetically pleasing documents.
However, if you are printing a report where you want the information
to appear in a columnar format, you can see that using proportional
spacing would prevent the columns from lining up unless every one had
the exact same letters in it. The problem with using proportional
fonts is that they throw off the appearance of both a mailmerge
document or columnar report. Their use is, therefore, not
recommended. To select proportional spacing, you send the following
to the printer:
{ESC}(s1P for proportional
{ESC}(s0P for fixed spacing
Now you need to decide on a character pitch, or how many characters in
a horizontal inch. The default factory setting is 10 characters per
inch, but often times you need to get more information on a page. The
most common condensed character pitch is 16.66 characters lines per
inch. Increasing the character pitch value allows you to do this. To
change the character pitch you need to send the following to the
printer:
{ESC}(s#H
where the # is replaced by a numeric value representing the number of
characters per inch. For example, to get condensed print (16.66
characters per inch) you might put the following command in a program:
.??? "{ESC}(s16.66H"
Now you can select a point size. Point size indicates how tall the
letters are. There are 72 points in a vertical inch. If you wanted
your letters to be 1/2" tall you would specify a point size of 36. To
do this you would send the following to the printer:
{ESC}(s36V
Next is the stroke weight. Think of this as being how heavily you are
leaning on a pen while writing: the heavier you press on it, the
thicker the ink comes out on the page. A medium stroke weight is 0,
bold is 3, light is -3. To change the stroke weight you send the
following to the printer:
{ESC}(s#B
where # is replaced by either 3, 0 , or -3.
Now you select the style of the letters: upright or italic. The code
for upright letters is
{ESC}(s#S
where # is replaced by either 0 for upright or 1 for italic.
Finally, you select a typeface. The typeface is what most people
envision as being a font. For example, one typeface might look like
the output from a typewriter, and another might look like written
script. To select a typeface you send the following to the printer:
{ESC}(s#T
where # is the number of the typeface you want to select.
A very important fact to keep in mind is that your laser printer comes
from the factory with a relatively limited set of fonts. So the
printer might not be able to oblige you when you request a particular
font configuration. This is where font cartridges help by extending
the number of font configurations you have access to. The laser
printer tries its best to accommodate your requests by selecting the
most similar font settings to what you requested. So if you send
control codes to the printer and they don't appear to affect the
printout at all, maybe the printer does not have access to the font
combination you are requesting.
Drawing Box and Line Characters
Some of the most common questions people have are regarding setting up
fonts and not getting box and line characters. However, if you don't
have the right symbol set, you will not be able to get box and line
characters to your printout.
With regards to driver selection, dBASE IV relates to printers so
simply that drivers aren't critical, but more of a convenience. Since
dBASE IV does all of its printing through DOS, it does not communicate
directly with your printer. In other applications, you might not be
able to print if you don't select the exact printer driver for the
printer you are using because the printer is often accessed directly.
With dBASE IV, printer drivers give you access to enhanced printer
functionality like underlining, condensed printing, and boldface by
giving dBASE IV access to the special control codes that invoke those
features. If you don't find the driver for your printer in the list
of printers in DBSETUP, you can always print using the ASCII Text
driver (the exception are PostScript printers Ä use the Apple
Laserwriter driver).
The ASCII text driver does not send any control codes to the printer,
but you can still print in dBASE IV, just without any special
formatting. The printer will print using whatever settings you've
selected from its control panel. Specifically relating to HP laser
printers, the drivers we provide initialize the printer to use a
certain font, line and margin settings. If you are going to take care
of all of the settings through control codes, you can just use the
ASCII Text driver.
For those with LaserJet Series III printers, you can use any of the
same drivers because the same control codes are used to initialize the
printer. If you have a LaserJet III with a PostScript cartridge and
you want to use the printer in PostScript mode, use the Apple
LaserWriter driver.
Below is a list of the dBASE IV Hewlett Packard drivers and how they
set up your printer. NA means that particular setting is not
addressed. This will help you understand what your printer is set to
whenever you choose one of our drivers. You can always override these
settings by sending your own starting and ending control codes.
Driver Name Orient. Top Mar. Skip Perf? LPI G.Res
Symbol Set Duplex Text Length
HPLAS100.PR2 PORT 2 Y 6.5 100 HP ROMAN 8
NA NA
HPLAS260.PR2 PORT 3 Y 6.0 300 PC 8 NA
NA
HPLAS2I.PR2 PORT 2 Y 6.5 300 PC 8 NA
NA
HPLAS2ID.PR2 PORT 2 Y 6.5 300 PC 8
LONG NA
HPLAS60.PR2 PORT 3 Y 6.0 100 HP ROMAN 8
NA NA
HPLASD60.PR2 PORT 3 Y 6.0 300 PC 8
LONG NA
HPLASL.PR2 LAND 0 N NA NA HP ROMAN 8
NA 51
HPLASL45.PR2 LAND 3 Y NA NA HP ROMAN 8
NA NA
HPLS2L45.PR2 LAND 3 Y 6.0 NA PC 8 NA
NA
Blank Page Ejects
Often times, your printer decides to eject blank pages between each
page of your report. This is sometimes due to the Print: Control of
printer: New Page setting, but most of the time it is caused by the
printer disagreeing with dBASE IV as to how many lines should be
printed on a page. dBASE IV sends as many lines to the printer as you
specify in the Print: Page Dimensions: Length of Page setting. If you
tell dBASE IV that the page length is 66, for example, and the printer
knows that it can't really print 66 lines on a page, the printer will
automatically do a form feed when it gets to what it determines to be
the end of the page.
dBASE IV continues sending lines until it reaches the number of lines
per page set. It then informs the printer to do another form feed
because dBASE IV is not aware that the printer has already ejected the
page. The end result could be a blank page in between each page of
your report, or a small portion of one page being printed on the
subsequent page. The solution is to reduce the Print: Output options:
Length of Page setting or set the printer so that it can print more
lines per page.
Setting Up Fonts
Here is a suggestion on setting up fonts in your CONFIG.DB file.
Since the printer has a primary and secondary font, make the starting
control code for a font define a secondary font and then switch to
it. Then make the ending code a command to switch back to the primary
font. For example, your primary font is set to Times Roman with
standard character pitch, spacing, etc. and you want to select a font
that is Helvetica bold italic.
This code defines the secondary font and the {14} at the end tells the
printer to switch to the secondary font. As the ending control code
you would just have a {15} which tells the printer to switch back to
the primary font. Also, once you define the font codes in DBSETUP,
you have to tell dBASE IV that you want to use the printer that you
defined those fonts for. Once you do so from the Print Menu, when you
are designing your reports or labels, you can go to the Words menu and
open the Style submenu and have access to the fonts you defined. You
can apply a font to whatever text is currently highlighted. You
should never include an {ESC}E as part of your font code as this will
flush printer memory and set it to the settings that you entered on
the printer control panel, causing it to lose whatever font
definitions or data you've sent to it.
Now that you have an idea of how you can control your printer, you can
put together an application that let's you pick your printer
configuration from popups or menus. It's recommended you use the
ASCII driver as your default driver if you are going to consistently
use such an application to control your printer. That way you can be
assured of full control over all of the printer's configuration
settings. As mentioned earlier, by using the ??? command you can send
a control sequence to the printer. Look at the following code for a
fairly simple example of such a program. This program requires a
database with the following structure:
Field Name Type Width Index
FONTNAME Character 50 Y
CODE Character 60 N
Using this database you can define as many fonts as your printer
supports, and by putting in the appropriate code you can invoke
whichever font you like. The field FONTNAME will be used as a prompt
in a popup. When you select the desired font, the corresponding CODE
will be sent to the printer. Below are a few sample records.
FONTNAME CODE
Helvetica Bold fixed 12pt 10 pitch italic
{ESC}(s0p10.00h12.0v1s3b4T
Helvetica Bold proportional 12pt 10 pitch italic
{ESC}(s1p10.00h12.0v1s3b4T
Helvetica Bold proportional 12pt 17 pitch italic
{ESC}(s1p16.66h12.0v1s3b4T
Helvetica Bold fixed 12pt 17 pitch italic
{ESC}(s0p16.66h12.0v1s3b4T
Helvetica Bold fixed 10pt 10 pitch upright
{ESC}(s0p10.00h10.0v0s3b4T
Helvetica Light fixed 10pt 10 pitch upright
{ESC}(s0p10.00h10.0v0s-3b4T
PrintMan.PRG
SET TALK OFF
SET CONFIRM ON
SET ESCAPE OFF
CLEAR
IF .NOT. FILE("FONTS.DBF")
@ 4,9 CLEAR TO 8,69
@ 4,9 TO 8,69 DOUBLE
@ 6,14 SAY "You Must Create Fonts.DBF before using this
program"
SET TALK ON
SET CONFIRM OFF
SET ESCAPE ON
RETURN
ENDIF
IF .NOT. PRINTSTATUS()
@ 4,5 TO 9,72 DOUBLE
@ 6,10 SAY "Printer not ready Ä waiting for printer to be put
on-line"
@ 7,28 SAY "Press Any Key to Abandon"
SET ESCAPE OFF
mX = 0
DO WHILE .NOT. PRINTSTATUS() .AND. mX = 0
mX = INKEY()
ENDDO
IF .NOT. PRINTSTATUS()
SET TALK ON
SET CONFIRM OFF
SET ESCAPE ON
RETURN
ENDIF
ENDIF
CLEAR
USE FONTS ORDER FONTNAME
DEFINE WINDOW winTemp FROM 0,0 TO 23,79 NONE
DEFINE POPUP PrintMain FROM 0,0 TO 8,24
DEFINE BAR 1 OF PrintMain PROMPT " Select An Action" SKIP
DEFINE BAR 2 OF PrintMain PROMPT REPLICATE(CHR(205),23) SKIP && Bar
Character
DEFINE BAR 3 OF PrintMain PROMPT " Send Page Eject"
DEFINE BAR 4 OF PrintMain PROMPT " Orientation"
DEFINE BAR 5 OF PrintMain PROMPT " Lines Per Inch"
DEFINE BAR 6 OF PrintMain PROMPT " Font Selection"
DEFINE BAR 7 OF PrintMain PROMPT " Reset Printer ESC E"
ON SELECTION POPUP PrintMain DO MainProc
DEFINE POPUP OriPop FROM 5,18 TO 10,42
DEFINE BAR 1 OF OriPop PROMPT " Select an Orientation" SKIP
DEFINE BAR 2 OF OriPop PROMPT REPLICATE(CHR(205),23) SKIP
DEFINE BAR 3 OF OriPop PROMPT " Portrait"
DEFINE BAR 4 OF OriPop PROMPT " Landscape"
ON SELECTION POPUP OriPop DEACTIVATE POPUP
DEFINE POPUP FontPop FROM 5,14 TO 21,64 PROMPT FIELD FontName
ON SELECTION POPUP FontPop DO FontSend
ACTIVATE WINDOW winTemp
ACTIVATE POPUP PrintMain
DEACTIVATE WINDOW winTemp
RELEASE WINDOW winTemp
RELEASE POPUPS PrintMain, OriPop, FontPop
SET CONFIRM OFF
SET TALK ON
SET ESCAPE ON
USE
RETURN
PROCEDURE MainProc
DO CASE
CASE BAR() = 3
EJECT
DO MsgLine WITH "Page Eject sent to printer"
CASE BAR() = 4
ACTIVATE POPUP OriPop
IF LASTKEY() # 27
DO CASE
CASE BAR() = 3
??? "{ESC}&l0O"
DO MsgLine WITH "Printer set
to Portrait orientation"
CASE BAR() = 4
??? "{ESC}&l1O"
DO MsgLine WITH "Printer set
to Landscape orientation"
ENDCASE
ENDIF
CASE BAR() = 5
mLPI = "6 "
@ 0,25 TO 2,61 DOUBLE
@ 1,27 SAY "Enter desired lines per inch" GET mLPI
PICTURE "99" ;
VALID TRIM(mLPI) $ "1,2,3,4,6,8,12,16,24,48" ;
MESSAGE "Value must be 1,2,3,4,6,8,12,16,24 or
48"
READ
IF READKEY() = 12
@ 0,25 CLEAR TO 2,61
DO MsgLine WITH "Lines Per Inch Setting Not
Modified"
RETURN
ENDIF
@ 0,25 CLEAR TO 2,61
??? "{ESC}&l" + RTRIM(LTRIM(mLPI)) + "D"
DO MsgLine WITH "Lines per Inch set to " + mLPI
CASE BAR() = 6
IF RECCOUNT() < 1
DO MsgLine WITH "No Fonts in Fonts Database!"
ELSE
ACTIVATE POPUP FontPop
IF LASTKEY() # 27
DO MsgLine WITH TRIM(FontName)+" Sent
to Printer"
ENDIF
ENDIF
CASE BAR() = 7
??? "{ESC}E"
DO MsgLine WITH "Printer reset Ä ESC E Sent"
ENDCASE
RETURN
PROCEDURE FontSend
IF LASTKEY() # 27
mVar = TRIM(PROMPT())
SEEK mVar
??? TRIM(Code)
ENDIF
DEACTIVATE POPUP
RETURN
PROCEDURE MsgLine
PARAMETER MsgString
SET CURSOR OFF
@ 10, 40 - LEN(TRIM(MsgString))/2 SAY MsgString COLOR RG+/RB
X = 0
DO WHILE X = 0
X = INKEY()
ENDDO
SET CURSOR ON
KEYBOARD CHR(X)
@ 10,0 CLEAR TO 10,79
ACTIVATE WINDOW winTemp
RETURN
* End of PrintMan.PRG
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/