HP OpenVMS Systems Documentation |
VMS DECwindows Guide to Xlib (Release 4) Programming: MIT C Binding
8.4 Freeing Font ResourcesBecause allocating fonts requires large amounts of memory, it is important to deallocate these resources when the client no longer needs them. Table 8-6 lists complimentary font routines and the result when the deallocating routine is called.
8.5 Computing the Size of TextUse the TEXT WIDTH and TEXT WIDTH 16 routines to compute the width of 8-bit and 2-byte strings, respectively. The routines return the sum of the width of each character in the specified string. To compute the bounding box of a specified 8-bit string, use either the TEXT EXTENTS or QUERY TEXT EXTENTS routine. Both TEXT EXTENTS and QUERY TEXT EXTENTS return the direction hint, ascent, descent, and overall size of the character string being queried. TEXT EXTENTS passes to Xlib the font struct data structure returned by a previous call to either LOAD QUERY FONT or QUERY FONT. QUERY TEXT EXTENTS queries the server for font information, which the server returns to a font struct data structure. Because Xlib can process TEXT EXTENTS locally, without querying the server for font metrics, calling TEXT EXTENTS is significantly faster than calling QUERY TEXT EXTENTS.
To compute the bounding boxes of a specified 2-byte string, use either
the TEXT EXTENTS 16 or the QUERY TEXT EXTENTS 16 routine. Both routines
return information identical to information returned by TEXT EXTENTS
and QUERY TEXT EXTENTS. As with TEXT EXTENTS, calling TEXT EXTENTS 16
is significantly faster than calling QUERY TEXT EXTENTS 16 because Xlib
can process the call without making the round-trip to the server.
Xlib enables clients to draw text stored in text data structures, text whose foreground bits only are displayed, and text whose foreground and background bits are displayed. To draw 8-bit or 2-byte text stored in data structures, use either the DRAW TEXT or the DRAW TEXT 16 routine. Xlib includes text item and text item 16 data structures to enable clients to store text. The following illustrates the text item data structure:
Table 8-7 describes members of the text item data structure.
The following illustrates the text item 16 data structure:
Table 8-8 describes members of the text item 16 data structure.
Xlib provides a char 2B data structure to enable clients to store 2-byte text. The following illustrates the data structure:
Xlib processes each text item in turn. Each character image, as defined by the font in the graphics context, is treated as an additional mask for a fill operation on the drawable. The drawable is modified only where the font character has a bit set to 1. Example 8-1 illustrates using the DRAW TEXT routine to draw three words in one call.
To draw 8-bit or 2-byte text, use the DRAW STRING, DRAW STRING 16, DRAW IMAGE STRING, and DRAW IMAGE STRING 16 routines. DRAW STRING and DRAW STRING 16 display the foreground values of text only. DRAW IMAGE STRING and DRAW IMAGE STRING 16 display both foreground and background values. Example 8-2 illustrates drawing text with the DRAW STRING routine. The example modifies the sample program in Chapter 1 to draw shadow text.
The server refers to the following members of the GC data structure when writing text with DRAW TEXT, DRAW TEXT 16, DRAW STRING, and DRAW STRING 16:
To draw both foreground and background values of text, use the DRAW IMAGE STRING and DRAW IMAGE STRING 16 routines. For example, the sample program uses the DRAW IMAGE routine to write the text "Click here to exit," as follows:
The effect is first to fill a rectangle with the background defined in the graphics context and then to paint the text with the foreground pixel. The upper left corner of the filled rectangle is at 75, (75- font ascent ) . The width of the rectangle is equal to the width of the string. The height of the rectangle is equal to font ascent + font descent . When drawing text in response to calls to DRAW IMAGE STRING and DRAW IMAGE STRING 16, the server ignores the function and fill style the client has defined in the graphics context. The value of the function member of the GC data structure is effectively the value specified by the constant GXCopy. The value of the fill style member is effectively the value specified by the constant FillSolid. The server refers to the following members of the GC data structure when writing text with DRAW IMAGE STRING and DRAW IMAGE STRING 16:
8.7 Font Usage Hints
This section includes information about the Digital font fallback
strategy and hints for using font names efficiently.
When specifying fonts, the client should use fonts that are common to both DECwindows Motif and X Window System, Version 11, Release 4 software. Using common fonts makes a client application interoperable and enables it to display on a wide variety of third-party workstations and X terminals. The following lists the common font families:
If clients use other font families (such as ITC Avant Garde Gothic, ITC Lubalin Graph, or ITC Souvenir), the DECwindows toolkit provides the DxmFindFontFallback routine that supports the Digital font fallback strategy. For more information about this routine, see the DECwindows Extensions to Motif. Digital recommends that clients not use certain fonts. Table 8-9 lists the font families and the reason why. All other font families are for general use.
8.7.2 Speeding Up Font Name SearchesThe DECwindows X server uses a heuristic to speed up font name searching. When the client specifies the FAMILY_NAME, WEIGHT_NAME, SLANT, SETWIDTH_NAME, CHARSET_REGISTRY, and CHARSET_ENCODING fields explicitly, the server uses a hash table to speed up font name searching. For example, the following font name is specified correctly to use the heuristic:
The previous example will be found more quickly than the following because a wildcard has been used in the SLANT field:
The client can specify other fields, such as the FOUNDRY field;
however, all fourteen hyphens in a font name must be specified for the
heuristic to work. The ADD_STYLE_NAME field (the field after Normal in
the example) should be left empty because this field may be used in the
hashing algorithm in the future.
To choose a particular sized font without regard to the density of the
monitor, the client should always use a wildcard for the PIXEL_SIZE
field and never use a wildcard for the POINT_SIZE field. In addition,
the client should use a wildcard for the RESOLUTION_X and RESOLUTION_Y
fields.
The client should always explicitly specify the CHARSET_REGISTRY and CHARSET_ENCODING fields (for example, ISO8859-1), not only because they speed up font name searching, but because they ensure that the client uses the correct character set. ISO8859-1 specifies the Latin-1 character set that is normally used in text files. There are other possible character sets that could match a wildcard search, such as Latin-2 or Latin-3, but they should not be used if the client can only process and display Latin-1 text.
|