• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hillegass printing challenge
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hillegass printing challenge


  • Subject: Re: Hillegass printing challenge
  • From: Graham Cox <email@hidden>
  • Date: Fri, 19 Feb 2010 11:13:21 +1100

On 19/02/2010, at 6:06 AM, Michael de Haan wrote:

> Hi all,
> May I ask about an issue I am having adding page numbers to a print out.
> I implemented the following method:
>
>
> - (void)drawPageBorderWithSize:(NSSize)borderSize
> {
>   // NSPrintOperation *po = [NSPrintOperation currentOperation];
>    //NSPrintInfo *pi = [po printInfo];
>
>    NSRect currentFrame = [self frame];
>    NSRect newFrame= NSMakeRect(0, 0, borderSize.width, borderSize.height);
>    [self setFrame:newFrame];
>
>    NSFont *f = [attributes objectForKey:NSFontAttributeName];
>    float capHeigth = [ f capHeight];
>    NSString *string = [ NSString stringWithFormat:@"Page %d", currentPage + 1];
>    float stringX = (borderSize.width - (float)[string length])/2.0;
>    [self lockFocus];
>    [string drawAtPoint:NSMakePoint(stringX, borderSize.height - (1.7 * capHeigth))
>    withAttributes:attributes];
>    [self unlockFocus];
>    [self setFrame:currentFrame];
> }
>
>
> A while ago, there were questions to the list about printInfo "margin" calls. At that time, it appears  the consensus was that these calls are buggy. I think they still are, as my code showed that the margins returned bore no relationship to the margins set in page Setup.  As a workaround, I used the above approach. What do others do to deduce the user's margin settings....or it's possible that I am missing something else.


Hi Michael,

I'm not sure that they're buggy, it's just they don't return what you think they do, or what their name appears to imply. I added the following to NSPrintInfo as a category so I can get the actual paper margins set in Page Setup, it might come in handy for you too.



enum
{
	PrintInfoTopMarginIndex		= 0,
	PrintInfoLeftMarginIndex	= 1,
	PrintInfoBottomMarginIndex	= 2,
	PrintInfoRightMarginIndex	= 3
};


@implementation NSPrintInfo (PaperMargins)


- (NSArray*)	paperMargins
{
	PMPageFormat	format = (PMPageFormat)[self PMPageFormat];
	PMPaper		paper;
	OSStatus	err = PMGetPageFormatPaper( format, &paper );

	if( err == noErr )
	{
		PMPaperMargins	margins;
		err = PMPaperGetMargins( paper, &margins );

		if( err == noErr )
		{
			NSMutableArray* array = [NSMutableArray array];
			[array addObject:[NSNumber numberWithDouble:margins.top]];
			[array addObject:[NSNumber numberWithDouble:margins.left]];
			[array addObject:[NSNumber numberWithDouble:margins.bottom]];
			[array addObject:[NSNumber numberWithDouble:margins.right]];

			return array;
		}
	}

	return nil;
}



- (double)		topPaperMargin
{
	return [[[self paperMargins] objectAtIndex:PrintInfoTopMarginIndex] doubleValue];
}



- (double)		leftPaperMargin
{
	return [[[self paperMargins] objectAtIndex:PrintInfoLeftMarginIndex] doubleValue];
}



- (double)		bottomPaperMargin
{
	return [[[self paperMargins] objectAtIndex:PrintInfoBottomMarginIndex] doubleValue];
}



- (double)		rightPaperMargin
{
	return [[[self paperMargins] objectAtIndex:PrintInfoRightMarginIndex] doubleValue];
}


@end


--Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Hillegass printing challenge
      • From: Joanna Carter <email@hidden>
References: 
 >Hillegass printing challenge (From: Michael de Haan <email@hidden>)

  • Prev by Date: Re: NSTableView with PopUpButtonCell column with different content per row
  • Next by Date: NSTableColumn's 'fontSize' Binding: Just Doesn't Work?
  • Previous by thread: Hillegass printing challenge
  • Next by thread: Re: Hillegass printing challenge
  • Index(es):
    • Date
    • Thread