Text size relative to shape

G

Gary Shell

Is there any way to resize the text to fit a shape or resize a shape to fit
text?

I have some Swim lane diagrams (aka cross functional process charts) where I
place a process shape in a lane and then set it's text. Sometimes the text
overflows the shape. I'd like to force the text to fit the shape and or
vice versa.

I think I can use the SpaceLine property set to a percentage to adjust the
text. And have figured out how to do that. But can't figure out how to tell
when I NEED to adjust the text.

How can I tell if the text has overflowed outside the bounds of the process
shape? If I can do that I can adjust the text or adjust the shape size.

Or is there some command I can use to accomplish this?

Thanks,
Gary
 
C

Chris Roth [ Visio MVP ]

Here's Shape To Text 101:

Width = Guard(TextWidth(TheText))
Height = Guard(TextHeight(TheText,Width))

The width and height of this shape will change to accomodate the text.
You'll have to force character returns manually.

You can mix and match. If you only use the Height formula, then you can
manually resize the width of the shape. I call this the "Paragraph shape" or
the "Pagemaker Shape" You fill it with text, choose the column width, and
get the height for free!


--

Hope this helps,

Chris Roth
Visio MVP
 
G

Gary Shell

Yes that gets me started. But is there any way to place the text into a
shape, let it do it's own character returns, and THEN determine the height
of the text?

I'd like to keep the shape size and adjust the font to force the text to
fit. While I may have to use "Shape to Text", I'd prefer to do "Text to
Shape".

Thanks,
Gary
 
G

Gary Shell

To answer my own question, yes there is! I used Chris' second formula all
by itself and it did let me set the width of the cell, place the text in
place and the height of the shape adjusts itself. Thanks, Chris.

I still would like to understand how could adjust the font size to fit the
shape. I think I know how to adjust it I can't figure out how to tell WHEN
I need to.

Gary
 
C

Chris Roth [ Visio MVP ]

You could use a SETF formula to change the text size until it is small
enough, but this might fire everytime you type a character. SETF allows you
to jam a formula or a result into another cell. By reducing the font size in
increments, you'd probably end up triggering a loop, which is something that
a spreadsheet really isn't designed to do. IE: I wouldn't bet it would be
officially suppored by MS, could be unsupported in the next version, yada,
yada, yada.

This works:

User.setFont
=IF(TEXTWIDTH(TheText)>Width,SETF(GetRef(Char.Size),MAX(Char.Size-1 pt,2
pt)),0)
What it does is diminished Char.Size by 2 pt untio the IF statement fails.
It makes a loop in the ShapeSheet, and your font size gets tinier as you
type too much text into the shape.

What it doesn't do is make the text bigger when you delete text. I tried
putting a SETF on the other side of the IF statement as well, to make the
font bigger. It worked, but very very s l o w l y.

It might be better to add an Action cell to manually reset the font size.

Also, this won't work if the user makes multiple formatting.

If possible, it's probably better to do this with code. I did a project for
a customer where I created a dummy User cell with the TextWidth formula. I
then reduced font size until the TextWidth was small enough. This worked
fine, and didn't put weird stuff in the shape.

--

Hope this helps,

Chris Roth
Visio MVP
 
G

Gary Shell

This application has no "user" as such. The Visio OCX is instantiated on a
form, The user presses a button and the swimlane diagram is generated. The
"user" does not change or enter anything in Visio. Even latter after the
document is saved there is no intention for the user to modify it in any
way. In my instance, I think of Visio as a "report generator" only.

Saying all that, I don't anticipate any "typing a character" so your
technique would be fine. I'd found another way to adjust the text size in
code, but couldn't figure out how to look at a shape and determine if the
current text extended beyond the shapes boundary so I could invoke my
technique. Is there a way, in code, to see what the current text height of
a shape is?

BTW I used your "automatic height" idea we discussed last week. I set the
process shape width, add my text and your formula ,

Height = Guard(TextHeight(TheText,Width))

adjusts the height. That works great. But, I wonder If I can declare a
MINIMUM height. Something like:

Height = Guard(IIF(TextHeight(TheText,Width)<.5 in, .5 in,
TextHeight(TheText,Width))

Is that even possible?

Gary
 
G

Gary Shell

Close but no cigar. However THIS worked great:

shpObj.Cells("Height").Formula = "= Guard(max(.5,TextHeight(TheText,
Width)))"

This gets me a shape with a height of at least a half an inch and as large
as the text dictates.

Gary
 
C

Chris Roth [ Visio MVP ]

You can just put in a cell in the shape:

User.TW = (TextWidth(TheText) > Width)

After you programmatically change the font size or set the text, you can
check the ResultIU of User.TW. If it's true, then your text is too big.

You'll have to take into consideration LeftMargin and RightMargin, plus the
fact that Visio adds an extra god-knows-what character at the end of each
string. So there's a bit of a fudge factor involved in the User.TW test --
you'll have a small region where the result does not reflect reality.

I ended up building some sort of empirical database for various font sizes
and types to determine the extras "junk spacing" and get a more reliable
value for whether-the-text-has-wrapped.

--

Hope this helps,

Chris Roth
Visio MVP
 
G

Gary Shell

Thanks Chris that does help a lot.

By the way, did you see my other message posted under the subject "Part of
formula replaced by value"? Are you able to shed any light on THAT issue?

I was trying to stick a formula in a shape so that it re-centered itself in
a swim lane when the swimlane size changed. What I got was a "one time
shot" sort of solution. That is I could set the shape into the center, but
the next time the size of the swimlane changed the shape did not recenter.
I wound up righting a ton of code to deal with this myself. Each time a
lane changed I iterated through the shapes looking for ones that needed
repositioning. Ugly, but effective.

If you have a response to this, please do so in the other thread so some
poor soul looking for similar help latter via Google finds our discussion.

Thanks,
Gary


Chris Roth said:
You can just put in a cell in the shape:

User.TW = (TextWidth(TheText) > Width)

After you programmatically change the font size or set the text, you can
check the ResultIU of User.TW. If it's true, then your text is too big.

You'll have to take into consideration LeftMargin and RightMargin, plus the
fact that Visio adds an extra god-knows-what character at the end of each
string. So there's a bit of a fudge factor involved in the User.TW test --
you'll have a small region where the result does not reflect reality.

I ended up building some sort of empirical database for various font sizes
and types to determine the extras "junk spacing" and get a more reliable
value for whether-the-text-has-wrapped.

--

Hope this helps,

Chris Roth
Visio MVP


Gary Shell said:
Close but no cigar. However THIS worked great:

shpObj.Cells("Height").Formula = "= Guard(max(.5,TextHeight(TheText,
Width)))"

This gets me a shape with a height of at least a half an inch and as large
as the text dictates.

Gary

Gary Shell said:
This application has no "user" as such. The Visio OCX is instantiated
on
a
form, The user presses a button and the swimlane diagram is generated. The
"user" does not change or enter anything in Visio. Even latter after the
document is saved there is no intention for the user to modify it in any
way. In my instance, I think of Visio as a "report generator" only.

Saying all that, I don't anticipate any "typing a character" so your
technique would be fine. I'd found another way to adjust the text size
in
code, but couldn't figure out how to look at a shape and determine if the
current text extended beyond the shapes boundary so I could invoke my
technique. Is there a way, in code, to see what the current text
height
of
a shape is?

BTW I used your "automatic height" idea we discussed last week. I set
the
process shape width, add my text and your formula ,

Height = Guard(TextHeight(TheText,Width))

adjusts the height. That works great. But, I wonder If I can declare a
MINIMUM height. Something like:

Height = Guard(IIF(TextHeight(TheText,Width)<.5 in, .5 in,
TextHeight(TheText,Width))

Is that even possible?

Gary


message You could use a SETF formula to change the text size until it is small
enough, but this might fire everytime you type a character. SETF
allows
you
to jam a formula or a result into another cell. By reducing the font size
in
increments, you'd probably end up triggering a loop, which is something
that
a spreadsheet really isn't designed to do. IE: I wouldn't bet it
would
be
officially suppored by MS, could be unsupported in the next version, yada,
yada, yada.

This works:

User.setFont
=IF(TEXTWIDTH(TheText)>Width,SETF(GetRef(Char.Size),MAX(Char.Size-1
pt,2
pt)),0)
What it does is diminished Char.Size by 2 pt untio the IF statement fails.
It makes a loop in the ShapeSheet, and your font size gets tinier as
you
type too much text into the shape.

What it doesn't do is make the text bigger when you delete text. I
tried
putting a SETF on the other side of the IF statement as well, to make the
font bigger. It worked, but very very s l o w l y.

It might be better to add an Action cell to manually reset the font size.

Also, this won't work if the user makes multiple formatting.

If possible, it's probably better to do this with code. I did a project
for
a customer where I created a dummy User cell with the TextWidth
formula. I
then reduced font size until the TextWidth was small enough. This
worked
fine, and didn't put weird stuff in the shape.

--

Hope this helps,

Chris Roth
Visio MVP


To answer my own question, yes there is! I used Chris' second
formula
all
by itself and it did let me set the width of the cell, place the
text
in
place and the height of the shape adjusts itself. Thanks, Chris.

I still would like to understand how could adjust the font size to
fit
the
shape. I think I know how to adjust it I can't figure out how to
tell
WHEN
I need to.

Gary


Yes that gets me started. But is there any way to place the text
into a
shape, let it do it's own character returns, and THEN determine the
height
of the text?

I'd like to keep the shape size and adjust the font to force the
text
to
fit. While I may have to use "Shape to Text", I'd prefer to do
"Text
to
Shape".

Thanks,
Gary

"Chris Roth [ Visio MVP ]" <[email protected]>
wrote
in
message Here's Shape To Text 101:

Width = Guard(TextWidth(TheText))
Height = Guard(TextHeight(TheText,Width))

The width and height of this shape will change to accomodate the
text.
You'll have to force character returns manually.

You can mix and match. If you only use the Height formula, then
you
can
manually resize the width of the shape. I call this the "Paragraph
shape"
or
the "Pagemaker Shape" You fill it with text, choose the column width,
and
get the height for free!


--

Hope this helps,

Chris Roth
Visio MVP


Is there any way to resize the text to fit a shape or resize a
shape
to
fit
text?

I have some Swim lane diagrams (aka cross functional process
charts)
where
I
place a process shape in a lane and then set it's text. Sometimes
the
text
overflows the shape. I'd like to force the text to fit the
shape
and
or
vice versa.

I think I can use the SpaceLine property set to a percentage to
adjust
the
text. And have figured out how to do that. But can't figure out
how
to
tell
when I NEED to adjust the text.

How can I tell if the text has overflowed outside the bounds
of
the
process
shape? If I can do that I can adjust the text or adjust the shape
size.

Or is there some command I can use to accomplish this?

Thanks,
Gary
 

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