При печати изображение должно быть маленьким, чтобы читать текст на некоторых больших дисплеях - PullRequest
0 голосов
/ 27 февраля 2012

Необходимо ограничить изменение размера изображения при создании вывода на печать минимальный размер (чтобы он был читабельным) и разрешить вывод для перетекания в несколько страниц шириной в несколько страниц в длину если необходимо. В настоящее время он ограничен одной страницей.

ниже пример кода для этого

public DisplayPrinter(DisplayManager displayManager, PrintPlugin configuration, String header, String footer)
 {
        this.displayManager = displayManager;
        this.configuration = configuration;
        this.header = header;
        this.footer = footer;

        Font configHeaderFont = configuration.getHeaderFont();
        headerFont = (configHeaderFont != null) ? configHeaderFont : defaultHeaderFont;

        Font configFooterFont = configuration.getFooterFont();
        footerFont = (configFooterFont != null) ? configFooterFont : defaultFooterFont;
    }

и другой метод

public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex != 0)
            return NO_SUCH_PAGE;

        Graphics2D g2d = (Graphics2D) g;

        Rectangle2D.Double printBounds = new Rectangle2D.Double(
                pageFormat.getImageableX(), 
                pageFormat.getImageableY(),
                pageFormat.getImageableWidth(),
                pageFormat.getImageableHeight()
                );

        // Print the header and reduce the height for printing
        float headerHeight = printHeader(printBounds, g2d);
        printBounds.y += headerHeight;
        printBounds.height -= headerHeight;

        // Carve off the amount of space needed for the footer
        printBounds.height -= getFooterHeight(g2d);

        // Print the nodes and edges
        printDisplay( printBounds, g2d, 0 );

        if (footer != null) {
            printBounds.y += (printBounds.height + 15);
            printFooter(printBounds, g2d);
        }

        return PAGE_EXISTS;
    }

Я хочу напечатать изображение на нескольких страницах для большого изображения. и одна страница для маленького изображения

и еще один метод

protected void printDisplay( Rectangle2D.Double printBounds, Graphics2D g2d, double margin ) {
        // Get a rectangle that represents the bounds of all of the DisplayEntities
        Rectangle r = null;
        for (Enumeration e=displayManager.getEntitySet().getEntityEnumeration();e.hasMoreElements();) {
            DisplayEntity de = (DisplayEntity)e.nextElement();
            if (r == null)
                r = de.getBounds();
            else
                r = r.union(de.getBounds());   
        }

        // Get that as doubles, rather than ints, and expand by half the margin
        // height in all directions
        Rectangle2D.Double entityBounds = new Rectangle2D.Double(r.x,r.y,r.width,r.height);
        entityBounds.x -= margin/2;
        entityBounds.y -= margin/2;
        entityBounds.width += margin;
        entityBounds.height += margin;

        // See if height and/or width was specified
        Unit specifiedSize = configuration.getHeight();
        double printHeight = (specifiedSize != null) ?
            specifiedSize.getValueAsPixels((int)printBounds.height) :
                printBounds.height;

        specifiedSize = configuration.getWidth();
        double printWidth = (specifiedSize != null) ?
            specifiedSize.getValueAsPixels((int)printBounds.width) :
                printBounds.width;

        // Figure out the ratio of print-bounds to the entities' bounds
        double scaleX = 1;
        double scaleY = 1;

        // See if we need to scale
        boolean canExpand = configuration.expandToFit();
        boolean canShrink = configuration.shrinkToFit();

        if (canExpand == false && canShrink == false) {
            scaleX = scaleY = configuration.getScale();
        }
        else {
            if ((canShrink && canExpand) || 
                (canShrink &&
                    (entityBounds.width > printWidth || 
                     entityBounds.height > printHeight)) ||
                (canExpand &&
                    (entityBounds.width < printWidth ||
                     entityBounds.height < printHeight))) {
                scaleX = printWidth / entityBounds.width;
                scaleY = printHeight / entityBounds.height;
            }
        }

        if (configuration.maintainAspectRatio()) { // Scale the same
            if (scaleX > scaleY)
                scaleX = scaleY;
            else 
                scaleY = scaleX;
        }

заранее спасибо

...