当前位置: 首页>>代码示例>>Java>>正文


Java Printer.computeTrim方法代码示例

本文整理汇总了Java中org.eclipse.swt.printing.Printer.computeTrim方法的典型用法代码示例。如果您正苦于以下问题:Java Printer.computeTrim方法的具体用法?Java Printer.computeTrim怎么用?Java Printer.computeTrim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.swt.printing.Printer的用法示例。


在下文中一共展示了Printer.computeTrim方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPrintableArea

import org.eclipse.swt.printing.Printer; //导入方法依赖的package包/类
/**
 * @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);
}
 
开发者ID:mdzio,项目名称:ccu-historian,代码行数:28,代码来源:ChartPrintJob.java

示例2: getPrinterArea

import org.eclipse.swt.printing.Printer; //导入方法依赖的package包/类
protected TGRectangle getPrinterArea(Printer printer, float margin) {
	Rectangle clientArea = printer.getClientArea();
	Rectangle trim = printer.computeTrim(0, 0, 0, 0);
	Point dpi = printer.getDPI();
	
	float x = (trim.x + (dpi.x * margin));
	float y = (trim.y + (dpi.y * margin));
	float width = ((clientArea.width + trim.width) - (dpi.x * margin));
	float height = ((clientArea.height + trim.height) - (dpi.y * margin));
	
	return new TGRectangle(x, y, width, height);
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:13,代码来源:TGPrintAction.java

示例3: initialize

import org.eclipse.swt.printing.Printer; //导入方法依赖的package包/类
public static void initialize( Printer printer )
{
	Rectangle bounds = printer.getClientArea();
	Rectangle trim = printer.computeTrim(0, 0, 0, 0);
	Point dpi = printer.getDPI();
	left = dpi.x/UNIT_DIVIDER + trim.x; // half inch from left side
	right = bounds.width - dpi.x/UNIT_DIVIDER + trim.x + trim.width; // half inch from right side
	top = dpi.y/UNIT_DIVIDER + trim.y; // half inch from top edge
	bottom = bounds.height - dpi.y/UNIT_DIVIDER + trim.y + trim.height; // half inch from bottom paper
}
 
开发者ID:Spacecraft-Code,项目名称:SPELL,代码行数:11,代码来源:Geometry.java

示例4: computePrintArea

import org.eclipse.swt.printing.Printer; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:31,代码来源:GridLayerPrinter.java

示例5: menuPrint

import org.eclipse.swt.printing.Printer; //导入方法依赖的package包/类
void menuPrint() {
	if (image == null) {
		return;
	}

	try {
		// Ask the user to specify the printer.
		PrintDialog dialog = new PrintDialog(getShell(), SWT.NULL);
		PrinterData printerData = dialog.open();
		if (printerData == null) {
			return;
		}

		Printer printer = new Printer(printerData);
		Point screenDPI = display.getDPI();
		Point printerDPI = printer.getDPI();
		int scaleFactor = printerDPI.x / screenDPI.x;
		Rectangle trim = printer.computeTrim(0, 0, 0, 0);
		if (printer.startJob(currentName)) {
			if (printer.startPage()) {
				GC gc = new GC(printer);
				int transparentPixel = imageData.transparentPixel;
				if ((transparentPixel != -1) && !transparent) {
					imageData.transparentPixel = -1;
				}
				Image printerImage = new Image(printer, imageData);
				gc.drawImage(printerImage, 0, 0, imageData.width, imageData.height, -trim.x, -trim.y, scaleFactor
				        * imageData.width, scaleFactor * imageData.height);
				if ((transparentPixel != -1) && !transparent) {
					imageData.transparentPixel = transparentPixel;
				}
				printerImage.dispose();
				gc.dispose();
				printer.endPage();
			}
			printer.endJob();
		}
		printer.dispose();
	}
	catch (SWTError e) {
		MessageBox box = new MessageBox(getShell(), SWT.ICON_ERROR);
		box.setMessage(ImageAnalyzer.bundle.getString("Printing_error") + e.getMessage());
		box.open();
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:46,代码来源:ImageAnalyzer.java

示例6: run

import org.eclipse.swt.printing.Printer; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void run()
{
    // Get snapshot. Disposed at end of printing
    final Image snapshot = media_pool.get(ImageConverter.convertToSWT(graph.getImage()));

    if (snapshot == null)
    {
        Logger.getLogger(getClass().getName()).fine("Cannot obtain image");
        return;
    }

    // Printer GUI
    final PrintDialog dlg = new PrintDialog(shell);
    PrinterData data = dlg.open();
    if (data == null)
    {
        Logger.getLogger(getClass().getName()).fine("Cannot obtain printer");
        snapshot.dispose();
        return;
    }
    // At least on Linux, access to SWT Printer must be on UI thread.
    // Printing in other thread can deadlock with UI thread.
    final Printer printer = new Printer(data);
    try
    {
        if (!printer.startJob("Data Browser"))
        {
            Logger.getLogger(getClass().getName()).fine("Cannot start print job");
            return;
        }
        try
        {   // Printer page info
            final Rectangle area = printer.getClientArea();
            final Rectangle trim = printer.computeTrim(0, 0, 0, 0);
            final Point dpi = printer.getDPI();

            // Compute layout
            final Rectangle image_rect = snapshot.getBounds();
            // Leave one inch on each border.
            // (copied the computeTrim stuff from an SWT example.
            //  Really no clue...)
            final int left_right = dpi.x + trim.x;
            final int top_bottom = dpi.y + trim.y;
            final int printed_width = area.width - 2*left_right;
            // Try to scale height according to on-screen aspect ratio.
            final int max_height = area.height - 2*top_bottom;
            final int printed_height = Math.min(max_height,
                    image_rect.height * printed_width / image_rect.width);

            // Print one page
            printer.startPage();
            final GC gc = new GC(printer);
            gc.drawImage(snapshot, 0, 0, image_rect.width, image_rect.height,
                    left_right, top_bottom, printed_width, printed_height);
            printer.endPage();
        }
        finally
        {
            printer.endJob();
        }
    }
    finally
    {
        printer.dispose();
        snapshot.dispose();
    }
}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:70,代码来源:PrintAction.java


注:本文中的org.eclipse.swt.printing.Printer.computeTrim方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。