use of org.pentaho.di.ui.core.dialog.EnterPrintDialog in project pentaho-kettle by pentaho.
the class PrintSpool method printImage.
public void printImage(Shell sh, Image img) {
if (printerdata != null) {
Rectangle imgbounds = img.getBounds();
Point max = new Point(imgbounds.width, imgbounds.height);
// What's the printers DPI?
Point dpi_printer = printer.getDPI();
// What's the screens DPI?
Point dpi_screen = Display.getCurrent().getDPI();
// Resize on printer: calculate factor:
double factorx = (double) dpi_printer.x / (double) dpi_screen.x;
double factory = (double) dpi_printer.y / (double) dpi_screen.y;
// Get size of 1 page?
Rectangle page = printer.getBounds();
// 0,40 inch about 1cm
double margin_left = 0.40;
double margin_right = 0.40;
double margin_top = 0.40;
double margin_bottom = 0.40;
EnterPrintDialog epd = new EnterPrintDialog(sh, 1, 1, 100, factorx, factory, page, margin_left, margin_right, margin_top, margin_bottom, img);
if (epd.open() == SWT.OK) {
double page_left = epd.leftMargin * dpi_printer.x;
double page_right = epd.rightMargin * dpi_printer.x;
double page_top = epd.topMargin * dpi_printer.y;
double page_bottom = epd.bottomMargin * dpi_printer.y;
double page_sizex = page.width - page_left - page_right;
double page_sizey = page.height - page_top - page_bottom;
double size_on_paperx = max.x * factorx;
double size_on_papery = max.y * factory;
double actual_sizex = size_on_paperx * epd.scale / 100;
double actual_sizey = size_on_papery * epd.scale / 100;
// Create new print job.
printer.startJob("Kettle : Spoon print job");
for (int c = 0; c < epd.nrcols; c++) {
double left_to_printx = actual_sizex - page_sizex * c;
double printx = (left_to_printx > page_sizex) ? page_sizex : (left_to_printx >= 0 ? left_to_printx : 0);
for (int r = 0; r < epd.nrrows; r++) {
double left_to_printy = actual_sizey - page_sizey * r;
double printy = (left_to_printy > page_sizey) ? page_sizey : (left_to_printy >= 0 ? left_to_printy : 0);
int startx = (int) (actual_sizex - left_to_printx);
int starty = (int) (actual_sizey - left_to_printy);
int fromx = (int) (startx / (factorx * epd.scale / 100));
int fromy = (int) (starty / (factory * epd.scale / 100));
int imx = (int) (max.x * printx / actual_sizex) - 1;
int imy = (int) (max.y * printy / actual_sizey) - 1;
printer.startPage();
GC gc_printer = new GC(printer);
gc_printer.drawImage(img, fromx, fromy, imx, imy, (int) page_left, (int) page_top, (int) printx, (int) printy);
// ShowImageDialog sid = new ShowImageDialog(sh, props, img);
// sid.open();
System.out.println("img dept = " + img.getImageData().depth);
System.out.println("prn dept = " + printer.getDepth());
System.out.println("img size = (" + img.getBounds().x + "," + img.getBounds().y + ") : (" + img.getBounds().width + "," + img.getBounds().height + ")");
System.out.println("fromx=" + fromx + ", fromy=" + fromy + ", imx=" + imx + ", imy=" + imy + ", page_left=" + (int) page_left + ", page_top=" + (int) page_top + ", printx=" + (int) printx + ", printy=" + (int) printy);
printer.endPage();
gc_printer.dispose();
}
}
printer.endJob();
printer.dispose();
}
img.dispose();
}
}
Aggregations