Text scaling using an IF?

P

Pista

Hello guys, I've created an icon with a text custom property. I want to
secure, that if I write a text which exceeds e.g. icon width there, then the
text size would decrease and the whole text would be visible in one line.
Should I use IF? But how? :)

I don't know if you understand me :) But anyway, thank you for your help.

Stefan
 
C

Chris Roth [MVP]

Hi Stefan,

You *can* get this to happen, but I'm not sure how kosher it is. You can
actually get the ShapeSheet to loop to some extent, or "ratchet" perhaps is
a better term.

Try inserting a user-cell, say User.textWatch, and set the formula as so:

User.textWatch =
=IF(TEXTWIDTH(TheText)>Width,SETF(GetRef(Char.Size),Char.Size*0.9),0)

The formula uses the TEXTWIDTH function to measure the text.

If the text is not wider than the shape, then nothing happens -- the "0".

If the text is wider than the shape, then SETF jams a new value into the
font-size cell: Char.Size. The expression sets the value of Char.Size to 90%
of itself. You can imagine that this might happen a number of times - a
loop! But we don't really see the loop happening.

The performance seems OK. I believe the the ShapeSheet designers put some
safeguards in to prevent infinite loops, so you probably won't break
anything. But this is a bit of a stretch for a spreadsheet engine : )

Note, this won't make your text automatically bigger. But the user can
simply choose a larger font size. If it's too big, then Char.Size will get
ratcheted down until it fits.

Note also that we are only setting Char.Size. If you have multiple
formatting in the shape's text (bold, italic, etc) then you'll have multiple
Character rows. I.e. setting Char.Size won't be enough because there will be
multiple cells that need setting. At this point, you're getting beyond what
the ShapeSheet can handle on it's own, and need code to track all the rows.

Last note: to make sure that the font size doesn't go negative or get too
small, the formula should have some bounds. Here's an example of a
lower-bound:

=IF(TEXTWIDTH(TheText)>Width,SETF(GetRef(Char.Size),MAX(1
pt,Char.Size*0.9)),0)


--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 
P

Pista

Hi Chris,

that is exactly what I needed, but there is a small problem. If I put a
wider text there, it decreases, that's what I wanted, but if I put back the
text which doesn't exceed the wide of the icon, the text size doesn't
increase back, it stays small :) How can I fix it?
Thanks a lot Chris.

Stefan
 
C

Chris Roth [MVP]

P

Pista

Thanks!

The problem is, that I am making these icons for the university professors
for their presentations. The icons have some custom properties like text
(String), Size(fixed list), They just want to click&drag the icons to their
presentations, then setup the size from the list, insert a text. I think they
won't use ShapeSheet and Formatting, because they don't know how :) It's up
on me to handle this.... Is there really not a possibility to do that?

Anyway thanks for your help, I've learned a lot from your posts... Thanks!

Stefan
 
C

Chris Roth [MVP]

C

Chris Roth [MVP]

Whoops, CORRECTION:

I had a Max where I needed a Min:

user.TextSizeWatcher =
IF(TEXTWIDTH(TheText)>Width,SETF(GetRef(Char.Size),MAX(1
pt,Char.Size*0.9)),IF(TEXTWIDTH(TheText)<Width*0.9,SETF(GetRef(Char.Size),MIN(50
pt,Char.Size*1.1)),0))

The minimum size is 1pt
The maximum size is 50pt
The increment factor is 1.1
The decrement factor is 0.9

You can change these values in the formula

--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 
P

Pista

Hello Chris,
thankyou :)
but...
I have another problem. If I put there a big text, it divides into two or
more lines and the TEXTWIDTH(TheText)>Width does not work properly :( Is
there any posibillity to secure that the text wouldn't divide into more
lines, so the textWatch would work?

Thank you!

Stefan
 

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