recalculate margins every time the paper type changes, do not stick to thos calculated on the default in init

This commit is contained in:
Riccardo Mottola 2025-04-11 09:24:28 +02:00
parent 2e5f204d6a
commit 4f54f4d6cf

View file

@ -133,6 +133,20 @@ static NSPrintInfo *sharedPrintInfo = nil;
[[principalClass printInfoClass] setDefaultPrinter: printer];
}
- (void) _updateMargins
{
NSPrinter *printer = [self printer];
NSRect imageableRect;
NSSize paperSize;
paperSize = [printer pageSizeForPaper: [self paperName]];
imageableRect = [printer imageRectForPaper: [self paperName]];
[self setRightMargin: (paperSize.width - NSMaxX(imageableRect))];
[self setLeftMargin: imageableRect.origin.y];
[self setTopMargin: (paperSize.height - NSMaxY(imageableRect))];
[self setBottomMargin: imageableRect.origin.x];
}
//
// Instance methods
//
@ -143,8 +157,6 @@ static NSPrintInfo *sharedPrintInfo = nil;
{
NSPrinter *printer;
NSString *pageSize;
NSRect imageRect;
NSSize paperSize;
if (!(self = [super init]))
{
@ -174,14 +186,10 @@ static NSPrintInfo *sharedPrintInfo = nil;
[self setPaperName: pageSize];
/* Set default margins. */
paperSize = [printer pageSizeForPaper: pageSize];
imageRect = [printer imageRectForPaper: pageSize];
[self setRightMargin: (paperSize.width - NSMaxX(imageRect))];
[self setLeftMargin: imageRect.origin.y];
[self setTopMargin: (paperSize.height - NSMaxY(imageRect))];
[self setBottomMargin: imageRect.origin.x];
[self setOrientation: NSPortraitOrientation];
[self _updateMargins];
[self setOrientation: NSPortraitOrientation];
if (aDict != nil)
{
[_info addEntriesFromDictionary: aDict];
@ -293,6 +301,7 @@ static NSPrintInfo *sharedPrintInfo = nil;
[_info setObject: [NSValue valueWithSize:
[NSPrintInfo sizeForPaperName: name]]
forKey: NSPrintPaperSize];
[self _updateMargins];
}
- (void) setPaperSize: (NSSize)size