Garry's Mod Wiki

surface.GetTextSize

surface.GetTextSize

number, number surface.GetTextSize( string text )

Description

Returns the width and height (in pixels) of the given text, but only if the font has been set with surface.SetFont.

Arguments

1 string text
The string to check the size of.

Returns

1 number
Width of the provided text.
2 number
Height of the provided text.

Example

Prints out the size of Hello World in the Trebuchet24 font.

surface.SetFont( "Trebuchet24" ) local text = "Hello World" local width, height = surface.GetTextSize( text ) print("Text width: " .. width .. ", text height: " .. height)
Output:
Text width: 100, text height: 24

Example

Get text height very quickly. No tables or spare variables used.

surface.SetFont( "Trebuchet24" ) local text = "Hello World" local height = select( 2, surface.GetTextSize( text ) ) print( height )
Output:
24

Special Pages


Wikis

?

Render Time: 23ms

DB GetPage 2
Generate Html 4
SaveChanges (1) 5
Render Body 0
Render Sidebar 9