开发者

Large SWT Image is not printed properly

Hei, SWT Gurus, I have a pretty weird situation. The thing is, that I am trying to print gantt chart in my Eclipse RCP application. Gantt chart is quite long and sometimes high as well. Its dimensions are following: height=3008px (2 vertical pages), width > 20000px. My print area can fit something like 1400x2000 px. First of all, I am creating image out with my chart (image is OK, I can save it separately and see, that everything is there). However, in order to print it on the paper, I am printing it piece by piece (moving source X and Y positions respectively). This algorithm was working fine for some time, but now something strange happened:

When chart is not high enough and can fit on 1 vertical page, then it is printed normally, but when it is 2 vertical pages, then only second vertical page is printed and first one is left out. There are no errors, nor anything, that could help me. I thought, may be there is not enough heap memory, so I allocated -Xmx1014m space to my application, but it didn't helped. So, I am really lost, and can not find any solution or even an explanation to this problem. I was trying to simply print image by gc.drwImage(image, x, y), but is also printed me only the second half of it. I am also printing some text after every try of printing an image, and it is printed

The code, that is responsibl开发者_如何学Pythone for printing an image is following:

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();
            }
        }

Thanks in advance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜