Function GraQueryTextBox() Foundation
Determines coordinates for the boundaries of a character string.
GraQueryTextBox( [<oPS>], <cString> ) --> aPoints
The function GraQueryTextBox() returns a two dimensional array of five elements. Each element contains a subarray with two elements which are the relative coordinates for five points. The first four elements designate the corner points for a parallelogram which represents the boundaries of the specified character string <cString>. The fifth element is the pen position at which the pen is found after the character string is drawn with GraStringAt():
aPoints := { { nXLeft , nYTop }, ; // upper left corner
{ nXLeft , nYBottom }, ; // lower left corner
{ nXRight, nYTop }, ; // upper right corner
{ nXRight, nYBottom }, ; // lower right corner
{ nXPen , nYPen } } // pen position
The points designate the boundaries if the string is displayed at the origin of the coordinate system (the point {0,0}). To calculate the actual coordinates for a box surrounding a string, add the x and y positions at which <cString> is drawn.
The function GraQueryTextBox() determines the corner points of the parallelogram in which the output of a character string occurs. The coordinates describe a rectangle which outlines the character string, unless the characters are output in italic.
GraQueryTextBox() is well suited for determining the space required for a character string displayed in a proportional typeface before it is drawn with GraStringAt().
// The example contains the user-defined function DrawTextBox(),
// in which a character string is displayed with a border. For
// demonstration the procedure main() varies the angle attributes
// for the way in which a character string is drawn.
// The call of GraQueryTextBox() occurs in DrawTextBox().
#include "Gra.ch"
PROCEDURE Main
LOCAL cString, aAttr, oFont
SETCOLOR( "N/W" )
CLS
#ifdef __OS2__ // Create a vector font
oFont := XbpFont():new():create( "10.Helv.normal" )
#else
oFont := XbpFont():new():create( "10.Arial.normal" )
#endif
GraSetFont( NIL, oFont )
cString := "Xbase++: Graphical text output with surrounding box"
DrawTextBox( {120,280}, cString) // output characters with
// border in UDF
GraMarker( NIL ) // mark pen position
aAttr := ARRAY( GRA_AS_COUNT ) // various angle attributes
cString := "GRA_AS_ANGLE is {5, 3}"
aAttr[ GRA_AS_ANGLE ] := {5, 3} // incline to upper right
GraSetAttrString( NIL, aAttr )
DrawTextBox( {300, 140}, cString )
GraMarker( NIL )
cString := "GRA_AS_ANGLE is {5, -3}"
aAttr[ GRA_AS_ANGLE ] := {5, -3} // incline to lower right
GraSetAttrString( NIL, aAttr )
DrawTextBox( {300, 120}, cString )
GraMarker( NIL )
cString := "GRA_AS_ANGLE is {-5, 3}"
aAttr[ GRA_AS_ANGLE ] := {-5, 3} // incline to upper left
GraSetAttrString( NIL, aAttr )
DrawTextBox( {290, 140}, cString )
GraMarker( NIL )
cString := "GRA_AS_ANGLE is {-5, -3}"
aAttr[ GRA_AS_ANGLE ] := {-5, -3} // incline to lower left
GraSetAttrString( NIL, aAttr )
DrawTextBox( {290, 120}, cString )
GraMarker( NIL )
INKEY(0)
RETURN
*****************************************
* Draws character string with border *
*****************************************
PROCEDURE DrawTextBox( aPenPos, cString )
LOCAL aTextBox, aLeftTop, aLeftBottom, aRightTop, aRightBottom
// determine coordinates for
// border
aTextBox := GraQueryTextBox( NIL, cString )
aLeftTop := aTextBox[1] // relative coordinates for
aLeftBottom := aTextBox[2] // the four corner points of the
aRightTop := aTextBox[3] // parallelogram
aRightBottom := aTextBox[4]
aLeftTop[1] += aPenPos[1] // convert relative coordinates
aLeftTop[2] += aPenPos[2] // to absolute coordinates
aLeftBottom[1] += aPenPos[1]
aLeftBottom[2] += aPenPos[2]
aRightTop[1] += aPenPos[1]
aRightTop[2] += aPenPos[2]
aRightBottom[1] += aPenPos[1]
aRightBottom[2] += aPenPos[2]
// draw border
GraLine( NIL, aLeftTop, aRightTop )
GraLine( NIL, NIL, aRightBottom )
GraLine( NIL, NIL, aLeftBottom )
GraLine( NIL, NIL, aLeftTop )
// draw character string
GraStringAt( NIL, aPenPos, cString )
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.