detecting valid paper name?
detecting valid paper name?
- Subject: detecting valid paper name?
- From: Ken Victor <email@hidden>
- Date: Fri, 16 Sep 2005 18:52:15 -0700
i'm developing a highly scriptable app and i'm letting the user set
the page setup via a set script command. eg:
set default page setup for document 1 to {property:value, ...}
where property can be paper name, paper width, paper height,
orientation, or scale. the first problem i'm having is validating
that the user has specified an acceptable paper name, since the user
has a localized name, and all the NSPrinter apis use an internal
name. the following routine seems to work, but i'm not at all sure if
it is correct! can anyone tell me one way or the other if it is? or
if there is a better or faster way to accomplish this.
-(BOOL) validUserPaperName: (NSString*) userPaperName {
NSEnumerator* en = [[NSPrinter printerNames] objectEnumerator];
BOOL result = NO;
while (NSString* printerName = [en nextObject]) {
NSPrinter* aPrinter = [NSPrinter printerWithName: printerName];
NSArray* ppdKeys = [aPrinter stringListForKey: @"PageSize"
inTable: @"PPD"];
if ([ppdKeys count])
{
NSEnumerator* en2 = [ppdKeys objectEnumerator];
while (NSString* aPPDKey = [en2 nextObject])
{
NSString* optionKey = [NSString stringWithFormat:
@"PageSize/%@", aPPDKey];
NSArray* options = [aPrinter stringListForKey: optionKey
inTable: @"PPDOptionTranslation"];
NSEnumerator* en3 = [options objectEnumerator];
while (NSString* optionName = [en3 nextObject])
{
if ([optionName isEqualToString: userPaperName])
{
NSSize paperSize = [aPrinter pageSizeForPaper: aPPDKey];
if (result = ((paperSize.height != 0) && (paperSize.width != 0)))
break;
}
}
if (result)
break;
}
}
if (result)
break;
}
return result;
}
the other, but fairly minor problem i have is that the page
setup/layout dialog provides 3 options for orientation: portrait and
two variants of landscape, yet the NSPrintInfo dictionary only
provides the two keys for NSPrintOrientation: NSPortraitOrientation
and NSLandscapeOrientation. is the 3rd option (2nd landscape option)
supposed to be ignored?
thanx for any help,
ken
_______________________________________________
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