Java Code Examples for org.eclipse.swt.printing.Printer#getDPI()
The following examples show how to use
org.eclipse.swt.printing.Printer#getDPI() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartPrintJob.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * @param printer * @param safetyBorder * @return the rectangle in pixels to print on (and which is also supported * by the printer hardware) */ private Rectangle getPrintableArea(Printer printer, double safetyBorder) { int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x); int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y); Rectangle trim = printer.computeTrim(0, 0, 0, 0); int trimLeft = -trim.x; int trimTop = -trim.y; int trimRight = trim.x + trim.width; int trimBottom = trim.y + trim.height; int marginLeft = Math.max(trimLeft, safetyBorderWidth); int marginRight = Math.max(trimRight, safetyBorderWidth); int marginTop = Math.max(trimTop, safetyBorderHeight); int marginBottom = Math.max(trimBottom, safetyBorderHeight); int availWidth = printer.getClientArea().width - marginLeft - marginRight; int availHeight = printer.getClientArea().height - marginTop - marginBottom; return new Rectangle(marginLeft, marginTop, availWidth, availHeight); }
Example 2
Source File: PaperClips.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Returns the bounding rectangle of the printable area which is inside the * given margins on the paper. The printer's minimum margins are reflected * in the returned rectangle. * * @param printer * the printer device. * @param margins * the desired page margins. * @return the bounding rectangle on the printable area which is within the * margins. */ public static Rectangle getMarginBounds(Margins margins, Printer printer) { Rectangle paperBounds = getPaperBounds(printer); // Calculate the pixel coordinates for the margins Point dpi = printer.getDPI(); int top = paperBounds.y + (margins.top * dpi.y / 72); int left = paperBounds.x + (margins.left * dpi.x / 72); int right = paperBounds.x + paperBounds.width - (margins.right * dpi.x / 72); int bottom = paperBounds.y + paperBounds.height - (margins.bottom * dpi.y / 72); // Enforce the printer's minimum margins. Rectangle printableBounds = getPrintableBounds(printer); if (top < printableBounds.y) top = printableBounds.y; if (left < printableBounds.x) left = printableBounds.x; if (right > printableBounds.x + printableBounds.width) right = printableBounds.x + printableBounds.width; if (bottom > printableBounds.y + printableBounds.height) bottom = printableBounds.y + printableBounds.height; return new Rectangle(left, top, right - left, bottom - top); }
Example 3
Source File: ChartPrintJob.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * @param printer * @param safetyBorder * @return the rectangle in pixels to print on (and which is also supported * by the printer hardware) */ private Rectangle getPrintableArea(Printer printer, double safetyBorder) { int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x); int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y); Rectangle trim = printer.computeTrim(0, 0, 0, 0); int trimLeft = -trim.x; int trimTop = -trim.y; int trimRight = trim.x + trim.width; int trimBottom = trim.y + trim.height; int marginLeft = Math.max(trimLeft, safetyBorderWidth); int marginRight = Math.max(trimRight, safetyBorderWidth); int marginTop = Math.max(trimTop, safetyBorderHeight); int marginBottom = Math.max(trimBottom, safetyBorderHeight); int availWidth = printer.getClientArea().width - marginLeft - marginRight; int availHeight = printer.getClientArea().height - marginTop - marginBottom; return new Rectangle(marginLeft, marginTop, availWidth, availHeight); }
Example 4
Source File: ChartPrintJob.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * @param printer * @param safetyBorder * @return the rectangle in pixels to print on (and which is also supported * by the printer hardware) */ private Rectangle getPrintableArea(Printer printer, double safetyBorder) { int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x); int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y); Rectangle trim = printer.computeTrim(0, 0, 0, 0); int trimLeft = -trim.x; int trimTop = -trim.y; int trimRight = trim.x + trim.width; int trimBottom = trim.y + trim.height; int marginLeft = Math.max(trimLeft, safetyBorderWidth); int marginRight = Math.max(trimRight, safetyBorderWidth); int marginTop = Math.max(trimTop, safetyBorderHeight); int marginBottom = Math.max(trimBottom, safetyBorderHeight); int availWidth = printer.getClientArea().width - marginLeft - marginRight; int availHeight = printer.getClientArea().height - marginTop - marginBottom; return new Rectangle(marginLeft, marginTop, availWidth, availHeight); }
Example 5
Source File: ChartPrintJob.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * @param printer * @param safetyBorder * @return the rectangle in pixels to print on (and which is also supported * by the printer hardware) */ private Rectangle getPrintableArea(Printer printer, double safetyBorder) { int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x); int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y); Rectangle trim = printer.computeTrim(0, 0, 0, 0); int trimLeft = -trim.x; int trimTop = -trim.y; int trimRight = trim.x + trim.width; int trimBottom = trim.y + trim.height; int marginLeft = Math.max(trimLeft, safetyBorderWidth); int marginRight = Math.max(trimRight, safetyBorderWidth); int marginTop = Math.max(trimTop, safetyBorderHeight); int marginBottom = Math.max(trimBottom, safetyBorderHeight); int availWidth = printer.getClientArea().width - marginLeft - marginRight; int availHeight = printer.getClientArea().height - marginTop - marginBottom; return new Rectangle(marginLeft, marginTop, availWidth, availHeight); }
Example 6
Source File: ChartPrintJob.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * @param printer * @param safetyBorder * @return the rectangle in pixels to print on (and which is also supported * by the printer hardware) */ private Rectangle getPrintableArea(Printer printer, double safetyBorder) { int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x); int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y); Rectangle trim = printer.computeTrim(0, 0, 0, 0); int trimLeft = -trim.x; int trimTop = -trim.y; int trimRight = trim.x + trim.width; int trimBottom = trim.y + trim.height; int marginLeft = Math.max(trimLeft, safetyBorderWidth); int marginRight = Math.max(trimRight, safetyBorderWidth); int marginTop = Math.max(trimTop, safetyBorderHeight); int marginBottom = Math.max(trimBottom, safetyBorderHeight); int availWidth = printer.getClientArea().width - marginLeft - marginRight; int availHeight = printer.getClientArea().height - marginTop - marginBottom; return new Rectangle(marginLeft, marginTop, availWidth, availHeight); }
Example 7
Source File: ImageCaptureExample.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Demonstrate capturing the pages of a print to in-memory images. * * @param args * command-line arguments (ignored) */ public static void main(String[] args) { Display display = new Display(); Point displayDPI = display.getDPI(); display.dispose(); Printer printer = new Printer(new PrinterData()); Point printerDPI = printer.getDPI(); try { PrintJob job = new PrintJob("ImageCapture.java", createPrint()); PrintPiece[] pages = PaperClips.getPages(job, printer); ImageLoader imageLoader = new ImageLoader(); for (int i = 0; i < pages.length; i++) { PrintPiece page = pages[i]; Point pageSize = page.getSize(); pageSize.x = pageSize.x * displayDPI.x / printerDPI.x; pageSize.y = pageSize.y * displayDPI.y / printerDPI.y; ImageData pageImage = captureImageData(printer, page, pageSize); // Do something with the image pageImage.scanlinePad = 1; imageLoader.data = new ImageData[] { pageImage }; imageLoader.save(getImageName(i), SWT.IMAGE_JPEG); } } finally { printer.dispose(); } }
Example 8
Source File: PrintUtils.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Computes the print area, including margins * @param printer The printer that will be used to print the chart * @return The print area */ public static Rectangle computePrintArea(Printer printer) { // Get the printable area Rectangle rect = printer.getClientArea(); // Compute the trim Rectangle trim = printer.computeTrim(0, 0, 0, 0); // Get the printer's DPI Point dpi = printer.getDPI(); dpi.x = dpi.x / 2; dpi.y = dpi.y / 2; // Calculate the printable area, using 1 inch margins int left = trim.x + dpi.x; if (left < rect.x) left = rect.x; int right = (rect.width + trim.x + trim.width) - dpi.x; if (right > rect.width) right = rect.width; int top = trim.y + dpi.y; if (top < rect.y) top = rect.y; int bottom = (rect.height + trim.y + trim.height) - dpi.y; if (bottom > rect.height) bottom = rect.height; return new Rectangle(left, top, right - left, bottom - top); }
Example 9
Source File: PrintUtils.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * * @param printer The printer that will be used to print the chart * @return Amount to scale the screen resolution by, to match the printer * resolution. */ public static Point computeScaleFactor(Printer printer) { Point screenDPI = Display.getDefault().getDPI(); Point printerDPI = printer.getDPI(); int scaleFactorX = printerDPI.x / screenDPI.x; int scaleFactorY = printerDPI.y / screenDPI.y; return new Point(scaleFactorX, scaleFactorY); }
Example 10
Source File: GridLayerPrinter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Amount to scale the screen resolution by, to match the printer the * resolution. */ private Point computeScaleFactor(Printer printer) { Point screenDPI = Display.getDefault().getDPI(); Point printerDPI = printer.getDPI(); int scaleFactorX = printerDPI.x / screenDPI.x; int scaleFactorY = printerDPI.y / screenDPI.y; return new Point(scaleFactorX, scaleFactorY); }
Example 11
Source File: GridLayerPrinter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Computes the print area, including margins */ private static Rectangle computePrintArea(Printer printer) { // Get the printable area Rectangle rect = printer.getClientArea(); // Compute the trim Rectangle trim = printer.computeTrim(0, 0, 0, 0); // Get the printer's DPI Point dpi = printer.getDPI(); dpi.x = dpi.x / 2; dpi.y = dpi.y / 2; // Calculate the printable area, using 1 inch margins int left = trim.x + dpi.x; if (left < rect.x) left = rect.x; int right = (rect.width + trim.x + trim.width) - dpi.x; if (right > rect.width) right = rect.width; int top = trim.y + dpi.y; if (top < rect.y) top = rect.y; int bottom = (rect.height + trim.y + trim.height) - dpi.y; if (bottom > rect.height) bottom = rect.height; return new Rectangle(left, top, right - left, bottom - top); }
Example 12
Source File: GridLayerPrinter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Amount to scale the screen resolution by, to match the printer the * resolution. */ private Point computeScaleFactor(Printer printer) { Point screenDPI = Display.getDefault().getDPI(); Point printerDPI = printer.getDPI(); int scaleFactorX = printerDPI.x / screenDPI.x; int scaleFactorY = printerDPI.y / screenDPI.y; return new Point(scaleFactorX, scaleFactorY); }
Example 13
Source File: GridLayerPrinter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Computes the print area, including margins */ private static Rectangle computePrintArea(Printer printer) { // Get the printable area Rectangle rect = printer.getClientArea(); // Compute the trim Rectangle trim = printer.computeTrim(0, 0, 0, 0); // Get the printer's DPI Point dpi = printer.getDPI(); dpi.x = dpi.x / 2; dpi.y = dpi.y / 2; // Calculate the printable area, using 1 inch margins int left = trim.x + dpi.x; if (left < rect.x) left = rect.x; int right = (rect.width + trim.x + trim.width) - dpi.x; if (right > rect.width) right = rect.width; int top = trim.y + dpi.y; if (top < rect.y) top = rect.y; int bottom = (rect.height + trim.y + trim.height) - dpi.y; if (bottom > rect.height) bottom = rect.height; return new Rectangle(left, top, right - left, bottom - top); }