Original Author Paul Laughton, 2011
Page 172
De Re BASIC!
Gr.text.draw positions text so the the body of the characters sit on a line called the baseline. The down
and up values are reported as offsets from this baseline. The up value is negative, because it defines a
position above the baseline. The down value is positive, because its position is below the baseline. The
height value is not an offset, so it is always positive. down - up is always larger than height.
Sometimes you want to know the real screen positions of the top and bottom of the area where your
text will be drawn, independent of the actual text you will draw there. The bottom of this area is the y
coordinate of Gr.text.draw plus the down value of Gr.text.height. For most applications, the top of the
text area is the bottom position minus the height value of Gr.text.height, so y + down - height. For
some applications (such as a Polish text field), you may need the extra height you get with y + up.
GR.TEXT.SIZE 40
GR.TEXT.HEIGHT ht, up, dn
% ht is 40
GR.TEXT.DRAW t, x, y, "Hello, World!"
txtBottom = y + dn
txtTop = txtBottom - ht
% good for most applications
txtTop = y + up
% high enough for all possible text (up is negative)
Gr.text.width <nvar>, <exp>
Returns the pixel width of a string (from <exp>) in the variable <nvar>.
If the parameter <exp> is a string expression, the return value is the width of the string as if it were
displayed on the screen using the latest text attribute settings: the typeface, size, and style as set by
the Gr.text.* commands (or default values if you did not set them).
If the parameter <exp> is a numeric expression, its value must be a text object number from
Gr.text.draw, or you will get a run-time error. The return value is the width of the text of the object
as it would be displayed on the screen by Gr.render.
Advanced usage: To calculate dimensions, both Gr.text.width and Gr.get.textbounds (below) use a text
string and a set of text attributes. The text attributes are kept in a Paint object. The source of the string
and the Paint depends on the type of the <exp> parameter:
If <exp> is a
value of <exp> is
source of text string is
Source of text attributes is
string
expression
the string to measure
value of <exp>
Current Paint (most recent
Gr.text.* settings)
numeric
expression
a text object number
from Gr.text.draw
string from Gr.text.draw
(kept in text object)
Paint attached to the text object
(see Note, below)
Note: Gr.text.draw attaches a Paint to the text object using the text attributes that are current at that
time. This is the Paint Gr.render uses to display the text on the screen. If you modify this Paint,
the changes are reflected in values returned by Gr.text.width and Gr.get.textbounds, and also
shown on the screen with the next Gr.render.
Gr.get.textbounds <exp>, left, top, right, bottom
Gets the boundary rectangle of a string as it would be drawn on the screen. The returned coordinate
values give you the dimensions of the bounding rectangle but not its location.