Software Characters

Software characters, also called stroke characters or vector characters in other literature, are proportionally spaced characters you can display in any size, angle, and aspect ratio. However, software characters usually take longer to draw than stock fonts or logical fonts, and they require floating point math. Fastgraph includes two software character fonts, called the primary font and the alternate font. The primary font contains upper and lower case letters, numbers, punctuation, and most other printable ASCII characters. The alternate font contains upper and lower case Greek letters and other mathematical and scientific symbols.

If you compare the primary font with the alternate font, you'll see the alternate font contains fewer characters. For example, the letters Q and V (either upper or lower case) have no corresponding character in the alternate font. In addition, the primary font does not support the full printable ASCII character set.

The fg_swchar() function displays a string of software characters in the current color. The string may contain any characters from the primary font, the alternate font, or both. You can display the characters left justified, centered, or right justified relative to the graphics cursor position. Just as fg_print() updates the text cursor position, fg_swchar() leaves the graphics cursor positioned just to the right of the last character drawn. The characters are clipped according to the current clipping region. In addition to the characters, the string passed to fg_swchar() also may contain operators for switching fonts, underlining, subscripting, or superscripting characters. Because fg_swchar() internally uses world space coordinates, you must call the fg_initw() function at some point in your program before the first call to fg_swchar(). You also must establish a world space coordinate system with the fg_setworld() function.

The fg_swchar() function has three parameters. The first parameter is the character string to display. The second parameter is an integer value that specifies the number of characters in the string, including any characters used as special operators. The third parameter is an integer value that determines the position of the string relative to the graphics cursor position. If this value is negative, the lower left corner of the first character will be at the graphics cursor position. If it is positive, the lower right corner of the last character will be at the graphics cursor position. If it is zero, the string will be horizontally centered at the graphics cursor position. Any character in a string passed to fg_swchar() that does not have a corresponding character in the current font will display a blank character.

The size of software characters is determined by the values passed to fg_setsize(), fg_setsizew(), and fg_setratio(). The fg_setsize() function has a single integer parameter that defines the height of software characters in screen space units, while fg_setsizew() has a single floating point parameter that defines the height in world space units. If neither of these functions is called, Fastgraph will use its default character height of one world space unit. The fg_setratio() function has a single floating point parameter that defines the aspect ratio for software characters. The aspect ratio is the ratio of character width to character height. For example, an aspect ratio of 2.0 means characters are twice as wide as they are high. If fg_setratio() is not called, Fastgraph uses its default aspect ratio of 1.

In most programs, the alternate font is not needed. However, if you use the fg_swchar() function, Fastgraph includes the definitions of these characters in your program's data segment. To prevent wasting this space, use fg_swtext() instead of fg_swchar(). The fg_swtext() function is same as fg_swchar(), but it does not include the alternate font. Since the font selection operator does not apply when using fg_swtext(), the function simply ignores it. You should only use fg_swtext() if do not use fg_swchar(). If you use both functions, your program will still work correctly, but its data segment will contain an extra copy of the primary font definitions.

Another software character support function is fg_setangle(), which sets the angle of rotation at which software characters are displayed. Its only parameter is a floating point value that specifies the angle, measured in degrees counterclockwise from the positive x axis. If a program draws software characters before calling fg_setangle(), Fastgraph will use its default angle of zero degrees (that is, the characters will be oriented horizontally).

The final function pertaining to software characters is fg_swlength(), which returns the length of a specified string of software characters in world space units. The length is returned as the function's floating point function value. The fg_swlength() function has two parameters: a string of software characters, and an integer value specifying the number of characters in the string. As with fg_swchar() and fg_swtext(), the count includes any of the special operator characters.

The following code snippet demonstrates a typical use of the fg_swlength() function:

C/C++:

fg_initw();
fg_setworld(0.0,6.39,0.0,3.49);
fg_setsizew(0.2);
fg_setcolor(17);
half = fg_swlength(" Hello there. ",14) * 0.5;
fg_rectw(3.2-half,3.2+half,1.6,1.9);
fg_setcolor(20);
fg_movew(3.2,1.65);
fg_swtext("Hello there.",12,0);

Delphi:

fg_initw;
fg_setworld(0.0,6.39,0.0,3.49);
fg_setsizew(0.2);
fg_setcolor(17);
half := fg_swlength(' Hello there. ',14) * 0.5;
fg_rectw(3.2-half,3.2+half,1.6,1.9);
fg_setcolor(20);
fg_movew(3.2,1.65);
fg_swtext('Hello there.',12,0);

Visual Basic:

Call fg_initw
Call fg_setworld(0.0, 6.39, 0.0, 3.49)
Call fg_setsizew(0.2)
Call fg_setcolor(17)
half = fg_swlength(" Hello there. ", 14) * 0.5
Call fg_rectw(3.2 - half, 3.2 + half, 1.6, 1.9)
Call fg_setcolor(20)
Call fg_movew(3.2, 1.65)
Call fg_swtext("Hello there.", 12, 0)

This code displays string "Hello there." in light green against a gray background in the middle of the virtual buffer. Following the world space initialization, fg_swlength() computes the length in world space units of the string. Note we have added blank characters to each end of the string passed to fg_swlength(); this increases the length of the actual string and will effectively give the gray rectangle an extended border on its left and right sides. The string length returned by fg_swlength() is multiplied by 0.5, giving the distance from the middle of the virtual buffer to either side of the rectangle. We then use this value to compute the minimum and maximum x coordinates passed to fg_rectw(). After drawing the gray rectangle, fg_swtext() draws the string of software characters in the middle of the virtual buffer.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.