25.3.4 Text−related Values
Text is almost always an important part of a graphical user interface. UIL supports string, character set, and font
values, all of which are related to the display of text in your interface. A string consists of displayable text. A string
only makes sense in the context of a character set, which defines the supported characters in a string and the encoding
(or mapping from values to glyphs) of the string. A font contains the actual glyphs that visually represent a character
on the screen or on paper. These three elements are closely related as all are necessary to display text. the figure
illustrates the relationships among these types under UIL.
Relationships among strings, character sets, and fonts in UIL
This figure may look complicated, but UIL and Motif provide default values for character sets and fonts. You don't
have to worry about these values unless you are customizing or internationalizing an application. Of course, you must
always provide the strings, but that's the easy part. Before we can explain strings or fonts, you need to understand
character sets, because both strings and fonts depend on them. The character set of a string determines the string's
parsing direction, writing direction, and the number of bytes per character. For example, character sets for
Latin−based languages like English are read from left to right, are written from left to right, and are typically encoded
using one byte per character.
25 Creating a User Interface With UIL 25.3.4 Text−related Values
676
When a string is displayed, it must be drawn with a font that uses the same character set as the string because a
character set defines a mapping from character codes to character glyphs. For example, in the ISO 8859−1 character
set (ISO Latin−1), the value 65 represent an A, the value 66 represents a B, etc. In a font for ISO 8859−1, the symbol
A occupies position 65, B occupies position 66, and so on. If the character set of a string doesn't match the character
set of the font with which it is drawn, there's a good chance that the rendered text will be gibberish.
UIL provides a number of built−in character sets that should meet the needs of most applications. lists the built−in
UIL character sets and specifies the UIL name, the official name, and the attributes of each. lp9 | lp9 | lp9 | lp9 | lp9
lp9 | lp9 | lp9 | lp9 | lp9. UIL Name Character Set Parse Direction Writing Direction 16 Bit
_
iso_latin1 ISO8859−1 L to R L to R No iso_latin2 ISO8859−2 L to R L to R No iso_latin3 ISO8859−3
L to R L to R No iso_latin4 ISO8859−4 L to R L to R No iso_latin5 ISO8859−5 L to R L to R No
iso_cyrillic ISO8859−5 L to R L to R No iso_arabic ISO8859−6 L to R L to R No iso_greek
ISO8859−7 L to R L to R No iso_latin8 ISO8859−8 R to L R to L No iso_latin8_lr ISO8859−8 L to R R
to L No iso_hebrew ISO8859−8 R to L R to L No iso_hebrew_lr ISO8859−8 L to R R to L No gb_hanzi
GB2313.1980−0 L to R L to R Yes gb_hanzi_gr GB2313.1980−1 L to R L to R Yes jis_kanji
JISX0208.1983−0 L to R L to R Yes jis_kanji_gr JISX0208.1983−1 L to R L to R Yes jis_katakana
JISX0201.1976−0 L to R L to R No ksc_hangul KSC5601.1987−0 L to R L to R Yes ksc_hangul_gr
KSC5601.1987−1 L to R L to R Yes _ If you need to use a character set that is not built into UIL, you can define your
own character set. UIL allows user−defined character sets anywhere a built−in is expected, except in the
character_set option at the beginning of a module. The specification of a user−defined character set takes the
following form:
character_set ('string_expression'
[, right_to_left = boolean_expression]
[, sixteen_bit = boolean_expression] )
The string_expression that is used to name a user−defined character set is the key that links a string to a font, as you'll
see shortly. The name is followed by two optional character set properties that only affect string values. When the
right_to_left property is set to false, strings that use the character set are parsed and written from left to right.
When the property is set to true, strings are parsed and written from right to left. When the sixteen_bit property
is set to false, each character in a string that uses the character set is one byte long, but when it is set to true, each
character is two bytes long. Since both properties default to false, you do not need to specify them in most cases.
Here are a few specifications of user−defined character sets:
character_set ('bold');
character_set ('italic');
character_set ('hieroglyphic', sixteen_bit = true);
character_set ('xnaye, right_to_left = true);
UIL does not allow the definition of character set variables. You can only specify a character set by using the
character_set option in the module header or by explicitly specifying the character set of a string. We describe
how to specify the character set for a string in the next section. While a character set traditionally represents the
characters of a language, you can also represent different font styles with user−defined character sets. UIL supports
several different types of strings so that it can represent the various string values used for Motif widget resources. The
asciz_string_table type is the only type that is not associated with a widget resource. lists all of the UIL string
types and their corresponding C types. lp9 | lp9 lp9 | lp9. UIL Type Name C/Xt/Motif Type Name
_
string char *, String compound_string XmString wide_character char_t *
asciz_string_table char **, String * asciz_table char **, String *
compound_string_table XmString *, XmStringTable string_table XmString *,
XmStringTable
25 Creating a User Interface With UIL 25.3.4 Text−related Values
677
_ The basic representation of all strings in UIL is a sequence of zero or more characters within single or double
quotes. In Motif 1.1, quoted strings are limited to 2000 characters, but later releases allow greater lengths. The exact
type of a string can be determined implicitly by the context in which it appears or explicitly when it is used in a
named−string definition. All of the string types except string have an explicit form.
Both single and double−quoted strings can contain any of the printable single−byte characters. These are the
characters with decimal values in the ranges 32 to 126 and 160 to 255. Characters with values outside of the ranges
can only be entered using the \value\ escape sequence, where value represents the character code desired. In
addition, you must escape a single quote (') in a single−quoted string and a double quote (") in a double−quoted
string. To allow the easy specification of commonly used nonprinting characters, UIL recognizes the escape sequences
shown in l | l c | l.
Escape Sequence Meaning
_
\b Backspace \f Formfeed \n Newline \r Carriage return \t Horizontal tab \v Vertical tab \\ Backslash \'
Single quote \" Double quote
_ The following code fragment shows some examples of quoted string variable definitions that include escape
sequences:
value
bell : 'Beep\7\';
quote : "\"You don't believe me?\" asked the lawyer.";
The first string includes some normal text and an escaped control character, decimal 7, which is the bell character on
most terminals. The second string contains a couple of double quotes that must be escaped because the string itself is
double−quoted. Alternatively, we could have made it a single−quoted string, thereby eliminating the need for escaping
the double quotes within it. In general, non−printable escape characters only make sense in the context of
NULL−terminated strings and may produce strange results if you use them within compound strings (which we'll
discuss shortly).
You can continue a single−quoted string over multiple lines by adding the backslash character as the last character on
a continued line. The string continues with the first character on the following line and does not include a newline. If
you want a newline in a string, you must use the \n escape sequence. Double−quoted strings cannot span multiple
lines. The following definition shows an example of a multi−line single−quoted string:
value
sentence : 'TRUE! −− NERVOUS −− VERY, very dreadfully nervous \
I had been and am; but why will you say that I am mad?';
UIL NULL−terminated strings are the same as C strings. While most Motif text resources are XmString values, there
are a few strings that are NULL−terminated. The most common is the XmNvalue resource of the Text and TextField
widgets. You also use NULL−terminated strings in the literal syntax of many UIL variable definitions, and you can use
a NULL−terminated string as the argument to a callback. The following fragment demonstrates the use of
NULL−terminated strings:
procedure
verify (string);
object phone : XmTextField {
arguments {
XmNvalue = '(512) 555−1212';
XmNbackground = color ('wheat');
};
callbacks {
25 Creating a User Interface With UIL 25.3.4 Text−related Values
678
XmNmodifyVerifyCallback = procedure verify ('(###) ###−####');
};
};
In this widget definition, we assign a NULL−terminated string to the XmNvalue resource, we use one in the definition
of a UIL color value, and we pass one as a callback argument. The callback is declared as taking a string value,
which is the UIL type for NULL−terminated strings. We recommend using the convention of writing
NULL−terminated strings as single−quoted strings. This distinguishes them from compound strings, which we
recommend writing as double−quoted strings.
You can concatenate two or more NULL−terminated strings with the ampersand (&), which is the UIL string
concatenation operator. It is a binary operator that creates a new string consisting of the left operand followed by the
right operand. You can use this operand with NULL−terminated strings that are used for resource settings, callback
arguments, and variable definitions. However, using string concatenation in the literal syntax of a UIL value definition
may crash the UIL compiler or result in an incorrect definition. The following fragment shows an example of string
concatenation:
value
first : 'Bilbo';
last : 'Baggins';
full : first & ' ' & last;
The full variable is defined as the concatenation of the variables first and last, separated by a space. The
resulting string is 'Bilbo Baggins'. You can use both variables and NULL−terminated string literals as the
operands for string concatenation. Most text values in the Motif widget set are handled as XmString values, or
compound strings. Compound strings differ from NULL−terminated strings in that they contain information about the
character set and writing direction of the string along with the textual information. This additional information is
necessary for displaying text in different languages and fonts. Essentially, a compound string is a string that comes
with all of the information that is needed to render it. In most situations, you can simply specify the text, and the UIL
compiler provides the character set, as in the following familiar example:
object hello : XmLabel
{
arguments {
XmNlabelString = "Hello, World!";
};
};
XmNlabelString is an XmString resource, but in this definition we only specify the text portion of the
compound string. This specification works because there is a default character set associated with every UIL module.
As we explained in Chapter 22, Introduction to UIL, you can specify the default character set by setting the LANG
environment variable or by setting the character_set option at the beginning of the module. If you do not specify
the default character set, the UIL compiler uses a built−in default which is vendor specific. In any event, you can use a
single or double−quoted string wherever a compound string is expected, and the UIL compiler will automatically
convert it to a compound string. the figure illustrates how the UIL compiler determines the character set for compound
strings.
25 Creating a User Interface With UIL 25.3.4 Text−related Values
679
Character set determination for compound strings
The character set of an individual string can also be specified explicitly. You do so by preceding a string with the
pound sign (#) and specifying the name of a built−in or user−defined character set. This syntax only works with
double−quoted strings, however, which is why we recommend using double−quoted strings to represent compound
strings. In early releases of Motif 1.2, the UIL compiler does not generate an error if you specify a character set for a
single−quoted string. The compiler silently ignores the specification, so you should be careful to always use
double−quoted strings when specifying a character set. The following code fragment demonstrates how to set the
character set of a string explicitly:
object hello : XmLabel {
arguments {
XmNlabelString = #iso_greek"[[chi]][[alpha]][[iota]][[rho]][[epsilon]]";
};
};
In this example, we explicitly set the character set to iso_greek, which is one of the built−in UIL character sets. At
run−time, the string is displayed in Greek as long as the font list of the Label is set correctly. (We explain font lists
later in this section.) It is rare for an application to specify a character set explicitly, as most applications only display
text using one language for a given invocation, although the language may vary between invocations.
You can also specify different font styles using character sets, although that is not their primary purpose. You can
define your own character set to represent a different style, as shown in the following fragment:
object title : XmLabel {
arguments {
XmNlabelString = #character_set('italic')"Elsinore";
};
};
The XmNlabelString resource is set to a compound string that contains the text "Elsinore" and uses the character
set named italic. Displaying the string in italics requires that the font list of the Label contain an italic
character set.
Unlike other UIL values, you cannot define a character set variable, which means that you must always specify a
user−defined character set explicitly, as shown in this example. Specifying font styles with character sets is most
25 Creating a User Interface With UIL 25.3.4 Text−related Values
680
Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.