Custom pagination clipping

  • I have an NSTextView that I'm trying to paginate so that lines aren't
    cut when printing across several pages.  In knowsPageRange I figure
    out where the page boundaries should be in the view's coordinate
    system.  Then I've overridden rectForPage as follows:

    - (NSRect)rectForPage:(int)pageNumber {
    NSRect rect = [self bounds];

    if ([pageBoundaries count]) {
      rect.origin.y = 0;
      if (pageNumber > 1)
      rect.origin.y = [[pageBoundaries objectAtIndex: pageNumber - 2]
    floatValue];
      rect.size.height = [[pageBoundaries objectAtIndex: pageNumber - 1]
    floatValue] - rect.origin.y;
    }

    return rect;
    }

    The problem is that the view is wider than the printed page and it
    gets clipped.  I'd hoped that the rect I return from rectFromPage
    would be scaled to fit the printed area, but apparently not.  The
    default printing from NSVIew handles this scaling great.  Can someone
    fill in what I'm missing?

    Thanks,
    Greg
  • On Wed, 12 Sep 2007 14:14:38 -0700, Greg Hoover <ghoover...> said:
    > I have an NSTextView that I'm trying to paginate so that lines aren't
    > cut when printing across several pages.  In knowsPageRange I figure
    > out where the page boundaries should be in the view's coordinate
    > system.  Then I've overridden rectForPage as follows:
    >
    > - (NSRect)rectForPage:(int)pageNumber {
    > NSRect rect = [self bounds];
    >
    > if ([pageBoundaries count]) {
    > rect.origin.y = 0;
    > if (pageNumber > 1)
    > rect.origin.y = [[pageBoundaries objectAtIndex: pageNumber - 2]
    > floatValue];
    > rect.size.height = [[pageBoundaries objectAtIndex: pageNumber - 1]
    > floatValue] - rect.origin.y;
    > }
    >
    > return rect;
    > }
    >
    > The problem is that the view is wider than the printed page and it
    > gets clipped.  I'd hoped that the rect I return from rectFromPage
    > would be scaled to fit the printed area, but apparently not.  The
    > default printing from NSVIew handles this scaling great.  Can someone
    > fill in what I'm missing?

    I'm a little hesitant to jump in here, but I *think* the problem lies in
    your sentence "The problem is that the view is wider than the printed page."
    This may betray a misconception about how to print. It is your job to see to
    it that the view is NOT wider than the printed page. Typically, you do this
    by making a view, in real time, specifically for the act of printing, using
    the information about the user's print settings to help you get the size
    right. In other words, my advice would be, don't ask the views in your user
    interface to print themselves; set up a whole new view structure for
    printing purposes, populate it, tell it to print itself, and let it tear
    down again when printing is over. m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • Thanks Matt.  I kind of figured that, but I went another route to
    temporarily solve the problem -- I'm using adjustPageHeight and
    allowing the default NSView implementation take care of the rest.

    Greg
    On Sep 13, 2007, at 12:39 PM, Matt Neuburg wrote:

    > On Wed, 12 Sep 2007 14:14:38 -0700, Greg Hoover <ghoover...>-
    > web.net> said:
    >> I have an NSTextView that I'm trying to paginate so that lines aren't
    >> cut when printing across several pages.  In knowsPageRange I figure
    >> out where the page boundaries should be in the view's coordinate
    >> system.  Then I've overridden rectForPage as follows:
    >>
    >> - (NSRect)rectForPage:(int)pageNumber {
    >> NSRect rect = [self bounds];
    >>
    >> if ([pageBoundaries count]) {
    >> rect.origin.y = 0;
    >> if (pageNumber > 1)
    >> rect.origin.y = [[pageBoundaries objectAtIndex: pageNumber - 2]
    >> floatValue];
    >> rect.size.height = [[pageBoundaries objectAtIndex: pageNumber - 1]
    >> floatValue] - rect.origin.y;
    >> }
    >>
    >> return rect;
    >> }
    >>
    >> The problem is that the view is wider than the printed page and it
    >> gets clipped.  I'd hoped that the rect I return from rectFromPage
    >> would be scaled to fit the printed area, but apparently not.  The
    >> default printing from NSVIew handles this scaling great.  Can someone
    >> fill in what I'm missing?
    >
    > I'm a little hesitant to jump in here, but I *think* the problem
    > lies in
    > your sentence "The problem is that the view is wider than the
    > printed page."
    > This may betray a misconception about how to print. It is your job
    > to see to
    > it that the view is NOT wider than the printed page. Typically, you
    > do this
    > by making a view, in real time, specifically for the act of
    > printing, using
    > the information about the user's print settings to help you get the
    > size
    > right. In other words, my advice would be, don't ask the views in
    > your user
    > interface to print themselves; set up a whole new view structure for
    > printing purposes, populate it, tell it to print itself, and let it
    > tear
    > down again when printing is over. m.
    >
    > --
    > matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    > A fool + a tool + an autorelease pool = cool!
    > One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
    > AppleScript: the Definitive Guide - Second Edition!
    > <http://www.amazon.com/gp/product/0596102119>
    >
    >
    >
previous month september 2007 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