Java Code Examples for org.eclipse.swt.printing.Printer#computeTrim()

The following examples show how to use org.eclipse.swt.printing.Printer#computeTrim() . 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 vote down vote up
/**
 * @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: ChartPrintJob.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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 3
Source File: ChartPrintJob.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * @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 ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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: PrintUtils.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: GridLayerPrinter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 8
Source File: GridLayerPrinter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 9
Source File: PaperClips.java    From nebula with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the bounding rectangle of the paper, including non-printable
 * margins.
 * 
 * @param printer
 *            the printer device.
 * @return a rectangle whose edges correspond to the edges of the paper.
 */
public static Rectangle getPaperBounds(Printer printer) {
	Rectangle rect = getPrintableBounds(printer);
	return printer.computeTrim(rect.x, rect.y, rect.width, rect.height);
}