Re: CGContextShowTextAtPoint

2015-10-14 Thread Raglan T. Tiger

-rags



> On Oct 14, 2015, at 2:37 PM, David Duncan  wrote:
> 
> Ensure that the text matrix is sane 


I have been doing this:

CGAffineTransform t = CGAffineTransformMakeScale (1.0, -1.0);
CGContextSetTextMatrix (ctx, t);


changing the sx and sy just scrunches the text into a blob

what the crusade am I not understanding?


-rags


___

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

Re: CGContextShowTextAtPoint

2015-10-14 Thread David Duncan
Ensure that the text matrix is sane (its separate from the current ctm and not 
stored with the graphics state).
> On Oct 14, 2015, at 1:36 PM, Raglan T. Tiger  wrote:
> 
> 
>> On Oct 13, 2015, at 4:42 PM, Wim Lewis  wrote:
>> 
>> 
>> On Oct 13, 2015, at 3:02 PM, Raglan T. Tiger  wrote:
>>> CGContextShowTextAtPoint (ctx, pt.x,pt.y,(const char*)txt, len );
>>> 
>>> This has printed my text UNTIL 10.11.
>>> 
>>> I see that CGContextShowTextAtPoint is deprecated in 10.9 ... is it gone in 
>>> 10.11?
>> 
>> As Quincey Morris says, Core Text 
> 
> I have text printing in the correct orientation now using
> 
> CFAttributedStringRef attrString = 
> CFAttributedStringCreate(kCFAllocatorDefault, cfstr, attributes);
> 
> CTLineRef line = CTLineCreateWithAttributedString(attrString);
> 
>// Set text position and draw the line into the graphics context
>CGContextSetTextPosition(ctx, pt.x, pt.y);
>CTLineDraw(line, ctx);
> 
> Now, I cannot increase the font size.  I set up attributes as:
> 
>CFStringRef keys[] = { kCTFontAttributeName };
>CFTypeRef values[] = { [ NSFont systemFontOfSize:48 ] };
> 
>CFDictionaryRef attributes =
>CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys,
>   (const void**)&values, sizeof(keys) / 
> sizeof(keys[0]),
>   &kCFTypeDictionaryKeyCallBacks,
>   &kCFTypeDictionaryValueCallBacks);
> 
> 
> and see my attributed string as:
> 
> 667 x, 2.3 y{
>NSFont = "\".HelveticaNeueDeskInterface-Regular 48.00 pt. P [] 
> (0x1128ca30) fobj=0x11d04390, spc=12.93\"";
> }
> 
> but the result is like 8 pt not 48. 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

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

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

Re: CGContextShowTextAtPoint

2015-10-14 Thread Raglan T. Tiger

> On Oct 13, 2015, at 4:42 PM, Wim Lewis  wrote:
> 
> 
> On Oct 13, 2015, at 3:02 PM, Raglan T. Tiger  wrote:
>> CGContextShowTextAtPoint (ctx, pt.x,pt.y,(const char*)txt, len );
>> 
>> This has printed my text UNTIL 10.11.
>> 
>> I see that CGContextShowTextAtPoint is deprecated in 10.9 ... is it gone in 
>> 10.11?
> 
> As Quincey Morris says, Core Text 

I have text printing in the correct orientation now using

CFAttributedStringRef attrString = 
CFAttributedStringCreate(kCFAllocatorDefault, cfstr, attributes);

CTLineRef line = CTLineCreateWithAttributedString(attrString);

// Set text position and draw the line into the graphics context
CGContextSetTextPosition(ctx, pt.x, pt.y);
CTLineDraw(line, ctx);

Now, I cannot increase the font size.  I set up attributes as:

CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { [ NSFont systemFontOfSize:48 ] };

CFDictionaryRef attributes =
CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys,
   (const void**)&values, sizeof(keys) / 
sizeof(keys[0]),
   &kCFTypeDictionaryKeyCallBacks,
   &kCFTypeDictionaryValueCallBacks);


and see my attributed string as:

667 x, 2.3 y{
NSFont = "\".HelveticaNeueDeskInterface-Regular 48.00 pt. P [] (0x1128ca30) 
fobj=0x11d04390, spc=12.93\"";
}

but the result is like 8 pt not 48. 
___

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

Re: CGContextShowTextAtPoint

2015-10-14 Thread Conrad Shultz

> On Oct 14, 2015, at 11:41 AM, Raglan T. Tiger  wrote:
> 
> 
> 
>> On Oct 14, 2015, at 10:02 AM, Jens Alfke  wrote:
>> 
>> The view is probably using flipped coordinates. Look up flipped coordinates 
>> in the Cocoa view documentation to understand what they are and how to work 
>> around the problem.
>> 
>> As for the size, have you set the size of the NSFont in ‘sysFont’?
>> 
> 
> I am using -graphicsContextWithBitmapImageRep and then adding text 
> annotations.  The reason for using CGContextShowTextAtPoint in the first 
> place was to solve this problem when drawing NSStrings.
> 
> I guess the real question is "How to you draw NSStrings as flipped == YES 
> when the current NSGraphicsContext is graphicsContextWithBitmapImageRep which 
> is flipped = NO.

If I understand your question, I’d expect you could set the graphics context’s 
transform (see the CGContextFooCTM() family of functions), draw your text, then 
reset the transform.

-Conrad
___

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

Re: CGContextShowTextAtPoint

2015-10-14 Thread Raglan T. Tiger


> On Oct 14, 2015, at 10:02 AM, Jens Alfke  wrote:
> 
> The view is probably using flipped coordinates. Look up flipped coordinates 
> in the Cocoa view documentation to understand what they are and how to work 
> around the problem.
> 
> As for the size, have you set the size of the NSFont in ‘sysFont’?
> 

I am using -graphicsContextWithBitmapImageRep and then adding text annotations. 
 The reason for using CGContextShowTextAtPoint in the first place was to solve 
this problem when drawing NSStrings.

I guess the real question is "How to you draw NSStrings as flipped == YES when 
the current NSGraphicsContext is graphicsContextWithBitmapImageRep which is 
flipped = NO.


-rags
___

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

Re: CGContextShowTextAtPoint

2015-10-14 Thread Jens Alfke

> On Oct 14, 2015, at 8:54 AM, Raglan T. Tiger  wrote:
> 
> I did all the above ... now my text prints upside down andI cannot get it to 
> size up regardless of the font size.

The view is probably using flipped coordinates. Look up flipped coordinates in 
the Cocoa view documentation to understand what they are and how to work around 
the problem.

As for the size, have you set the size of the NSFont in ‘sysFont’?

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

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

Re: CGContextShowTextAtPoint

2015-10-14 Thread Raglan T. Tiger


> On Oct 13, 2015, at 4:56 PM, Graham Cox  wrote:
> 
> Converting this to use string drawing is easy enough:
> 
> NSDictionary* attributes = @{NSFontAttributedName:sysFont};
> NSString* myText = [NSString stringWithUTF8String:txt];   // 
> check encoding if not UTF-8
> 
> [myText drawAtPoint:pt withAttributes:attributes];


I did all the above ... now my text prints upside down andI cannot get it to 
size up regardless of the font size.

Any direction is much appreciated.

-rags
___

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

Re: CGContextShowTextAtPoint

2015-10-13 Thread Graham Cox

> On 14 Oct 2015, at 9:02 am, Raglan T. Tiger  wrote:
> 
>   NSFont *sysFont = [NSFont systemFontOfSize:10];
>   NSString *sysFontName = [sysFont fontName];
>   CGContextSelectFont(ctx, [sysFontName 
> cStringUsingEncoding:NSASCIIStringEncoding], 90, kCGEncodingMacRoman);
>   CGContextSetTextDrawingMode(ctx,  kCGTextFill);

> CGContextShowTextAtPoint (ctx, pt.x,pt.y,(const char*)txt, len );


Converting this to use string drawing is easy enough:

NSDictionary* attributes = @{NSFontAttributedName:sysFont};
NSString* myText = [NSString stringWithUTF8String:txt]; // check 
encoding if not UTF-8

[myText drawAtPoint:pt withAttributes:attributes];



—G.
___

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

Re: CGContextShowTextAtPoint

2015-10-13 Thread Wim Lewis

On Oct 13, 2015, at 3:02 PM, Raglan T. Tiger  wrote:
> CGContextShowTextAtPoint (ctx, pt.x,pt.y,(const char*)txt, len );
> 
> This has printed my text UNTIL 10.11.
> 
> I see that CGContextShowTextAtPoint is deprecated in 10.9 ... is it gone in 
> 10.11?

As Quincey Morris says, Core Text is the recommended low-level API for drawing 
text now. It handles some typographical niceties that a direct PDF-equivalent 
CG call doesn't.

Another option is the -[NSAttributedString drawAtPoint:] method, which is a 
very easy method for simple string drawing.



___

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

Re: CGContextShowTextAtPoint

2015-10-13 Thread Quincey Morris
On Oct 13, 2015, at 15:02 , Raglan T. Tiger  wrote:
> 
> I see that CGContextShowTextAtPoint is deprecated in 10.9 ... is it gone in 
> 10.11?

Apparently. There’s this:


https://developer.apple.com/library/prerelease/mac/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF101

which says:

> "This chapter previously described the basic text support provided by Quartz. 
> However, the low-level support provided by Quartz has been deprecated and 
> superceded by Core Text, an advanced low-level technology for laying out text 
> and handing fonts. Core Text is designed for high performance and ease of use 
> and allows you to draw Unicode text directly to a graphics context. If you 
> are writing an application that needs precise control over how text is 
> displayed, see Core Text Programming Guide."

So it’s time to move on.

___

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

Re: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread Graham Cox

On 10/08/2011, at 2:06 AM, Gabriel Zachmann wrote:

> Just checked the doc of CATextLayer but couldn't find a hint on how it helps 
> me determine whether or not a font is installed ... can you tell me?


I doesn't. But it falls back gracefully, AFAIK.

If you need a specific non-standard font, you can bundle it with your app to 
ensure its present.

--Graham


___

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: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread Gabriel Zachmann
>>CGContextSelectFont( ctxt, "AndaleMono", 14, kCGEncodingMacRoman ); 
>> // "Andale Mono" doesn't work either
> 
> Perhaps he doesn't have "Andale Mono" on his machine? I'm not sure what CG 
> does with text if the font isn't there, does it fall back to something else 
> or just silently fail?
> I think the way your code assumes this font is going to be there is a bit 
> flaky.

I didn't find an easy way to check whether a font is installed - do you know 
how to do it?

> But anyway, CATextLayer takes all this pain away for you.

Just checked the doc of CATextLayer but couldn't find a hint on how it helps me 
determine whether or not a font is installed ... can you tell me?

Best regards,
Gabriel.



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


Re: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread glenn andreas

On Aug 9, 2011, at 9:48 AM, Gabriel Zachmann wrote:

> Thanks a lot for your response ...
> 
>> I've found the Core Graphics text handling methods to be gnarly and awkward 
>> the few times I've attempted to use them, and always ended up going some 
>> other route to render text.
> 
> Could you please point me to a few of them?
> 
>> 
>> In your case, the choice seems simple - just use CATextLayer. Why not?
> 
> Can CATextLayer render text with a shadow?
> Like this:
>  CGContextSetShadowWithColor( ctxt, CGSizeMake(0,0), 10, blue );
> 
> I really need the shadow to be able to discern it from a background layer, 
> the color of which is unknown and changes fairly often.


CATextLayer is a subclass of CALayer, which has a wide variety of shadowing 
options:

/** Shadow properties. **/

/* The color of the shadow. Defaults to opaque black. Colors created
 * from patterns are currently NOT supported. Animatable. */

@property CGColorRef shadowColor;

/* The opacity of the shadow. Defaults to 0. Specifying a value outside the
 * [0,1] range will give undefined results. Animatable. */

@property float shadowOpacity;

/* The shadow offset. Defaults to (0, -3). Animatable. */

@property CGSize shadowOffset;

/* The blur radius used to create the shadow. Defaults to 3. Animatable. */

@property CGFloat shadowRadius;

/* When non-null this path defines the outline used to construct the
 * layer's shadow instead of using the layer's composited alpha
 * channel. The path is rendered using the non-zero winding rule.
 * Specifying the path explicitly using this property will usually
 * improve rendering performance, as will sharing the same path
 * reference across multiple layers. Defaults to null. Animatable. */

@property CGPathRef shadowPath;



So not only does it have a shadow that you can change, you can even animate the 
shadow.

Glenn Andreas  gandr...@gandreas.com 
The most merciful thing in the world ... is the inability of the human mind to 
correlate all its contents - HPL

___

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: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread Graham Cox

On 10/08/2011, at 12:48 AM, Gabriel Zachmann wrote:

> Could you please point me to a few of them?

NSString, NSAttributedString, Core Text


> Can CATextLayer render text with a shadow?
> Like this:
>  CGContextSetShadowWithColor( ctxt, CGSizeMake(0,0), 10, blue );
> 
> I really need the shadow to be able to discern it from a background layer, 
> the color of which is unknown and changes fairly often.


Yes. It inherits from CALayer, so it has all of its properties, including all 
the shadow properties.

--Graham___

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: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread Gabriel Zachmann
Thanks a lot for your response ...

> I've found the Core Graphics text handling methods to be gnarly and awkward 
> the few times I've attempted to use them, and always ended up going some 
> other route to render text.

Could you please point me to a few of them?

> 
> In your case, the choice seems simple - just use CATextLayer. Why not?

Can CATextLayer render text with a shadow?
Like this:
  CGContextSetShadowWithColor( ctxt, CGSizeMake(0,0), 10, blue );

I really need the shadow to be able to discern it from a background layer, the 
color of which is unknown and changes fairly often.

Best regards,
Gabriel.



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


Re: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread Graham Cox

On 09/08/2011, at 10:43 PM, Gabriel Zachmann wrote:

> I have checked that 'str' does actually hold a valid string at the user's 
> instance. (I logged it and had him send me the log file.)

>CGContextSelectFont( ctxt, "AndaleMono", 14, kCGEncodingMacRoman ); // 
> "Andale Mono" doesn't work either


Perhaps he doesn't have "Andale Mono" on his machine? I'm not sure what CG does 
with text if the font isn't there, does it fall back to something else or just 
silently fail? Maybe the fallback font is too big for the space and it isn't 
rendered as a result?

I think the way your code assumes this font is going to be there is a bit flaky.

But anyway, CATextLayer takes all this pain away for you.

--Graham


___

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: CGContextShowTextAtPoint doesn't show text

2011-08-09 Thread Graham Cox

On 09/08/2011, at 10:43 PM, Gabriel Zachmann wrote:

> I have checked that 'str' does actually hold a valid string at the user's 
> instance. (I logged it and had him send me the log file.)
> I have also tried different font sizes.
> I have also googled around.
> All to no avail.
> 
> 
> Does anybody have an idea what else might be wrong?


I've found the Core Graphics text handling methods to be gnarly and awkward the 
few times I've attempted to use them, and always ended up going some other 
route to render text.

In your case, the choice seems simple - just use CATextLayer. Why not?

--Graham


___

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