Re: Drawing text like Lion's Mail

2011-08-08 Thread Chase Latta
Andre,

I was digging through some old code and found this method I wrote awhile ago.  
I remember basing this off of a blog post or email thread but I don't remember 
the original source.  I used this for something real quick so the code is not 
perfect but may be a good starting point to get what you need.  Essentially you 
draw the string into an offscreen bitmap context and then use that to apply a 
mask.  You can then draw a gradient which gives the text a nice gradient.  The 
problem with this code is that it applies the gradient to the entire rect that 
you are passing so if your text is smaller than your rect you might not get the 
results you expect; this should be easy to fix though.  Note that this is a 
category on NSString.  I hope this helps.

Chase

- (void)drawInRect:(NSRect)rect withAttributes:(NSDictionary *)attributes 
andGradient:(NSGradient *)gradient;
{
NSMutableDictionary *maskAttrs; 
if (attributes != nil) 
maskAttrs = [[attributes mutableCopy] autorelease];
else 
maskAttrs = [NSMutableDictionary dictionary];

NSRect maskRect = NSMakeRect(0, 0, rect.size.width, rect.size.height);
[maskAttrs setValue:[NSColor whiteColor] 
forKey:NSForegroundColorAttributeName];
[maskAttrs setValue:[NSColor blackColor] 
forKey:NSBackgroundColorAttributeName];

CGColorSpaceRef grayScale = CGColorSpaceCreateDeviceGray();
CGContextRef maskContext = CGBitmapContextCreate(NULL, rect.size.width, 
rect.size.height, 8, rect.size.width, grayScale, 0);
CGColorSpaceRelease(grayScale);

// Draw the text into an offscreen context
NSGraphicsContext *maskGraphicsContext = [NSGraphicsContext 
graphicsContextWithGraphicsPort:maskContext flipped:NO];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:maskGraphicsContext];

[self drawInRect:maskRect withAttributes:maskAttrs];

[NSGraphicsContext restoreGraphicsState];

CGImageRef alphaMask = CGBitmapContextCreateImage(maskContext);

CGContextRef ctx = [[NSGraphicsContext  currentContext] graphicsPort];

// Draw the gradient clipped by the mask of the text
CGContextSaveGState(ctx);
CGContextClipToMask(ctx, NSRectToCGRect(rect), alphaMask);
CGFloat angle = -90;

[gradient drawInRect:rect angle:angle];

CGContextRestoreGState(ctx);
CGImageRelease(alphaMask);
}

> Seems like a lot of work for a simple effect. I may play again with this 
> later on this project. I have save this thread in Mail which is telling me 
> that there's "20 messages selected" using its fancy font effect :-)
> 
> Thanks for all infos guys,
> 
> Andre Masse
> 

___

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

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


Re: Drawing text like Lion's Mail

2011-08-08 Thread Andre Masse
Seems like a lot of work for a simple effect. I may play again with this later 
on this project. I have save this thread in Mail which is telling me that 
there's "20 messages selected" using its fancy font effect :-)

Thanks for all infos guys,

Andre Masse



On 08/08/2011, at 13:29 , David Duncan wrote:

> On Aug 8, 2011, at 10:21 AM, Jean-Daniel Dupas wrote:
> 
>> Le 8 août 2011 à 18:50, David Duncan a écrit :
>> 
>>> On Aug 8, 2011, at 8:16 AM, Jean-Daniel Dupas wrote:
>>> 
 
 I think you can create a CGPath from some text using CTFrameGetPath().
 Once you get the path, you can do whatever you want (clipping, shadow, 
 gradient, …).
>>> 
>>> 
>>> CTFrameGetPath() returns the path used to create the frame, typically a 
>>> rectangle, not a path that describes the text therein.
>> 
>> My bad.
>> So I guess the only way to get the path is to use CTFontCreatePathForGlyph() 
>> on each glyph and using other CT methods to get there positions.
>> Not as convenient, but possible, especially if this is for a single line of 
>> text as requested by the OP.
> 
> 
> If you just need the text outlines for clipping, then you should be able to 
> use the Text Drawing mode of the context. By setting it to kCGText*Clip, the 
> clipping region is set to that of the text after it is "drawn".
> 
> Unfortunately there is no simple way to get the path this way if it is what 
> you need (at least not that I can tell). CTFontCreatePathForGlyph() is one 
> way to go about it, and I think a combination of NSLayoutManager and 
> NSBezierPath can also do it, although I believe you have to subclass 
> NSLayoutManager to do so (I haven't done this, but I recall Aki Inoue 
> outlining it to me a long time ago). If you are already using NSLayoutManager 
> this would probably be the way to go since your metrics won't change as much 
> going this route.
> --
> David Duncan
> 
> ___
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/andre.masse%40videotron.ca
> 
> This email sent to andre.ma...@videotron.ca

___

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

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


Re: Drawing text like Lion's Mail

2011-08-08 Thread David Duncan
On Aug 8, 2011, at 10:21 AM, Jean-Daniel Dupas wrote:

> Le 8 août 2011 à 18:50, David Duncan a écrit :
> 
>> On Aug 8, 2011, at 8:16 AM, Jean-Daniel Dupas wrote:
>> 
>>> 
>>> I think you can create a CGPath from some text using CTFrameGetPath().
>>> Once you get the path, you can do whatever you want (clipping, shadow, 
>>> gradient, …).
>> 
>> 
>> CTFrameGetPath() returns the path used to create the frame, typically a 
>> rectangle, not a path that describes the text therein.
> 
> My bad.
> So I guess the only way to get the path is to use CTFontCreatePathForGlyph() 
> on each glyph and using other CT methods to get there positions.
> Not as convenient, but possible, especially if this is for a single line of 
> text as requested by the OP.


If you just need the text outlines for clipping, then you should be able to use 
the Text Drawing mode of the context. By setting it to kCGText*Clip, the 
clipping region is set to that of the text after it is "drawn".

Unfortunately there is no simple way to get the path this way if it is what you 
need (at least not that I can tell). CTFontCreatePathForGlyph() is one way to 
go about it, and I think a combination of NSLayoutManager and NSBezierPath can 
also do it, although I believe you have to subclass NSLayoutManager to do so (I 
haven't done this, but I recall Aki Inoue outlining it to me a long time ago). 
If you are already using NSLayoutManager this would probably be the way to go 
since your metrics won't change as much going this route.
--
David Duncan

___

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

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


Re: Drawing text like Lion's Mail

2011-08-08 Thread Jean-Daniel Dupas

Le 8 août 2011 à 18:50, David Duncan a écrit :

> On Aug 8, 2011, at 8:16 AM, Jean-Daniel Dupas wrote:
> 
>> 
>> I think you can create a CGPath from some text using CTFrameGetPath().
>> Once you get the path, you can do whatever you want (clipping, shadow, 
>> gradient, …).
> 
> 
> CTFrameGetPath() returns the path used to create the frame, typically a 
> rectangle, not a path that describes the text therein.

My bad.
So I guess the only way to get the path is to use CTFontCreatePathForGlyph() on 
each glyph and using other CT methods to get there positions.
Not as convenient, but possible, especially if this is for a single line of 
text as requested by the OP.

-- Jean-Daniel




___

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

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


Re: Drawing text like Lion's Mail

2011-08-08 Thread David Duncan
On Aug 8, 2011, at 8:16 AM, Jean-Daniel Dupas wrote:

> 
> I think you can create a CGPath from some text using CTFrameGetPath().
> Once you get the path, you can do whatever you want (clipping, shadow, 
> gradient, …).


CTFrameGetPath() returns the path used to create the frame, typically a 
rectangle, not a path that describes the text therein.
--
David Duncan

___

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

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


Re: Drawing text like Lion's Mail

2011-08-08 Thread Siegfried
On 08/08/2011, at 12:16, Jean-Daniel Dupas wrote:

> I think you can create a CGPath from some text using CTFrameGetPath().
> Once you get the path, you can do whatever you want (clipping, shadow, 
> gradient, …).

Ah, then that's the way to go! Thanks Jean-Daniel.

The image I created used as background a gray ~79% (RGB 201/255). Then, the 
shadow can be applied in a 115º angle or so, 1px distant and size of 3 px. 115º 
in x,y coordinates after a rough calculation gives 0.422 and 0.906 (sin and cos 
of 65º). Also, the color used to produce the shadow was a gray 25%. The result 
is pretty similar.

> 
> Le 8 août 2011 à 02:22, Andre Masse a écrit :
> 
>> Interesting. Not sure if could be possible to convert the text to an image, 
>> apply a gradient and use one of the copy method of NSImage. I needed a break 
>> from coding data migration, hence the pause trying this. Now, I'm back to 
>> the boring part ;-)
>> 
>> 
>> On 07/08/2011, at 14:12 , Siegfried wrote:
>> 
>>> 
>>> On 07/08/2011, at 10:52, Andre Masse wrote:
>>> 
 For those interested, Matt and Kyle were right. Helvetica Neue Bold 20pts. 
 All my attempts to replicate the shadow have failed though. I'm using 85% 
 white and it's good enough for me.
 
>>> 
>>> The shadow is just an "inner shadow". The problem is that I have no idea on 
>>> how to create an inner shadow in Cocoa. The obvious technique is to apply a 
>>> shadow on a white layer that has holes in form of letters. But I also have 
>>> no idea on how to do such intersection.
>>> 
>>> See the attached image and tell me if you like it. By the way, let's see if 
>>> you find which one is the original :-)
> 
> 
> 
> -- Jean-Daniel
> 
___

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

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


Re: Drawing text like Lion's Mail

2011-08-08 Thread Jean-Daniel Dupas

I think you can create a CGPath from some text using CTFrameGetPath().
Once you get the path, you can do whatever you want (clipping, shadow, 
gradient, …).

Le 8 août 2011 à 02:22, Andre Masse a écrit :

> Interesting. Not sure if could be possible to convert the text to an image, 
> apply a gradient and use one of the copy method of NSImage. I needed a break 
> from coding data migration, hence the pause trying this. Now, I'm back to the 
> boring part ;-)
> 
> Looks like your image didn't pass the list. Feel free to email it to me 
> directly.
> 
> Thanks,
> 
> Andre Masse
> 
> 
> On 07/08/2011, at 14:12 , Siegfried wrote:
> 
>> 
>> On 07/08/2011, at 10:52, Andre Masse wrote:
>> 
>>> For those interested, Matt and Kyle were right. Helvetica Neue Bold 20pts. 
>>> All my attempts to replicate the shadow have failed though. I'm using 85% 
>>> white and it's good enough for me.
>>> 
>> 
>> The shadow is just an "inner shadow". The problem is that I have no idea on 
>> how to create an inner shadow in Cocoa. The obvious technique is to apply a 
>> shadow on a white layer that has holes in form of letters. But I also have 
>> no idea on how to do such intersection.
>> 
>> See the attached image and tell me if you like it. By the way, let's see if 
>> you find which one is the original :-)



-- Jean-Daniel




___

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

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


Re: Drawing text like Lion's Mail

2011-08-07 Thread Andre Masse
Interesting. Not sure if could be possible to convert the text to an image, 
apply a gradient and use one of the copy method of NSImage. I needed a break 
from coding data migration, hence the pause trying this. Now, I'm back to the 
boring part ;-)

Looks like your image didn't pass the list. Feel free to email it to me 
directly.

Thanks,

Andre Masse


On 07/08/2011, at 14:12 , Siegfried wrote:

> 
> On 07/08/2011, at 10:52, Andre Masse wrote:
> 
>> For those interested, Matt and Kyle were right. Helvetica Neue Bold 20pts. 
>> All my attempts to replicate the shadow have failed though. I'm using 85% 
>> white and it's good enough for me.
>> 
> 
> The shadow is just an "inner shadow". The problem is that I have no idea on 
> how to create an inner shadow in Cocoa. The obvious technique is to apply a 
> shadow on a white layer that has holes in form of letters. But I also have no 
> idea on how to do such intersection.
> 
> See the attached image and tell me if you like it. By the way, let's see if 
> you find which one is the original :-)

___

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

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


Re: Drawing text like Lion's Mail

2011-08-07 Thread Siegfried

On 07/08/2011, at 10:52, Andre Masse wrote:

> For those interested, Matt and Kyle were right. Helvetica Neue Bold 20pts. 
> All my attempts to replicate the shadow have failed though. I'm using 85% 
> white and it's good enough for me.
> 

The shadow is just an "inner shadow". The problem is that I have no idea on how 
to create an inner shadow in Cocoa. The obvious technique is to apply a shadow 
on a white layer that has holes in form of letters. But I also have no idea on 
how to do such intersection.

See the attached image and tell me if you like it. By the way, let's see if you 
find which one is the original :-)

___

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

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


Re: Drawing text like Lion's Mail

2011-08-07 Thread Andre Masse
For those interested, Matt and Kyle were right. Helvetica Neue Bold 20pts. All 
my attempts to replicate the shadow have failed though. I'm using 85% white and 
it's good enough for me.

Thanks to all,

Andre Masse


___

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

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


Re: Drawing text like Lion's Mail

2011-08-05 Thread Durango
Helvetica Neue?

-- Matt

On Wed, Aug 3, 2011 3:26 PM, Andre Masse  wrote:

>Thanks but after having done 10+ screenshots and doing side by side
>comparisons, it clearly isn't Lucida Grande. It's very close to
>Helvetica but the kerning is different.
>
>Andre Masse
>
>On 03/08/2011, at 17:52 , Thomas Davie wrote:
>
>>
>> No - it's using the system font - Lucida Grande.
>>
>> Bob


___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
I've downloaded it and looks like it works on Lion. Never used it, so I may 
have to spend some time looking at tutorials.

Thanks for the suggestion,

Andre Masse


On 03/08/2011, at 22:02 , Andy Lee wrote:

> Does F-Script Anywhere work on Lion? Maybe you can inspect the view and find 
> a clue. A bit of a long shot if they're doing totally custom drawing, but 
> might be worth a try. Maybe they're using a custom cell of some kind and you 
> can look at the font settings.
> 
> --Andy

___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andy Lee
Does F-Script Anywhere work on Lion? Maybe you can inspect the view and find a 
clue. A bit of a long shot if they're doing totally custom drawing, but might 
be worth a try. Maybe they're using a custom cell of some kind and you can look 
at the font settings.

--Andy

On Aug 3, 2011, at 7:18 PM, Andre Masse wrote:

> Good guess but no luck. Looks like a demi bold version of Helvetica, but 
> since there's no font inside Mail's package, it can't be. Well, I don't 
> really need to be perfect. Close but pretty would be enough. It's definitely 
> 19.0pt its though. Could be drawn letter by letter, you never know :-)
> 
> Thanks,
> 
> Andre Masse
> 
> 
> On 03/08/2011, at 18:41 , Kyle Sluder wrote:
>> 
>> Helvetica Neue?
>> 
>> It's very clearly not Lucida Grande.
>> 
>> --Kyle Sluder


___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
Forget that last one. Found how and it's worst :-)

Andre Masse

PS: if anybody want that, here's how:

CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] 
graphicsPort];
CGContextSetShouldAntialias(context, NO);


On 03/08/2011, at 20:10 , Andre Masse wrote:

> Think I could be close if I could turn off anti-aliasing. Is there any way to 
> do that in -drawRect ?
> 
> Thanks,
> 
> Andre Masse
> ___
___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
Think I could be close if I could turn off anti-aliasing. Is there any way to 
do that in -drawRect ?

Thanks,

Andre Masse
___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
Good guess but no luck. Looks like a demi bold version of Helvetica, but since 
there's no font inside Mail's package, it can't be. Well, I don't really need 
to be perfect. Close but pretty would be enough. It's definitely 19.0pt its 
though. Could be drawn letter by letter, you never know :-)

Thanks,

Andre Masse


On 03/08/2011, at 18:41 , Kyle Sluder wrote:
> 
> Helvetica Neue?
> 
> It's very clearly not Lucida Grande.
> 
> --Kyle Sluder

___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Kyle Sluder
On Wed, Aug 3, 2011 at 3:26 PM, Andre Masse  wrote:
> Thanks but after having done 10+ screenshots and doing side by side 
> comparisons, it clearly isn't Lucida Grande. It's very close to Helvetica but 
> the kerning is different.

Helvetica Neue?

It's very clearly not Lucida Grande.

--Kyle Sluder
___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
Thanks but after having done 10+ screenshots and doing side by side 
comparisons, it clearly isn't Lucida Grande. It's very close to Helvetica but 
the kerning is different.

Andre Masse

On 03/08/2011, at 17:52 , Thomas Davie wrote:

> 
> No – it's using the system font – Lucida Grande.
> 
> Bob

___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Thomas Davie

On 3 Aug 2011, at 22:40, Andre Masse wrote:

> One less pass is good. Thanks.
> 
> Unfortunately, text is not as clean as Mail at this point. Small characters 
> like "e" loose sharpness (white space inside the character is reduced). Still 
> trying to find a winner by mixing different values. I'm not so sure Mail is 
> using Helvetica now.
> 
> Thanks for your help,

No – it's using the system font – Lucida Grande.

Bob___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
One less pass is good. Thanks.

Unfortunately, text is not as clean as Mail at this point. Small characters 
like "e" loose sharpness (white space inside the character is reduced). Still 
trying to find a winner by mixing different values. I'm not so sure Mail is 
using Helvetica now.

Thanks for your help,

Andre Masse

On 03/08/2011, at 16:51 , Jens Alfke wrote:

> You can draw it in one pass using NSShadowAttributeName.
> 
> —Jens

___

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

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


Re: Drawing text like Lion's Mail

2011-08-03 Thread Jens Alfke
You can draw it in one pass using NSShadowAttributeName.

—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

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

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


Drawing text like Lion's Mail

2011-08-03 Thread Andre Masse
Hi,

In the new Mail, when there's no selection, the detail's view show "No Message 
Selected" in an what seems to be embossed text. My various attempts to emulate 
that, have failed. Well it kinda work but it's a bit ugly.

Here's what I've done:

- (BOOL)isFlipped
{
return YES;
}

- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor whiteColor] set];
[NSBezierPath fillRect:[self bounds]];  
[[NSColor grayColor] set];
[NSBezierPath strokeRect:[self bounds]];
// draw image
CGFloat imgW = [banner size].width;
CGFloat imgH = [banner size].height;
CGFloat centerX = [self bounds].size.width / 2.0f;
CGFloat centerY = [self bounds].size.height /2.0f;
CGFloat x = centerX - (imgW / 2.0f);
CGFloat y = centerY - (imgH / 2.0f);
NSRect rectToDraw = NSMakeRect(x, y, imgW, imgH);
NSRect imgRect = NSMakeRect(0.0f, 0.0f, imgW, imgH);
[banner drawInRect:rectToDraw fromRect:imgRect operation:NSCompositeCopy 
fraction:1.0];
// draw text
CGFloat fontSize = 18.0f;
NSString *fontName = @"Helvetica";
NSString *message = @"No Message Selected";
CGFloat offset = 1.0f;

NSDictionary *attributes = [NSDictionary 
dictionaryWithObjectsAndKeys:[NSFont fontWithName:fontName size:fontSize],
NSFontAttributeName,
[NSColor grayColor],
NSForegroundColorAttributeName, 
nil];

NSAttributedString * currentText=[[NSAttributedString alloc] 
initWithString:message attributes: attributes];
CGFloat textW = [currentText size].width;
NSPoint textPt = NSMakePoint(centerX - (textW / 2.0f), centerY + (imgH / 
2.0f) + 10);
[currentText drawAtPoint:textPt];
[NSGraphicsContext restoreGraphicsState];

NSDictionary *attributesOffset = [NSDictionary 
dictionaryWithObjectsAndKeys:[NSFont fontWithName:fontName size:fontSize],
NSFontAttributeName,
[NSColor lightGrayColor],
NSForegroundColorAttributeName, 
nil];

NSAttributedString * currentTextOffset=[[NSAttributedString alloc] 
initWithString:message attributes: attributesOffset];
//textPt.x += offset;
textPt.y += offset;
[currentTextOffset drawAtPoint:textPt];
}

Any suggestions?

Thanks,

Andre Masse
___

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

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