[Previous] [Contents] [Index] [Next]


Calculate the extent of a string of text


PhRect_t *PgExtentText( PhRect_t *extent,
                        PhPoint_t const *pos,
                        char const *font,
                        char const *str,
                        unsigned n );


This function determines the extent that would be occupied if str were rendered at pos, using font. The extent information is returned in both extent and in the return value for the function. If you pass extent as NULL, the function returns NULL.

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


A pointer to a PhRect_t structure, or NULL if an error occurred.


The following fragment determines the extent of a string drawn with the helv18BI font:

PhRect_t extent;

if( PgExtentText( &extent, NULL, "helv18BI", 
                  "Hello World!", 0 ) ) {
   printf( "Ascent: %d Descent: %d Width: %d\n",
           -extent.ul.y, extent.lr.y, 
           extent.lr.x - extent.ul.x + 1 );
} else
   printf( "Error.\n" );



Interrupt handler No
Signal handler No
Thread No

See also:

PgDrawText(), PgSetFont()

[Previous] [Contents] [Index] [Next]