Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java PDF 2D: Dessiner une Intersection de cercle

Java PDF 2D: Dessiner une Intersection de cercle
{filelink=10439}

/***** Code de MesExemples.com *******/
/**
 * @(#)G2DExempleCerclePDF.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/4/30
 */
 
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.io.FileOutputStream;
import java.io.IOException;
 
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.FontFactory;
import com.itextpdf.awt.DefaultFontMapper;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
 
public class G2DExempleCerclePDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter.getInstance(document,
       new FileOutputStream("c:/G2DExempleCerclePDF.pdf"));
      document.open();
      DefaultFontMapper mapper = new DefaultFontMapper();
      FontFactory.registerDirectories();
      mapper.insertDirectory("c:windowsfonts");
 
      int w = 150;
      int h = 150;
      PdfContentByte cb = writer.getDirectContent();
      PdfTemplate tp = cb.createTemplate(w, h);
      Graphics2D g2 = tp.createGraphics(w, h, mapper);
      tp.setWidth(w);
      tp.setHeight(h);
      double ew = w / 2;
      double eh = h / 2;
      Ellipse2D.Double circle, circle1;
 
      circle = new Ellipse2D.Double(ew - 16, eh - 29, 50.0, 50.0);
 
      g2.setColor(Color.green);
      g2.fill(circle);
 
      g2.setColor(Color.red);
      circle1 = new Ellipse2D.Double(ew, eh, 50.0, 50.0);
      g2.fill(circle1);
 
      Area area1 = new Area(circle);
      Area area2 = new Area(circle1);
 
      g2.setColor(Color.BLUE);
      area1.intersect(area2);
      g2.fill(area1);
 
      g2.dispose();
      cb.addTemplate(tp, 50, 400);
 
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
 
}