Auto resize text

R

rodionos

I'm trying to come up with a ShapeSheet formula for Character Size cell so
that theText stays on one line by resizing automatically to prevent line
breaks.

Any thoughts are appreciated.
 
R

rodionos

Also, what's going on inside =TEXTWIDTH(theText)? The formula doesn't seem to
raise a circular error, but it results in widely different character sizes
for the same text (try to retype over the existing text and the trailing
white space).
 
M

Mark Nelson [MS]

I don't know of a direct way to do this. The problem is that you want to
calculate what the correct answer is, but the Shapesheet formulas like
TEXTWIDTH will only tell you whether your current text will fit or not.
Thus you would need an iterative process to solve the problem.

One way I have worked around this in the past is to add another sub-shape
with the exact same text (but invisible). Then I get the TEXTWIDTH of that
shape and do some math to estimate how much I would need to scale things
down to fit the available space. This is an imprecise solution at best.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Michel LAPLANE

Did you try to put "TEXTWIDTH(TheText)" in the width cell of the shape. So
when you type the text the shape resize automatically and the text cannot
break.
 
S

Smerchek

I figured out a solution for this.
Mr. Nelson is correct that you cannot do this in the shapesheet. It looks
good one key click but bad the next.

The solution I came up with implements a macro in the drawing/template
utilizing the Document_ShapeExitedTextEdit event.

The shape is a group that has an addition shape where the text is moved to
in the edit event. This other shape is used to peform the calculations on
then the main shape is updated with the new font. This shape also scales the
font when the shape is resized too.

The calculation is based on the 12pt font and the inital length of the shape
being 1.75in. I just haven't had time to tweak the calc to support resizing
the shape and getting the text to auto-fit after that.

I have included the function and shape sheet properties.


[Main Shape]


(User-defined cells)
User.FontSize =12pt

(character)
size =User.FontSize


[Sub Shape]

(User-defined cells)
user.TextWidth =TEXTWIDTH(TheText)
User.FontSize =12pt

(character)
size =User.FontSize
transparency =100%


[ThisDocument]

Private Sub Document_ShapeExitedTextEdit(ByVal Shape As IVShape)

Shape.Shapes(1).Text = Shape.Text

If Shape.Shapes(1).CellExistsU("user.TextWidth", visExistsAnywhere) <> 0
Then
Set curTextWidth = Shape.Shapes(1).CellsU("user.TextWidth")
End If

If Shape.Shapes(1).CellExistsU("Width", visExistsAnywhere) <> 0 Then
Set curWidth = Shape.Shapes(1).CellsU("Width")
End If

curCell = "Width * 0.095"

If (curWidth < curTextWidth) Then

curCell = "Width * " & ((0.095 / (curTextWidth / curWidth) - 0.002))

End If

If Shape.CellExistsU("user.FontSize", visExistsAnywhere) <> 0 Then
Set curCellO = Shape.CellsU("user.FontSize")
curCellO.FormulaU = curCell
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top