Using Text Strings (XForms (Forms Library) - Version 1.2 (Rev. 4) A Graphical User Interface Toolkit for X)

Next: Using Markers, Up: Image Annotation [Contents][Index]

#### 37.7.9.1 Using Text Strings

To place text into the image, use the following routine

    int flimage_add_text(FL_IMAGE *im, const char *str, int len,
                         int fstyle, int fsize, unsigned tcolor,
                         unsigned bcolor, int nobk, double tx,
                         double ty, int rotation);

where `fstyle` and `fsize` are the same as the label font style and size defined earlier in Section 3.11.3. `tcolor` and `bcolor` specify the colors to use for the text `str` and the background if the `nobk` argument is false. If `nobk` is true the text is drawn without a background. `tx` and `ty` specify the location of the text relative to the image origin. The location specified is the lower-right corner of the text. Note that the location specified can be in some physical space other than pixel space. For example, if the pixel-pixel distance represents 10 miles on a map, you’d like to be able to specify the text location in miles rather than pixels. The location is converted into pixel space using the following code

        tx_pixel = im->xdist_scale * tx + im->xdist_offset;
        ty_pixel = im->ydist_scale * ty + im->ydist_offset;

By default, the offsets `im->xdist_offset` and `im->yxdist_offset` are initialized to 0 and the scales `im->xdist_scale` and `im->ydist_scale` to 1.

The function returns the current number of strings for the image. The interpretation of text used also used elsewhere applies, i.e., if `str` starts with character `@` a symbol is drawn.

There is another function, maybe more convenient depending on the application, that you can use

    int flimage_add_text_struct(FL_IMAGE *im,
                                const FLIMAGE_TEXT *text);

With this function instead of passing all the parameters individual;y you pass a `FLIMAGE_TEXT` structure to the function. The structure has the following fields:

`str`

  The string to append to the image.

`len`

  Length of the string in bytes.

`x, y`

  A location relative to the image origin, given in pixels (no conversion from other coordinate systems is done)

`align`

  Specifies the alignment of the string relative to the give location.

`style, size`

  The font style and size to use.

`color`

  The text color

`bcolor`

  The background color

`nobk`

  If true indicates that no background is to be drawn.

`angle`

  Angle (in thenth of a degree) the text is to be rotated from the default horizontal orientation. Currently only PostScript output handles this correctly.

To delete the all texts you added to an image, use

    void flimage_delete_all_text(FL_IMAGE *im);

You also can suppress the display of annotation text without deleting it. To do this, simply set `im->dont_display_text` to true.

Next: Using Markers, Up: Image Annotation [Contents][Index]