Re: A4 and NSMakeRect
Re: A4 and NSMakeRect
- Subject: Re: A4 and NSMakeRect
- From: Matt Gemmell <email@hidden>
- Date: Sun, 27 Jul 2003 16:14:45 +0100
On 27/7/03 at 12:28 pm, Sanri Parov said:
>
I'm going to print some informations from the database of my project
>
using an hidden NSTextView such as this:
>
>
[[NSTextView alloc]initWithFrame:NSMakeRect(0.0,0.0 ,x,y)];
>
>
The point is that I want the rectangle to be large exactly 1
>
centimetre less than the normal borders of a common A4 paper sheet.
>
What are the values I have to insert into NSMakeRect's 'x' and 'y'?
Hi Sanri,
Generally speaking, it's not a good idea to hard-code a paper-size for
printing. If your app is document-based, you get all the Page Setup
functionality completely for free, and it's easy to make use of. The
user may want to print the data on any number of kinds of paper, so
forcing A4 with 1cm margins may not be the best strategy. If at all
possible, let the user choose the paper-size.
With that obligatory lecture out of the way, for A4 with 1cm margins, I
think the pixel dimensions you'd want would be about 451w x 662h
(actually slightly less, since those are the default A4 settings, using
0.63cm margins top left and right and 1.4cm bottom, instead of your 1cm
all round).
Now, having said all that, I wouldn't do it that way anyway. :)
NSTextView knows how to paginate text reasonably well, and you should
take advantage of that. What I usually do when printing an NSTextView's
contents is this:
1. Obtain the NSPrintInfo for whatever I'm printing. If your app is
document-based, you can ask your NSDocument subclass for its -printInfo.
This will reflect any changes the user has made in Page Setup.
2. Set up the printInfo for sensible text-printing behaviour:
[printInfo setHorizontalPagination:NSAutoPagination];
[printInfo setVerticalPagination:NSAutoPagination];
[printInfo setVerticallyCentered:NO];
3. Create your temporary NSTextView with the appropriate width, and with
height 0. If you're not overriding the default paper size, try using
this for the width:
([printInfo paperSize].width - [printInfo leftMargin] -
[printInfo rightMargin]) - 1)
4. I then always explicitly set these:
[tempTextView setHorizontallyResizable:NO];
[tempTextView setVerticallyResizable:YES];
5. Now put appropriate text into the tempTextView, probably using this:
[[tempView textStorage] setAttributedString: ... ];
The NSTextView will vertically resize itself to accommodate all the text
at its current width.
6. Go ahead and print. The NSTextView will paginate the text sensibly.
printOp = [NSPrintOperation printOperationWithView:tempTextView
printInfo:printInfo];
[printOp setShowPanels:flag];
[printOp runOperation];
7. Don't forget to release the temporary NSTextView.
Some variation of that should work fairly well.
Cheers,
-Matt
--
Matt Gemmell
Irate Scotsman
http://www.scotlandsoftware.com/blog/
_______________________________________________
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.