Example usage for com.lowagie.text Rectangle getWidth

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

Introduction

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

Prototype

public float getWidth() 

Source Link

Document

Returns the width of the rectangle.

Usage

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

License:Open Source License

@Override
public void render(PdfContext context) {
    // draw the tics
    float lowX = 0.5f * tickSizes.get(0).getWidth();
    float lowY = 0;
    float highX = lowX;
    float highY = 0.333f * ticHeight;
    Rectangle baseRect = new Rectangle(0, 0, ticWidth, 0.333f * ticHeight);

    // fills/*from  w w  w . jav  a 2s . co  m*/
    for (int i = 0; i < ticNumber; i++) {
        if (i % 2 == 0) {
            context.moveRectangleTo(baseRect, lowX, lowY);
            context.fillRectangle(baseRect, Color.white);
            context.strokeRectangle(baseRect, Color.black, 0.5f);
            context.moveRectangleTo(baseRect, highX, highY);
            context.fillRectangle(baseRect, Color.black);
            context.strokeRectangle(baseRect, Color.black, 0.5f);
        } else {
            context.moveRectangleTo(baseRect, highX, highY);
            context.fillRectangle(baseRect, Color.white);
            context.strokeRectangle(baseRect, Color.black, 0.5f);
            context.moveRectangleTo(baseRect, lowX, lowY);
            context.fillRectangle(baseRect, Color.black);
            context.strokeRectangle(baseRect, Color.black, 0.5f);
        }
        lowX += ticWidth;
        highX += ticWidth;
    }

    // tick extensions
    highX = 0.5f * tickSizes.get(0).getWidth();
    highY = 0.6666f * ticHeight;
    for (int i = 0; i <= ticNumber; i++) {
        context.drawRelativePath(new float[] { 0, 0 }, new float[] { 0, 1 },
                new Rectangle(highX, highY, highX, 0.75f * ticHeight), Color.black, 0.5f, null);
        highX += ticWidth;
    }

    // position and print the labels
    float labelX = 0.5f * tickSizes.get(0).getWidth();
    float labelY = ticHeight;
    for (int i = 0; i < tickLabels.size(); i++) {
        Rectangle box = tickSizes.get(i);
        // center the label
        context.moveRectangleTo(box, labelX - 0.5f * box.getWidth(), labelY);
        context.drawText(tickLabels.get(i), font, box, Color.black);
        labelX += ticWidth;
    }
}

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 w w.  j a  v a2s.  com*/
    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

/**
 * Initializes context size.//from www .  j  av  a 2s  . c  o  m
 *
 * @param rectangle rectangle
 */
public void initSize(Rectangle rectangle) {
    template = writer.getDirectContent().createTemplate(rectangle.getWidth(), rectangle.getHeight());
}

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

License:Open Source License

/**
 * Draw text in the center of the specified box.
 *
 * @param text text//  w  w  w.j av a 2  s.c  o  m
 * @param font font
 * @param box box to put text int
 * @param fontColor colour
 */
public void drawText(String text, Font font, Rectangle box, Color fontColor) {
    template.saveState();
    // get the font
    DefaultFontMapper mapper = new DefaultFontMapper();
    BaseFont bf = mapper.awtToPdf(font);
    template.setFontAndSize(bf, font.getSize());

    // calculate descent
    float descent = 0;
    if (text != null) {
        descent = bf.getDescentPoint(text, font.getSize());
    }

    // calculate the fitting size
    Rectangle fit = getTextSize(text, font);

    // draw text if necessary
    template.setColorFill(fontColor);
    template.beginText();
    template.showTextAligned(PdfContentByte.ALIGN_LEFT, text,
            origX + box.getLeft() + 0.5f * (box.getWidth() - fit.getWidth()),
            origY + box.getBottom() + 0.5f * (box.getHeight() - fit.getHeight()) - descent, 0);
    template.endText();
    template.restoreState();
}

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

License:Open Source License

public void strokeRectangle(Rectangle rect, Color color, float linewidth, float[] dashArray) {
    template.saveState();// w w  w  .j ava 2  s . c  o  m
    setStroke(color, linewidth, dashArray);
    template.rectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight());
    template.stroke();
    template.restoreState();
}

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

License:Open Source License

/**
 * Draw a rounded rectangular boundary.//from www. j  a  v a2 s . com
 *
 * @param rect rectangle
 * @param color colour
 * @param linewidth line width
 * @param r radius for rounded corners
 */
public void strokeRoundRectangle(Rectangle rect, Color color, float linewidth, float r) {
    template.saveState();
    setStroke(color, linewidth, null);
    template.roundRectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight(),
            r);
    template.stroke();
    template.restoreState();
}

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

License:Open Source License

/**
 * Draw a rectangle's interior with this color.
 *
 * @param rect rectangle/*w  w w .  j  a v  a  2 s  .com*/
 * @param color colour
 */
public void fillRectangle(Rectangle rect, Color color) {
    template.saveState();
    setFill(color);
    template.rectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight());
    template.fill();
    template.restoreState();
}

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

License:Open Source License

public void fillRoundRectangle(Rectangle rect, Color color, float r) {
    template.saveState();/*  www  . j a v  a  2 s  . co  m*/
    setFill(color);
    template.roundRectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight(),
            r);
    template.fill();
    template.restoreState();
}

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

License:Open Source License

/**
 * Move this rectangle to the specified bottom-left point.
 *
 * @param rect rectangle to move/* w  w w .ja  va 2  s  . c o m*/
 * @param x new x origin
 * @param y new y origin
 */
public void moveRectangleTo(Rectangle rect, float x, float y) {
    float width = rect.getWidth();
    float height = rect.getHeight();
    rect.setLeft(x);
    rect.setBottom(y);
    rect.setRight(rect.getLeft() + width);
    rect.setTop(rect.getBottom() + height);
}

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

License:Open Source License

/**
 * Translate this rectangle over the specified following distances.
 *
 * @param rect rectangle to move//from   w ww.  j  a  va2s.  c  o m
 * @param dx delta x
 * @param dy delta y
 */
public void translateRectangle(Rectangle rect, float dx, float dy) {
    float width = rect.getWidth();
    float height = rect.getHeight();
    rect.setLeft(rect.getLeft() + dx);
    rect.setBottom(rect.getBottom() + dy);
    rect.setRight(rect.getLeft() + dx + width);
    rect.setTop(rect.getBottom() + dy + height);
}