GetStringMetrics

Bitmaps
Aptilis 1

GetStringMetrics(BitmapHandle, DestinationArray, String)

GetStringMetrics returns the size in pixels of rectangle large enough to contain the specified string. The result is returned in an array, where the first element is the width of the string and the second, its height.

Return Value:
0 and a width and a height in the specified array or -1 if you indicated a non-valid bitmap.

Example:

b = createBitmap(250, 50)
if b = -1
print("Ooops, could not create the bitmap....\n")
else

// White background
clearBitmap(b, RGB(255, 255, 255))

// Unix user need to find a true type font and copy its file
// somewhere on their system, and refer to it here correctly.
// Windows user can choose another ttf file if they want.

setFont(b, "c:\\windows\\system\\aribl0.ttf", 20)

getStringMetrics(b, mf[], "Aptilis is ")
getStringMetrics(b, ms[], "COOL!")

// total width
w = mf[0] + ms[0]


x = (250 - w) / 2
// The y coordinate is the bottom of the string, hence the plus.
y = (50 + mf[1]) / 2


printAt(b, x, y, "Aptilis is", RGB(0, 0, 0))
printAt(b, x + mf[0], y, "COOL!", RGB(0, 255, 255))

saveGIFFile("font.gif", b)


end if
Result:

For more details see the Bitmap topic.