• 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: drawing a simple string with NSFont
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drawing a simple string with NSFont


  • Subject: Re: drawing a simple string with NSFont
  • From: Scott F Bayes <email@hidden>
  • Date: Wed, 8 Aug 2007 10:57:48 +0900

Hi Andrew,

I did notice the explicit Postscript mention in the line you cite below, thought "odd, maybe they're referring to the connection between Display Postscript and PDF" (I think there was such a connection), and decided not to trust it overmuch. If set won't work properly, or only in certain circumstances, it should be at least deprecated, probably beyond deprecated -> obsoleted.

The NSFont mention of set would seem to be wrong from my recent experience, though I'm not absolutely sure I used it the intended way.

Does sound like a doc bug (or code regression problem).

Meanwhile, Felix Franz's response solved my original problem. Thanks again, Felix.

Thanks,


ScottB

On Aug 7, 2007, at 23:13 , Andrew Merenbach wrote:

Hi, Scott,

Apple lists -set as follows:

set
Establishes the receiver as the current font for PostScript show and other text-drawing operators.


- (void)set

Discussion

During a print operation, also records the font as used in the PostScript code emitted.


Note that this involves PostScript. Mac OS X no longer uses PostScript for the underlying drawing mechanism (as you may know, it now uses PDF). Thus -set may be nonfunctional now.


The docs *may* be misleading in that the summary of NSFont still says,
NSFont objects represent fonts to an application, providing access to characteristics of the font and assistance in laying out glyphs relative to one another. Font objects are also used to establish the current font when drawing in an NSView, using the set method.


If I'm wrong, someone correct me; but should we be filing a bug here?

Cheers,
	Andrew


On Aug 7, 2007, at 3:34 AM, Scott F Bayes wrote:

Hi Fritz,

Thank you! That is exactly the page I was looking for, but couldn't find in the Apple docs.

Your example is much appreciated, too. Very similar to what I had in mind.

Best Regards


Scottb

On Aug 7, 2007, at 19:05 , Felix Franz wrote:

Hi Scott,

I never used [myFont set] for myself, but using an attribute dictionary is
not difficult. The keys are the same as for Attributed strings:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ AttributedStrings/Articles/standardAttributes.html#//apple_ref/ doc/uid/TP40004903>


To draw a String in red color using myFont you can construct the dictionary
like:


NSDictionary* attributes =
[NSDictionary dictionaryWithObjectsAndKeys:myFont, NSFontAttributeName, [NSColor redColor], NSForegroundColorAttributeName, nil];


and then use the drawInRect:withAttributes: method:

[@"Hola" drawInRect: rect withAttributes: attributes];

(Typed in Mail, watch out for typos ...)

Cheers,

felix



On Aug 7, 2007, at 11:29 AM, Scott F Bayes wrote:

I'm trying to draw an NSString on a NSView while in its drawRect, using
- (void)drawInRect:(NSRect)aRect withAttributes:(NSDictionary *) attribute


from the AppKit NSString additions. I can draw the string where I want to without problem, but I want to select a font and a font size. "Simple Text Drawing" in the Drawing Guide says:
"For an NSString object, you can apply basic attributes (such as font, color, and style settings) to the entire string during drawing." Perfect!


It sounds like setting font&size can be accomplished either with the NSDictionary *withAttributes for drawInRect above, or by [myFont set] while in drawRect.

I find I can create what appears to be a valid NSFont, no problem. But [myFont set] in drawRect doesn't appear to do anything, and I don't know how to construct the NSDictionary mentioned above, assuming it's what I need; I can't figure out what key to use.

Documentation has led me through enough twists and turns that I'm now thoroughly confused.

Any advice or a short example would be appreciated.



Scott B

_______________________________________________

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:
40ergosign.de


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



_______________________________________________

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: 
 >drawing a simple string with NSFont (From: Scott F Bayes <email@hidden>)
 >Re: drawing a simple string with NSFont (From: Felix Franz <email@hidden>)
 >Re: drawing a simple string with NSFont (From: Scott F Bayes <email@hidden>)
 >Re: drawing a simple string with NSFont (From: Andrew Merenbach <email@hidden>)

  • Prev by Date: Re: Is this the Mailing list?
  • Next by Date: NSScroller icon / split view
  • Previous by thread: Re: drawing a simple string with NSFont
  • Next by thread: Re: drawing a simple string with NSFont
  • Index(es):
    • Date
    • Thread