Hei,SWT Gurus,我有一个非常奇怪的情况。问题是,我正在尝试在Eclipse RCP应用程序中打印甘特图。甘特图很长,有时也很高。其尺寸如下:高度= 3008px(2个垂直页面),宽度> 20000px。我的打印区域可以适合1400x2000像素。首先,我用我的图表创建图像(图像没问题,我可以单独保存,看看,一切都在那里)。但是,为了将它打印在纸上,我将它逐个打印(分别移动源X和Y位置)。这个算法运行良好一段时间了,但现在发生了一些奇怪的事情:
当图表不够高并且可以放在1个垂直页面上时,它会正常打印,但是当它是2个垂直页面时,则只打印第二个垂直页面而第一个页面被省略。没有错误,也没有任何可以帮助我的错误。我想,可能是没有足够的堆内存,所以我为我的应用程序分配了-Xmx1014m空间,但它没有帮助。所以,我真的迷路了,找不到任何解决方案甚至解释这个问题。我试图通过gc.drwImage(图像,x,y)简单地打印图像,但是也只打印了它的后半部分。每次尝试打印图像后,我也会打印一些文本,并打印出来
负责打印图像的代码如下:
for (int verticalPageNumber = 0; verticalPageNumber <= pageCount.vGanttChartPagesCount; verticalPageNumber++) {
// horizontal position needs to be reset to 0 before printing next bunch of horizontal pages
int imgPieceSrcX = 0;
for (int horizontalPageNumber = 0; horizontalPageNumber <= pageCount.hGanttChartPagesCount; horizontalPageNumber++) {
// Calculate bounds for the next page
final Rectangle printBounds = PrintingUtils.calculatePrintBounds(printerClientArea, scaleFactor, verticalPageNumber, horizontalPageNumber);
if (shouldPrint(printer.getPrinterData(), currentPageNr)
&& nextPageHasSomethingToPrint(imgPieceSrcX, imgPieceSrcY, totalGanttChartArea.width, totalGanttChartArea.height)) {
printer.startPage();
final Transform printerTransform = PrintingUtils.setUpTransform(printer, printerClientArea, scaleFactor, gc, printBounds);
printHeader(gc, currentPageNr, printBounds);
imgPieceSrcY = printBounds.y;
final int imgPieceSrcHeight =
imgPieceSrcY + printBounds.height < ganttChartImage.getBounds().height ? printBounds.height : ganttChartImage.getBounds().height
- imgPieceSrcY;
final int imgPieceSrcWidth =
imgPieceSrcX + printBounds.width < ganttChartImage.getBounds().width ? printBounds.width : ganttChartImage.getBounds().width
- imgPieceSrcX;
if (imgPieceSrcHeight > 0 && imgPieceSrcWidth > 0) {
// gantt chart is printed as image, piece by piece
gc.drawImage(ganttChartImage,
imgPieceSrcX, imgPieceSrcY,
imgPieceSrcWidth, imgPieceSrcHeight,
printBounds.x, printBounds.y,
imgPieceSrcWidth, imgPieceSrcHeight); // destination width and height equal to source width and height to prevent
// stretching/shrinking of image
// move x and y to print next image piece
gc.drawText("Text " + currentPageNr, imgPieceSrcX, imgPieceSrcY);
imgPieceSrcX += printBounds.width;
}
currentPageNr++;
printer.endPage();
printerTransform.dispose();
}
}
提前致谢。