Text Object Class


Overview

The Text object class draws a character string that can span multiple lines within a rectangular area. Since the Text class is derived from the Rectangle class, a background fill and/or an outline around the text can also be drawn.

The Text object class can display fixed size text, using the standard X bitmap font technology or scalable text, using an outlined font technology provided with the INT library. Resource XmNtextScale is used to control whether fixed size or scalable fonts are used. If resource XmNtextScale is NULL, a fixed size font will be used. The size of this font, specified using resource XmNfontSize, must be a valid X font size. Otherwise, if resource XmNtextScale is not NULL, a scalable font is used. The size of scalable text object is specified in user coordinates. Its size will change when the coordinate system changes (for example if you resize the parent widget window).

When using scalable text, the Text object must access a file containing the description of the outline for the specified font. The font descriptions must reside in a directory which you can specify as follows:

  1. Set CompBase resource XmNfontPath on the Text parent widget.
  2. Set environment variable INT_FONT_PATH.

If neither of these is defined, the current directory will be searched. If a valid font description is not found, a default stroke font will be used.

The Text object supports rotation for both fixed size and scalable text.

The position of the text is specified in user coordinates using structure XintTextLocation and resource XmNtextLocation. The positioning of the text relative to this location is controlled by resources XmNhorizontalTextAlignment and XmNverticalTextAlignment.


Inherited Behavior and Resources

The Text object class inherits behavior and resources from the Xt Object, Graphic and Rectangle classes.
The following resources are defined by the Text object class:
NameTypeDefaultAccess
XmNfontFamilyintXintHELVETICACSG
XmNfontSizeint10CSG
XmNfontSlantintXintSLANT_REGULARCSG
XmNfontWeightintXintWEIGHT_MEDIUMCSG
XmNhorizontalTextAlignmentintXintHALIGN_LEFTCSG
XmNmarginHeightDimension4CSG
XmNmarginWidthDimension4CSG
XmNrotateAngleint0CSG
XmNtextLocationXintTextLocation *NULLCSG
XmNtextScaleXintTextScale *NULLCSG
XmNtextStringchar *NULLCSG
XmNverticalTextAlignmentintXintVALIGN_TOPCSG


XmNfontFamily

Specifies the font family used to draw the text string. You can specify one of the following constants:

Resource ValueDescription
XintDEFAULTUse the default font family. For scalable text, a stroke font is selected. For fixed size text, the default X font for the specified size and weight is selected.
XintHELVETICA (default)Use the Helvetica font family.
XintTIMESUse the Times font family.
XintCOURIERUse the Courier font family.
XintNEW_CENTURY_SCHOOLBOOKUse the New Century Schoolbook font family
XintSYMBOLUse the Symbol font family.


XmNfontSize

Specifies the size in points of the font. Specify XintFONT_SIZE_DEFAULT to get the default font for the specified family. Valid font sizes are 8, 10, 12, 14, 18 and 24. See resource XmNfontScale to specify a font size in user coordinates.

XmNfontSlant

Specifies the slant of the font used to draw the text string. You can specify XintSLANT_REGULAR, XintSLANT_OBLIQUE or XintSLANT_DEFAULT.

XmNfontWeight

Specifies the weight of the font used to draw the text string. You can specify XintWEIGHT_MEDIUM or XintWEIGHT_BOLD or XintWEIGHT_DEFAULT.

XmNhorizontalTextAlignment

Specifies the horizontal alignment of the text. You can specify one of the following constants:

Resource ValueDescription
XintHALIGN_LEFTText is aligned left in the horizontal direction.
XintHALIGN_CENTERText is centered in the horizontal direction.
XintHALIGN_RIGHTText is aligned right in the horizontal direction.


XmNmarginHeight

Specifies the space (in pixels) between the text and the top and bottom edges of the rectangular area containing the text.

XmNmarginWidth

Specifies the space (in pixels) between the text and the left and right edges of the rectangular area containing the text.

XmNrotateAngle

Specifies an angle of rotation in degrees for the text object. The text rotates about the location defined in resource XmNtextLocation.

XmNtextLocation

Specifies the location of the text object in user coordinates. This resource is specified as a pointer to a data structure of type XintTextLocation which takes the following form:

   typedef struct {
                   float x;
                   float y;
   } XintTextLocation; 


XmNtextScale

Specifies the text font size in user coordinates and a horizontal stretch factor. When this resource is set, a scalable font will be used to display the text string. The stretch value should be set to 1.0 unless you want to stretch ( > 1.0) or shrink ( <1.0) the text in the horizontal direction. This resource is specified as a pointer to a data structure of type XintTextScale which takes the following form:

   typedef struct {
                   float size;
                   float stretch;
   } XintTextScale; 


XmNtextString

Specifies the string to display. Use the new line symbol `\n` to separate lines.

XmNverticalTextAlignment

Specifies the vertical alignment of the text with respect to the text location specified in resource XmNtextLocation. You can specify one of the following constants:

Resource ValueDescription
XintVALIGN_TOPText is aligned with respect to the top in the vertical direction.
XintVALIGN_CENTERText is centered in the vertical direction.
XintVALIGN_BOTTOMText is aligned with respect to the bottom in the vertical direction.


Text Callbacks

The Text object class does not define any new callbacks. However, the callback structure returned with callback XmNverifyCallback (see class Graphic) is redefined. The following ordered table lists the members of the callback structure XintTextVerifyCallbackStruct.

Data TypeMemberDescription
intreasonIndicates why the callback was invoked.
XEvent *eventPoints to the XEvent that triggered the callback.
BooleandoitSet to False to cancel the operation.
XintTextLocationold_locationOld location of the Text object.
XintTextLocationlocationNew location proposed for the Text object.


Defined Functions

The XintCreateText function creates a Text object.

     Object XintCreateText (...)

WidgetparentParent of new Text object.
char *nameName of new Text object.
ArgListarglistList of resource/value items.
CardinalargcountNumber of items in arglist.


Macros

Macro XintIsText returns True if the specified object is a Text object.

     Boolean XintIsText (Object object)