Re: Reports via NSView and NSString drawAtPoint:
Re: Reports via NSView and NSString drawAtPoint:
- Subject: Re: Reports via NSView and NSString drawAtPoint:
- From: Don Arbow <email@hidden>
- Date: Sun, 10 Oct 2004 12:01:09 -0700
Just a few thoughts here, I'm working on a similar project for my company that allows users to enter data, then produce a printed report. The report is fairly simple, spreadsheet-like, with fixed height rows.
First, my custom view is flipped so I can draw from the top-left down. For me, it's much easier to visualize and calculate positions.
Second, the view's drawRect: method passes a rect where you should draw, it is clipped so there is no worry about writing outside the bounds.You should check for rect intersection between that rect and the items you are drawing, no need to draw items that can't be seen on screen. I stop drawing once my current row position is greater than the bottom of the given rect (and conversely, only start drawing when my row position is greater than the rect top).
You should implement rectForPage: (and knowsPageRange:) in your custom view. This is used for printing (and helps so that a user can print just page x out of many pages). But it also helps so that you can treat each page's items as if they are being drawn on a page whose origin is 0,0 and then just offset the items with the y origin of the rect from rectForPage:.
When you go from on screen displaying to printing, your view needs to be able to easily calculate the total number of pages required based on the amount of data. In my application, I can determine the number of pages needed by dividing the total number of rows in the dataArray by the number of lines allowed per page.
Here's a condensed fragment from my drawRect: method:
for (pageNum = 0; pageNum < [self pageCount]; pageNum++) {
pageBounds = [self rectForPage:(pageNum + 1)];
// Don't draw what we can't see
if (!NSIntersectsRect(rect, pageBounds))
continue;
// Calculate the line range for this page
start = pageNum * LINES_PER_PAGE;
lineRange = NSMakeRange(start,
(rowCount > start + LINES_PER_PAGE ?
LINES_PER_PAGE : rowCount - start));
// Draw the page
[self drawPage:lineRange withRect:pageBounds];
}
Don
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden