# Get pixel size of font characters? (SOLVED)

**URL:** <https://forum.defold.com/t/get-pixel-size-of-font-characters-solved/14585>\
**Category:** Questions\
**Created:** [December 12, 2017, 12:54am UTC](https://forum.defold.com/t/get-pixel-size-of-font-characters-solved/14585 "2017-12-12T00:54:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gmanicus](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gmanicus/32/10312_2.png) [@Gmanicus](https://forum.defold.com/u/Gmanicus)\
**Post date:** [December 12, 2017, 12:54am UTC](https://forum.defold.com/t/get-pixel-size-of-font-characters-solved/14585/1 "2017-12-12T00:54:38Z")

</div>

Is there a function for measuring text before it is set to a label or GUI text node? It would be useful for me, as I am currently having trouble getting exact measurements for variable button sizes, menu sizes, and such. I wish to calculate for the amount of text given, and fit the size of my node to that after calculating for linebreaks and etc.

Currently I’ve accomplished this by trial and error. I know there is gui.get\_text\_metrics, but this sounds like a workaround for what I’m trying to accomplish.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [December 12, 2017, 2:45am UTC](https://forum.defold.com/t/get-pixel-size-of-font-characters-solved/14585/2 "2017-12-12T02:45:49Z")

</div>

I don’t know why you think gui.get\_text\_metrics is a workaround, that’s exactly what it’s for: getting the size of text. There’s also gui.get\_text\_metrics\_from\_node, you only give it the text node and it gives you the metrics. You shouldn’t have to calculate anything yourself, just use `width` and `height` from the metrics to set your button sizes (with some padding added presumably).

---

<div class="post-metadata">

**Author:** ![Gmanicus](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gmanicus/32/10312_2.png) [@Gmanicus](https://forum.defold.com/u/Gmanicus)\
**Post date:** [December 12, 2017, 3:13am UTC](https://forum.defold.com/t/get-pixel-size-of-font-characters-solved/14585/3 "2017-12-12T03:13:02Z")

</div>

I just reread the API. Thanks. I think I confused get\_text\_metrics\_from\_node with get\_text\_metrics.
