CS-460/560
Spring, 1998
R. Eckert
STROKED CHARACTERS--AN ILLUSTRATION
The following illustrates how an 'F' could be displayed using the stroked technique:
1. Assuming we have a POINT structure (or equivalent), define a character (CH) type.
In this structure, the pts array defines each endpoint of each stroke of the
character:
typedef struct tagCH
{
int n;
POINT * pts;
} CH;
2. Define a function that will display the character whose strokes are given in the
character c (of type CH) at pixel coordinates (xx,yy):
disp_letter (int xx, int yy, CH c)
{
int i,j;
j=c.n/2; /* n points ==> n/2 strokes */
for (i=0; i<j; i++)
line(xx+c.pts[2*i].x, yy+c.pts[2*i].y,
xx+c.pts[2*i+1].x, yy+c.pts[2*i+1].y);
}
[Here we are assuming that we have a line-drawing function, line[x1,y1,x2,y2)]
3. Define the character's CH structure. The following could be for an 'F':
POINT p[6];
CH f;
p[0].x=0;
p[0].y=0;
p[1].x=0;
p[1].y=80;
p[2].x=0;
p[2].y=0;
p[3].x=80;
p[3].y=0;
p[4].x=60;
p[4].y=40;
p[5].x=0;
p[5].y=40;
f.n = 6;
f.pts = p;
[In general, you could have a file that contains similar descriptions of each
character in the character set that is to be displayed.]
3. Call the character-display function, passing it the desired character (CH)
disp_letter (50,100,f); /* draw the letter F at (50,100) */
In a Win32 application, the disp_letter() function would be called from the
WndProc().