Re: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-19 Thread Aki Inoue
Or, you could create an NSView subclass instance with -isFlipped  
overridden shared among non-flipped views.


You can add the flipped view to your view inside -drawRect: and - 
lockFocus to it temporarily.


Depending on your rendering needs, this approach is preferable  
performance-wise than allocating graphics context.


Aki

On 2008/11/19, at 14:22, Ken Ferry wrote:


On Tue, Nov 18, 2008 at 1:57 PM, Rua Haszard Morris
[EMAIL PROTECTED] wrote:

What are the different options for flipping the coordinates of the
destination view? I've tried doing it by scaling and translating the
CGContext, but this results in problems with underlining or the  
character
orientation (depending on whether i flip the view back before or  
after

drawing the text).

At the moment the only method which results in correct text is to  
have a
custom view and override isFlipped - is this the only recommended  
method?


Doug answered the overall question, but maybe I'll chime on this bit
specifically.

As you're finding, -isFlipped and the CTM are entirely orthogonal
pieces of data.  If you're using NSLayoutManager, you need the current
context to return YES to -[NSGraphicsContext isFlipped], and you also
want the CTM set up so that the text goes where you want.

There is no setter for -[NSGraphicsContext isFlipped], but you don't
need to use a custom view.  [NSGraphicsContext
graphicsContextWithGraphicsPort:[originalContext graphicsPort]
flipped:YES] would give you a graphics context object that is flipped
without otherwise modifying the CTM or anything.

-Ken

I ask because I have to use these strings within custom views  
(which may for
example have rotated contexts), as well as in standard controls,  
and simpler
custom views purely for drawing these attributed strings. If the  
only method
to have the attributes (particularly underline) interpreted  
correctly is to
perform the drawing in a isFlipped NSView subclass, then I need to  
rejig
things so the complex custom views embed an NSView rather than draw  
the

attributed string manually.

thanks
Rua HM.

On Nov 19, 2008, at 9:40 am, 11(November)/19/08, Rua Haszard Morris  
wrote:



Thanks for the link, you are right, I had not seen that document!

On Nov 19, 2008, at 9:33 am, 11(November)/19/08, Douglas Davidson  
wrote:




On Nov 18, 2008, at 12:18 PM, Rua Haszard Morris wrote:

To follow up.. below I have pasted the code that draws the text  
(for my
test app, as opposed to the more complex ways of reproducing the  
bug
elsewhere in my code). (the full test app is attached to the  
radar bug)


I have been consulting the Text System Overview documentation,  
which I

don't believe mentions this fact.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html

I can understand that drawing text top to bottom makes sense,  
but I am
surprised that the coordinate system of the destination context  
has such

far-reaching side effects.


You're looking at the Text Systems Overview, which is very general
conceptual documentation, the sort you would consult to decide  
which class
to use.  What you want is the Text Layout Programming Guide for  
Cocoa, which
gives more detailed direction as to how to use these classes.   
The first

section,
http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html 
 under
the heading Glyph Drawing says, The text system expects view  
coordinates
to be flipped, like those of NSTextView.  If you are going to be  
drawing

using the layout manager directly, this is a hard-and-fast rule.

Douglas Davidson



___

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/r.haszardmorris%40adinstruments.com

This email sent to [EMAIL PROTECTED]


___

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/kenferry%40gmail.com

This email sent to [EMAIL PROTECTED]


___

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/aki%40apple.com

This email sent to [EMAIL PROTECTED]


___

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 

Re: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-19 Thread Rua Haszard Morris
Or, you could create an NSView subclass instance with -isFlipped  
overridden shared among non-flipped views.


You can add the flipped view to your view inside -drawRect: and - 
lockFocus to it temporarily.


Depending on your rendering needs, this approach is preferable  
performance-wise than allocating graphics context.
Yep, I did do this initially, but in the end I just implemented it  
using drawAtPoint to keep things simple (since my needs are fairly  
modest). The view class is pretty lightweight, its main role is to  
ensure the baseline lines up with where the caller needs it.


thanks for all the informative suggestions,
Rua HM.




Aki

On 2008/11/19, at 14:22, Ken Ferry wrote:


On Tue, Nov 18, 2008 at 1:57 PM, Rua Haszard Morris
[EMAIL PROTECTED] wrote:

What are the different options for flipping the coordinates of the
destination view? I've tried doing it by scaling and translating the
CGContext, but this results in problems with underlining or the  
character
orientation (depending on whether i flip the view back before or  
after

drawing the text).

At the moment the only method which results in correct text is to  
have a
custom view and override isFlipped - is this the only recommended  
method?


Doug answered the overall question, but maybe I'll chime on this bit
specifically.

As you're finding, -isFlipped and the CTM are entirely orthogonal
pieces of data.  If you're using NSLayoutManager, you need the  
current

context to return YES to -[NSGraphicsContext isFlipped], and you also
want the CTM set up so that the text goes where you want.

There is no setter for -[NSGraphicsContext isFlipped], but you don't
need to use a custom view.  [NSGraphicsContext
graphicsContextWithGraphicsPort:[originalContext graphicsPort]
flipped:YES] would give you a graphics context object that is flipped
without otherwise modifying the CTM or anything.

-Ken

I ask because I have to use these strings within custom views  
(which may for
example have rotated contexts), as well as in standard controls,  
and simpler
custom views purely for drawing these attributed strings. If the  
only method
to have the attributes (particularly underline) interpreted  
correctly is to
perform the drawing in a isFlipped NSView subclass, then I need to  
rejig
things so the complex custom views embed an NSView rather than  
draw the

attributed string manually.

thanks
Rua HM.

On Nov 19, 2008, at 9:40 am, 11(November)/19/08, Rua Haszard  
Morris wrote:



Thanks for the link, you are right, I had not seen that document!

On Nov 19, 2008, at 9:33 am, 11(November)/19/08, Douglas Davidson  
wrote:




On Nov 18, 2008, at 12:18 PM, Rua Haszard Morris wrote:

To follow up.. below I have pasted the code that draws the text  
(for my
test app, as opposed to the more complex ways of reproducing  
the bug
elsewhere in my code). (the full test app is attached to the  
radar bug)


I have been consulting the Text System Overview documentation,  
which I

don't believe mentions this fact.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html

I can understand that drawing text top to bottom makes sense,  
but I am
surprised that the coordinate system of the destination context  
has such

far-reaching side effects.


You're looking at the Text Systems Overview, which is very general
conceptual documentation, the sort you would consult to decide  
which class
to use.  What you want is the Text Layout Programming Guide for  
Cocoa, which
gives more detailed direction as to how to use these classes.   
The first

section,
http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html 
 under
the heading Glyph Drawing says, The text system expects view  
coordinates
to be flipped, like those of NSTextView.  If you are going to  
be drawing

using the layout manager directly, this is a hard-and-fast rule.

Douglas Davidson



___

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/r.haszardmorris%40adinstruments.com

This email sent to [EMAIL PROTECTED]


___

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/kenferry 
%40gmail.com


This email sent to [EMAIL PROTECTED]


___

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 

SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-18 Thread Rua Haszard Morris
To follow up.. below I have pasted the code that draws the text (for  
my test app, as opposed to the more complex ways of reproducing the  
bug elsewhere in my code). (the full test app is attached to the radar  
bug)


I have been consulting the Text System Overview documentation, which I  
don't believe mentions this fact.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html

I can understand that drawing text top to bottom makes sense, but I am  
surprised that the coordinate system of the destination context has  
such far-reaching side effects.


Thanks for all the info,
Rua HM.

- (void)drawRect:(NSRect)rect {
CGContextRef context = (CGContextRef)[[NSGraphicsContext  
currentContext]graphicsPort];


CGContextSaveGState(context);

NSTextStorage* textStorage = [[NSTextStorage alloc]  
initWithAttributedString:attribString];


NSLayoutManager *layoutManager;
layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];

NSTextContainer *container = [[NSTextContainer alloc]  
initWithContainerSize:NSMakeSize(, )];

[layoutManager addTextContainer:container];

NSRange glyphRange = [layoutManager  
glyphRangeForTextContainer:container];
[layoutManager drawGlyphsForGlyphRange:glyphRange  
atPoint:NSMakePoint(10, 10)];


[container release];
[layoutManager release];
[textStorage release];

CGContextRestoreGState(context);
}


On Nov 19, 2008, at 9:09 am, 11(November)/19/08, Douglas Davidson wrote:



On Nov 18, 2008, at 11:53 AM, Rua Haszard Morris wrote:

I was ensuring that I am _not_ drawing in a flipped context... (!)  
now, as you suggest I tried flipping the custom view (override  
isFlipped) that the attributed string is drawn in, and note that it  
works correctly!


So an improved workaround is to tweak the positioning logic (to  
account for the flipped context) instead of tweaking (hacking) the  
actual attributes.


I'm still not clear on why this should be the case. Thanks for the  
vastly better workaround though..


The text system generally prefers a flipped context, because text  
generally runs from top to bottom rather than the reverse.  You  
didn't post code, so I'm not sure exactly what you're doing, but  
this is a good general rule.


Douglas Davidson



___

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 [EMAIL PROTECTED]


Re: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-18 Thread Douglas Davidson


On Nov 18, 2008, at 12:18 PM, Rua Haszard Morris wrote:

To follow up.. below I have pasted the code that draws the text (for  
my test app, as opposed to the more complex ways of reproducing the  
bug elsewhere in my code). (the full test app is attached to the  
radar bug)


I have been consulting the Text System Overview documentation, which  
I don't believe mentions this fact.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html

I can understand that drawing text top to bottom makes sense, but I  
am surprised that the coordinate system of the destination context  
has such far-reaching side effects.


You're looking at the Text Systems Overview, which is very general  
conceptual documentation, the sort you would consult to decide which  
class to use.  What you want is the Text Layout Programming Guide for  
Cocoa, which gives more detailed direction as to how to use these  
classes.  The first section, http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html 
 under the heading Glyph Drawing says, The text system expects  
view coordinates to be flipped, like those of NSTextView.  If you are  
going to be drawing using the layout manager directly, this is a hard- 
and-fast rule.


Douglas Davidson

___

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 [EMAIL PROTECTED]


Re: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-18 Thread Rua Haszard Morris

Thanks for the link, you are right, I had not seen that document!

On Nov 19, 2008, at 9:33 am, 11(November)/19/08, Douglas Davidson wrote:



On Nov 18, 2008, at 12:18 PM, Rua Haszard Morris wrote:

To follow up.. below I have pasted the code that draws the text  
(for my test app, as opposed to the more complex ways of  
reproducing the bug elsewhere in my code). (the full test app is  
attached to the radar bug)


I have been consulting the Text System Overview documentation,  
which I don't believe mentions this fact.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html

I can understand that drawing text top to bottom makes sense, but I  
am surprised that the coordinate system of the destination context  
has such far-reaching side effects.


You're looking at the Text Systems Overview, which is very general  
conceptual documentation, the sort you would consult to decide which  
class to use.  What you want is the Text Layout Programming Guide  
for Cocoa, which gives more detailed direction as to how to use  
these classes.  The first section, http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html 
 under the heading Glyph Drawing says, The text system expects  
view coordinates to be flipped, like those of NSTextView.  If you  
are going to be drawing using the layout manager directly, this is a  
hard-and-fast rule.


Douglas Davidson



___

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 [EMAIL PROTECTED]


Re: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-18 Thread Rua Haszard Morris
What are the different options for flipping the coordinates of the  
destination view? I've tried doing it by scaling and translating the  
CGContext, but this results in problems with underlining or the  
character orientation (depending on whether i flip the view back  
before or after drawing the text).


At the moment the only method which results in correct text is to have  
a custom view and override isFlipped - is this the only recommended  
method?


I ask because I have to use these strings within custom views (which  
may for example have rotated contexts), as well as in standard  
controls, and simpler custom views purely for drawing these attributed  
strings. If the only method to have the attributes (particularly  
underline) interpreted correctly is to perform the drawing in a  
isFlipped NSView subclass, then I need to rejig things so the complex  
custom views embed an NSView rather than draw the attributed string  
manually.


thanks
Rua HM.

On Nov 19, 2008, at 9:40 am, 11(November)/19/08, Rua Haszard Morris  
wrote:



Thanks for the link, you are right, I had not seen that document!

On Nov 19, 2008, at 9:33 am, 11(November)/19/08, Douglas Davidson  
wrote:




On Nov 18, 2008, at 12:18 PM, Rua Haszard Morris wrote:

To follow up.. below I have pasted the code that draws the text  
(for my test app, as opposed to the more complex ways of  
reproducing the bug elsewhere in my code). (the full test app is  
attached to the radar bug)


I have been consulting the Text System Overview documentation,  
which I don't believe mentions this fact.

http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/TextArchitecture.html

I can understand that drawing text top to bottom makes sense, but  
I am surprised that the coordinate system of the destination  
context has such far-reaching side effects.


You're looking at the Text Systems Overview, which is very general  
conceptual documentation, the sort you would consult to decide  
which class to use.  What you want is the Text Layout Programming  
Guide for Cocoa, which gives more detailed direction as to how to  
use these classes.  The first section, http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Concepts/LayoutManager.html 
 under the heading Glyph Drawing says, The text system expects  
view coordinates to be flipped, like those of NSTextView.  If you  
are going to be drawing using the layout manager directly, this is  
a hard-and-fast rule.


Douglas Davidson



___

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/r.haszardmorris%40adinstruments.com

This email sent to [EMAIL PROTECTED]


___

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 [EMAIL PROTECTED]


Re: SOLVED Re: NSAttributedString rendering bugs when rendered with Cocoa Text (rdar://6379047)

2008-11-18 Thread Douglas Davidson


On Nov 18, 2008, at 1:57 PM, Rua Haszard Morris wrote:

What are the different options for flipping the coordinates of the  
destination view? I've tried doing it by scaling and translating the  
CGContext, but this results in problems with underlining or the  
character orientation (depending on whether i flip the view back  
before or after drawing the text).


At the moment the only method which results in correct text is to  
have a custom view and override isFlipped - is this the only  
recommended method?


I ask because I have to use these strings within custom views (which  
may for example have rotated contexts), as well as in standard  
controls, and simpler custom views purely for drawing these  
attributed strings. If the only method to have the attributes  
(particularly underline) interpreted correctly is to perform the  
drawing in a isFlipped NSView subclass, then I need to rejig things  
so the complex custom views embed an NSView rather than draw the  
attributed string manually.


The other alternative would be to use the NSStringDrawing APIs instead  
of using NSLayoutManager directly.


Douglas Davidson

___

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 [EMAIL PROTECTED]