• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa-dev Digest, Vol 4, Issue 34
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa-dev Digest, Vol 4, Issue 34


  • Subject: Re: Cocoa-dev Digest, Vol 4, Issue 34
  • From: Gordon Apple <email@hidden>
  • Date: Fri, 12 Jan 2007 16:10:17 -0600

    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

  • Follow-Ups:
    • Re: NSTextView inside the polygon.
      • From: Gordon Apple <email@hidden>
  • Prev by Date: Illegal NSTableView data source
  • Next by Date: Re: NSTextView inside the polygon.
  • Previous by thread: Re: Illegal NSTableView data source
  • Next by thread: Re: NSTextView inside the polygon.
  • Index(es):
    • Date
    • Thread