Example usage for com.lowagie.text.pdf PdfContentByte arc

List of usage examples for com.lowagie.text.pdf PdfContentByte arc

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte arc.

Prototype

public void arc(float x1, float y1, float x2, float y2, float startAng, float extent) 

Source Link

Document

Draws a partial ellipse inscribed within the rectangle x1,y1,x2,y2, starting at startAng degrees and covering extent degrees.

Usage

From source file:br.org.archimedes.io.pdf.elements.ArcExporter.java

License:Open Source License

public void exportElement(Arc arc, Object outputObject) throws IOException {

    PDFWriterHelper helper = (PDFWriterHelper) outputObject;
    PdfContentByte cb = helper.getPdfContentByte();

    Point center = arc.getCenter();
    Point initial = arc.getInitialPoint();
    Point ending = arc.getEndingPoint();
    float start = 0;
    float extent = 0;
    try {/*from   ww  w.  ja va2 s .co  m*/
        start = (float) Geometrics.calculateAngle(center, initial);
        extent = (float) Geometrics.calculateAngle(center, ending);
    } catch (NullArgumentException e) {
        // Should never happen
        e.printStackTrace();
    }
    start *= (180 / Math.PI);
    extent *= (180 / Math.PI);
    extent -= start;
    if (extent < 0) {
        extent += 360;
    }

    center = helper.modelToDocument(center);
    double radius = helper.getZoom() * arc.getRadius();
    float x1 = (float) (center.getX() - radius);
    float y1 = (float) (center.getY() - radius);
    float x2 = (float) (center.getX() + radius);
    float y2 = (float) (center.getY() + radius);

    cb.arc(x1, y1, x2, y2, start, extent);
    cb.stroke();
}