Author Topic: Stretching or Squeezing a text to fit in the shape  (Read 6378 times)

0 Members and 1 Guest are viewing this topic.

nashwaan

  • Full Member
  • ***
  • Posts: 85
Stretching or Squeezing a text to fit in the shape
« on: January 04, 2014, 03:27:33 PM »
Sometimes we don't want to resize the shape when a text is little bit more than what the shape can take:



Solution 1:
In this solution, the text will always stretch to fit the shape.
Create a User row 'User.TEXTWIDTH':

User.TEXTWIDTH.Value = TEXTWIDTH(TheText)
User.TEXTWIDTH.Prompt = SETF(GetRef(Char.FontScale), GetVal(Char.FontScale)*Width/User.TEXTWIDTH)


Solution 2 (better):
In this solution, the text will not be stretched out but it will be squeezed up to 60% only. If more text is required, it will be warped (this is not shown in the above image).
Create a User row 'User.TEXTWIDTH':

User.TEXTWIDTH.Value = TEXTWIDTH(TheText)
User.TEXTWIDTH.Prompt = SETF(GetRef(Char.FontScale), "BOUND(" & GetVal(Char.FontScale)*Width/User.TEXTWIDTH & ",0,FALSE,60%,100%)")


Note both solutions will stretch the text interactively as the text is typed.
The GetVal() is crucial and it took me a while to figure this out.
In the User.TEXTWIDTH.Prompt formulas, we could have used TEXTWIDTH(TheText) directly in place of User.TEXTWIDTH but it will affect the performance severely as TEXTWIDTH() function is very slow so we don't want to calculate it twice every time the formula is evaluated.

Attached is a working example.

Regards,
Yousuf.
« Last Edit: January 09, 2014, 12:48:56 PM by nashwaan »
Give me six hours to chop down a tree and I will spend the first four sharpening the axe — Abraham Lincoln

kannich

  • Newbie
  • *
  • Posts: 2
Re: Stretching or Squeezing a text to fit in the shape
« Reply #1 on: November 06, 2014, 05:42:06 AM »
Hello Yousuf,

first, thanks for your tip.

Could you tell me which Visio version do you use? I tried to implement your solution 2 in Visio 2010 Standard.
If I enter the formula:

SETF(GetRef(Char.FontScale), "BOUND(" & GetVal(Char.FontScale)*Width/User.TEXTWIDTH & ",0,FALSE,60%,100%)")

in the new created User row field prompt I got the error message that the formula is not correct.
I took a look in your attached file (during the opening I got the message that the file was converted so I can use it with my Visio version) and saw that there was following formula in the prompt field:

=DEPENDSON(User.TEXTWIDTH)+SETF(GetRef(Char.FontScale),"BOUND("&GetVal(Char.FontScale)*Width/User.TEXTWIDTH&",0,FALSE,60%,100%)")

Ok, I tried this formula now but no strechting or squeezing of the text happened.

Could you help me, please? Thanks

Regards
kannich

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • Ideas Visio-lized into solutions
Re: Stretching or Squeezing a text to fit in the shape
« Reply #2 on: November 06, 2014, 09:15:56 PM »
The following works in V2007, should be good for V2010 & V2013.  Note, you only need a single user entry, e.g. user.row_1, but, name it whatever you desire.  The formula is:
=SETF(GetRef(Char.FontScale),BOUND(GetVal(Char.FontScale)*Width/TEXTWIDTH(TheText),0,FALSE,2%,100%)).  Note the absence of quotes!  Changing the character scaling only reduces (or increases) the width.  The font height is unchanged. 

You can do something similar with the character size cell.  (But, don't do both.  Gets weird.)  This reduces the font size, so, if the text is really long, the font gets really small:
=SETF(GetRef(Char.Size),BOUND(GetVal(Char.Size)*Width/TEXTWIDTH(TheText),0,FALSE,2 pt,14 pt)).  The other disadvantage is that you have to enter the maximum font size in the bound function manually.

@Yousuf:  nice work using the GetVal function!

HTH
Wapperdude.
« Last Edit: November 06, 2014, 09:18:51 PM by wapperdude »
Visio 2019 Pro

kannich

  • Newbie
  • *
  • Posts: 2
Re: Stretching or Squeezing a text to fit in the shape
« Reply #3 on: November 07, 2014, 01:20:38 AM »
Hello Wapperdude,

thanks a lot for your fast help. The formulae work fine and do what I want.
I think the first will be my favourite one because the disadvantages of the second formula which you also mentioned are not so nice.

Regards
kannich

Yacine

  • Hero Member
  • *****
  • Posts: 2698
Re: Stretching or Squeezing a text to fit in the shape
« Reply #4 on: November 07, 2014, 01:50:59 AM »
I did not know the Getval function. It opens great possibilities for smartshapes development.
First one would be to avoid temporary fields to store values that you want to use only once.
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • Ideas Visio-lized into solutions
Re: Stretching or Squeezing a text to fit in the shape
« Reply #5 on: November 07, 2014, 02:02:16 AM »
Regarding the original formulae with quotes...it's almost like they were cut from code rather than shapesheet...just an observation.

Glad to assist.

@Yacine:  Yousuf made a great discovery!  I've fought with the stupid resizing a long time, and none of the MS sites ever addressed it adequately.  The setatref could have worked, but, it has limited application, and this text sizing isn't one of them.  So, the setf, getref, and getval seem to do the same thing and avoid the circular argument problem and the recalculation problem.

Looks like time to celebrate!
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2698
Re: Stretching or Squeezing a text to fit in the shape
« Reply #6 on: November 07, 2014, 03:26:08 AM »
Celebrate!!!
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • Ideas Visio-lized into solutions
Re: Stretching or Squeezing a text to fit in the shape
« Reply #7 on: November 07, 2014, 11:09:11 AM »
Hmmmm.  Perhaps I should change my avatar!   ???    NOT!    ;D
Visio 2019 Pro

along

  • Newbie
  • *
  • Posts: 5
Re: Stretching or Squeezing a text to fit in the shape
« Reply #8 on: June 29, 2020, 04:23:17 AM »
Hi,

Just found out this solution and it's really helpful!

Thanks a lot!

One question, if someone already figured it out. The OP's solution shrinks the widths down to 60% and than adds a row, but remain in 60%. Did anyone figure out how to use the minimal number of lines, but using the maximal possible width for that number of lines (e.g., determining that we need at least three rows for the text in order not to go below 60%, but that reducing the width to 88% would still allow the text to fit within three rows).

Thanks, Alon

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • Ideas Visio-lized into solutions
Re: Stretching or Squeezing a text to fit in the shape
« Reply #9 on: June 29, 2020, 11:58:12 AM »
The main issue to doing this, is that there's no way, that I'm aware of, to limit the number of line wraps to a specific value.
Visio 2019 Pro

vojo

  • Hero Member
  • *****
  • Posts: 1475
Re: Stretching or Squeezing a text to fit in the shape
« Reply #10 on: June 29, 2020, 04:40:22 PM »
might be able to do this

Shapesheet fontsize cell in millimeters or centimeters.

actions to increase or decrease fontsize based on appearance....or....increase or decrease box size.

use spacing, etc to determine characters in a given row...from there, could determine characters per row ==>rows in box size.

Maybe size box to max number of spaces and use SUBSTITUTE or SETF/SETATREF functions.

not ideal since still needs some manual intervention and may be so convoluted that its not worth it

Of course, thee is always VBA



along

  • Newbie
  • *
  • Posts: 5
Re: Stretching or Squeezing a text to fit in the shape
« Reply #11 on: July 01, 2020, 03:34:39 AM »
Thanks all!

I think VBA will be the way to go about this. I can probably estimate a limit on the required number of lines and than take some extra leeway, but as mentioned above, it'll get too convoluted.

Thanks for your advice!

Alon