Re: Reports via NSView and NSString drawAtPoint:
Re: Reports via NSView and NSString drawAtPoint:
- Subject: Re: Reports via NSView and NSString drawAtPoint:
- From: J Tichenor <email@hidden>
- Date: Mon, 11 Oct 2004 08:56:46 +0100
Sounds like you are going down the same road, which is good. Thanks for the code. After reading through your example, I realized one big problem I'm going to have is the drawAtPoint: method precludes situations where I have more than a few words worth of data. What I need is something that will grow and contract depending on the amount of text that needs to be printed. Maybe some use of NSCells? Or as a few people off list have suggested, NSLayoutManager, etc.
But at least I know that I am on the right track. Cheers for that. the overridden -isFlipped solved all problems with size of view, etc. Just need to do more research.
J
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
_______________________________________________
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