About Text in Shapes and Masters

The text of a shape or a master has a coordinate system defined by an origin and axes relative to the shape's local coordinate system. This coordinate system is called the text block. When you create a shape or master, by default its text block is exactly the same size as the shape's or master's width-height box: It has the same width and height and has zero rotation in relation to the shape. The default text block pin is in the center.

The local coordinate systems of a shape and its text block

The local coordinate systems of a shape and its text block

  1. Local coordinates of the unrotated shape
  1. Text block rotated with respect to the shape's local coordinate system

The following table outlines some of the questions that you should consider when you design the text behavior for a shape or a master.

Factors to consider when designing text behavior

Item

Questions to ask

Text block position

Location in shape or master?

Should the shape or master have multiple text blocks?

Text block size

Limit to a minimum or maximum size?

Grow text block as more text is added?

Should text determine shape size?

Affected by shape resizing, rotating, or flipping?

Text block appearance

Should text use opaque background or transparent color?

User interaction

Should the user be prevented from adding or changing the text in a shape?

Should the user be able to move the text block in relation to the shape?

In this section…

Viewing Text Attributes in the ShapeSheet Window

Controlling the Text Block's Position

Controlling Text in a Group

Viewing Text Attributes in the ShapeSheet Window

A shape's Text Transform section defines a text block's size, location, and rotation within the shape's local coordinate system, just as the Shape Transform section positions a shape within its group or page. To view the Text Transform section: Open the ShapeSheet® window for the shape or master, click Section on the Insert menu, select Text transform, and then click OK. By default, the Text Transform section contains the values shown in the following table.

Text Transform section default values for a new shape

Cell

Formula

TxtAngle

= 0 deg.

TxtHeight

= Height * 1

TxtLocPinX

= TxtWidth * 0.5

TxtLocPinY

= TxtHeight * 0.5

TxtPinX

= Width * 0.5

TxtPinY

= Height * 0.5

TxtWidth

= Width * 1

Options in the Text dialog box correspond to cells in the shape's Character, Paragraph, Tabs, and Text Block Format sections. When a user applies a formatting command on the Format menu, Microsoft® Visio® updates cells in these sections of the shape's sheet.

The row numbers displayed in these sections reflect the number of bytes of text that use the formatting defined in that row, as shown in the following figure. The number of bytes and the number of characters in a text block are often the same; however, in a multi-byte character set such as Japanese, the byte count and the character count might be different. For example, in a Character section with the row numbers 18, 16, and 13, the first 18 bytes of text in the text block have the format described in the first row. The next 16 bytes of text have the format described in the second row, and so on.

The Character section for a shape with several different font formats

The Character section for a shape with several different font formats

In general, if you write custom formulas in the Character, Paragraph, Tabs, or Text Block Format sections, be sure you consider user actions that could overwrite your work. For example, if a user locally formats characters in a text block, a new row is added to describe the formatting of those characters. When a user cuts text, the affected rows are deleted. If you want to write a custom formula in a cell of the Character section, copy the formula into that cell in each row of the section. That way, as rows are added and deleted, the formula remains intact.

Note If the shape is a group, formulas that refer to the Width and Height cells might need to be modified to access the group's values rather than those of a component shape.

TOP

Controlling the Text Block's Position

As you develop a shape, it often makes sense to move the text block from its default position to more easily accommodate readable text. For example, in many Visio shapes, the text block appears below the shape by default so that typing in it doesn't obscure the shape.

Moving a text block manually

You can easily move a shape's text block manually by selecting the shape using the Text Block tool Aa200987.ic_TextBlock(en-us,office.10).gif.

To move the text block manually, select a shape with the text block tool, then drag. The text block tool turns into a double box when you select a shape's text block.

To move the text block manually, select a shape with the Text Block tool, and then drag. The Text Block tool turns into a double box when you select a shape's text block.

When you select a shape's text block using the Text Block tool you can also quickly resize it by dragging a side selection handle, or rotate it by dragging a rotation handle. If you are designing shapes to distribute to other users, make sure that the text block is big enough for users to select and adjust easily. For example, the default size of a one-dimensional (1-D) shape's text block may be too small for a user to select and adjust with the Text Block tool.

Adding control handles to a text block

If you want to provide the users of your shapes with a more obvious method of adjusting text position, you can add a control handle that moves the text block.

Adding a control handle to a shape's text block makes it easy for users to reposition it.

Adding a control handle to a shape's text block makes it easy for users to reposition it.

You can set the text block position and define a control handle for the block's pin by adding a Controls section in the ShapeSheet for the shape, and entering formulas in that row. A control handle is added for each row that you add to the Controls section. The formulas in the control handle's row can vary depending on the position you choose for the text block. The following steps describe how to add a control handle for a text block that is centered below the shape.

To add a control handle to a text block

  1. Draw a shape on the page and then select it.
  1. On the Window menu, click Show ShapeSheet.
  1. On the Insert menu, click Section, select Controls, and then click OK.
  1. Add these formulas in the Controls section to center the text block below the shape with a control handle that appears in the center of the text block:
  • X = Width * 0.5 + TxtWidth * 0
  • Y = Height * 0 + TxtHeight * - 0.5
  • X Dynamics = Width/2
  • Y Dynamics = Height/2
  • X Behavior = (Controls.X1 > Width/2) * 2 + 2
  • Y Behavior = (Controls.Y1 > Height/2) * 2 + 2
  1. Add these formulas to the Text Transform section:
  • TxtPinX = Controls.X1
  • TxtPinY = Controls.Y1

The formulas in the X and Y cells in the Controls section specify the position of the control handle in relation to the shape's local coordinates. The formulas in the X Dynamics and Y Dynamics cells set the position of the control handle's anchor point at the center of the shape. For details about control handle anchor points, see Setting a Control Handle's Anchor Point in Chapter 7, Enhancing Shape Behavior. The X Behavior and Y Behavior cells define the behavior of the control handle after it is moved or after the shape is resized.

TOP

Controlling Text in a Group

When you group shapes, a text block is created for the group; you can also work with the text blocks for individual shapes contained in the group. By default, the group's text block opens when a user presses the F2 key, selects the Text tool Aa200987.ic_text(en-us,office.10).gif, or begins typing. To add text to any other shape in the group, a user must first subselect the shape.

It's a good idea to use a group's text block to contain text in a master that represents a group that you want users to edit easily. For example, you might create a master for a road sign indicating a speed limit. To allow users to edit the speed limit value easily, you could use the group's text block to contain the speed limit number, while a shape contained in the group might contain the "Speed Limit" label.

Using a group's text block makes it easy for users to edit text in masters you create. When a master is a group (A), the group's text block (B) can contain the text that users are most likely to edit.

Using a group's text block makes it easy for users to edit text in masters you create. When a master is a group (A), the group's text block (B) can contain the text that users are most likely to edit.

You can prevent a group's text block from being edited either by clearing Edit text of group under Group behavior in the group's Behavior dialog box (on the Format menu, click Behavior) or by changing the value of the group's IsTextEditTarget cell from true to false.

If the group's text block cannot be edited, the text block of the topmost shape in a group is opened when a user presses F2, selects the Text tool, or begins typing. If a group's text block cannot be edited and the topmost shape in a group is itself a group, the text block settings for that group determine whether the group's text block or that of the topmost shape in the group is opened.

For details about grouping shapes, see Chapter 6, Grouping and Merging Shapes.