We occasionally get questions about how to size shapes to text or text to shapes. While most Visio shapes do not behave like this by default, both cases are made possible through ShapeSheet formulas. In fact, Visio includes some shapes that resize based on their text. Go to File > Shapes > Visio Extras > Callouts and try out the shapes near the top of the stencil. Let’s look at how to make a shape resize its text based on its width or height.
First, select a shape on the page. We’ll start with a simple Process shape from the Basic Flowchart stencil. Open its ShapeSheet by choosing Window > Show ShapeSheet. Visio opens a new window that shows the properties that drive the shape’s behavior.
In the ShapeSheet window, scroll down to the Character section. The Size cell is set to “8 pt” which matches the text size shown in Visio’s Formatting toolbar.
Let’s say 12 pt is the baseline size we want for our text at the shape’s current size of 1 inch by 0.75 inch. We want the text to size with the width of the shape. A simple formula in the Size cell achieves this.
This scales a base size of 12 pt by the width of the shape. (Width is the name of a cell in the Shape Transform section, at the top of the ShapeSheet.) Our shape’s text is now 12 pt. Note that if we do not specify a unit, Visio assumes a default that is appropriate for the locale. Multiplying by 1 pt scales the Width to points.
If the shape is stretched to twice its original width, the text becomes 24 pt.
What if we want the text to also size with height? What if we only want the font size to change in increments of 2 points? We just need to change the formula. This formula scales the text size based on the larger of the two dimensions in 2 pt steps.
We don’t want to lose this formula when manually setting a font size using the Formatting toolbar. Wrapping the formula in a GUARD() will prevent it from being changed, even from the toolbar. The SETATREF functions offer ways to combine formulas with changes made through the user interface, but are a bit more complex to use.
All of the ShapeSheet cells and formulas are described in the Visio SDK documentation – downloadable or online at MSDN . In a future post, we’ll look at the reverse of this behavior, how to resize shapes based on the text they contain.