Caution: This version of this document is no longer maintained. For the latest documentation, see


Calculate the extent of a multiline text string


PhRect_t *PgExtentMultiText( PhRect_t *extent,
                             PhPoint_t *pos,
                             char *font,
                             char *str,
                             unsigned n,
                             int linespacing );




This function determines the extent that would be occupied if str were rendered at pos, using font (which you should create by calling PfGenerateFontName()). The extent information is stored in the PhRect_t structure pointed to by extent.

The function calculates the extent of the first n characters of the string. To calculate the extent of the entire string, set n to zero. If you pass pos as NULL, it's assumed to be (0,0).

The linespacing is in pixels. A positive linespacing has the obvious effect: increased spacing between lines, and a taller extent. A negative linespacing causes the function to compute an extent for overlapping lines. Larger negative linespacing make the extent decrease in height. The minimum height of the extent is the height of font.


The same pointer as extent, or NULL if an error occurred.


The following fragment determines the extent of a multiline string drawn in 14-point Helvetica. The characters in neighboring lines overlap by 4 pixels.

PhRect_t extent;
char Helvetica14[MAX_FONT_TAG];

if(PfGenerateFontName("Helvetica", 0, 14, 
                      Helvetica14) == NULL) {
    perror("Unable to find font");
} else {
    if (PgExtentMultiText( &extent, NULL, Helvetica14,
          "First line\nSecond line\nThird line", 0, -4))
        printf( "Width: %d  Height: %d\n", 
       - extent.ul.x + 1, 
       - extent.ul.y + 1);
        printf( "Error.\n" );



Interrupt handler No
Signal handler No
Thread No

See also:

PfGenerateFontName(), PgDrawMultiTextArea(), PgDrawTextArea(), PgExtentText(), PhPoint_t, PhRect_t

Text in the Raw Drawing and Animation chapter of the Photon Programmer's Guide