Trouble with knowsPageRank:

  • Hi,

    I've a lot of data sets to print. But I don't know how tall the rect
    for a data set is until it is printed. This is because a field in the
    data set can have free text, which could be very long[1], and
    therefore I don't know how tall is the line until it is
    calculated.

    So I really don't know the size of the NSView to print until I go
    thru all of the data sets.

    The function *knowsPageRange:* now is the problem. It looks strange
    to me that I've to do the same calculations twice: one time for
    *knowsPageRange* and one time the same again for *drawRect:*

    Is there a simple way to avoid the double calculations? It looks very
    inefficient to me.

    Regards,
    Konni

    [1] I solved this by linking a new subview to the printed view. This
    NSTextView holds the free text and I get the size of this
    NSTextView from the corrosponding layoutManager. Better solutions are
    welcome.
  • On Thu, 14 Dec 2006 12:51:59 +0100, Konni Scheller <konni...>
    said:
    > Hi,
    >
    > I've a lot of data sets to print. But I don't know how tall the rect
    > for a data set is until it is printed. This is because a field in the
    > data set can have free text, which could be very long[1], and
    > therefore I don't know how tall is the line until it is
    > calculated.
    >
    > So I really don't know the size of the NSView to print until I go
    > thru all of the data sets.
    >
    > The function *knowsPageRange:* now is the problem. It looks strange
    > to me that I've to do the same calculations twice: one time for
    > *knowsPageRange* and one time the same again for *drawRect:*
    >
    > Is there a simple way to avoid the double calculations? It looks very
    > inefficient to me.

    One solution is not to use knowsPageRange for this. Just use the
    adjustPageHeightNew: mechanism. This is a wonderful device because the call
    is automatically passed along to all subviews of your main printing view. So
    if every block of material that is to be printed is itself a subview, then
    any subview can say where to split itself (or can prevent itself from being
    split). If every block of material knows how to draw itself and how to split
    itself (or prevent itself from being split), then printing just happens, and
    it just happens once; in fact, your main printing view's drawRect can be
    empty.

    m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>