<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/DxGetRealFontHeight?action=history&amp;feed=atom</id>
	<title>DxGetRealFontHeight - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/DxGetRealFontHeight?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=DxGetRealFontHeight&amp;action=history"/>
	<updated>2026-05-13T03:10:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=DxGetRealFontHeight&amp;diff=34130&amp;oldid=prev</id>
		<title>Ccw: Created page with &quot;&lt;pageclass class=&quot;#228B22&quot; subcaption=&quot;Useful Function&quot;&gt;&lt;/pageclass&gt; &lt;lowercasetitle/&gt; __NOTOC__ This function calculates the real pixel height of a given font. It does this by d...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=DxGetRealFontHeight&amp;diff=34130&amp;oldid=prev"/>
		<updated>2012-11-16T22:39:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pageclass class=&amp;quot;#228B22&amp;quot; subcaption=&amp;quot;Useful Function&amp;quot;&amp;gt;&amp;lt;/pageclass&amp;gt; &amp;lt;lowercasetitle/&amp;gt; __NOTOC__ This function calculates the real pixel height of a given font. It does this by d...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pageclass class=&amp;quot;#228B22&amp;quot; subcaption=&amp;quot;Useful Function&amp;quot;&amp;gt;&amp;lt;/pageclass&amp;gt;&lt;br /&gt;
&amp;lt;lowercasetitle/&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function calculates the real pixel height of a given font. It does this by drawing and measuring pixels. Therefore it is super accurate (and super slow). Only do this once per font!&lt;br /&gt;
&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;float dxGetRealFontHeight( element font )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''font''': Either a custom [[DX font]] element or the name of a built-in dx font&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns a float representing the pixel height from the top of the ascenders to the base of the descenders.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Clientside Script&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function dxGetRealFontHeight(font)&lt;br /&gt;
    local cap,base = measureGlyph(font, &amp;quot;S&amp;quot;)&lt;br /&gt;
    local median,decend = measureGlyph(font, &amp;quot;p&amp;quot;)&lt;br /&gt;
    local ascend,base2 = measureGlyph(font, &amp;quot;h&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    local ascenderSize = median - ascend&lt;br /&gt;
    local capsSize = median - cap&lt;br /&gt;
    local xHeight = base - median&lt;br /&gt;
    local decenderSize = decend - base&lt;br /&gt;
&lt;br /&gt;
    return math.max(capsSize,ascenderSize) + xHeight + decenderSize&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function measureGlyph(font, character)&lt;br /&gt;
    local rt = dxCreateRenderTarget(128,128)&lt;br /&gt;
    dxSetRenderTarget(rt,true)&lt;br /&gt;
    dxDrawText(character,0,0,0,0,tocolor(255,255,255),1,font)&lt;br /&gt;
    dxSetRenderTarget()&lt;br /&gt;
    local pixels = dxGetTexturePixels(rt)&lt;br /&gt;
    local first,last = 127,0&lt;br /&gt;
    for y=0,127 do&lt;br /&gt;
        for x=0,127 do&lt;br /&gt;
            local r = dxGetPixelColor( pixels,x,y )&lt;br /&gt;
            if r &amp;gt; 0 then&lt;br /&gt;
                first = math.min( first, y )&lt;br /&gt;
                last = math.max( last, y )&lt;br /&gt;
                break&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        if last &amp;gt; 0 and y &amp;gt; last+2 then break end&lt;br /&gt;
    end&lt;br /&gt;
    destroyElement(rt)&lt;br /&gt;
    return first,last&lt;br /&gt;
end &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Clientside Script&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- TODO&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Useful Functions]]&lt;/div&gt;</summary>
		<author><name>Ccw</name></author>
	</entry>
</feed>