HP LaserJet 4PJ Programming Tips
This section provides programming tips concerning specific
considerations for the HP LaserJet 4PJ printer. This section covers
general print job initialization, font metric calculation, vertical writing,
and other issues which are pertinent to printing Japanese text on the
HP LaserJet 4PJ printer using PCL 5.
General Print Job Initialization
This example demonstrates the general print job initialization
procedure for the HP LaserJet 4PJ printer, which is slightly different
than that used for other HP LaserJet printers.
Output from pre-LaserJet 4PJ PCL drivers (for example, a
HP LaserJet 4P driver) will only print correctly on the
HP LaserJet 4PJ printer if the default PCL symbol set is set to a value
other than the Japanese Windows 3.1 (Win3.1J) symbol set. This is
because the default PCL text parsing method is set based on the
default PCL symbol set. When the default PCL symbol set is set to
Win3.1J, the default text parsing method is Shift-JIS parsing; for any
other value, such as Roman-8, the default text parsing method is
1-byte parsing. To set the default PCL symbol set value, use PJL or
the control panel.
The first example given here is nearly identical to the initialization
used for other HP LaserJet 4 family printers. The only difference is
that it includes a PJL command to set the default PCL symbol set to
Roman-8.
?
%-12345X@PJL<CR><LF>
@PJL SET RESOLUTION=600<CR><LF>
@PJL PAGEPROTECT=OFF<CR><LF>
@PJL RET=MEDIUM<CR><LF>
@PJL COMMENT *** This command is added ***
@PJL SET LPARM:PCL SYMSET=ROMAN8<CR><LF>
@PJL ENTER LANGUAGE=PCL<CR><LF>
?
E
?
&l1x1s1h2a0o8c6e54F
?
&a5L
?
(0U
?
(s1p9vs3b41
~
01T
The commands in the above example are explained in more detail in
the PCL 5 and PJL technical reference manuals.
ENWW
Printer-Specific Differences 2-49
The second example given here initializes a PCL 5 print job for
printing Japanese text. The major differences from the previous
example are that it specifies A4 paper, initializes the text parsing
method to Shift-JIS, selects Win3.1J as the primary symbol set,
selects MS-Mincho as the primary font.
?
%-12345X@PJL<CR><LF>
@PJL SET RESOLUTION=600<CR><LF>
@PJL PAGEPROTECT=OFF<CR><LF>
@PJL RET=MEDIUM<CR><LF>
@PJL ENTER LANGUAGE=PCL<CR><LF>
?
E
?
&l1x1h26a0o8c6e60F
?
&a5L
?
&t31P
?
(19K
~?
(s1p10v0s0b28752T
The last line (2 lines, as shown) in the above example is a PCL 5
initialization string. This set of commands resets the printer, specifies
1 copy, specifies the paper tray as a paper source, chooses A4-size
paper, selects portrait orientation, VMI=8 (6LPI), sets top margin to
6 lines, selects a text length of 60 lines, a 5-column left margin,
Shift-JIS parsing, WIN3.1J symbol set, and a proportional, 10-point,
upright, text-weight MS-Mincho font.
After the PCL print data, the following commands would be used to
complete the job:
?
E
?
%-12345X
Font Metric Calculation
Accurate character placement relies on the ability to predict character
width and height. As a character’s point size changes, so does its
width and height. (CAP displacement, the distance the CAP moves
for vertically rotated text, is a full-width calculation.)
In proportionally spaced fonts, character widths also vary from
character to character within the font. Variable character widths add
complexity to maintaining accurate line widths, page breaks, or
WYSIWYG operation. To support most proportionally spaced fonts,
font metrics must be extracted from the font metric files.
2-50 Printer-Specific Differences
ENWW
In the MS-Mincho and MS-Gothic fonts provided in the
HP LaserJet 4PJ, font metric calculation is somewhat easier than for
the Latin-based fonts. Width calculations are easier because all
characters of these fonts conform to one of two different character
widths at a particular point size. The characters are either considered
full-width or half- width. One-byte characters are always half-width
and two-byte characters are always full-width.
Full-width characters occupy the entire EM width at a particular point
size. Half-width characters occupy half of an EM width. The following
equations show how to calculate the EM width and character widths
for a full-width and a half-width character.
ppem = round (DeviceResolution * PointSize/72)
FullWidthDeltaX = round (ppem * PCLUnits/ DeviceResolution)
HalfWidthDeltaX=round ((ppem/2) * PCLUnits/DeviceResolution)
where:
ppem = EM width in pixels
DeviceResolution = current device resolution in dots per inch
(600 or 300dpi)
PointSize = point size requested
FullWidthDeltaX = character width of full-width character in PCL Units
HalfWidthDeltaX = character width of half-width character in PCL Units
PCLUnits = PCL Units
The PCL Unit of measure is explained in more detail in the PCL 5
Technical Reference Manual. The default PCL Unit size is 1/300th of
an inch, but the Unit of Measure command can be used to set the
PCL Unit size to other values.
Note that HalfWidthDeltaX may not be exactly half of FullWidthDeltaX
because of rounding. For example, if FullWidthDeltaX = round(99.0) =
99, then the corresponding HalfWidthDeltaX = round(99.0/2) =
round(49.5) = 50.
ENWW
Printer-Specific Differences 2-51
Character Enhancements
The HP LaserJet 4PJ printer supports PCL pseudo-bold and
pseudo-italic character enhancements. These enhancements can be
applied to the internal MS-Mincho and MS-Gothic fonts. They can
also be applied to a TrueType soft font if a suitable “Character
Enhancement” Segment is downloaded with the font header.
The enhancements are selected using PCL font selection commands.
The pseudo-italic enhancement can be selected using the Style
command. The pseudo-bold enhancement can be selected using the
Stroke Weight command. The bold levels which can be applied to the
internal MS-Mincho and MS-Gothic fonts are Semi Bold, Demi Bold,
Bold, and Extra Bold. For example, to select a 10-point, Extra Bold,
Italic, MS-Mincho font, use the following PCL command:
?
(19K
?
(s1p10v1s4b28752T
In the above command, Italics style (1s) and Extra Bold weight (4b)
are selected. Since there is not an Extra Bold Italic MS-Mincho font
resident in the printer, pseudo-italics and pseudo-bolding algorithms
are applied to characters printed from the regular MS-Mincho font.
If a soft font is selected using the “Font Selection by ID” command
(e.g.
?
(#X ), the font is selected without any character
enhancements applied. To select a soft font by ID with character
enhancements, first select the font by ID, then select the desired
attributes. For example, assume a soft font is downloaded with ID = 1
and a Character Enhancement Segment indicating that pseudo-bold
and pseudo-italics character enhancements can be applied. The
following command can be used to select that font with those
enhancements:
?
(
1X
?
(s1s3B
Other font effects, such as character shadowing, strike-through, and
gray-shading can be accomplished using the print model.
2-52 Printer-Specific Differences
ENWW
Note
HP-GL/2 as implemented in HP LaserJet printers has no mechanism
for parsing 2-byte characters. Therefore, HP-GL/2 character
transformations (e.g. SI and SR commands) cannot be applied to
these characters.
HP-GL/2 as implemented in HP LaserJet printers has no mechanism
for parsing 2-byte characters. Therefore, HP-GL/2 character
transformations (e.g. SI and SR commands) cannot be applied to
these characters.
Vertical Writing
Vertical writing can be accomplished using the vertical rotated (“-1”)
mode of the Character Text Path command (
?
&c-1T). When using a
vertical rotated text path direction, full-width characters are rotated
and printed “on their sides.” All other characters are unaffected and
the CAP is still advanced in the horizontal direction. The “-1” mode
has the effect of transforming a portrait page with horizontal full-width
characters into a landscape page with vertical full-width characters.
This can be combined with the Print Direction command (
?
&a#P) to
achieve the desired text orientation (e.g. portrait, landscape, reverse
portrait, or reverse landscape).
An example of horizontal and vertical rotated writing is shown below.
The first line of text is horizontal writing and the second line is vertical
rotated writing. Note that the “~” character is replaced with a vertical
substitute on the second line. The C program that follows was used to
generate the PCL commands for this example.
ENWW
Printer-Specific Differences 2-53
#include <stdio.h>
#include <fcntl.h>
#define MONTH “\202P\202P\214\216"
#define DAY1 ”\202P\202U\223\372"
#define TILDE “\201\140"
#define DAY2 ”\202P\202V\223\372"
#define KANJITXT MONTH DAY1 TILDE MONTH DAY2
FILE *prn;
main()
{
int point_size=24;
prn = fopen(“lpt1",”wb"); /* open lpt1 for writing */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
fprintf(prn,"@PJL ENTER LANGUAGE=PCL\n"); /* Enter PCL */
fprintf(prn,"\33E"); /* send an esc E to reset printer */
fprintf(prn,"\33&a4L"); /* left margin */
fprintf(prn,"\33&t31P"); /* text parsing = Shift-JIS */
fprintf(prn,"\33(19K"); /* symbol set = Win3.1J */
fprintf(prn,"\33(s1p%dv0s0b28752T",point_size); /* MS-Mincho */
fprintf(prn,"\n\n\n\r" KANJITXT); /* print horizontal version */
fprintf(prn,"\33&c-1T"); /* select vertical writing */
fprintf(prn,"\n\n\n\r" KANJITXT); /* print vertical version */
fprintf(prn,"\f"); /* formfeed */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
}
Printing Ruby Characters (Furigana)
Ruby characters, also known in Japanese as furigana, are small
characters typically used as an aid in kanji pronunciation. Ruby
characters are usually (but not always) hiragana. They are generally
placed above the corresponding kanji in horizontal writing and to the
right in vertical writing. Ruby characters can be generated using font
scaling and cursor positioning commands.
An example of ruby characters is shown below. In this example, the
ruby characters are printed at one-third the size of the kanji. The C
program that follows was used to generate the PCL commands for
this example.
2-54 Printer-Specific Differences
ENWW
#include <stdio.h>
#include <fcntl.h>
#define KANJITXT “\225\127\226\173"
#define RUBYTXT ”\202\320\202\345\202\244 \202\331\202\361 “
FILE *prn;
main()
{
int point_size=72;
prn = fopen(”lpt1","wb"); /* open lpt1 for writing */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
fprintf(prn,"@PJL ENTER LANGUAGE=PCL\n"); /* Enter PCL */
fprintf(prn,"\33E"); /* EscE to reset printer */
fprintf(prn,"\33&t31P"); /* text parsing = Shift-JIS */
fprintf(prn,"\33(19K"); /* symbol set = Win3.1J */
fprintf(prn,"\33(s1p%dv0s0b28752T",point_size); /* MS-Mincho */
fprintf(prn,"\33*p300x400Y"); /* set cursor position */
fprintf(prn,KANJITXT); /* print kanji characters */
fprintf(prn,"\33(s%dV",point_size/3); /*furigana point size */
fprintf(prn,"\33*p300x%dY",400-4*point_size);/*cursor position*/
fprintf(prn,RUBYTXT); /* print ruby characters */
fprintf(prn,"\f"); /* formfeed */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
}
ENWW
Printer-Specific Differences 2-55
Vertical Underlining
In Japanese writing, vertical underlines are placed to the right of
vertical columns of text. This can be accomplished in PCL 5 using the
Fill Rectangular Area command.
An underline is simply a long thin black-filled box. The length of the
underline depends on the length of the text to be underlined.
An example of vertical underlining is shown below. The C program
that follows was used to generate the PCL commands for this
example.
#include <stdio.h>
#include <fcntl.h>
#define MONTH “\202P\202P\214\216"
#define DAY1 ”\202P\202U\223\372"
#define TILDE “\201\140"
#define DAY2 ”\202P\202V\223\372"
#define KANJITXT MONTH DAY1 TILDE MONTH DAY2
FILE *prn;
main()
{
int point_size=24;
prn = fopen(“lpt1",”wb"); /* open lpt1 for writing */
2-56 Printer-Specific Differences
ENWW
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
fprintf(prn,"@PJL ENTER LANGUAGE=PCL\n"); /* Enter PCL */
fprintf(prn,"\33E"); /* Esc E to reset printer */
fprintf(prn,"\33&t31P"); /* text parsing = Shift-JIS */
fprintf(prn,"\33(19K"); /* symbol set = Win3.1J */
fprintf(prn,"\33&a270P"); /* print direction = 270 */
fprintf(prn,"\33*p500x1300Y"); /* set CAP position */
fprintf(prn,"\33(s1p%dv0s0b28752T",point_size); /* MS-Mincho */
fprintf(prn,"\33&c-1T"); /* select vertical writing */
fprintf(prn, KANJITXT); /* print vertical text */
fprintf(prn,"\33*p500x%dY",1300-point_size*4); /* set CAP for
underline*/
/* draw underline */
fprintf(prn,"\33*c%da3b0P",300 * strlen(KANJITXT)/2 *
point_size/72);
fprintf(prn,"\f"); /* formfeed */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
}
ENWW
Printer-Specific Differences 2-57
Vertical Clusters
Vertical clusters are groups of two or three narrow characters
side-by-side in a vertical line of text. Vertical clusters containing
half-width characters can be created by using a combination of print
direction and cursor positioning commands.
An example of vertical clusters is shown below. The C program that
follows was used to generate the PCL commands for this example. In
this example, two half- width characters (e.g. 2-digit numbers) were
printed as vertical clusters.
#include <stdio.h>
#include <fcntl.h>
#define MONTH “\214\216"
#define TILDE ”\201\140"
#define DAY “\223\372"
#define CLUSTER ”\201\100\033&f0S\033&a0P%s%d\033&a270P\033&f1S"
FILE *prn;
main()
{
int point_size=24;
int offset;
char OFFSET[40];
prn = fopen(“lpt1",”wb"); /* open lpt1 for writing */
offset = ( 36 * point_size * 300) /
2-58 Printer-Specific Differences
ENWW
/* —— ————— */
( 256 * 72 );
sprintf(OFFSET,"\33*p-%dx-%dY",offset,offset); /* used to
place cluster */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
fprintf(prn,"@PJL ENTER LANGUAGE=PCL\n"); /* Enter PCL */
fprintf(prn,"\33E"); /* Esc E to reset printer */
fprintf(prn,"\33&t31P"); /* text parsing = Shift-JIS */
fprintf(prn,"\33(19K"); /* symbol set = Win3.1J */
fprintf(prn,"\33&a270P"); /* print direction = 270 */
fprintf(prn,"\33*p500x1300Y"); /* set CAP position */
fprintf(prn,"\33(s1p%dv0s0b28752T",point_size); /* MS-Mincho */
fprintf(prn,"\33&c-1T"); /* select vertical writing mode */
fprintf(prn, CLUSTER MONTH, OFFSET, 11); /* print month */
fprintf(prn, CLUSTER DAY, OFFSET, 16); /* print day */
fprintf(prn, TILDE); /* print tilde */
fprintf(prn, CLUSTER MONTH, OFFSET, 11); /* print month */
fprintf(prn, CLUSTER DAY, OFFSET, 17); /* print day */
fprintf(prn,"\f"); /* formfeed */
fprintf(prn,"\33%%-12345X"); /* send UEL to get to PJL */
}
ENWW
Printer-Specific Differences 2-59