Wrapping Text Within an Arbitrary Container
Wrapping Text Within an Arbitrary Container
- Subject: Wrapping Text Within an Arbitrary Container
- From: Gordon Apple <email@hidden>
- Date: Tue, 02 Jan 2007 11:44:08 -0600
Has anyone solved the problem of text wrapping within an arbitrary
Bezier path container?
Apparently, text wrapping generally gets done by overriding
lineFragmentRectForProposedRect: in NSTextContainer. The task is to return
the largest viable rectangle when given a proposed rectangle. While I can
see how to do this for specific known simple geometric shapes, It would
certainly be nice to have a subclass that does it for arbitrary Bezier path
containers (e.g., a draw shape). So far, I can postulate four possible
methods of doing this:
- Math
- Set manipulations
- Brute force by pixel
- Graphical
In the first attempt, I would restrict the set of Bezier paths to be
what I might call "horizontal convex" in that left and right sides would be
vertically monotonic which (if I have couched the problem correctly) would
restrict every horizontal intersecting line to have no more than two
intercepts (one on each side), i.e., no holes, no loops, no up/down waves.
Math
I think I can do an algorithm that would handle arbitrary straight line
segments. (Even that is not simple.) The problem is curved segments.
Maximum/minimum horizontal extents could probably be obtained by calculus
and their relevance determined according to whether or not they occur inside
or outside the vertical rectangle limits. Solutions for the intercepts at
the vertical limits would also be needed.
Set manipulation
I don't even know if this is viable. It seems that "region" type set
manipulations are done in determining clipping areas, so the logic must be
in there somewhere.
Brute force by pixel
Within the vertical limits, compute horizontal values line-by-line and
do the max/min thing on these values over the vertical line range. That is
certainly not resolution independent, but might be adequate.
Graphical
Draw (stroke) the Bezier path into a bitmap the size and location of the
proposed rectangle and sweep the sides of an enclosed rectangle (of the same
height) wider until it is no longer empty. This seems easy to show
visually, like in the examples, but not as easy algorithmicly.
Am I making this too hard? Is there a simpler approach I am missing?
Is there something already available that will do this? I searched the
archives and a few other resources, but didn't find anything.
Are there any Bezier utilities I'm missing, like finding the intercepts
with a horizontal straight line? Surely, this is a solved problem
somewhere.
Of course, it would be nice to also have this solved for the more
general case with holes, waves, and loops, but for now I would settle for
the limited case described above.
--
G. Gordon Apple, PhD
Ed4U
Little Rock, AR
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden