# How can I calculate text size without using DrawHUD?

**URL:** <https://forums.unrealengine.com/t/how-can-i-calculate-text-size-without-using-drawhud/341519>\
**Category:** UI\
**Tags:** text, unreal-engine, UE4, CPP, question\
**Created:** [December 15, 2015, 1:35pm UTC](https://forums.unrealengine.com/t/how-can-i-calculate-text-size-without-using-drawhud/341519 "2015-12-15T13:35:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![z0q](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@z0q](https://forums.unrealengine.com/u/z0q)\
**Post date:** [December 15, 2015, 1:35pm UTC](https://forums.unrealengine.com/t/how-can-i-calculate-text-size-without-using-drawhud/341519/1 "2015-12-15T13:35:19Z")

</div>

Currently I am using the following code:

```
//if (IsCanvasValid_WarnIfNot())
{
	UFont* Font = HUDFonts[fontID];
	Canvas->TextSize(Font ? Font : GEngine->GetMediumFont(), txt, w, h, scale, scale);
}

```

However, it returns the wrong text size. I’ve read that this should only be accessed from the DrawHUD() function. Is it possible to instantly calculate the size outside of the DrawHUD() function? I would like to call this function from C# by posting the parameters and return the size directly.

Any ideas?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ecb5cc49](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ecb5cc49](https://forums.unrealengine.com/u/anonymous_user_ecb5cc49)\
**Post date:** [December 16, 2015, 1:14am UTC](https://forums.unrealengine.com/t/how-can-i-calculate-text-size-without-using-drawhud/341519/2 "2015-12-16T01:14:34Z")

</div>

That’s a tough one. You need to take into consider things like kerning which I believe is done at render time. If you know your font details and you know they won’t change (bold, size, etc) then you could take the size of the largest letter (`W` in many cases) and get a ballpark of what what coefficients you need for it. You might be able to work out a reliable formula after some trial and error but I don’t think there is any easy way to do this.
