Adds a function that gets the visual height of the provided characters.
May be very helpful at positioning text by height where surface.GetTextSize happens to be inconvenient or insufficient.
Newlines are supported.
local Font = 'DermaLarge'
local Chars = 'Lorem ipsum'
-- local Chars = 'Lorem ipsum\ndolor sit amet'
hook.Add( 'HUDPaint', 'GetVisualCharacterHeightDemo', function()
surface.SetFont( Font )
local w, h = surface.GetTextSize( Chars )
local x = ScrW() * 0.5 - w - 5
local y = ScrH() * 0.5
surface.SetDrawColor( 255, 255, 255 )
surface.DrawOutlinedRect( x - 1, y - 1, w + 2, h + 2 )
surface.SetDrawColor( 130, 150, 255 )
surface.DrawRect( x, y, w, h )
draw.DrawText( Chars, Font, x, y, color_black )
x = ScrW() * 0.5 + 5
local visualheight, roofheight = surface.GetVisualCharacterHeight( Chars, Font )
surface.SetDrawColor( 255, 255, 255 )
surface.DrawOutlinedRect( x - 1, y - 1, w + 2, visualheight + 2 )
surface.SetDrawColor( 150, 255, 150 )
surface.DrawRect( x, y, w, visualheight )
y = y - roofheight
draw.DrawText( Chars, Font, x, y, color_black )
end )
