On 10 Dec 2012, at 19:13, Kyle Sluder <k...@ksluder.com> wrote:

> It's my understanding that the intent of NSStringDrawing is to provide
> the exact same drawing as NSTextFieldCell.
Is that stated anywhere?

> But the following code
> produces text that is offset by 2pt to the left from a standard
> NSTextFieldCell:
> 
> @implementation MyTextFieldCell /* : NSTextFieldCell */
> 
> - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView
> *)controlView {
>    NSStringDrawingOptions options = 0;
>    if (self.truncatesLastVisibleLine)
>        options |= NSStringDrawingTruncatesLastVisibleLine;
>    if (!self.usesSingleLineMode)
>        options |= NSStringDrawingUsesLineFragmentOrigin;
> 
>    [self.attributedString drawWithRect:[self
>    titleRectForBounds:cellFrame] options:options];
> }
> 
> @end
> 
> I can't tell if I'm using the wrong rect or failing to pass the right
> arguments to -drawWithRect:options:. Anyone have any clues?
> 
Have you confirmed that the issue occurs with an NSString instance?

In the past I have experienced layout differences when calling either 
drawAtPoint: or drawWithRect:options.
I would experiment with calling drawAtPoint: and drawInRect:

The Text Layout Programming Guide says:

String Drawing and Typesetter Behaviors

There are differences among Cocoa’s three ways to draw text with regard to 
typesetter behavior, which is described in “Typesetter Behaviors and Versions.” 
By default, the string-drawing convenience methods and NSCell objects supplied 
by the Application Kit useNSTypesetterBehavior_10_2_WithCompatibility, whereas 
NSLayoutManager objects use NSTypesetterLatestBehavior. It is important to use 
the same typesetter behavior when both measuring and rendering text, to avoid 
differences in paragraph spacing, line spacing, and head indent handling.

In cases where you must measure text one way and render it another, set the 
typesetter behavior to match using thesetTypesetterBehavior: method defined by 
NSLayoutManager and NSTypesetter. For example, if you need to use 
anNSLayoutManager object to measure text and convenience string drawing methods 
to draw it, change the layout manager’s typesetter behavior to 
NSTypesetterBehavior_10_2_WithCompatibility.

Jonathan


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to