grafic function ttg_textsize()

This procedure immediateley returns the width and height of a text string in pixels as a string (width/height). The return value is the same format as bitmap creating commands return and you may extract the numbers using get_x() and get_y(). Check the example please.
You need not define or open a bitmap for this command and no ttg_execute() is necessary. Very helpful to right allign or center a text.
ttg_textsize() receives information about the font to be used. Please read and understand the concept of defining different fonts using ttg_font() and selecting for the text to write by ttg_fontselect(). If you want to choose a font form your Windows® font definitions, use the FoxPro® command getfont(). It returns exactly the three parameters you have to supply to ttg_textsize(). Please add the weight or normal and bold characters. A good default is 100 for normal and 300 for bold. Do not forget to set the font using ttg_font() before you print at the determined position.
Parameters:
1. Name of the font2. Size of font in points
3. Attributes (B->Bold, N->Normal, I->Italic, U->Underline)
4. String to recon size for
***************************** | |
* Tool&Task example program * | |
* ttg_textsize() * | |
* last compile: 16.03.2018 * | |
***************************** |
LOCAL lstring, lfont, lwh, ln, lx, ly | |
ttg_createbmp(148, 148, FORMCOLOR) | |
lstring = "Tool&Task" |
&& string to display using different fonts |
DIMENSION lfont(5, 5) |
&& array to store font, color and width info |
lfont(1, 1) = "Arial" | |
lfont(1, 2) = 8 | |
lfont(1, 3) = "N" | |
lfont(1, 4) = BLUE | |
lfont(2, 1) = "Courier" | |
lfont(2, 2) = 9 | |
lfont(2, 3) = "N" | |
lfont(2, 4) = LIGHTRED | |
lfont(3, 1) = "Courier New" | |
lfont(3, 2) = 10 | |
lfont(3, 3) = "BI" | |
lfont(3, 4) = RGB(100, 100, 100) |
&& three equal colors = grey |
lfont(4, 1) = "Courier" | |
lfont(4, 2) = 11 | |
lfont(4, 3) = "N" | |
lfont(4, 4) = BLACK | |
lfont(5, 1) = "Courier New" | |
lfont(5, 2) = 12 | |
lfont(5, 3) = "N" | |
lfont(5, 4) = RED | |
* the letter 'G' has an ascii value of 71 se how the index for 5 fonts is defined: | |
FOR ln = 1 TO 5 | |
ttg_font(chr(70+ln), lfont(ln, 1), lfont(ln, 2), lfont(ln, 3), 100, 300, lfont(ln, 4)) | |
lwh = ttg_textsize(lfont(ln, 1), lfont(ln, 2), lfont(ln, 3), 100, 300, lstring) | |
lfont(ln, 5) = get_x(lwh) | |
ENDFOR | |
* all fonts to use are defined now | |
ly = 3 |
&& y position for the first line |
ldist = 30 |
&& vertical space between lines |
FOR ln = 1 TO 5 | |
ttg_fontselect(chr(70+ln)) | |
ttg_text(140 - lfont(ln, 5), ly, lstring) |
&& right aligned |
ly = ly + ldist | |
ENDFOR | |
ttg_execute() | |
ttg_display() |