Next: Tool Tips, Previous: Bounding Boxes, Up: Changing Attributes [Contents][Index]
There are also a number of routines to change the appearance of the label. The first one is
void fl_set_object_lcolor(FL_OBJECT *obj, FL_COLOR lcol);
It sets the color of the label. The default is black (FL_BLACK
).
The font size of the label can be changed using the routine
void fl_set_object_lsize(FL_OBJECT *obj, int lsize);
where lsize
gives the size in points. Depending on the server and
fonts installed, arbitrary sizes may or may not be possible. Fig 3.5
shows the font sizes that are standard with MIT/XConsortium
distribution. So use of these values is encouraged. In any case, if a
requested size can not be honored, substitution will be made. The
default size for XForms is 10pt.
FL_TINY_SIZE | 8pt |
FL_SMALL_SIZE | 10pt |
FL_NORMAL_SIZE | 12pt |
FL_MEDIUM_SIZE | 14pt |
FL_LARGE_SIZE | 18pt |
FL_HUGE_SIZE | 24pt |
Labels can be drawn in many different font styles. The style of the label can be controlled with the routine
void fl_set_object_lstyle(FL_OBJECT *obj, int lstyle);
The default font for the Forms Library is Helvetica at 10pt.
Additional styles are available:
The last three styles are special in that they are modifiers, i.e.,
they do not cause font changes themselves, they only modify the
appearance of the font already active. E.g., to get a bold engraved
text, set lstyle
to FL_BOLD_STYLE|FL_ENGRAVED_STYLE
.
Other styles correspond to the first 12 fonts. The package, however, can handle up to 48 different fonts. The first 16 (numbers 0-15) have been pre-defined. The following table gives their names:
0 helvetica-medium-r 1 helvetica-bold-r 2 helvetica-medium-o 3 helvetica-bold-o 4 courier-medium-r 5 courier-bold-r 6 courier-medium-o 7 courier-bold-o 8 times-medium-r 9 times-bold-r 10 times-medium-o 11 times-bold-o 12 charter-medium-r 13 charter-bold-r 14 charter-medium-i 15 Symbol
The other 32 fonts (numbers 16-47) can be filled in by the application program. Actually, the application program can also change the first 16 fonts if required (e.g., to force a particular resolution). To change a font for the the entire application, use one of the following routines:
int fl_set_font_name(int index, const char *name); int fl_set_font_name(int index, const char *fmt, ...);
The first form accepts just a simple string for the font name while
the second assembles the name from a format string as it’s used with
printf()
etc. and the following arguments. The first argument,
index
, is the number of the font (between 0 and
FL_MAXFONTS-1
) and the font name should be a valid font name
(with the exception of the size field). If you are defining a
completely different font family starting at index k
, it’s a
good idea to define k + FL_BOLD_STYLE
to be the corresponding
bold font in the family , and k + FL_ITALIC_STYLE
the
corresponding italic font in the family (so object like browser can
obtain correct style when switching font styles):
#define Pretty 30 #define PrettyBold (Pretty + FL_BOLD_STYLE) #define PrettyItalic (Pretty + FL_ITALIC_STYLE) fl_set_font_name(Pretty, fontname); fl_set_font_name(PrettyBold, boldfontname); fl_set_font_name(PrettyItalic, italicfontname); ... fl_set_object_lstyle(obj, PrettyBold);
The function returns a negative value if the requested font is invalid
or otherwise can’t be loaded. Note however, if this routine is called
before fl_initialize()
, it will return 0, but may fail later if
the font name is not valid. To change the default font
(helvetica-medium), a program should change font FL_NORMAL_STYLE
.
To get the name of a font at a certain index use
If a font name in XLFD is given, a question mark (?
) in the
point size position (i.e.; between the eighth and the nineth dash)
informs the Forms Library that a scalable font should be requested
later. It is preferable that the complete XLFD name (i.e., with 14
dashes and possibly wildcards) be given because a complete name has
the advantage that the font may be re-scalable if scalable fonts are
available. This means that although both
"-*-helvetica-medium-r-*-*-*-?-*-*-*-*-*-*" "-*-helvetica-medium-r-*-*-*-?-*-*"
are valid font names, the first form may be re-scalable while the the second is not. To obtain the actual built-in font names, use the following function
int fl_enumerate_fonts(void (*cb)(const char *f), int shortform);
where cb
is a callback function that gets called once for every
built-in font name. The font name is passed to the callback function as
the string pointer parameter while shortform
selects if a short
form of the name should be used.
XForms only specifies the absolutely needed parts of the font names,
and assumes the font path is set so that the server always chooses the
most optimal fonts for the system. If this is not true, you can use
fl_set_font_name()
or fl_set_font_name_f()
to select the exact font you want. In general, this is not recommended
if your application is to be run/displayed on different servers.
See fonts.c for a demonstration of all the built-in font styles available.
You can change the alignment of the label with respect to the bounding box of the object. For this you should use the routine
void fl_set_object_lalign(FL_OBJECT *obj, int align);
with the following values for the align
argument:
Alignment requests with the abpve constants place the text outside the
box (except for FL_ALIGN_CENTER
). To get a value that can
be used to align the label within the object the function
int fl_to_inside_lalign(int align);
can be used, which returns the necessary value for the corresponding
inside alignment. Except for the case of FL_ALIGN_CENTER
(which is always inside the object) the result is the original value,
logically or’ed with the constant
.
There’s also a function for the reverse conversion, i.e., from a calue for inside to outside alignment
int fl_to_outside_lalign(int align);
Using this functions is a bit simpler than combining the value with
the FL_ALIGN_INSIDE
constant, especially when it comes
to FL_ALIGN_CENTER
(which doesn’t has the this bit set,
even though labels with this alignment will always be shown within
the object.
Both functions return -1
if an invalid value for the alignment
is passed to them.
There exist also three functions to test for the inside or outside alignment:
int fl_is_inside_lalign(int align); int fl_is_outside_lalign(int align); int fl_is_center_lalign(int align);
Note that these functions return 0
also in the case that the
alignment value passed to them is invalid.
Not all objects accept all kinds of label alignment. For example for
sliders, inputs etc. it doesn’t make sense to have the label within
the object und in these cases a request for an inside label is ignored
(or, more precisely, converted to the corresponding request for an
outside label or, on a request with FL_ALIGN_CENTER
, the
reversion to the default label position). On the other hand, some
objects like the text object (where the text to be shown is the
label’s text) accept only inside alignment and a request for an
outside alignment will automatically replaced by the corresponding
inside alignment.
See also the demo program lalign.c for an example of the positioning of labels using the above constants.
void fl_set_object_label(FL_OBJECT *obj, const char *label); void fl_set_object_label_f(FL_OBJECT *obj, const char *fmt, ...);
change the label of a given object. Whilw the first function expects a
simple string for the label. the second one accepts a format string
with the same format specifiers as printf()
etc., followed by
as many additional arguments as there are format specifiers. An
internal copy of the label for the object is made. As mentioned
earlier, newline (\n
) can be embedded in the label to generate
multiple lines. By embedding <Ctrl>H
(\010
) in the
label, the entire label or one of the characters in the label can be
underlined. The function
const char * fl_get_object_label(FL_OBJECT *obj);
returns the label string.
Next: Tool Tips, Previous: Bounding Boxes, Up: Changing Attributes [Contents][Index]