Dynamically change Shape font size

Started by anico, December 10, 2018, 05:14:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

anico

Howdy folks,

I'm trying to determine the easiest way to dynamically change the font size of shape text. I want my text to be as large possible without flowing outside the shape.

Context:
I have about 60 shapes on a page. I have the same case-statement macro assigned to double-clicking all the shapes. Depending on which shape you double click, the corresponding case executes. I use this case to populate the .Characters of my "table" (a bunch of rectangle shapes arranged like a table)  Ultimately, the values that I'm using to populate the .Characters of my table are user-inputs from a separate macro, so they can be as short as one word or as long as several sentences.

Dilemma:
I'd like the text that populates my table to be as large as possible without overflowing out of the shapes. Is there an easier way to do this other than something like...
a. measuring the length of the string (I assume there is an easy way of counting characters)
b. assigning different font sizes to different ranges of string lengths (another case statement)
c. saving the appropriate font size as a variable, including a line in each case to set the shape's font size to that variable

Here is some code to help picture what I'm doing:

'Gets shape you double click on
Dim Sel As Visio.Selection
Set Sel = ActiveWindow.Selection
Dim shp As Visio.Shape
Sel.IterationMode = 0
Set shp = Sel.PrimaryItem

'Executes code appropriate for that shape (populates table with the correct values)
Select Case shp.Name

    Case "Shape1"
        'code here
    Case "Shape2"
        'code here
' .....
    Case "Shape60"
        'code here
End Select

wapperdude

Scaling text to fit a shape has two solutions.  These are done in the shapesheet, see attached. These options alter either The FontScale or the Char.Size.  Each has unique impact.

The main formulas are in the User-defined Section:  User.Option1 and User.Option2.  Option2 is probably the preferred method. 

Text wrapping in Visio is not as "friendly" as other Office apps, particularly Power Point.  So, multiple lines present a problem, as the font scaling is based upon width.  The TextTransform section has basic entries to handle TextHeight growth.

Note:  I've lost track of original source for these formulae.


Visio 2019 Pro

wapperdude

Visio 2019 Pro

vojo


The setatref approach is certainly more flexible and versatile...so if the opp is there, use it

But, FWIW, there is another less flexible option but simpler to implement

user.linewt = width/<some value maybe original with)

lineweight = user.linewt * 1pt

same approach for font

This approach goes back 20 years in visio.