• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why must [NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:] be computed twice?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Why must [NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:] be computed twice?
  • From: "Ewan Delanoy" <email@hidden>
  • Date: Thu, 27 Dec 2007 13:09:46 +0100 (CET)
  • Importance: Normal

    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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Why must [NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:] be computed twice?
      • From: Gerd Knops <email@hidden>
  • Prev by Date: Re: capturing text from window in external application
  • Next by Date: Re: Scripting Bridge && filteredArrayUsingPredicate
  • Previous by thread: CFMessagePortCreateRemote fails in Leopard
  • Next by thread: Re: Why must [NSLayoutManager lineFragmentRectForGlyphAtIndex:effectiveRange:] be computed twice?
  • Index(es):
    • Date
    • Thread