Re: Controlling line-breaking in a text view

2008-08-13 Thread Ross Carter


On Aug 12, 2008, at 9:07 PM, Ken Ferry wrote:


Hi Andy,

I'm still not familiar with the text system, so I don't know if the
proxy was a good way to do this.


The basics of subclassing NSTextStorage are described here:
http://www.cocoabuilder.com/archive/message/cocoa/2002/2/5/14848
___

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]


Re: Controlling line-breaking in a text view

2008-08-12 Thread Ken Ferry
Hi Andy,

I'm still not familiar with the text system, so I don't know if the
proxy was a good way to do this.

But assuming it was, try implementing forwardingTargetForSelector:
instead of forwardInvocation:. It's less flexible, but much faster,
and your case doesn't require the flexibility.

-Ken

On Tue, Aug 12, 2008 at 5:12 PM, Andy Kim <[EMAIL PROTECTED]> wrote:
> Many thanks to everyone who helped in this thread.
>
>> I wonder if this is a larger bug in the text system? I was going to
>> suggest
>> just inserting the Unicode character "zero-width no-break space" (U+FEFF)
>> after the slash, but when I tried it (in TextEdit) I got the very
>> phenomenon
>> you describe - the break occurs before "delete", not after.
>>
>> I was able to solve the problem, though, by also inserting a "zero-width
>> space" (U+200B) before the slash... So there's a solution for you, but it
>> seems unnecessarily elaborate. m.
>
> Matt,
>
> I may have to go with your solution for cell drawing although I'm hesitant
> before proceeding. The program has to make it seem like the character is not
> there and that could get a bit hairy with all the delete operations and copy
> paste, but I'm leaning towards that solution because I can't figure out how
> to get an outline view cell to draw efficiently using a custom
> NSTextStorage.
>
> In a text view though, Ken's suggestion of subclassing a NSTextStorage and
> overriding lineBreakBeforeIndex:withinRange: worked out well. It turns out
> that subclassing is a little tricky because NSTextStorage is not a concrete
> class so here's what I did for posterity sake:
>
> @interface PFTextStorage : NSProxy
> {
>NSTextStorage *realStorage;
> }
> - (id)initWithTextStorage:(NSTextStorage *)storage;
> @end
>
>
> @implementation PFTextStorage
>
> - (id)init
> {
>realStorage = [[NSTextStorage alloc] init];
>return self;
> }
>
> - (id)initWithTextStorage:(NSTextStorage *)storage
> {
>realStorage = [storage retain];
>return self;
> }
>
> - (void)dealloc
> {
>[realStorage release];
>[super dealloc];
> }
>
> - (BOOL)respondsToSelector:(SEL)aSelector
> {
>return [realStorage respondsToSelector:aSelector];
> }
>
> - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
> {
>return [realStorage methodSignatureForSelector:aSelector];
> }
>
> - (void)forwardInvocation:(NSInvocation *)invocation
> {
>SEL aSelector = [invocation selector];
>
>   if ([realStorage respondsToSelector:aSelector])
>   [invocation invokeWithTarget:realStorage];
>   else
>   [realStorage doesNotRecognizeSelector:aSelector];
> }
>
> - (NSUInteger)lineBreakBeforeIndex:(NSUInteger)index
> withinRange:(NSRange)aRange
> {
>NSString *string = [realStorage string];
>NSUInteger breakIndex = [realStorage lineBreakBeforeIndex:index
> withinRange:aRange];
>if (breakIndex >= 2 &&
>[string characterAtIndex:breakIndex-1] == '/' &&
>[[NSCharacterSet whitespaceCharacterSet]
> characterIsMember:[string characterAtIndex:breakIndex-2]])
>return breakIndex - 2;
>
>return breakIndex;
> }
>
> @end
>
> ___
>
> 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]


Re: Controlling line-breaking in a text view

2008-08-12 Thread Andy Kim

Many thanks to everyone who helped in this thread.

I wonder if this is a larger bug in the text system? I was going to  
suggest
just inserting the Unicode character "zero-width no-break space" (U 
+FEFF)
after the slash, but when I tried it (in TextEdit) I got the very  
phenomenon

you describe - the break occurs before "delete", not after.

I was able to solve the problem, though, by also inserting a "zero- 
width
space" (U+200B) before the slash... So there's a solution for you,  
but it

seems unnecessarily elaborate. m.


Matt,

I may have to go with your solution for cell drawing although I'm  
hesitant before proceeding. The program has to make it seem like the  
character is not there and that could get a bit hairy with all the  
delete operations and copy paste, but I'm leaning towards that  
solution because I can't figure out how to get an outline view cell to  
draw efficiently using a custom NSTextStorage.


In a text view though, Ken's suggestion of subclassing a NSTextStorage  
and overriding lineBreakBeforeIndex:withinRange: worked out well. It  
turns out that subclassing is a little tricky because NSTextStorage is  
not a concrete class so here's what I did for posterity sake:


@interface PFTextStorage : NSProxy
{
NSTextStorage *realStorage;
}
- (id)initWithTextStorage:(NSTextStorage *)storage;
@end


@implementation PFTextStorage

- (id)init
{
realStorage = [[NSTextStorage alloc] init];
return self;
}

- (id)initWithTextStorage:(NSTextStorage *)storage
{
realStorage = [storage retain];
return self;
}

- (void)dealloc
{
[realStorage release];
[super dealloc];
}

- (BOOL)respondsToSelector:(SEL)aSelector
{
return [realStorage respondsToSelector:aSelector];
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
return [realStorage methodSignatureForSelector:aSelector];
}

- (void)forwardInvocation:(NSInvocation *)invocation
{
SEL aSelector = [invocation selector];

   if ([realStorage respondsToSelector:aSelector])
   [invocation invokeWithTarget:realStorage];
   else
   [realStorage doesNotRecognizeSelector:aSelector];
}

- (NSUInteger)lineBreakBeforeIndex:(NSUInteger)index withinRange: 
(NSRange)aRange

{
NSString *string = [realStorage string];
	NSUInteger breakIndex = [realStorage lineBreakBeforeIndex:index  
withinRange:aRange];

if (breakIndex >= 2 &&
[string characterAtIndex:breakIndex-1] == '/' &&
		[[NSCharacterSet whitespaceCharacterSet] characterIsMember:[string  
characterAtIndex:breakIndex-2]])

return breakIndex - 2;

return breakIndex;
}

@end


smime.p7s
Description: S/MIME cryptographic signature
___

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]

Re: Controlling line-breaking in a text view

2008-08-10 Thread John Joyce
You might consider subclassing, but you might also want to read a lot  
more stuff first.

Cocoa (and Carbon) text facilities are pretty deep.

There is nothing about a bug in the text system. It is just that the  
text handling in Cocoa is very sophisticated and is designed to handle  
things depending on language and locale and function. Where and how to  
break words and what is a word can be a very complex subject, even  
just in one language. Even in page layout for print media, some things  
are hand-tooled.


For your purposes, you might want something that recognizes a path or  
URL and formats it.


Text Layout Programming Guide
file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/TextLayout/TextLayout.html

NSTypesetter Class
file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTypesetter_Class/Reference/Reference.html

___

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]


Re: Controlling line-breaking in a text view

2008-08-10 Thread Matt Neuburg
I wonder if this is a larger bug in the text system? I was going to suggest
just inserting the Unicode character "zero-width no-break space" (U+FEFF)
after the slash, but when I tried it (in TextEdit) I got the very phenomenon
you describe - the break occurs before "delete", not after.

I was able to solve the problem, though, by also inserting a "zero-width
space" (U+200B) before the slash... So there's a solution for you, but it
seems unnecessarily elaborate. m.

On Sat, 9 Aug 2008 20:43:37 -0700, Andy Kim <[EMAIL PROTECTED]> said:
>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?


-- 
matt neuburg, phd = [EMAIL PROTECTED], 
A fool + a tool + an autorelease pool = cool!
One of the 2007 MacTech Top 25: 
AppleScript: the Definitive Guide - Second Edition!




___

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]


Re: Controlling line-breaking in a text view

2008-08-09 Thread Ken Ferry
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]


Controlling line-breaking in a text view

2008-08-09 Thread Andy Kim

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



smime.p7s
Description: S/MIME cryptographic signature
___

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]