RE: Print 2 pages from customview
RE: Print 2 pages from customview
- Subject: RE: Print 2 pages from customview
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Mon, 29 Dec 2003 12:38:16 -0500
I think one problem may be that you are printing outside the imageable area
of your printer. You've set the margins to 1 point. Most printers can't
get closer to the edge than 18 points. Check out -[NSPrintInfo
imageablePageBounds];
Also, your rectForPage method has an error.
>
- (NSRect)rectForPage:(int)pageNum {
>
NSRect frontRect = NSMakeRect([self bounds].origin.x, [self
>
bounds].origin.y, [self bounds].size.width, [self
>
bounds].size.height/2.0);
This seems fine. You want a rectangle that is half the height of your view,
starting from the origin. The origin of the bounds rectangle is always
{0,0}, so you could have done NSMakeRect(0.0, 0.0, width, height/2.0)
>
NSRect backRect = NSMakeRect([self bounds].origin.x, [self
>
bounds].size.height/2.0, [self bounds].size.width, [self
>
bounds].size.height);
This seems wrong. You want the height to be height/2.0, not height.
>
>
if (pageNum == 1)
>
return frontRect;
>
else
>
return backRect;
>
}
This is OK, but you'll find your code a little more useful and
comprehensible if you do it this way:
- (NSRect) rectForPage:(int)pageNum
{
float pageHeight = 760.0;
float pageWidth = 595.0;
return NSMakeRect(0.0, (pageNum - 1) * pageHeight, pageWidth, pageHeight);
}
Third, how sure are you about the height of your view? Is it possible that
it is really 2400 high or so? Try putting this code relatively early in
your print method:
[self setFrameSize:NSMakeSize(595, 1520)];
You also might try using NSLog to see what the bounds are.
Finally, what is the deal with your drawRect method? You don't use myBounds
for anything, and you don't loop. Why not this?
- (void)drawRect:(NSRect)rect
{
NSDictionary *attributes = [NSDictionary dictionary];
float x;
NSPoint point = NSMakePoint(200.0, 10.0);
[NSStringFromPoint(point) drawAtPoint:point withAttributes:attributes];
for (x = 100.0; x < [self bounds].size.height; x += 100.0)
{
point = NSMakePoint(200.0,x);
[NSStringFromPoint(point) drawAtPoint:point withAttributes:attributes];
}
}
Jonathan
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Ivan Myrvold
>
Sent: Monday, December 29, 2003 9:36 AM
>
To: email@hidden
>
Subject: Print 2 pages from customview
>
>
>
I have problems with printing of a custom view. I must have
>
misunderstood some fundamental things about printing in Cocoa.
>
Here is what I tries to do:
>
>
In IB a have made a custom view in a window, with the size of the
>
custom view being w 595 and h 1520. That should be about two A4 pages
>
high.
>
>
My window size is only of height 760, so I can only see the first page.
>
Running the application, the first page shows up nicely in the window.
>
I have no need to see the second page.
>
>
But when I print out the two pages, the second page is supposed to
>
start with the line with the (200, 800), but in fact the first line I
>
can see is the line with (200, 1200) Where have the other lines
>
disappeared. And the last line printed is about in the middle of the
>
page with (200, 1500). The first page is OK. Can anyone see what is
>
wrong here? I have been scratching my head all day over this, and can't
>
see what's wrong:
>
In my subclassed custom view, I have these routines:
>
>
- (void)drawRect:(NSRect)rect {
>
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
>
NSRect myBounds;
>
>
myBounds = NSMakeRect(0.0, 0.0, 595.0, 1520);
>
[@"NSMakePoint(200, 10)" drawAtPoint:NSMakePoint(200, 10)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 100)" drawAtPoint:NSMakePoint(200, 100)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 200)" drawAtPoint:NSMakePoint(200, 200)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 300)" drawAtPoint:NSMakePoint(200, 300)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 400)" drawAtPoint:NSMakePoint(200, 400)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 500)" drawAtPoint:NSMakePoint(200, 500)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 600)" drawAtPoint:NSMakePoint(200, 600)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 700)" drawAtPoint:NSMakePoint(200, 700)
>
withAttributes:attributes];
>
// here the second page is to begin
>
[@"NSMakePoint(200, 800)" drawAtPoint:NSMakePoint(200, 800)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 900)" drawAtPoint:NSMakePoint(200, 900)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1000)" drawAtPoint:NSMakePoint(200, 1000)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1100)" drawAtPoint:NSMakePoint(200, 1100)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1200)" drawAtPoint:NSMakePoint(200, 1200)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1300)" drawAtPoint:NSMakePoint(200, 1300)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1400)" drawAtPoint:NSMakePoint(200, 1400)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1500)" drawAtPoint:NSMakePoint(200, 1500)
>
withAttributes:attributes];
>
[@"NSMakePoint(200, 1600)" drawAtPoint:NSMakePoint(200, 1600)
>
withAttributes:attributes];
>
}
>
>
- (BOOL)knowsPageRange:(NSRange *)rptr {
>
rptr->location = 1;
>
rptr->length = 2;
>
return YES;
>
}
>
>
- (NSRect)rectForPage:(int)pageNum {
>
NSRect frontRect = NSMakeRect([self bounds].origin.x, [self
>
bounds].origin.y, [self bounds].size.width, [self
>
bounds].size.height/2.0);
>
NSRect backRect = NSMakeRect([self bounds].origin.x, [self
>
bounds].size.height/2.0, [self bounds].size.width, [self
>
bounds].size.height);
>
>
if (pageNum == 1)
>
return frontRect;
>
else
>
return backRect;
>
}
>
>
- (IBAction)print:(id)sender {
>
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
>
>
[printInfo setLeftMargin:1.0];
>
[printInfo setRightMargin:1.0];
>
[printInfo setTopMargin:1.0];
>
[printInfo setBottomMargin:1.0];
>
NSPrintOperation *printOp = [NSPrintOperation
>
printOperationWithView:self printInfo:printInfo];
>
[printOp setShowPanels:YES];
>
[printOp runOperation];
>
}
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.