# textBounds() -- can it be used on the default font?

**URL:** <https://discourse.processing.org/t/textbounds-can-it-be-used-on-the-default-font/12578>\
**Category:** p5.js\
**Created:** [July 8, 2019, 4:45am UTC](https://discourse.processing.org/t/textbounds-can-it-be-used-on-the-default-font/12578 "2019-07-08T04:45:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drail](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@drail](https://discourse.processing.org/u/drail)\
**Post date:** [July 8, 2019, 4:45am UTC](https://discourse.processing.org/t/textbounds-can-it-be-used-on-the-default-font/12578/1 "2019-07-08T04:45:04Z")

</div>

If I want to make a background just behind some text that I draw on the canvas, I could draw a box behind the text, and I would get the box’s position and size with the `textBounds()` method.

Can this be done with the default font? The example at [http://p5js.org/reference/#/p5.Font/textBounds](http://p5js.org/reference/#/p5.Font/textBounds) shows this done only with a **loaded** font. I feel that this should be easy and obvious to do without having to load a font. What if I don’t want to load a font? I suppose the bigger question is if it is possible to call methods on default objects, or do similar things to the default environment?

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [July 8, 2019, 3:58pm UTC](https://discourse.processing.org/t/textbounds-can-it-be-used-on-the-default-font/12578/2 "2019-07-08T15:58:08Z")

</div>

After some digging through the source code, I would just suggest loading a font because I didn’t see an easy way to extract the default font. The `textBounds()` function only works on a p5.Font object so you would need to find the default font. It appears however that the way the default text works is it’s never a p5.Font object. To setup the text some hidden variables are set in [p5.Renderer](https://github.com/processing/p5.js/blob/2fb3ac803b941af4dfa64bc7a94cbdade0f5ee1b/src/core/p5.Renderer.js#L155).

It appears that the default font is just the browser’s default ‘sans-serif’ font which I think is Helvetica or Arial depending on your operating system so you could just use one of those if the look is important.

I could be wrong I only spent about 15 minutes looking at the source code so I’d be interested to hear if someone else knows how to do this.
