Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why must [NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:] be computed twice?



    Hello all,

 I have a Cocoa-made text editor involving an extension of the
"MultiplePageView"
class from the TextEdit source code. One of its functionalities is the
ability
to transform a rectangular region of a page (selected by the user) into
several columns (each corresponding to a new NSTextView object).

  To compute the coordinates of this rectangular region, I use
the -selectedRange method of NSTextView and the
-lineFragmentRectForGlyphAtIndex: method of NSLayoutManager
(basically, the rect I want to compute is the union of the
lineFragmentRect of all the glyphs in the selected range).

 The surprising thing is, to make my code work I have
to execute
[myLayoutManager lineFragmentRectForGlyphAtIndex:myGlyphIndex
effectiveRange:NULL] twice in order to get the correct result. The first call
to this method yields a wrong value for one of the coordinates of the
rectangle :
(gdb) p lm
$9 = (class NSLayoutManager *) 0x4641620
(gdb) p (NSRect) [lm lineFragmentRectForGlyphAtIndex:42025]
$10 = {
  origin = {
    x = 67,
    y = 509
  },
  size = {
    width = 461,
    height = 23
  }
}
(gdb) p (NSRect) [lm lineFragmentRectForGlyphAtIndex:42025]
$11 = {
  origin = {
    x = 67,
    y = 65728
  },
  size = {
    width = 461,
    height = 23
  }
}

 The corresponding part of my code is as follows :

@implementation NSLayoutManager (LayoutManagerAdditions)

-(NSRect)lineFragmentRectForGlyphAtIndex:(unsigned)aGlyphIndex
{

   unsigned theContainerIndex=[self
textContainerPositiveIndexForGlyphAtIndex:aGlyphIndex];
   NSTextContainer* theContainer=[[self textContainers]
objectAtPositiveIndex:theContainerIndex];
   NSTextView* theTextView=[theContainer textView];
   NSRect theRect=[self lineFragmentRectForGlyphAtIndex:aGlyphIndex
effectiveRange:NULL];
   theRect=[theTextView convertRect:theRect toView:[theTextView
superview]]; return theRect;
}

(...)

@end

   Can anyone explain to me what's going on here ? Should i use another
method of
NSLayoutManager to compute this selected rectangle's coordinates ?

                                                                                        TIA,


                                                                                            Ewan




_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.