Home » Questions » Computers [ Ask a new question ]

Fit text to shape in Visio

Fit text to shape in Visio

I'm trying to find a way to get the text in a Visio shape to shrink to fit the width of the shape, otherwise leave the font at the default.

Asked by: Guest | Views: 32
Total answers/comments: 2
Guest [Entry]

"You can resize the font of the text block using automation if the text exceeds the size of the shape. I found that the following works.

Open the shape's shapesheet (Window->Show Shapesheet) and add the user section (Insert->Section->User-defined Cells). Put this formula in the value cell for User.Row_1:

=Min(1,Height/TEXTHEIGHT(TheText,Width)))

After the shape text changes, get the value of the user cell. in c#:

double scale = shape.get_CellsSRC((short)IVisio.VisSectionIndices.visSectionUser, (short)IVisio.VisRowIndices.visRowUser, (short)IVisio.VisCellIndices.visUserValue).ResultIU;

Then set the font, and the TextMargins (for any that are non-zero) with the following (assuming the normal font size is 12 and the left margin is 4pt.:

shape.get_CellsSRC((short)IVisio.VisSectionIndices.visSectionCharacter, 0, (short)IVisio.VisCellIndices.visCharacterSize).FormulaU = (scale*12).ToString() + ""pt"";

shape.get_CellsSRC((short)IVisio.VisSectionIndices.visSectionObject, (short)IVisio.VisRowIndices.visRowText, (short)IVisio.VisCellIndices.visTxtBlkLeftMargin).FormulaU = (scale * 4).ToString() + ""pt"";"
Guest [Entry]

"Other than changing the font size itself, the 2 other controls I have found to make text fit inside of a shape are these:
First, click on the shape with the text in it and select the main Text button from the task bar (the one that brings up the full set of Text options).
Select the Character tab and change the Scale % to what will make the text small enough but readable enough for you. Next, click the Paragraph tab and modify any Indentation or Spacing values to make the text fit. I have found the Line % to be the most effective.
Note: For the above changes, use the Apply button to see what the value will actually look like, before you hit the OK button to close the Text menu dialog."