Re: NSTextView inside the polygon.
Re: NSTextView inside the polygon.
- Subject: Re: NSTextView inside the polygon.
- From: Gordon Apple <email@hidden>
- Date: Fri, 12 Jan 2007 16:17:51 -0600
(Apology: I didn't get the response title updated the first time -- GA)
=======================
Good luck. I asked that a week or so ago. If you are familiar with the
documentation, what you have to do is override
"isSimpleRectangularTextContainer" to return "NO" and override
"lineFragmentRectForProposedRect" in your subclass of NSTextContainer. Then
in your subclass of NSTextView:
- (void)awakeFromNib
{
(...)
ShapedTextContainer* newContainer = [ShapedTextContainer new];
[self replaceTextContainer:newContainer];
}
In your text container, in "lineFragmentRectForProposedRect", you have
to take the proposed rectangle and horizontally stretch or compress it to
fit within your Bezier shape. The documentation shows this graphically, but
is useless algorithmically. I proposed four possible approaches, but
haven't tried to implement any of them.
It's relatively easy to do for a specific known shape. For example, I
took the DocBooker example from the Hillegass Cocoa book and was quickly
able to shape text into a triangle. I next tried bounding the right side by
a vertical sine wave. Unfortunately, the general case of bounding it by
even a horizontally convex polygon (much less a general Bezier shape) is not
trivial.
For cubic Bezier segments, you could make use of the convex hull
illustrated in the Thompson Quartz 2D book (p143), although that approach is
less than optimal. I'm sure there's a way to do arc segments, but I haven't
tried to do it. The problem is that you have to consider a lot of different
ways a segment can intercept the vertical limits of the proposed rectangle
and how much it can bulge inward within those limits. You probably have to
step through the segments, figure out which side of the shape you are on,
then evaluate each segment individually to determine relevance and
intercepts, then deal with the specific type of Bezier segment. A general
(or even limited) solution would be most welcome. I'm sure a lot of people
could use it. If I ever do it, I'll post it.
> I am developing a cocoa application in which i am drawing irregular shapes
> using NSBezierPath. I am able to draw any shape.I want to add text inside the
> BezierPath.Can anybody suggest the way to acheive this?
>
> Any help to solve this problem will be appreciable.
>
> Regards,
> Shruti
>
_______________________________________________
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