• 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: NSAttributedString fill with gradient
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAttributedString fill with gradient


  • Subject: Re: NSAttributedString fill with gradient
  • From: "John C. Randolph" <email@hidden>
  • Date: Sat, 19 Dec 2009 06:15:32 -0800

There's a far easier way to do it than that, which is to use compositing instead of clipping.

On Dec 17, 2009, at 9:49 PM, Gordon Apple wrote:

If you capture the entire laid-out text string as a single Bezier path,
then you can fill it with whatever you want -- gradient, image, burning fire
QTMovie, more text, etc. I've done it and it works. Of course, all of that
takes a significant amount of effort. In my case, I already had all the
fill mechanisms, so all I had to do was get the Bezier Path.


The SpeedyCatagories file in the SpeedometerView example has most of what
you need to get the Bezier. You have to modify it somewhat to get
everything you need.


On 12/17/09 8:29 PM, "email@hidden"
<email@hidden> wrote:

On 18/12/2009, at 4:31 AM, Chris Purcell wrote:

I've tried setting the gradient as NSForegroundColorAttributeName in the
attributes dictionary when creating the string but as I expected that didn't
work. How would I go about filling the string with a gradient?

Why would you even expect that to work? NSGradient is not a colour. At present
there is no supported attribute for gradients.


You could create this effect by converting the string to its glyphs as a path
and fill the path. Alternatively you can create a subclass of NSLayoutManager
and override the method:


- (void)showPackedGlyphs:(char *)glyphs
length:(NSUInteger)glyphLenglyphRange:(NSRange)glyphRange
atPoint:(NSPoint)point font:(NSFont *)font color:(NSColor*)color
printingAdjustment:(NSSize)printingAdjustment

and render the glyphs using a gradient. Doing that implies you'll need to set
up a text system programatically, which is a fairly advanced topic - see:


http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/TextArch
itecture/TextArchitecture.pdf

--Graham




_______________________________________________

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

_______________________________________________

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


References: 
 >Re: NSAttributedString fill with gradient (From: Gordon Apple <email@hidden>)

  • Prev by Date: Re: Normalizing text in elements from NSXMLParser
  • Next by Date: Re: Subview and window size
  • Previous by thread: Re: NSAttributedString fill with gradient
  • Next by thread: Overriding NSArrayController to be used in a many-to-many RS and NSTable Bindings
  • Index(es):
    • Date
    • Thread