Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic glyph/character advancement



Ok, I tried to do this by implementing an NSATSTypesetter subclass that has the following Methods:
- (NSTypesetterControlCharacterAction) actionForControlCharacterAtIndex:(unsigned)charIndex {
// take care of ASCII 11:
unichar character = [[[self attributedString] string] characterAtIndex:charIndex];
NSTypesetterControlCharacterAction result = [super actionForControlCharacterAtIndex:charIndex];
if (character == 11) return NSTypesetterWhitespaceAction;
return result;
}


and

- (NSRect)boundingBoxForControlGlyphAtIndex:(unsigned)glyphIndex
forTextContainer:(NSTextContainer *) textContainer
proposedLineFragment:(NSRect)proposedRect
glyphPosition:(NSPoint)glyphPosition
characterIndex:(unsigned)charIndex {
NSRect result = NSZeroRect;
if ([super respondsToSelector:@selector (boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment :glyphPosition:characterIndex:)]) {
result = [super boundingBoxForControlGlyphAtIndex:glyphIndex
forTextContainer:textContainer
proposedLineFragment:proposedRect
glyphPosition:glyphPosition
characterIndex:charIndex];
}
unichar character = [[[self attributedString] string] characterAtIndex:charIndex];
if (character = 11) NSLog(@"%@", NSStringFromRect(result));
return result;
}


in the lower if I want to change the bounding box if the character was an ascii 11.

Sadly even before I can look at what the superclass returns I get an:
2006-04-10 16:34:55.419 SubEthaEdit[10267] *** -[Typesetter boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment: glyphPosition:characterIndex:]: selector not recognized [self = 0x16e20a10]
(gdb) continue
2006-04-10 16:34:59.735 SubEthaEdit[10267] <Typesetter: 0x16e20a10>: Exception *** -[Typesetter boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment: glyphPosition:characterIndex:]: selector not recognized [self = 0x16e20a10] raised during typesetting layout manager <LayoutManager: 0x14fe47c0>
1 containers, text backing has 9 characters
selected character range {0, 0} affinty: upstream granularity: character
marked character range {9, 0}
Currently holding 9 glyphs with 0 glyph holes and 1 layout holes.
Glyph holes: ()
Layout holes: (Hard layout hole for chars: {0, 9})
, glyph range {0 9}. Ignoring...


which strikes me as odd, because I check beforehand if the superclass responds to the selector (which is the first countermeasure i added when I got the exception). So lets see, if the superclass really doesn't implement this call I just have to return something meaningfull myself - how would i return the fitting size of a glyph here? Just get the size attribute out of the attributed string in at that location?

Thats what i tried next, put
NSDictionary *attributes = [[self attributedString] attributesAtIndex:charIndex effectiveRange:NULL];
result.size.width += [@"W" sizeWithAttributes:attributes].width;
into the if an removed the call to super (although i feel uneasy about doing this).


But this worked, and NSLogs showedt that my returned NSRect is modified, but that doesn't change anything for the layout.

so what am i missing?

Best,
  dominik


On 14.03.2006, at 21:54, Douglas Davidson wrote:


On Mar 14, 2006, at 8:06 AM, Dominik Wagner wrote:

But what to do if I want do make room to display an invisible character/glyph? Is there any way to dynamically add an advancement to an otherwise unadvancing invisible? e.g. ASCII 11? This has to be dynamically show invisibles can be turned on and off.


One possible solution would be a custom glyph generator to substitute a visible glyph for NSControlGlyph. Another would be a custom typesetter implementing actionForControlCharacterAtIndex: and boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragmen t:glyphPosition:characterIndex:.


Douglas Davidson


-- Dominik Wagner Mail: email@hidden TheCodingMonkeys http://www.codingmonkeys.de/ Blog - DasGenie: !Scrap http://scrap.dasgenie.com/

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.