• 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
Problem with drawBackgroundForGlyphRange:atPoint:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with drawBackgroundForGlyphRange:atPoint:


  • Subject: Problem with drawBackgroundForGlyphRange:atPoint:
  • From: "Jjgod Jiang" <email@hidden>
  • Date: Mon, 13 Aug 2007 02:03:32 +0800

Hi,

When I was trying to do custom text drawing with NSLayoutManager,
I got the following problem:

- (void) drawRect:(NSRect)rect
{
    NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString: @""];
    NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
    NSTextContainer *textContainer = [[NSTextContainer alloc]
initWithContainerSize: NSMakeSize(1.0e7, 1.0e7)];
    [layoutManager addTextContainer: textContainer];
    [textContainer release];
    [textStorage addLayoutManager: layoutManager];
    [layoutManager release];

    NSString *string = @"Hello World";

    NSMutableDictionary *attributes = [NSMutableDictionary
dictionaryWithObjectsAndKeys:
                            [NSColor blueColor],
                            NSBackgroundColorAttributeName,
                            [NSColor whiteColor],
                            NSForegroundColorAttributeName,
                            nil];

    NSRange charRange = NSMakeRange(0, [string length]);
    [[textStorage mutableString] setString: string];
    [textStorage setAttributes: attributes range: charRange];

    NSRange glyphRange = [layoutManager glyphRangeForCharacterRange: charRange
                                               actualCharacterRange: NULL];

    [layoutManager drawBackgroundForGlyphRange: glyphRange atPoint:
NSMakePoint(0, 0)];
    [layoutManager drawGlyphsForGlyphRange: glyphRange atPoint:
NSMakePoint(0, 0)];

    [textStorage release];
}

Foreground text is drawn correctly, but background is never drawn
no matter which color I set for NSBackgroundColorAttributeName.

- Jiang
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem with drawBackgroundForGlyphRange:atPoint:
      • From: "Lukhnos D. Liu" <email@hidden>
  • Prev by Date: iPhoto 08 Plugin SDK question
  • Next by Date: Re: file reading/writing over 2 gig
  • Previous by thread: Re: iPhoto 08 Plugin SDK question
  • Next by thread: Re: Problem with drawBackgroundForGlyphRange:atPoint:
  • Index(es):
    • Date
    • Thread