Java Reference
In-Depth Information
11-5. Example 11-10 demonstrates how font glyphs can be used as
Shape
objects
and shows how those
Shape
objects can be transformed with an arbitrary
AffineTransform
object. Write a custom
Stroke
object that is initialized with
a
Font
and a string of text. When this
Stroke
class is used to draw a shape,
it should display the specified text, using the specified font, along the out-
line of the specified shape. The text should hug the outline of the shape as
closely as possible, which means that each font glyph has to be rotated,
positioned, and drawn independently of the other glyphs. Use the two-argu-
ment version of
Shape.getPathIterator()
to obtain a
FlatteningPathIter-
ator
that approximates the shape using straight line segments. You'll need
to use geometry to compute the slope of each line segment and trigonome-
try to convert the slope to a rotation angle for each font glyph (you may
find
Math.atan2()
helpful). Write a
GraphicsExample
class that displays
some text art that demonstrates your new
Stroke
object.