Example usage for com.lowagie.text Rectangle getRight

List of usage examples for com.lowagie.text Rectangle getRight

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle getRight.

Prototype

public float getRight() 

Source Link

Document

Returns the upper right x-coordinate.

Usage

From source file:org.geomajas.plugin.print.component.impl.MapComponentImpl.java

License:Open Source License

private void renderViewPort(ViewPortComponentImpl viewPort, PdfContext context) {
    Coordinate portOrigin = viewPort.getLocation();
    float x = (float) (portOrigin.x - location.x) * getPpUnit();
    float y = (float) (portOrigin.y - location.y) * getPpUnit();
    Rectangle shadowRect = new Rectangle(x, y, x + viewPort.getBounds().getWidth() / viewPort.getZoomScale(),
            y + viewPort.getBounds().getHeight() / viewPort.getZoomScale());
    context.fillRectangle(shadowRect, context.makeTransparent(Color.lightGray, 0.5f));
    context.strokeRectangle(shadowRect, Color.white, 1);
    Rectangle rect = context.toRelative(viewPort.getBounds());
    // connection lines
    float deltaLeft = shadowRect.getLeft() - rect.getLeft();
    float deltaRight = shadowRect.getRight() - rect.getRight();

    float deltaBottom = shadowRect.getBottom() - rect.getBottom();
    float deltaTop = shadowRect.getTop() - rect.getTop();

    if ((deltaLeft <= 0 && deltaBottom >= 0) || (deltaLeft >= 0 && deltaBottom <= 0)) {
        context.drawLine(rect.getLeft(), rect.getBottom(), shadowRect.getLeft(), shadowRect.getBottom(),
                Color.white, 1);// w  w  w  .java2s  . c  om
    }
    if ((deltaLeft >= 0 && deltaTop >= 0) || (deltaLeft <= 0 && deltaTop <= 0)) {
        context.drawLine(rect.getLeft(), rect.getTop(), shadowRect.getLeft(), shadowRect.getTop(), Color.white,
                1);
    }
    if ((deltaRight <= 0 && deltaBottom <= 0) || (deltaRight >= 0 && deltaBottom >= 0)) {
        context.drawLine(rect.getRight(), rect.getBottom(), shadowRect.getRight(), shadowRect.getBottom(),
                Color.white, 1);
    }
    if ((deltaRight >= 0 && deltaTop <= 0) || (deltaRight <= 0 && deltaTop >= 0)) {
        context.drawLine(rect.getRight(), rect.getTop(), shadowRect.getRight(), shadowRect.getTop(),
                Color.white, 1);
    }
}

From source file:org.geomajas.plugin.print.component.impl.VectorLayerComponentImpl.java

License:Open Source License

private void drawLabel(PdfContext context, InternalFeature f) {
    LabelStyleInfo labelType = styleInfo.getLabelStyle();
    String label = f.getLabel();//from   w w  w .  j  a va  2s  . c  om
    if (label != null) {
        Font font = new Font("Helvetica", Font.ITALIC, 10);
        Color fontColor = Color.black;
        if (labelType.getFontStyle() != null) {
            fontColor = context.getColor(labelType.getFontStyle().getColor(),
                    labelType.getFontStyle().getOpacity());
        }
        Rectangle rect = calculateLabelRect(context, f, label, font);
        Color bgColor = Color.white;
        if (labelType.getBackgroundStyle() != null) {
            bgColor = context.getColor(labelType.getBackgroundStyle().getFillColor(),
                    labelType.getBackgroundStyle().getFillOpacity());
        }
        context.fillRoundRectangle(rect, bgColor, 3);
        Color borderColor = Color.black;
        if (labelType.getBackgroundStyle() != null) {
            borderColor = context.getColor(labelType.getBackgroundStyle().getStrokeColor(),
                    labelType.getBackgroundStyle().getStrokeOpacity());
        }
        float linewidth = 0.5f;
        if (labelType.getBackgroundStyle() != null) {
            linewidth = labelType.getBackgroundStyle().getStrokeWidth();
        }
        context.strokeRoundRectangle(rect, borderColor, linewidth, 3);
        context.drawText(label, font, rect, fontColor);
        if (f.getGeometry() instanceof Point) {
            context.drawLine(0.5f * (rect.getLeft() + rect.getRight()), rect.getBottom(),
                    0.5f * (rect.getLeft() + rect.getRight()), rect.getBottom() - SYMBOL_CONNECT_LENGTH,
                    borderColor, linewidth);
        }
    }
}

From source file:org.geomajas.plugin.print.component.impl.VectorLayerComponentImpl.java

License:Open Source License

private Rectangle calculateLabelRect(PdfContext context, InternalFeature f, String label, Font font) {
    Rectangle textSize = context.getTextSize(label, font);
    float margin = 0.25f * font.getSize();
    Rectangle rect = new Rectangle(textSize.getWidth() + 2 * margin, textSize.getHeight() + 2 * margin);
    Coordinate labelPosition = geoService.calcDefaultLabelPosition(f);
    // SPRINT-53 Labels should be rendered in Screen Space
    new MapToUserFilter().filter(labelPosition);

    context.moveRectangleTo(rect, (float) labelPosition.x - rect.getWidth() / 2f,
            (float) labelPosition.y - rect.getHeight() / 2f);
    if (f.getGeometry() instanceof Point) {
        float shiftHeight = 0.5f * (rect.getHeight() + getSymbolHeight(f));
        // move up 15 pixels to make the symbol visible
        context.moveRectangleTo(rect, rect.getLeft(), rect.getBottom() + shiftHeight + SYMBOL_CONNECT_LENGTH);
    }//from w ww .j a  v a 2s  . c o  m
    if (rect.getLeft() < 0) {
        context.moveRectangleTo(rect, 10, rect.getBottom());
    }
    if (rect.getBottom() < 0) {
        context.moveRectangleTo(rect, rect.getLeft(), 10);
    }
    if (rect.getTop() > getBounds().getHeight()) {
        context.moveRectangleTo(rect, rect.getLeft(), getBounds().getHeight() - rect.getHeight() - 10);
    }
    if (rect.getRight() > getBounds().getWidth()) {
        context.moveRectangleTo(rect, getBounds().getWidth() - rect.getWidth() - 10, rect.getBottom());
    }
    return rect;
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Draw an elliptical exterior with this color.
 *
 * @param rect rectangle in which ellipse should fit
 * @param color colour to use for stroking
 * @param linewidth line width/* w w  w.  j  a v a2  s .  c  o m*/
 */
public void strokeEllipse(Rectangle rect, Color color, float linewidth) {
    template.saveState();
    setStroke(color, linewidth, null);
    template.ellipse(origX + rect.getLeft(), origY + rect.getBottom(), origX + rect.getRight(),
            origY + rect.getTop());
    template.stroke();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Draw an elliptical interior with this color.
 *
 * @param rect rectangle in which ellipse should fit
 * @param color colour to use for filling
 *//*from  w  ww.j  av  a  2 s. c  o  m*/
public void fillEllipse(Rectangle rect, Color color) {
    template.saveState();
    setFill(color);
    template.ellipse(origX + rect.getLeft(), origY + rect.getBottom(), origX + rect.getRight(),
            origY + rect.getTop());
    template.fill();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Converts an absolute rectangle to a relative one wrt to the current coordinate system.
 *
 * @param rect absolute rectangle/*from   w w w . j a  va  2  s .  c o m*/
 * @return relative rectangle
 */
public Rectangle toRelative(Rectangle rect) {
    return new Rectangle(rect.getLeft() - origX, rect.getBottom() - origY, rect.getRight() - origX,
            rect.getTop() - origY);
}

From source file:org.geomajas.plugin.print.parser.RectangleConverter.java

License:Open Source License

@Override
public String toString(Object obj) {
    Rectangle rectangle = (Rectangle) obj;
    if (obj == null) {
        return null;
    }//from   w  ww  .  j  av a  2s  .com
    return rectangle.getLeft() + "," + rectangle.getBottom() + "," + rectangle.getRight() + ","
            + rectangle.getTop();
}

From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java

License:Open Source License

/**
 * Any work to start off printing the document
 * @throws FormPrintException Thrown if there is any form processing problems
 *//*  ww  w . j  a  v a  2  s .c  o m*/
protected void startDocument() throws FormPrintException {
    log.debug("startDocument:");

    Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage());
    log.debug("Page Size      : t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());
    r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage());
    log.debug("Page Size w/Rot: t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());

    m_generatedDoc = new Document(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()));
    //m_generatedDoc = new Document(m_templateReader.getPageSize(getCurrentTemplatePage()));
    m_output = new ByteArrayOutputStream();
    try {
        m_writer = PdfWriter.getInstance(m_generatedDoc, m_output);
    } catch (DocumentException e) {
        log.error("Error Creating Writer - " + e.getMessage(), e);
        throw new EngineProcessingException("Error Creating Writer - " + e.getMessage());
    }

    if (getDocumentProperties() != null) {
        Properties dp = (Properties) getDocumentProperties().clone();
        if (dp.getProperty(DOCUMENT_PROPERTY_TITLE) != null) {
            m_generatedDoc.addTitle(dp.getProperty(DOCUMENT_PROPERTY_TITLE));
            dp.remove(DOCUMENT_PROPERTY_TITLE);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_SUBJECT) != null) {
            m_generatedDoc.addSubject(dp.getProperty(DOCUMENT_PROPERTY_SUBJECT));
            dp.remove(DOCUMENT_PROPERTY_SUBJECT);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_KEYWORDS) != null) {
            m_generatedDoc.addKeywords(dp.getProperty(DOCUMENT_PROPERTY_KEYWORDS));
            dp.remove(DOCUMENT_PROPERTY_KEYWORDS);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_CREATOR) != null) {
            m_generatedDoc.addCreator(dp.getProperty(DOCUMENT_PROPERTY_CREATOR, "Jaffa Print Engine"));
            dp.remove(DOCUMENT_PROPERTY_CREATOR);
        }
        if (dp.getProperty(DOCUMENT_PROPERTY_AUTHOR) != null) {
            m_generatedDoc.addAuthor(dp.getProperty(DOCUMENT_PROPERTY_AUTHOR));
            dp.remove(DOCUMENT_PROPERTY_AUTHOR);
        }
        // loop through other properties and set them as header parameters
        for (Enumeration en = dp.elements(); en.hasMoreElements();) {
            Map.Entry e = (Map.Entry) en.nextElement();
            if (e.getKey() != null && e.getValue() != null)
                m_generatedDoc.addHeader(e.getKey().toString(), e.getValue().toString());
        }
    }
    m_generatedDoc.addCreationDate();

    m_generatedDoc.open();

}

From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java

License:Open Source License

/**
 * Any work to start off printing a page of the document
 * m_currentPage will contain the page being printed, and
 * m_currentTemplatePage will contain the template page number to base this
 * new page on./* w  w  w . ja  v a  2  s .  c  o m*/
 * @throws FormPrintException Thrown if there is any form processing problems
 */
protected void startPage() throws FormPrintException {
    log.debug("startPage: Page=" + getCurrentPage());

    Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage());
    log.debug("Page Size      : t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());
    r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage());
    log.debug("Page Size w/Rot: t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r="
            + r.getRight() + ", rot=" + r.getRotation());

    // Get rotation quadrent 0..3
    int q = (m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()).getRotation() % 360) / 90;
    float tX = (q == 2 ? r.getTop() : 0) + (q == 3 ? r.getRight() : 0);
    float tY = (q == 1 ? r.getTop() : 0) + (q == 2 ? r.getRight() : 0);
    float sX = 1f, sY = 1f;
    double angle = -r.getRotation() * (Math.PI / 180f);
    double transformA = sX * Math.cos(angle);
    double transformB = sY * Math.sin(angle);
    double transformC = -sX * Math.sin(angle);
    double transformD = sY * Math.cos(angle);
    double transformE = tX;
    double transformF = tY;

    m_generatedDoc.setPageSize(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()));
    //m_generatedDoc.setPageSize(m_templateReader.getPageSize(getCurrentTemplatePage()) );
    /**
     * try {
     * m_generatedDoc.newPage();
     * } catch (DocumentException e) {
     * log.error("Error Creating New Page - " + e.getMessage() ,e);
     * throw new EngineProcessingException("Error Creating New Page - " + e.getMessage());
     * }
     **/
    m_generatedDoc.newPage();

    PdfImportedPage page = m_writer.getImportedPage(m_templateReader, getCurrentTemplatePage());
    PdfContentByte cb = m_writer.getDirectContent();
    //cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
    cb.addTemplate(page, (float) transformA, (float) transformB, (float) transformC, (float) transformD,
            (float) transformE, (float) transformF);
    log.debug("Matrix = [A=" + transformA + ", B=" + transformB + ", C=" + transformC + ", D=" + transformD
            + ", E=" + transformE + ", F=" + transformF + " ]");
}

From source file:org.nuxeo.ecm.platform.signature.core.sign.SignatureServiceImpl.java

License:Open Source License

/**
 * Verifies that a provided value fits within the page bounds. If it does not, a sign exception is thrown. This is
 * to verify externally configurable signature positioning.
 *
 * @param isHorizontal - if false, the current value is checked agains the vertical page dimension
 *///w  w  w. j  ava2  s . c  o  m
protected void validatePageBounds(PdfReader pdfReader, int pageNo, float valueToCheck, boolean isHorizontal)
        throws SignException {
    if (valueToCheck < 0) {
        String message = "The new signature position " + valueToCheck
                + " exceeds the page bounds. The position must be a positive number.";
        log.debug(message);
        throw new SignException(message);
    }

    Rectangle pageRectangle = pdfReader.getPageSize(pageNo);
    if (isHorizontal && valueToCheck > pageRectangle.getRight()) {
        String message = "The new signature position " + valueToCheck
                + " exceeds the horizontal page bounds. The page dimensions are: (" + pageRectangle + ").";
        log.debug(message);
        throw new SignException(message);
    }
    if (!isHorizontal && valueToCheck > pageRectangle.getTop()) {
        String message = "The new signature position " + valueToCheck
                + " exceeds the vertical page bounds. The page dimensions are: (" + pageRectangle + ").";
        log.debug(message);
        throw new SignException(message);
    }
}