Hi Andy,

I have never needed to work with this stuff, but with that caveat:

Have you tried subclassing NSTextStorage and implementing
-lineBreakBeforeIndex:withinRange:?

-Ken

On Sat, Aug 9, 2008 at 8:43 PM, Andy Kim <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm having trouble figuring out how to make the text system not break words
> that begin with a '/', such as paths, when wrapping. Let's say that we're
> laying out the following line of text:
>
> =====================================
> Normally, you should never delete /Applications
> =====================================
>
> I want '/Applications' to stay intact when wrapping. By default, the text
> system wraps it the following way:
>
> =====================================
> Normally, you should never delete /
> Applications
> =====================================
>
> I'd like it to look like this:
>
> =====================================
> Normally, you should never delete
> /Applications
> =====================================
>
> After much searching, the best solution I've come up with so far is a
> subclass of NSATSTypesetter with the following method implementation in it:
>
> - (BOOL)shouldBreakLineByWordBeforeCharacterAtIndex:(NSUInteger)charIndex
> {
>        NSString *string = [[[self layoutManager] textStorage] string];
>
>        if (charIndex >= 1) {
>                NSTextStorage *ts = [[self layoutManager] textStorage];
>                if ([ts attribute:PFPathAttributeName atIndex:charIndex
> effectiveRange:NULL]) {
>                        // Only break if the previous character is not part
> of the path
>                        return [ts attribute:PFPathAttributeName
> atIndex:charIndex-1 effectiveRange:NULL] == nil;
>                }
>        }
>
>        return YES;
> }
>
> I am setting the attribute PFPathAttributeName to the text storage to mark
> the path. This works somewhat, but now the problem is that after wrapping,
> the text looks like this:
>
> =====================================
> Normally, you should never
> delete /Applications
> =====================================
>
> This happens because -shouldBreakLineByWordBeforeCharacterAtIndex: never
> gets called for the '/' and the next time it gets called is for the 'd' in
> 'delete'.
>
> This modified wrapping behavior makes it seem like 'delete /Applications' is
> one word. I think it's better than the default behavior but still not ideal.
>
> So how can I make it wrap exactly the way I want?
>
> - Andy Kim
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please 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:
> http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com
>
> This email sent to [EMAIL PROTECTED]
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to