GFONT Procedure

The Font Data Set

Overview: The Font Data Set

The font data set consists of a series of observations that describe the font. The variables in the font data set must be assigned certain names and types. Table of Font Data Set Variables describes the variables that are included in the font data set. These variables are described in Font Data Set Variables in more detail.
The font data set must include the horizontal and vertical coordinate values. It also includes line segment numbers that the GFONT procedure uses to generate each character. In addition, each observation must include a character code that is associated with the font character and is used to specify the font character in a text string. The font data set also determines whether the font is stroked or polygon. A font data set that generates a polygon font produces an outline font by default. You can use the FILLED option with the same data set to generate a filled font.
Specify the font data set with the DATA= argument, for example:
data mylib.fontdata;
 proc gfont data=fontdata name=mylogo;
run;
Table of Font Data Set Variables
Variable
Description
Type
Length
Valid Values
With Stroked Fonts
With Polygon Fonts
CHAR
The character code associated with the font character
Character
1 or 2
Keyboard characters or hexadecimal values
Required
Required
LP
The type of line segment being drawn, either a line or a polygon
Character
1
L or P
Optional
Required
PTYPE
The type of data in the observation
Character
1
V or C or W
Optional
Optional
SEGMENT
The number of the line segment or polygon being drawn
Numeric
Number
Required
Required
X
The horizontal coordinate
Numeric
Number
Required
Required
Y
The vertical coordinate
Numeric
Number
Required
Required

Font Data Set Variables

CHAR
provides a code for the character or figure that you are creating. CHAR is a character variable with a length of 1 or 2. CHAR is required for all fonts.
CAUTION:
Using reserved or undefined hexadecimal codes as CHAR values might require the use of the NOKEYMAP option.
The CHAR variable takes any character as its value, including keyboard characters and hexadecimal values from '00'x to 'FF'x. (If you use hexadecimal values as CHAR values, your font might not work correctly under a key map that is different from the one under which the font wax created. Positions that are not defined in one key map might be defined in another.)
When you specify the code for the character in a text string, the associated font character is drawn. For example, if you create a Roman alphabet font, typically the characters that you specify for CHAR are keyboard characters that match the character in the font. All of the observations that build the letter A have a CHAR value of A. When you specify 'A' in a text string, this creates an A in the output.
However, If you build a symbol font, the symbols might not have corresponding keyboard characters. In that case, you select a character or hexadecimal value to represent each symbol in the font and assign it to CHAR. For example in the Special font, the letter G is assigned as the code for the fleur-de-lis symbol. When you specify the code in a text string, the associated symbol displays.
Note: If the CODELEN= option is set to 2, the values for CHAR represent two characters, such as AA, or a four-digit hexadecimal value, such as '00A5'x.
LP
tells the GFONT procedure whether the coordinates of each segment form a line or a polygon. LP is a character variable with a length of 1. The LP variable is required for polygon fonts but is optional for stroked fonts. You can assign the LP variable either of the following values:
L lines
P polygons
Every group of line segments with an LP value of P is designated as a polygon. If the observations do not draw a completely closed figure, the program closes the figure automatically. For example, the following observations do not contain an LP variable. Observations that do not contain an LP variable create a shape like the one in LP Value of L.
Observations to Create the Following Figure
OBS
CHAR
SEG
X
Y
1
b
1
1
1
2
b
1
1
3
3
b
1
3
3
4
b
1
3
1
LP Value of L
Using an LP Value of Line
An LP variable with a value of P for all observations added to the data set produces a complete box like the one in LP Value of P.
Observations to Create the Following Figure
OBS
CHAR
SEG
X
Y
LP
1
b
1
1
1
P
2
b
1
1
3
P
3
b
1
3
3
P
4
b
1
3
1
P
LP Value of P
Using a LP Value of Polygon
The LP variable enables you to mix lines and polygons. These observations create the figure consisting of a polygon and a line segment as shown in Mixing LP Values of Line and Polygon.
Observations to Create the Following Figure
OBS
CHAR
SEG
X
Y
LP
1
b
1
1
1
P
2
b
1
1
3
P
3
b
1
3
3
P
4
b
1
3
1
P
5
b
2
0
0
L
6
b
2
2
4
L
7
b
2
4
0
L
Mixing LP Values of Line and Polygon
Making LP Values of Line and Polygon
PTYPE
tells the GFONT procedure what type of data is in the observation. PTYPE is a character variable of length 1 that is optional. For each observation, the PTYPE variable assigns a characteristic to the point that is determined by the X and Y values. You can assign the PTYPE variable to any of these values:
V
normal point in the line segment
Note:If a PTYPE variable is not specified, then all points are assumed to be V-type points.
C
center of a circular arc joining two V points
Restriction:Arcs are limited to 106 degrees or less.
W
width value for CHARSPACETYPE=DATA. An observation with a PTYPE value of W must always be the first observation for a character. The observation gives the minimum and maximum X values for the character. The Y variable observation contains the maximum X value. Usually, these values include a little extra space for intercharacter spacing.
Restriction:Use a PTYPE of W only if you have specified CHARSPACETYPE=DATA. Otherwise, the points are ignored.
The following observations illustrate how the PTYPE variable is used to draw an arc similar to Using the PTYPE Variable to Create an Arc.
OBS
CHAR
SEG
X
Y
LP
PTYPE
Comment
1
a
1
40
60
P
W
Define width of character as 20 font units, which is the number of units from left margin, 40, to right margin, 60
2
a
1
45
40
P
V
Start line segment at position 45,40
3
a
1
45
50
P
V
Draw a line to position 45,50, which is start point of arc
4
a
1
45
40
P
C
Draw an arc whose center is at 45,40
5
a
1
55
40
P
V
Finish drawing the arc at 55,40
After the figure was generated, a grid was overlaid on it to show the location of the points.
Using the PTYPE Variable to Create an Arc
Using the PTYPE Variable to Create an Arc
Note the following:
  • Three observations are required to draw an arc: observation 3 and observation 5 denote the start point and the end point of the arc. Observation 4 locates the center of the arc.
  • The figure is closed because the line segments have an LP value of P (polygon).
  • The font that contains the figure of the arc was created with a similar PROC GFONT statement:
    proc gfont data=arc name=arcfig charspacetype=data filled;
    The CHARSPACETYPE= DATA option specifies that the first observation sets the width of the character. The FILLED option fills the area of the arc.
SEGMENT
numbers the line segments that compose a character or symbol. SEGMENT is a required numeric variable. All observations for a given line segment have the same segment number. To start a new line segment, change the segment number.
When the GFONT procedure draws a stroked character with more than one line segment (for example, the letter E), or a polygon character with a hole (for example, the letter A), it needs to know when one line stops and where the next line begins. To indicate when one line stops and where the next line begins you can do either of the following:
  • Change the segment number when a new line begins. If the value of LP is L (line), a change in segment number tells the GFONT procedure not to connect the last point in line segment 1 and the first point in line segment 2.
    • The last point in line segment 1 ends the line.
    • The first point in line segment 2 starts a new line.
    If the value of LP is P (polygon), a change in segment numbers causes the following:
    • The last point in line segment 1 joins to the first point in line segment 1, which closes the polygon.
    • A new polygon starts. If the value of CHAR has not changed, the new polygon is part of the same character.
    Use this method for characters that consist of two polygons such as a question mark. This method is preferred, unless you are creating a polygon character with a hole in it.
  • Keep the same segment number for all lines. Insert an observation with missing values for X and Y. Insert the new observation between the observation that marks the end of the first line, and the observation that begins the next line. For example, if you are drawing the letter O, insert an observation with a missing value between the line that draws the outer circle and the beginning of the line that draws the inner circle.
The first method is preferred, unless you are creating a polygon character with a hole in it. The second method is preferred when creating a polygon with a character with a hole in it. In this case, you should separate the lines with a missing value and keep the same segment numbers.
If you use separate line segments when you create a polygon with a hole, the results can be unpredictable. For example, the observations from a data set called BOXES were used to draw the hollow square in Drawing Nested Polygons.
OBS
CHAR
SEG
X
Y
LP
1
b
1
1
1
P
2
b
1
1
3
P
3
b
1
3
3
P
4
b
1
3
1
P
5
b
1
-
-
P
6
b
1
0
0
P
7
b
1
0
4
P
8
b
1
4
4
P
9
b
1
4
0
P
Note the observation 5 has missing values for X and Y. This separates the observations that draw the inner box from those that draw the outer box. The segment number is the same for all the observations.
Drawing Nested Polygons was created with a similar GFONT statement:
proc gfont data=boxes name=boxes filled;
The FILLED option is included, and only the space between the two squares is filled.
The data points that form the figure are laid out on a grid shown next to the square.
Drawing Nested Polygons
Drawing Nested Polygons
X and Y
specify the horizontal and vertical coordinates of the points for each character. Their values describe the position of the points on the character. These variables have the following characteristics:
  • They must be numeric.
  • They must be named X and Y for the horizontal and vertical coordinates, respectively.
  • The values specified by them can be in any range.
  • They both must describe the character in the same scale or font units.
  • Vertical (Y) coordinates for all characters should be defined on the same baseline.
Interaction:When you specify PTYPE=W, both X and Y contain horizontal coordinate values.

Creating a Font Data Set

Create a font data set by digitizing the shape of the characters or figures either manually or with special digitizing equipment. To create a font data set by digitizing the characters manually:
  1. Determine the coordinate points for each line segment by drawing the characters on a grid.
  2. Lay out the observations for each character. Each observation describes a move from one point to another along a line segment. For each line segment, enter the coordinate points in the order in which they are drawn. For a stroked font, when you start a new line segment, change the segment number. For a polygon font, when you start a new polygon, change the line segment number.
    If the polygon has a hole in it, as in the letter O, keep the line segment number and separate the lines with a missing value. Use the same value for CHAR for all of the observations that describe one character.
  3. Create a SAS data set that contains the variables CHAR, SEGMENT, X, and Y, and read in the data for each observation. Include the variables LP and PTYPE if necessary.
  4. Sort the data set by CHAR and SEGMENT.
  5. Assign the font data set with the DATA= argument.
This process is illustrated in Creating Figures for a Symbol Font.