Category : Files from Magazines
Archive   : CGAZ2-4.ZIP
Filename : HPGRAPHA.C

 
Output of file : HPGRAPHA.C contained in archive : CGAZ2-4.ZIP
/************************ HPGRAPHA.C ****************************
* Program to demonstrate use of built-in graphics features of *
* the HP Laserjet II. (c) Copyright 1988, Billy Rubin. Veri- *
* fied on Datalite, DeSmet, Eco, Lattice, Metaware, MS, Turbo *
****************************************************************/

#include

/* -- UNITS OF MEASURE -- */
#define DOTS 1 /* 300 / inch maximum */
#define DECI 2 /* 1 inch = 720 decipoints */
#define COLS 3 /* Column width. Can be set. */
#define ROWS 4 /* Rows just means lines */

/* -- AREA FILL TYPES -- */
#define SOLID 0 /* Solid black, 100% shading */
#define SHADING 2 /* Specified in % of shading */
#define PATTERN 3 /* 1 of 6 ROM patterns in HP */

/* -- PATTERNS -- */
#define HORZ_LINE 1 /* Parallel horizontal lines */
#define VERT_LINE 2 /* Parallel vertical lines */
#define UP_DIAG 3 /* Diagonals going up: /// */
#define DOWN_DIAG 4 /* Diagonals going down: \\\ */
#define HATCH 5 /* Crossing horz & vert: +++ */
#define X_HATCH 6 /* HATCH shifted 45 deg: XXX */

/* -- MISCELLANEOUS -- */
#define ESC 0x1B /* Escape char for printer */
#define FORMFEED 0x0C /* ASCII form-feed character */

/* -- FONT CHARACTERISTICS */
#define PORTRAIT 0 /* Printing Orientation */
#define LANDSCAPE 1
#define ROMAN_8 "8U" /* Typical Character Sets */
#define IBM_PC "10U"
#define FIXED 0 /* Inter-character spacing */
#define PROPORTIONAL 1
#define PICA "10" /* Pitch (chars per inch) */
#define ELITE "12"
#define COMPRESS "16.66"
#define UPRIGHT 0 /* Font Styles */
#define ITALIC 1
#define LIGHT -3 /* Stroke Weight */
#define MEDIUM 0
#define BOLD 3
#define LINE_PRINTER 0 /* Typefaces */
#define COURIER 3
#define HELVETICA 4
#define TIMES_ROMAN 5

#define ON 1
#define OFF 0


FILE *prt, *fopen();

#define pattern(x) shading(x) /* Pattern selection uses same */
/* function as shading choice. */

/*** THE BASIC FUNCTIONS ***/

void open_printer() /* Open the LaserJet for print */
{
if ((prt = fopen ("PRN", "w")) == NULL)
{
puts ("Printer is closed\n");
exit (-1);
}
}

void reset_printer()
{
static char clear_codes[5] =
{ESC,0x45, /* Resets defaults (fonts, etc.)*/
ESC,0x39, /* Resets margins */
0}; /* Unneeded, but good practice. */

fprintf (prt, "%s", clear_codes);
}

void send_FF () /* Send a form-feed, print page */
{
fprintf (prt, "%c", FORMFEED);
}

void margin_set (cols) /* Indent left margin in columns*/
int cols;
{
fprintf (prt, "%c&a%dL", ESC, cols);
}

void underline(toggle) /* Toggle underline on or off. */
int toggle;
{
if (toggle == ON)
fprintf (prt, "%c&d0D", ESC);
else
if (toggle == OFF)
fprintf (prt, "%c&d@", ESC);
}


/*** BUILT-IN GRAPHIC ACCESS FUNCTIONS ***/

void pos_cursor(horiz, vert, units) /* Position the graphics cursor */
int horiz, vert, units;
{
switch (units)
{
case DOTS:
fprintf (prt, "%c*p%dx%dY", ESC, horiz, vert);
break;
case DECI:
fprintf (prt, "%c&a%dh%dV", ESC, horiz, vert);
break;
case ROWS:
case COLS:
fprintf (prt, "%c&a%dr%dC", ESC, horiz, vert);
break;
}
}

void rect_width (width, units) /* Specify rectangle width. All */
int width, units; /* widths are converted to points */
{ /* at a resolution of 300 dots/inch. */

fprintf (prt, "%c*c%d*%c", ESC, width, (units == DOTS ? 'A' : 'H'));
}

void rect_height (height, units) /* Specify rectangle height. All */
int height, units; /* heights are convereted to points */
{ /* at a resolution of 300 dots/inch. */

fprintf (prt, "%c*c%d*%c", ESC, height, (units == DOTS ? 'B' : 'V'));

}

void fill_type (type) /* Specify fill type in area: black */
int type; /* shading, or HP ROM pattern. */
{
fprintf (prt, "%c*c%dP", ESC, type);
}

void shading (percent) /* Specify percent of shading or the */
int percent; /* ROM pattern to print. */
{
fprintf (prt, "%c*c%dG", ESC, percent);
}

/*** FONT MANIPULATION ROUTINES ***/

void font_number (font) /* Select by number a font to use */
int font;
{
fprintf (prt, "%c(%dX", ESC, font);
}

void font_orientation (direction) /* Select portrait or landscape ltrs.*/
int direction; /* Portrait = up & down; landscape */
{ /* = sideways. */

if (direction != PORTRAIT &&
direction != LANDSCAPE)
return;
else
fprintf (prt, "%c&l%dO", ESC, direction);
}

void font_sym_set (set_ptr) /* Select symbol set of the font. */
char *set_ptr; /* Generally country-dependent. */
{
fprintf (prt, "%c(%3s", ESC, set_ptr);
}

void font_spacing (spacing) /* Inter-character spacing of font */
int spacing;
{
if (spacing != FIXED &&
spacing != PROPORTIONAL)
return;
else
fprintf (prt, "%c(s%dP", ESC, spacing);
}

void font_width (width) /* Sets the pitch for the font */
char *width;
{
fprintf (prt, "%c(s*%sH", ESC, width);
}

void font_height (height) /* Sets character height in points */
char *height;
{
fprintf (prt, "%c(s*%sV", ESC, height);
}

void font_style (style) /* Upright or italic. That's it! */
int style;
{
if (style != UPRIGHT &&
style != ITALIC)
return;
else
fprintf (prt, "%c(s%dS", ESC, style);
}

void font_weight (weight) /* Darkness of printing stroke */
int weight;
{
if (weight < -7) weight = -7;
if (weight > 7) weight = 7;
fprintf (prt, "%c(s%dB", ESC, weight);
}

void font_typeface (typeface) /* Typeface: What is colloquially */
int typeface; /* a font - Helvetica, Gothic, etc. */
{
fprintf (prt, "%c(s%dT", ESC, typeface);
}

/*** Higher-Level Fuctions ***/


void draw_frame (border, length, height, x, y, units) /* Build a frame by*/
int border, length, height, x, y, units; /* defining the sides as */
{ /* long thin rectangles. */

pos_cursor (x, y, units); /* Left vertical */
rect_width (border, units);
rect_height(height, units);
shading(100);
fill_type (SHADING);

pos_cursor ((x + length - border), y, units);/* Right vertical*/
rect_width (border, units);
rect_height(height, units);
shading(100);
fill_type (SHADING);

pos_cursor (x, y, units); /* Top Horizontal*/
rect_width (length, units);
rect_height(border, units);
shading(100);
fill_type (SHADING);

pos_cursor (x, (y + height - border), units);/* Low Horizontal*/
rect_width (length, units);
rect_height(border, units);
shading(100);
fill_type (SHADING);

}

/*---------*/


main () /* Sample driver for the routines above */
{

int i, j, k;
int h, l, b;

open_printer(); /* Open the printer (Gee!) */
reset_printer(); /* Clear previous settings */

/***************** DRAWS GRAPHIC SAMPLES ON 1ST PAGE ************/

i = 200;
for (j = 0, k = 300; j < 6; j++) /* Create six bars in a row */
{ /* starting at (200, 300), */
pos_cursor (k, i, DOTS); /* each bar being 1" x 2", */
rect_width (300, DOTS); /* and showing each of the */
rect_height(600, DOTS); /* six built-in patterns. */
pattern(j + 1);
fill_type (PATTERN);

k += 350;
}

i = 1000;
for (j = 0, k = 300; j < 6; j++) /* Create six bars in a row */
{ /* starting at (1000, 300), */
pos_cursor (k, i, DOTS); /* each bar being 1" x 2", */
rect_width (300, DOTS); /* and showing six of the */
rect_height(600, DOTS); /* eight shading levels */
switch (j + 1)
{
case 1: shading (1); break; /* Level 1 1 - 2 % */
case 2: shading (5); break; /* Level 2 3 - 10 % */
case 3: shading (15); break; /* Level 3 11 - 20 % */
case 4: shading (25); break; /* Level 4 21 - 35 % */
case 5: shading (50); break; /* Level 5 36 - 55 % */
case 6: shading (75); break; /* Level 6 56 - 80 % */
}
fill_type (SHADING);

k += 350;
}

/* Draw the rectangles at bottom */

i = 1800; /* Y axis of upper left corner */
k = 300; /* X axis of upper left corner */
b = 30; /* Border width */
l = 1800; /* Width of frame */
h = 1200; /* Height of frame */
draw_frame (b, l, h, k, i, DOTS); /* Build a frame at (1800, 300)*/
/* with a border 30 pts wide, */
/* size:1200 high x 1800 wide */

draw_frame (5, 600, 300, 900, 2250, DOTS); /* Build a thin frame */
/* within the first. */

/* Now print text between the printed graphics */

pos_cursor (300, 1700, DOTS); /* Position Cursor Betweeen rows */
font_number(1); /* Select font #1 - courier 10cpi*/
fprintf (prt, "%s",
" 1% 5% 15% 25% 50% 75%");

pos_cursor (300, 900, DOTS); /* Position Cursor Betweeen rows */
font_width ("10"); /* Select 10 chars/inch */
fprintf (prt, "%s",
" (1) (2) (3) (4) (5) (6)");


send_FF(); /* Forces the printing. */

/************ PRINTS THE FONT SAMPLES ON SECOND PAGE *************/

margin_set (4); /* Indent four columns */
fprintf (prt, "\nThis is courier - default to 10 pitch\n\n");
font_weight (BOLD);
fprintf (prt, "This is courier bold ");
underline (ON);
fprintf (prt, "with underline!\n\n");
underline (OFF);
font_width ("16.66");
fprintf (prt, "This is the built-in compressed print\n");
font_number (25); /* Select downloaded font */
fprintf (prt, "\nSample of a down-loaded font\n\n");


send_FF(); /* Print the page. */
}



  3 Responses to “Category : Files from Magazines
Archive   : CGAZ2-4.ZIP
Filename : HPGRAPHA.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. 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/