adding space for 'annotations' with a typesetter subclass

  • Hello,

    I'm able to add additional space around a paragraph in my subclass of NSATSTypesetter's implementation of willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:. However, I am not getting what I expect as I tweak the parameters to this method. I was hoping for some insight on what these parameters really mean from the group to help me understand why I'm not getting what I expect.

    When I increase the height of the lineFragmentRect and the usedRect the space for the paragraph does grow and I get the space I expect.

    What is confusing me is where the line of text is drawn in the lineFragmentRect. Based on experimentation the line of text is always drawn near the top. When I first encountered this I assumed that tweaking the baselineOffset would allow me control over where the text is drawn. I was unable to change where the text is drawn by tweaking baselineOffset.

    My next attempt was to tweak the origin of the lineFragmentRect. That did move the line of text, but not in ways I expected it to. My thinking was that moving the origin.y 3 would move the text by 3. That does not appear to be the case.

    Based my reading of the docs it looks to me as if the changes I make in willSetLineFrag… are passed on to setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:. During the implementation of setLineFrag… the layout manager must be called with setLocation:forStartOfGlyphRange:

    I'm trying to follow a sample from Doug Davidson's WWDC 2003 NSText talk, however the sample is not on the ADC site. I found this post where Doug pasted in part of the sample:

    http://lists.apple.com/archives/cocoa-dev/2006/Dec/msg00096.html

    My end goal is similar but not the same. I have multiple paragraphs that will be marked with an additional attribute. I only want the first and last lines to be expanded/moved.

    Thanks for your time!

    -bd
  • On Jun 1, 2012, at 9:36 AM, Bill Dudney wrote:
    > I'm able to add additional space around a paragraph in my subclass of NSATSTypesetter's implementation of willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:. However, I am not getting what I expect as I tweak the parameters to this method. I was hoping for some insight on what these parameters really mean from the group to help me understand why I'm not getting what I expect.
    >
    > When I increase the height of the lineFragmentRect and the usedRect the space for the paragraph does grow and I get the space I expect.
    >
    > What is confusing me is where the line of text is drawn in the lineFragmentRect. Based on experimentation the line of text is always drawn near the top. When I first encountered this I assumed that tweaking the baselineOffset would allow me control over where the text is drawn. I was unable to change where the text is drawn by tweaking baselineOffset.
    >
    > My next attempt was to tweak the origin of the lineFragmentRect. That did move the line of text, but not in ways I expected it to. My thinking was that moving the origin.y 3 would move the text by 3. That does not appear to be the case.
    >
    > Based my reading of the docs it looks to me as if the changes I make in willSetLineFrag… are passed on to setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:. During the implementation of setLineFrag… the layout manager must be called with setLocation:forStartOfGlyphRange:

    Bill, I had a similar problem, and I handled it by overriding -paragraphSpacingBeforeGlyphAtIndex: withProposedLineFragmentRect:.

    Ross
  • Thanks Ross,

    That appears to be doing the trick!

    Still trikes me as odd though that the other approach of tweaking the willSetLineFragmentRect: wouldn't work. I'll have to ask around at WWDC next week.

    Thanks again,

    -bd

    On Jun 4, 2012, at 12:45 PM, Ross Carter wrote:

    > On Jun 1, 2012, at 9:36 AM, Bill Dudney wrote:
    >> I'm able to add additional space around a paragraph in my subclass of NSATSTypesetter's implementation of willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:. However, I am not getting what I expect as I tweak the parameters to this method. I was hoping for some insight on what these parameters really mean from the group to help me understand why I'm not getting what I expect.
    >>
    >> When I increase the height of the lineFragmentRect and the usedRect the space for the paragraph does grow and I get the space I expect.
    >>
    >> What is confusing me is where the line of text is drawn in the lineFragmentRect. Based on experimentation the line of text is always drawn near the top. When I first encountered this I assumed that tweaking the baselineOffset would allow me control over where the text is drawn. I was unable to change where the text is drawn by tweaking baselineOffset.
    >>
    >> My next attempt was to tweak the origin of the lineFragmentRect. That did move the line of text, but not in ways I expected it to. My thinking was that moving the origin.y 3 would move the text by 3. That does not appear to be the case.
    >>
    >> Based my reading of the docs it looks to me as if the changes I make in willSetLineFrag… are passed on to setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:. During the implementation of setLineFrag… the layout manager must be called with setLocation:forStartOfGlyphRange:
    >
    > Bill, I had a similar problem, and I handled it by overriding -paragraphSpacingBeforeGlyphAtIndex: withProposedLineFragmentRect:.
    >
    > Ross
    >
    >
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today