A method and computer-readable medium are provided for fitting text to
shapes within a graphic. According to the method, initial constraints are
defined that comprise initial values describing how a shape and text
within the shape should be laid out. Constraint rules are also defined
for use in modifying the initial constraints when application of the
initial constraints to the text in a shape results in the text
overflowing the boundaries of the shape. A change may be detected to the
graphic that would affect the size or position of one or more of the
shapes or the text within one of the shapes. If such a change causes text
to overflow when laid out using the initial constraints, the constraint
rules are applied sequentially to modify the constraints. The modified
constraints are then reapplied to the shapes to create a new layout for
the graphic.