Inom
Hitta mer dokumentation
Supportresurser som ingår
| Ladda ner denna bok i PDF
Stroke Text
12
- This chapter discusses XGL stroke text. It includes information on the following topics:
-
- Stroke Font object operators and attributes.
- Context attributes defining the appearance of rendered text.
- Example programs illustrating Stroke Font concepts.
Introduction to the Stroke Font Object
- A font is a particular size and style of type from a font family. XGL text primitives can render a string of text composed of one font or composed of distinct fonts built from different character sets. Up to four character sets can be active simultaneously. Character sets are made accessible to the Context object by associating Stroke Font objects with the Context. Each Stroke Font object encapsulates one font, which can then be used by the Context for rendering text.
- Two text encoding schemes are provided. The application programmer can specify multi-byte encoding (also known as EUC or Extended UNIX Code) or ISO encoding. Multi-byte encoding enables the application to display characters that require more than one byte per character, such as Kanji. In addition, multiple fonts are allowed per text string. Allowing different encoding schemes and up to four fonts per Context object supports internationalization extensions, enabling switching between different languages (character sets) within a text string.
- Stroke text is drawn as a series of vectors (strokes) that can be clipped when rendered onto the Device. Text can be rendered in any 3D orientation, or it can be rendered as annotations that are guaranteed to be parallel to the display surface.
Fonts Provided by XGL
- At runtime, the XGL library looks for fonts in the font directory specified by the System State attribute XGL_SYS_ST_FONT_DIRECTORY. By default, XGL looks for fonts in $XGLHOME/lib/xglfonts/stroke if the XGLHOME environment variable is set or in /opt/SUNWits/Graphics-sw/xgl-3.0/lib/xglfonts/stroke if XGLHOME is not set. (For information on the XGLHOME environment variable, see page 23.) The application can change the search path for the font directory by setting the attribute XGL_SYS_ST_FONT_DIRECTORY to a different path. For more information on the XGL_SYS_ST_FONT_DIRECTORY attribute, see Chapter 4, "System State Information and Generic Operators". XGL fonts are named fontname.font. If the application does not plan to use a particular font, the font can be removed from disk to save space.
- The fonts that XGL provides are listed Table 12-1. The font names reflect variations on the number and complexity of the strokes used to draw the font characters. Characters in fontname_D or fontname_T fonts are drawn with more strokes and look a little more substantial than fontname fonts. A fontname_M font is a monospaced font. Font characters can also be drawn with complex segments, or serifs (fontname_C or fontname_G).
-
Table 12-1
| XGL Fonts |
|
| Cartographic | Headline | Roman_C |
| Cartographic_M | Italic_C | Roman_D |
| English_G | Italic_T | Roman_M |
| Greek | Miscellaneous | Roman_T |
| Greek_C | Miscellaneous_M | Script |
| Greek_M | Roman | Script_C |
Creating a Stroke Font Object
- By default, the Context object renders a monospaced Roman font, which is defined at initialization in character set 0. If an application is using ISO encoding, only character set 0 can be used. If an application is using EUC encoding, it can render text using more than one font by creating up to four Stroke Font objects and associating them with the Context object. A Stroke Font object is created with the operator xgl_object_create() with a type value of XGL_SFONT. To create a Stroke Font object, the xgl_object_create() operator also needs information on the name of the font. This information is provided via the desc parameter, which points to an Xgl_obj_desc structure containing the name of the font.
-
obj_desc.sfont_name = "Italic_T.font";
sfont = xgl_object_create(sys_st, XGL_SFONT, &obj_desc, NULL);
|
- The font file is retrieved from the stroke font directory, the location of which is specified by the System State attribute XGL_SYS_ST_SFONT_DIRECTORY. To request an XGL font, use the font name with either no file extension or with a file extension of .font. The handle for the Stroke Font object (sfont in the example above) can be used simultaneously by multiple Contexts. A Stroke Font object for a particular font name needs to be created only once.
- The Context attribute XGL_CTX_SFONT_x (where x is 0 through 3) associates the name of the Stroke Font object with the Context object. The default value for character set 0 is Roman_M; the other three character sets have no default value. The association of the Stroke Font object with the Context can be set when the Context is created, as in the example below, or set at a later time using the xgl_object_set() operator.
-
ctx = xgl_object_create(sys_st, XGL_2D_CTX, NULL,
XGL_CTX_DEVICE, ras,
XGL_CTX_SFONT_0, sfont,
XGL_CTX_STEXT_CHAR_HEIGHT, 15.0,
XGL_CTX_STEXT_TEXT_COLOR, &sf_color,
NULL);
|
Rendering Stroke Fonts
- The XGL text primitives render character strings at a specified position on a 2D plane. When stroke text is rendered, the characters are interpreted from the font file in a coordinate system called text local coordinates. This coordinate system is distinct from the application's coordinate system and is defined by the text position and text direction vectors specified in the primitive call. Figure 12-1 illustrates the text local coordinate system. Stroke characters are transformed to the application's model coordinate system before being rendered.

Figure 12-1
- Stroke text is rendered as a set of polylines. The width of the polylines is fixed, and a pattern cannot be applied to the rendered text. Depth cueing is applied to stroke text, but lighting and shading is not applied. Two text primitives are provided for rendering: a primitive to render general stroke text, and a primitive to render annotation text.
Rendering Stroke Text
- The xgl_stroke_text() operator renders a string indexed by the characters in the argument str. xgl_stroke_text() renders text in any orientation in 3D space. The operator is defined as:
-
void xgl_stroke_text (
Xgl_ctx ctx,
void *str,
Xgl_pt_f*d *pos,
Xgl_pt_f3d dir[] )
|
-
str is a NULL-terminated C-style list of characters if the character encoding selected is XGL_SINGLE_STR, or a pointer to a structure of type Xgl_mono_text_list, if the character encoding is XGL_MULTI_STR. The parameter pos is the 2D or 3D reference point for the position of the rendered string and for the origin of the text plane. dir is used for 3D Contexts only; it is an array containing the two direction vectors used for the orientation of the 2D plane on which the text sits. The first vector defines the horizontal direction of the text plane. The second vector specifies the vertical direction and defines an orientation for the text. For 2D Contexts, the text plane is the x-y plane of the model coordinate system.
Rendering Annotation Text
- The xgl_annotation_text() operator renders a string of text parallel to the display surface.
-
void xgl_annotation_text(
Xgl_ctx ctx,
void *str,
Xgl_pt_f*d *ref_pos,
Xgl_pt_f*d *anno_pos)
|
-
str is a NULL-terminated C-style list of characters if the character encoding selected is XGL_SINGLE_STR, or a pointer to a structure of type Xgl_mono_text_list, if the character encoding is XGL_MULTI_STR. The argument ref_pos specifies the reference point for the text string in Model Coordinates. The text is actually displayed at the annotation point. anno_pos
- defined in VDC is added to the transformed reference position to obtain the annotation point. If the Context attribute XGL_CTX_ATEXT_STYLE has been set to XGL_ATEXT_STYLE_LINE, a leader line is rendered between the reference point and the annotation point. A leader line connects the reference point to the annotation point and is used to refer to specific parts of an illustration. A leader is shown in Figure 12-2.

Figure 12-2
- For annotation text, the text local coordinate system is defined at the annotation point. The z value of annotation text is dependent on the z value of the annotation point. The text plane is the x-y plane passing through the z coordinate of the annotation point.
- Annotation text is clipped if the reference point is outside the clipping region or volume in 3D. If the reference point implies visible text, the text is clipped to the limits of the clipping region or volume.
Single String and Multiple String Rendering
- Single string encoding is the simplest way of handing text to XGL. A single C-style (NULL-terminated) text string is passed to the text functions. The attribute XGL_SINGLE_STR uses the font from the associated Context object, and the string of characters that is rendered is a normal C string.
- The attribute XGL_MULTI_STR specifies multiple string encoding. Multiple string encoding represents strings as an array of (font, string) elements. The application provides text as an array of Xgl_mono_text structures. The Xgl_mono_text structure is defined as:
-
typedef struct {
Xgl_object font_obj;
char *text;
} Xgl_mono_text;
|
- and used within a structure of type Xgl_mono_text_list:
-
typedef struct {
Xgl_usgn32 mono_num;
Xgl_mono_text *mono_list;
} Xgl_mono_text_list;
|
- XGL scans the array for the (font,string) elements, loads the corresponding font and extracts the characters from the string to be rendered. Each sub-string is concatenated to the previous string, forming a single string of text when rendered. Each string in a particular set is rendered using the Stroke Font object associated with it. There is no limit to the number of sets accepted in this coding scheme. The code fragment below shows single string and multiple string rendering.
-
-
Xgl_sfont font1;
Xgl_sfont font2;
Xgl_obj_desc font_desc;
Xgl_pt_f2d pos_2d;
Xgl_sgn32 euc = 0;
Xgl_mono_text_list textlist;
Xgl_mono_text text[2];
pos_2d.x = 100.0;
pos_2d.y = 100.0;
font_desc.sfont_name = "Script";
font1 = xgl_object_create(sys_state,XGL_SFONT,&font_desc,NULL);
font_desc.sfont_name = "Roman_C";
font2 = xgl_object_create(sys_state,XGL_SFONT,&font_desc,NULL);
-
-
if (!(euc & XGL_MULTI_STR)) {
xgl_stroke_text (ctx, "Hello World", &pos, NULL);
} else {
textlist.mono_num = 2;
textlist_mono_list = text;
text[0].font_obj = font1;
text[0].text = "Hello World";
text[1].font_obj = font2;
text[1].text = "This is XGL";
xgl_stoke_text (ctx, textlist, &pos, NULL);
}
Stroke Font Attributes
- To determine the name of the font associated with a Stroke Font object, the application can use the XGL_SFONT_NAME attribute with xgl_object_get(). The Stroke Font attribute XGL_SFONT_COMMENT can also be used to determine the font name. XGL_SFONT_COMMENT returns the comment text associated with the font; currently, this information consists of the name of the font only.
- The attribute XGL_SFONT_DEFAULT_CHARACTER is used to specify the character that is rendered in place of undefined characters in a font. Specifying a default character, such as a blank space, is recommended when first creating the Stroke Font object with xgl_object_create(). The default value for this attribute depends on the specified font and may be set in the font file.
- The read-only attribute XGL_SFONT_IS_MONO_SPACED indicates whether a Stroke Font object contains a monospaced font. In a monospaced font, all the characters of the font have the same width. Computing the area covered by a string of monospaced characters is simpler than computing the area covered by non-monospaced characters. With non-monospaced fonts, the application must call the text extent operator xgl_stroke_text_extent() (discussed on page 303) each time it needs to know the width of a particular text string. With monospaced fonts, the application can determine the area covered by the text string from the character width attribute because all characters in the font have the same width.
Context Stroke Text Attributes
- The characteristics of stroke text are specified with Context text attributes. Context attributes set character height, character up vector, character width expansion, character spacing, text color, text path, and text alignment. Fonts are associated with the Context object via XGL_CTX_SFONT_{0,1,2,3} attributes. The Stroke Font objects must have been created previously with the operator xgl_object_create() before being associated with the Context.
-
Note - If ISO character encoding is used (as defined by the XGL_CTX_STEXT_CHAR_ENCODING attribute), only character set 0 can be attached to the Context object. Characters sets 1, 2, and 3 as defined by the attributes XGL_CTX_SFONT_{1,2,3}, only apply in the case of EUC multi-byte encoding.
- For stroke text, characters are interpreted from the font file in text local coordinates and then transformed to the application Model Coordinate system. For information on annotation text, see page 302.
Character Height
- The character height attribute, XGL_CTX_STEXT_CHAR_HEIGHT, defines the nominal height of text characters. Character height is specified in the application's Local Model Coordinate system. This attribute globally affects character height, character width, and inter-character spacing; thus, if the character height changes, the character width and inter-character spacing will also change. The default value for this attribute is 100.0. Figure 12-3 illustrates the height of characters as defined within a font.

Figure 12-3
Character Expansion Factor
- The character expansion factor defines the horizontal width of text characters and is specified with the attribute XGL_CTX_STEXT_CHAR_EXPANSION_FACTOR. The character expansion factor modifies the width of characters without changing the character height or the space between characters. The value for this attribute should be positive and is evaluated relative to the character height set by the XGL_CTX_STEXT_CHAR_HEIGHT attribute. The default value of 1.0 renders characters at their normal width.
Character Spacing
- The spacing between characters is specified by the XGL_CTX_STEXT_CHAR_SPACING attribute. This attribute allows the application to modify the space between two consecutive stroke text characters without changing the height or width of the characters. Character spacing is expressed as a fraction of the character height specified by the XGL_CTX_STEXT_CHARACTER_HEIGHT attribute. For example, a value of 0.0 adds no additional spacing between characters beyond what is initially defined in the font file; however, a value of 1.0 adds space equal to 1 unit of nominal character height. The default value of this attribute is 0.0. Figure 12-4 shows the default character spacing and a spacing value of 0.5.

Figure 12-4
Character Up Vector
- The character up vector specifies the up direction for text characters and thus controls the orientation of characters. Changing the up vector is equivalent to defining a rotation for the text string. The up vector is defined in text local coordinates and is set with the attribute XGL_CTX_STEXT_CHAR_UP_VECTOR. Figure 12-5 illustrates the default up vector of (0.0, 1.0) and a modified up vector of (0.0,-1.0), which rotates the text string 180 degrees.

Figure 12-5
-
Note - The character up vector is independent of the VDC orientation defined with the XGL_CTX_VDC_ORIENTATION attribute. XGL automatically sets internal values for the transformation of font characters to the text local coordinate system so that the VDC orientation does not affect rendered text.
Character Slant Angle
- Characters can be given an angle with the XGL_CTX_STEXT_CHAR_SLANT_ANGLE attribute. This attribute specifies the angle of inclination of text characters in radians with respect to the upright direction of the text. An angle between - ./2 and 0 results in an inclination in the backward direction. An angle between 0 and ./2 results in an inclination in the forward direction. The angle is relative to the text path and the character up vector. The default value for the angle is 0.0. This attribute does not affect text alignment or the height of the characters. Figure 12-6 on page 298 illustrates slant angle.

Figure 12-6
Text Path
- Text path defines the path or direction that consecutive text characters are rendered relative to the up vector. The text path attribute, XGL_CTX_STEXT_PATH, provides four directions to render text from the specified text position. These values are listed below and illustrated in Figure 12-7.
-
-
XGL_STEXT_PATH_RIGHT
XGL_STEXT_PATH_LEFT
XGL_STEXT_PATH_UP
XGL_STEXT_PATH_DOWN
- The default value for text path is XGL_STEXT_PATH_RIGHT
- .

Figure 12-7
Text Alignment
- Text alignment defines the position of the character string relative to text position. Using a set of horizontal and vertical text alignment attributes, the application can align text in a variety of ways along the horizontal and vertical axes with respect to the text position and the character up vector. The attribute XGL_CTX_STEXT_ALIGN_HORIZ specifies the horizontal alignment.
- Along the horizontal axis, the text string can be aligned to the left of the text position, centered at the text position, or aligned to the right of the text position. Values for horizontal alignment are:
-
-
XGL_STEXT_ALIGN_HORIZ_RIGHT
XGL_STEXT_ALIGN_HORIZ_LEFT
XGL_STEXT_ALIGN_HORIZ_CENTER
XGL_STEXT_ALIGN_HORIZ_NORMAL
- The attribute XGL_CTX_STEXT_ALIGN_VERT specifies the vertical alignment. The vertical text alignment attributes refer to the internal font lines of a character, which are shown in Figure 12-8.

Figure 12-8
- Along the vertical axis, the text string can be aligned to the top and bottom of the character cell or to the cap, half, and base font lines. Values for vertical alignments are:
-
-
XGL_STEXT_ALIGN_VERT_BASE
XGL_STEXT_ALIGN_VERT_BOTTOM
XGL_STEXT_ALIGN_VERT_TOP
XGL_STEXT_ALIGN_VERT_HALF
XGL_STEXT_ALIGN_VERT_CAP
XGL_STEXT_ALIGN_VERT_NORMAL
-
Figure 12-9 shows some examples of text alignment for a right horizontal text path. The alignment values are similar for other text paths. The asterisks show the text position for stroke text or the reference position for annotation text.

Figure 12-9
- The default value for XGL_CTX_STEXT_ALIGN_HORIZ is XGL_STEXT_ALIGN_HORIZ_NORMAL. This value defines the usual horizontal text alignment for each text path. For horizontal text alignment, the normal values are listed in Table 12-2 on page 301.
-
Table 12-2
| Text Path | Horizontal Alignment |
| XGL_STEXT_PATH_RIGHT | XGL_STEXT_ALIGN_HORIZ_LEFT |
| XGL_STEXT_PATH_LEFT | XGL_STEXT_ALIGN_HORIZ_RIGHT |
| XGL_STEXT_PATH_UP | XGL_STEXT_ALIGN_HORIZ_CENTER |
| XGL_STEXT_PATH_DOWN | XGL_STEXT_ALIGN_HORIZ_CENTER |
- Similarly, the default value for XGL_CTX_STEXT_ALIGN_VERT is XGL_STEXT_ALIGN_VERT_NORMAL. For vertical text alignment, the normal values are listed in Table 12-3.
-
Table 12-3
| Text Path | Vertical Alignment |
| XGL_STEXT_PATH_RIGHT | XGL_STEXT_ALIGN_VERT_BASE |
| XGL_STEXT_PATH_LEFT | XGL_STEXT_ALIGN_VERT_BASE |
| XGL_STEXT_PATH_UP | XGL_STEXT_ALIGN_VERT_BASE |
| XGL_STEXT_PATH_DOWN | XGL_STEXT_ALIGN_VERT_TOP |
Text Color
- The XGL_CTX_STEXT_COLOR attribute defines the color used when rendering stroke text characters. The color must be set to a color index value or an RGB color according to the XGL_RAS_COLOR_TYPE of the Raster associated with the Context. The default value of this attribute is the color of index 1 for indexed devices, or green for RGB devices.
Text Precision
- Text precision specifies the minimum precision used when rendering stroke text. It ensures that a precision better than or equal to the precision requested by the application is used when rendering the stroke text. Although his attribute, XGL_CTX_STEXT_PRECISION, has several values, only XGL_STEXT_PRECISION_STROKE is currently supported.
- Text precision is related to the way a string of text is clipped when it falls outside the clipping boundaries. XGL_STEXT_PRECISION_STROKE ensures that stroke text is clipped with pixel precision.
Stroke Text Character Encoding
- Character encoding can be set with the attribute XGL_CTX_STEXT_CHAR_ENCODING. This attribute specifies which text encoding scheme is used by the application. Two text encoding schemes are currently supported: EUC multi-byte encoding with single or multiple strings or ISO encoding with single or multiple strings. The default value is XGL_SINGLE_STR | XGL_CHAR_MBY. See page 305 for more information on text encoding schemes.
Context Annotation Text Attributes
- Annotation text characteristics are specified with Context annotation text attributes. Context attributes set annotation text character height, character up vector, character slant angle, text path, and text horizontal and vertical alignment. A Context annotation text attribute also defines whether annotation text is rendered with a leader line.
- Most of the annotation text attributes are identical in function to Context stroke text attributes except that, for annotation text, the characters are transformed to the application Virtual Device Coordinate system rather than the Model Coordinate System. The effect of this is that annotation text is always drawn as if "squared up" to the screen. Table 12-4 on page 303 lists the annotation text attributes and references the page number for the relevant stroke text section for each annotation text attribute. Annotation text style is discussed in the section that follows. Note that for characteristics of annotation text that do not have attributes, the values for the stroke text attributes are automatically used. This is true of character spacing, character encoding, character expansion factor, and text color. Text precision is always stroke precision.
-
Table 12-4
| Text characteristic | Annotation text attribute | Page |
| Character height | XGL_CTX_ATEXT_CHAR_HEIGHT | See page 295. |
| Character up vector | XGL_CTX_ATEXT_CHAR_UP_VECTOR | See page 297. |
| Character slant angle | XGL_CTX_ATEXT_CHAR_SLANT_ANGLE | See page 297. |
| Text path | XGL_CTX_ATEXT_CHAR_PATH | See page 298. |
| Horizontal text alignment | XGL_CTX_ATEXT_CHAR_ALIGN_HORIZ | See page 299. |
| Vertical text alignment | XGL_CTX_ATEXT_CHAR_ALIGN_VERT | See page 299. |
| Annotation text style | XGL_CTX_ATEXT_STYLE | See below. |
Annotation Text Style
- Annotation text can be rendered in two text styles. The XGL_CTX_ATEXT_STYLE attribute displays annotation text at the annotation position with the value XGL_ATEXT_STYLE_NORMAL. With the value XGL_ATEXT_STYLE_LINE, a leader line links the reference point to the annotation point. The leader line has the current polyline attribute settings. The default value for XGL_CTX_ATEXT_STYLE is XGL_ATEXT_STYLE_NORMAL.
Determining the Text Extent
- The text extent is a rectangle that surrounds a text string after the Context stroke text attributes have been applied. Knowing the size of this rectangle can be useful when concatenating text strings. The operator xgl_stroke_text_extent() determines the extent of a text string by computing the rectangle in text local coordinates that completely encompasses the text string. The text extent operator is defined as:
-
void xgl_stroke_text_extent (
Xgl_ctx ctx,
void *text,
Xgl_bounds_f2d *rect,
Xgl_pt_f2d *cat_pt)
|
- The argument ctx contains the associated Stroke Font object. str is a pointer to the text string. The operator returns a pointer rect to the rectangular box that surrounds the entire string and returns the concatenation point cat_pt where the string ends in text local coordinates. The concatenation point is the lower right corner of the bounding box. Figure 12-10 shows the text extent rectangle and the concatenation point.

Figure 12-10
- All Context stroke text attributes except XGL_CTX_STEXT_CHAR_UP_VECTOR and XGL_CTX_STEXT_CHAR_SLANT_ANGLE are used when computing the text extent. This means that when text is drawn rotated at an angle, the concatenation point is calculated from the default up vector.
Text Encoding Schemes
- XGL supports two text encoding schemes: ISO encoding and multi-byte encoding. Each of these encoding schemes can be rendered as a string with a single font or as a string with multiple fonts. Thus, an application can render the following combinations of text:
-
Table 12-5
| EUC Encoding | ISO Encoding |
Single String
Encoding | 4 code sets | A single string of an ISO
character set, such as English. |
Multiple
String
Encoding | 4 code sets, for example Kanji,
English, Kanji | A string containing characters
from more than one character
set, for example English, French,
English. |
- The context attribute XGL_CTX_STEXT_CHAR_ENCODING is used to select from the different options by OR-ing together one of each of the following value pairs: XGL_CHAR_MBY,XGL_CHAR_ISO and XGL_SINGLE_STR,XGL_MULTI_STR. If an application plans to use only languages with ISO-defined character sets, using EUC encoding is unnecessary.
ISO Encoding
- When the application needs to access ISO character sets, ISO encoding must be used. The ISO standard defines 256-entry character sets that contain accentuation and frequently used character symbols. With ISO encoding, the full 8 bits of each character are used to select the character definition. XGL complies with the ISO 8859 normalization. XGL fonts comply with this standard.
- ISO strings can be represented as single strings, in which case XGL_CTX_STEXT_CHAR_ENCODING is set to XGL_CHAR_ISO and XGL_SINGLE_STR, and the font used is character set 0 of the Context. ISO can also be represented as multiple strings using the XGL_CTX_STEXT_CHAR_ENCODING value XGL_MULTI_STR, in which case the font is selected from the array of Xgl_mono_text structures passed to the stroke text primitive call.
EUC (Multi-Byte) Encoding:
- EUC encoding defines a character-encoding scheme that allows multi-byte characters as well as the mixing of different character sets within a string. EUC encoding uses bit patterns and control characters to specify the different character sets in the string. XGL supports up to four character-encoding sequences, also called code sets, which are numbered 0 to 3. EUC encoding uses the most significant bit (MSB) of the character byte and two special characters, SS2 and SS3, to map the characters in the input string into the code sets. The code sets are defined as shown in Table 12-6:
-
Table 12-6
| Code set | Defined by: |
| Code set 0 | Characters with the MSB set to 0. This is normal 7-bit ASCII character encoding. |
| Code set 1 | Characters with the MSB set to 1. |
| Code set 2 | Characters with the MSB set to 1 and preceded by a single shift byte SS2. |
| Code set 3 | Characters with the MSB set to 1 and preceded by a single shift byte SS3. |
- In multi-byte encoding, XGL selects the character set used for rendering by decoding the MSB of the byte passed with the character string and determining whether the special shift characters are present. Once the character set is selected, the font associated with the character set can be a single-byte-per-character font or a multiple-byte-per-character font.
- As an example of the use of EUC encoding, many Japanese applications use EUC encoding to display English, Kanji, and Katakana (phonetic Japanese) characters within a single string. In this case, the code sets might be associated with character sets as shown in Table 12-7 on page 307:
-
Table 12-7
| Code set | Used for: |
| Code set 0 | ASCII |
| Code set 1 | Kanji characters. Each pair of input bytes specifies
one Kanji character. |
| Code set 2 | Katakana characters |
| Code set 3 | Implementation-dependent. For example, code set 3 could be used for an additional character set, such as one for special symbols. |
- For more information on code sets, see the XGL_CTX_STEXT_CHAR_ENCODING man page in the XGL Reference Manual.
- As in the case of ISO encoding, the character string can be coded as a single string, in which case character set 0 of the Context is used, or as multiple strings. For multiple string encoding, the parameters passed to the stroke text call select the font used for the character representations.
Stroke Font Example Program
- The example program stroke_text.c sets several text attributes and renders a string. Program output is shown in Figure 12-11. To compile this program, type make stroke_text. This program includes the main routine and all the window system calls.

Figure 12-11 stroke_text.c
-
Code Example 12-1 Stroke Text Example
-
-
/*
* stroke_text.c.
*/
#include <xview/xview.h>
#include <xview/frame.h>
#include <xview/panel.h>
#include <xview/textsw.h>
#include <xview/canvas.h>
#include <xview/xv_xrect.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <xgl/xgl.h>
static void repaint_proc ();
static void resize_proc ();
static Notify_value quit_proc (Frame, Destroy_status);
-
-
static Xgl_color_rgb black_rgb = { 0., 0., 0. };
static Xgl_color_rgb white_rgb = { 1., 1., 1. };
/* Global variables */
static Xgl_object ctx = NULL; /* Context object */
static Xgl_object ras = NULL; /* Win ras to write to */
static Xgl_object sys_st; /* System state object */
static Xgl_obj_desc obj_desc; /* Win ras structure */
static Xgl_pt_f2d up_vector = {0.0, 1.0}; /* char up vector */
main (
int argc,
char *argv[])
{
Frame frame; /* XView frame around XGL window */
Canvas canvas; /* XView canvas inside frame */
Xgl_object sfont; /* XGL stroke font object */
Xgl_color sf_color; /* stroke font color */
Xgl_color bg_color; /* window background color */
xv_init (XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
/*
* Create a Frame and a Canvas
* Set "repaint_proc" as the procedure to call on repaint events.
*/
frame = (Frame) xv_create (NULL, FRAME,
FRAME_LABEL, "XGL Stroke Text",
XV_WIDTH, 220,
XV_HEIGHT, 210,
NULL);
canvas = (Canvas) xv_create (frame, CANVAS,
XV_X, 0,
CANVAS_AUTO_CLEAR, FALSE,
CANVAS_RETAINED, FALSE,
CANVAS_FIXED_IMAGE, FALSE,
CANVAS_REPAINT_PROC, repaint_proc,
CANVAS_RESIZE_PROC, resize_proc,
NULL);
/* set quit procedure where xgl_close is called */
(void) notify_interpose_destroy_func(frame, quit_proc);
-
-
{
Window frame_window; /* XID of frame */
Window canvas_window; /* XID of canvas */
Display *display; /* pointer to X display */
Xv_window pw; /* XView paint window */
Xgl_X_window xgl_x_win; /* XGL-X data structure */
Xgl_inquire *inq_info; /* XGL inquiry structure */
/* get X stuff */
display = (Display *) xv_get (frame, XV_DISPLAY);
pw = (Xv_Window) canvas_paint_window (canvas);
canvas_window = (Window) xv_get (pw, XV_XID);
frame_window = (Window) xv_get (frame, XV_XID);
/* put X stuff into XGL data structure */
xgl_x_win.X_display = (void *) XV_DISPLAY_FROM_WINDOW (pw);
xgl_x_win.X_window = (Xgl_usgn32) canvas_window;
xgl_x_win.X_screen = (int) DefaultScreen (display);
/*
* Open XGL, create a Raster, a Stroke Font, and a Context.
* Attach the raster as the Context's Device.
* Initialize the context text attributes to render the text.
*/
sys_st = xgl_open (NULL);
/* use XGL inquiry facility to get hw color type */
obj_desc.win_ras.type = XGL_WIN_X;
obj_desc.win_ras.desc = &xgl_x_win;
if (!(inq_info = xgl_inquire(sys_st, &obj_desc))) {
printf("error getting inquiry\n");
exit(1);
}
/* set stroke text and background colors appropriately */
if (inq_info->color_type.index) {
sf_color.index = 1;
bg_color.index = 0;
}
else if (inq_info->color_type.rgb) {
sf_color.rgb = white_rgb;
bg_color.rgb = black_rgb;
}
else { /* get info from visual */
-
-
XVisualInfo visual_info;
int visual_class = TrueColor;
int default_screen;
int default_depth;
/* locate a visual */
default_screen = DefaultScreen(display);
default_depth = DefaultDepth(display, default_screen);
while (!XMatchVisualInfo(display, default_screen,
default_depth, visual_class--, &visual_info));
if (visual_info.class == TrueColor) {
sf_color.rgb = white_rgb;
bg_color.rgb = black_rgb;
}
else {
sf_color.index = 1;
bg_color.index = 0;
}
}
/* user must free memory allocated by inquiry function */
free(inq_info);
/* create raster */
obj_desc.win_ras.type = XGL_WIN_X;
obj_desc.win_ras.desc = &xgl_x_win;
ras = xgl_object_create (sys_st, XGL_WIN_RAS, &obj_desc,
NULL);
/* create stroke font */
obj_desc.sfont_name = "Italic_T.font";
sfont = xgl_object_create (sys_st, XGL_SFONT, &obj_desc,
NULL);
ctx = xgl_object_create (sys_st, XGL_2D_CTX, NULL,
XGL_CTX_DEVICE, ras,
XGL_CTX_DEFERRAL_MODE, XGL_DEFER_ASAP,
XGL_CTX_SFONT_0, sfont,
XGL_CTX_STEXT_CHAR_HEIGHT, 15.0,
XGL_CTX_STEXT_CHAR_UP_VECTOR, up_vector,
XGL_CTX_STEXT_CHAR_SPACING, 0.5,
XGL_CTX_STEXT_COLOR, &sf_color,
XGL_CTX_LINE_COLOR, &sf_color,
XGL_CTX_BACKGROUND_COLOR, &bg_color,
NULL);
-
-
}
/*
* Let the window system handle the events.
*/
xv_main_loop (frame);
}
static void
resize_proc ()
{
if (ras)
xgl_window_raster_resize(ras);
}
static void
repaint_proc ()
{
static Xgl_pt_f2d text_pos;
if (ctx) {
xgl_window_raster_resize(ras);
}
static void
repaint_proc ()
{
static Xgl_pt_f2d text_pos;
if (ctx) {
xgl_window_raster_resize(ras);
/* clear the display */
xgl_context_new_frame (ctx);
/* draw the text string */
text_pos.x = 60.0, text_pos.y = 50.0;
xgl_stroke_text (ctx, "Hello", &text_pos, NULL);
text_pos.x = 20.0, text_pos.y = 80.0;
xgl_stroke_text (ctx, "Italicized", &text_pos, NULL);
text_pos.x = 68.0, text_pos.y = 110.0;
xgl_stroke_text (ctx, "XGL", &text_pos, NULL);
text_pos.x = 52.0, text_pos.y = 140.0;
xgl_stroke_text (ctx, "World", &text_pos, NULL);
}
}
-
-
static Notify_value
quit_proc(
Frame frame,
Destroy_status status)
{
if (status == DESTROY_CHECKING)
xgl_close(sys_st);
return(notify_next_destroy_func(frame, status));
}
|
|