Next: Font Handling, Previous: Clipping, Up: Part IV Drawing Objects [Contents][Index]

### 28.5 Getting the Size

To obtain the bounding box of an object with the label taken into account (in contrast to the result of the `fl_get_object_geometry() function which doesn't include a label that isn't inside the object` the following routine exists:

    void fl_get_object_bbox(FL_OBJECT *obj, FL_Coord *x, FL_Coord *y,
                            FL_Coord *w, FL_Coord *h);

For drawing text at the correct places you will need some information about the sizes of characters and strings. The following routines are provided:

    int fl_get_char_height(int style, int size, int *ascent, int *descent)
    int fl_get_char_width(int style, int size);

These two routines return the maximum height and width of the font used, where `size` indicates the point size for the font and `style` is the style in which the text is to be drawn. The first function, `fl_get_char_height()`, also returns the height above and below the baseline of the font via the `ascent` and `descent` arguments (if they aren’t `NULL` pointers). A list of valid styles can be found in Section 3.11.3.

To obtain the width and height information for a specific string use the following routines:

    int fl_get_string_width(int style, int size, const char *str,
                            int len);
    int fl_get_string_height(int style, int size, const char *str,
                             int len, int *ascent, int *descent);

where `len` is the length of the string `str`. The functions return the width and height of the string, respectively. The second function also returns the height above and below the fonts baseline if `ascent` and `descent` aren’t `NULL` pointers. Note that the string may not contain newline characters `'\n'` and that the height calculated from the ascent and descent of those characters in the string that extend the most above and below the fonts baseline. It thus may not be suitable for calculating line spacings, for that use the `fl_get_char_height()` or `fl_get_string_dimension()` function.

There exists also a routine that returns the width and height of a string in one call. In addition, the string passed can contain embedded newline characters `'\n'` and the routine will make proper adjustment so the values returned are large enough to contain the multiple lines of text. The height of each of the lines is the fonts height.

    void fl_get_string_dimension(int style, int size, const char *str,
                                 int len, int *width, int *height);

Next: Font Handling, Previous: Clipping, Up: Part IV Drawing Objects [Contents][Index]