diff options
author | Silenio Quarti <silenio> | 2008-07-23 15:54:10 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2008-07-23 15:54:10 +0000 |
commit | 2a447588a179054091314399b72570ae1bcbc552 (patch) | |
tree | 66401240b44d36b288d04f95fab47e43db15a9d7 /bundles/org.eclipse.swt/Eclipse SWT Printing | |
parent | 60a876126c9f4ab79a77ebcdd68cbfb8a249a5f0 (diff) | |
download | eclipse.platform.swt-2a447588a179054091314399b72570ae1bcbc552.tar.gz eclipse.platform.swt-2a447588a179054091314399b72570ae1bcbc552.tar.xz eclipse.platform.swt-2a447588a179054091314399b72570ae1bcbc552.zip |
219133 - printer.getDPI() returns 72x72
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Printing')
2 files changed, 55 insertions, 23 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/carbon/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/carbon/org/eclipse/swt/printing/Printer.java index b40af5194b..772c1fa278 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Printing/carbon/org/eclipse/swt/printing/Printer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/carbon/org/eclipse/swt/printing/Printer.java @@ -12,11 +12,8 @@ package org.eclipse.swt.printing; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.CFRange; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.PMRect; -import org.eclipse.swt.internal.carbon.PMResolution; -import org.eclipse.swt.internal.carbon.Rect; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.internal.carbon.*; /** * Instances of this class are used to print to a printer. @@ -113,6 +110,9 @@ static String getCurrentPrinterName(int printSession) { } return result; } +Point getIndependentDPI() { + return super.getDPI(); +} static String getString(int ptr) { int length = OS.CFStringGetLength(ptr); char [] buffer = new char[length]; @@ -233,7 +233,12 @@ public Rectangle computeTrim(int x, int y, int width, int height) { PMRect paperRect = new PMRect(); OS.PMGetAdjustedPageRect(pageFormat, pageRect); OS.PMGetAdjustedPaperRect(pageFormat, paperRect); - return new Rectangle(x+(int)paperRect.left, y+(int)paperRect.top, width+(int)(paperRect.right-pageRect.right), height+(int)(paperRect.bottom-pageRect.bottom)); + Point dpi = getDPI(), screenDPI = getIndependentDPI(); + x += paperRect.left * dpi.x / screenDPI.x; + y += paperRect.top * dpi.y / screenDPI.y; + width += ((paperRect.right-paperRect.left)-(pageRect.right-pageRect.left)) * dpi.x / screenDPI.x; + height += ((paperRect.bottom-paperRect.top)-(pageRect.bottom-pageRect.top)) * dpi.y / screenDPI.y; + return new Rectangle(x, y, width, height); } /** @@ -527,7 +532,14 @@ public void endPage() { public Point getDPI() { checkDevice(); PMResolution resolution = new PMResolution(); - OS.PMGetResolution(pageFormat, resolution); + if (OS.VERSION >= 0x1050) { + int[] printer = new int[1]; + OS.PMSessionGetCurrentPrinter(printSession, printer); + OS.PMPrinterGetOutputResolution(printer[0], printSettings, resolution); + } + if (resolution.hRes == 0 || resolution.vRes == 0) { + OS.PMGetResolution(pageFormat, resolution); + } return new Point((int)resolution.hRes, (int)resolution.vRes); } @@ -550,7 +562,8 @@ public Rectangle getBounds() { checkDevice(); PMRect paperRect = new PMRect(); OS.PMGetAdjustedPaperRect(pageFormat, paperRect); - return new Rectangle(0, 0, (int)(paperRect.right-paperRect.left), (int)(paperRect.bottom-paperRect.top)); + Point dpi = getDPI(), screenDPI = getIndependentDPI(); + return new Rectangle(0, 0, (int)((paperRect.right-paperRect.left) * dpi.x / screenDPI.x), (int)((paperRect.bottom-paperRect.top) * dpi.x / screenDPI.x)); } /** @@ -574,7 +587,8 @@ public Rectangle getClientArea() { checkDevice(); PMRect pageRect = new PMRect(); OS.PMGetAdjustedPageRect(pageFormat, pageRect); - return new Rectangle(0, 0, (int)(pageRect.right-pageRect.left), (int)(pageRect.bottom-pageRect.top)); + Point dpi = getDPI(), screenDPI = getIndependentDPI(); + return new Rectangle(0, 0, (int)((pageRect.right-pageRect.left) * dpi.x / screenDPI.x), (int)((pageRect.bottom-pageRect.top) * dpi.x / screenDPI.x)); } /** @@ -636,9 +650,13 @@ void setupNewPage() { if (context != buffer[0]) SWT.error(SWT.ERROR_UNSPECIFIED); } PMRect paperRect= new PMRect(); + PMRect pageRect= new PMRect(); OS.PMGetAdjustedPaperRect(pageFormat, paperRect); + OS.PMGetAdjustedPageRect(pageFormat, pageRect); + OS.CGContextTranslateCTM(context, (float)-paperRect.left, (float)(paperRect.bottom-paperRect.top) + (float)paperRect.top); OS.CGContextScaleCTM(context, 1, -1); - OS.CGContextTranslateCTM(context, 0, -(float)(paperRect.bottom-paperRect.top)); + Point dpi = getDPI(), screenDPI = getIndependentDPI(); + OS.CGContextScaleCTM(context, screenDPI.x / (float)dpi.x, screenDPI.y / (float)dpi.y); OS.CGContextSetStrokeColorSpace(context, colorspace); OS.CGContextSetFillColorSpace(context, colorspace); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java index 1da4053f2c..e94e5bb5dd 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java @@ -162,10 +162,11 @@ public Rectangle computeTrim(int x, int y, int width, int height) { checkDevice(); NSSize paperSize = printInfo.paperSize(); NSRect bounds = printInfo.imageablePageBounds(); - x -= bounds.x; - y -= bounds.y; - width += paperSize.width - bounds.width; - height += paperSize.height - bounds.height; + Point dpi = getDPI (), screenDPI = getIndependentDPI(); + x -= (bounds.x * dpi.x / screenDPI.x); + y -= (bounds.y * dpi.y / screenDPI.y); + width += (paperSize.width - bounds.width) * dpi.x / screenDPI.x; + height += (paperSize.height - bounds.height) * dpi.y / screenDPI.y; return new Rectangle(x, y, width, height); } @@ -177,8 +178,6 @@ public Rectangle computeTrim(int x, int y, int width, int height) { */ protected void create(DeviceData deviceData) { data = (PrinterData)deviceData; - printer = NSPrinter.static_printerWithName_(NSString.stringWith(data.name)); - printer.retain(); if (data.otherData != null) { NSData nsData = NSData.dataWithBytes(data.otherData, data.otherData.length); printInfo = new NSPrintInfo(NSKeyedUnarchiver.unarchiveObjectWithData(nsData).id); @@ -186,7 +185,11 @@ protected void create(DeviceData deviceData) { printInfo = NSPrintInfo.sharedPrintInfo(); } printInfo.retain(); - printInfo.setPrinter(printer); + printer = NSPrinter.static_printerWithName_(NSString.stringWith(data.name)); + if (printer != null) { + printer.retain(); + printInfo.setPrinter(printer); + } /* * Bug in Cocoa. For some reason, the output still goes to the printer when * the user chooses the preview button. The fix is to reset the job disposition. @@ -242,6 +245,7 @@ public int internal_new_GC(GCData data) { data.background = getSystemColor(SWT.COLOR_WHITE).handle; data.foreground = getSystemColor(SWT.COLOR_BLACK).handle; data.font = getSystemFont (); + data.size = printInfo.paperSize(); isGCCreated = true; } return operation.context().id; @@ -303,6 +307,7 @@ public boolean startJob(String jobName) { if (jobName != null && jobName.length() != 0) { operation.setJobTitle(NSString.stringWith(jobName)); } + printInfo.setUpPrintOperationDefaultValues(); NSPrintOperation.setCurrentOperation(operation); NSGraphicsContext context = operation.createContext(); if (context != null) { @@ -380,10 +385,13 @@ public boolean startPage() { rect.width = paperSize.width; rect.height = paperSize.height; view.beginPageInRect(rect, new NSPoint()); - NSBezierPath.bezierPathWithRect(rect).setClip(); + NSRect imageBounds = printInfo.imageablePageBounds(); + NSBezierPath.bezierPathWithRect(imageBounds).setClip(); NSAffineTransform transform = NSAffineTransform.transform(); - transform.translateXBy(0, rect.height); + transform.translateXBy(imageBounds.x, rect.height - imageBounds.y); transform.scaleXBy(1, -1); + Point dpi = getDPI (), screenDPI = getIndependentDPI(); + transform.scaleXBy(screenDPI.x / (float)dpi.x, screenDPI.y / (float)dpi.y); transform.concat(); return true; } @@ -417,8 +425,12 @@ public void endPage() { */ public Point getDPI() { checkDevice(); - //TODO - return new Point(72, 72); + //TODO get output resolution + return getIndependentDPI(); +} + +Point getIndependentDPI() { + return super.getDPI(); } /** @@ -439,7 +451,8 @@ public Point getDPI() { public Rectangle getBounds() { checkDevice(); NSSize size = printInfo.paperSize(); - return new Rectangle (0, 0, (int)size.width, (int)size.height); + Point dpi = getDPI (), screenDPI = getIndependentDPI(); + return new Rectangle (0, 0, (int)(size.width * dpi.x / screenDPI.x), (int)(size.height * dpi.y / screenDPI.y)); } /** @@ -462,7 +475,8 @@ public Rectangle getBounds() { public Rectangle getClientArea() { checkDevice(); NSRect rect = printInfo.imageablePageBounds(); - return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); + Point dpi = getDPI (), screenDPI = getIndependentDPI(); + return new Rectangle(0, 0, (int)(rect.width * dpi.x / screenDPI.x), (int)(rect.height * dpi.y / screenDPI.y)); } /** |