Example usage for com.lowagie.text Image getAbsoluteX

List of usage examples for com.lowagie.text Image getAbsoluteX

Introduction

In this page you can find the example usage for com.lowagie.text Image getAbsoluteX.

Prototype

public float getAbsoluteX() 

Source Link

Document

Returns the absolute X position.

Usage

From source file:org.locationtech.udig.printing.ui.pdf.ExportPDFWizard.java

License:Open Source License

/**
 * This function is used to draw very thin white borders over the outer 
 * edge of the raster map.  It's necessary because the map edge "bleeds" into
 * the adjacent pixels, and we need to cover that.
 * /*from  ww w  .  ja  v  a 2  s  . c  om*/
 * I think this quirky behaviour is possibly an iText bug
 */
private void addWhiteMapBorder(Image img, Document doc) {

    try {

        Color color = Color.white;
        int borderWidth = 1;

        BufferedImage bufferedTop = new BufferedImage((int) img.getScaledWidth(), borderWidth,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g1 = bufferedTop.createGraphics();
        g1.setBackground(color);
        g1.clearRect(0, 0, bufferedTop.getWidth(), bufferedTop.getHeight());
        Image top = Image.getInstance(bufferedImage2ByteArray(bufferedTop));
        top.setAbsolutePosition(img.getAbsoluteX(),
                img.getAbsoluteY() + img.getScaledHeight() - bufferedTop.getHeight() / 2);

        BufferedImage bufferedBottom = new BufferedImage((int) img.getScaledWidth(), borderWidth,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bufferedBottom.createGraphics();
        g2.setBackground(color);
        g2.clearRect(0, 0, bufferedBottom.getWidth(), bufferedBottom.getHeight());
        Image bottom = Image.getInstance(bufferedImage2ByteArray(bufferedBottom));
        bottom.setAbsolutePosition(img.getAbsoluteX(), img.getAbsoluteY() - bufferedTop.getHeight() / 2);

        BufferedImage bufferedLeft = new BufferedImage(borderWidth, (int) img.getScaledHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g3 = bufferedLeft.createGraphics();
        g3.setBackground(color);
        g3.clearRect(0, 0, bufferedLeft.getWidth(), bufferedLeft.getHeight());
        Image left = Image.getInstance(bufferedImage2ByteArray(bufferedLeft));
        left.setAbsolutePosition(img.getAbsoluteX() - bufferedLeft.getWidth() / 2, img.getAbsoluteY());

        BufferedImage bufferedRight = new BufferedImage(borderWidth, (int) img.getScaledHeight(),
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g4 = bufferedRight.createGraphics();
        g4.setBackground(color);
        g4.clearRect(0, 0, bufferedRight.getWidth(), bufferedRight.getHeight());
        Image right = Image.getInstance(bufferedImage2ByteArray(bufferedRight));
        right.setAbsolutePosition(img.getAbsoluteX() + img.getScaledWidth() - bufferedRight.getWidth() / 2,
                img.getAbsoluteY());

        doc.add(top);
        doc.add(bottom);
        doc.add(left);
        doc.add(right);
    } catch (Exception e) {
        e.printStackTrace();
    }
}