Exemplo n.º 1
0
 /** @see Graphics#create() */
 public Graphics create() {
   PdfGraphics2D g2 = new PdfGraphics2D();
   g2.onlyShapes = this.onlyShapes;
   g2.transform = new AffineTransform(this.transform);
   g2.baseFonts = this.baseFonts;
   g2.fontMapper = this.fontMapper;
   g2.kids = this.kids;
   g2.paint = this.paint;
   g2.fillGState = this.fillGState;
   g2.strokeGState = this.strokeGState;
   g2.background = this.background;
   g2.mediaTracker = this.mediaTracker;
   g2.convertImagesToJPEG = this.convertImagesToJPEG;
   g2.jpegQuality = this.jpegQuality;
   g2.setFont(this.font);
   g2.cb = this.cb.getDuplicate();
   g2.cb.saveState();
   g2.width = this.width;
   g2.height = this.height;
   g2.followPath(new Area(new Rectangle2D.Float(0, 0, width, height)), CLIP);
   if (this.clip != null) g2.clip = new Area(this.clip);
   g2.stroke = stroke;
   g2.originalStroke = originalStroke;
   g2.strokeOne = (BasicStroke) g2.transformStroke(g2.strokeOne);
   g2.oldStroke = g2.strokeOne;
   g2.setStrokeDiff(g2.oldStroke, null);
   g2.cb.saveState();
   if (g2.clip != null) g2.followPath(g2.clip, CLIP);
   g2.kid = true;
   synchronized (kids) {
     kids.add(g2);
   }
   return g2;
 }
Exemplo n.º 2
0
 /** Constructor for PDFGraphics2D. */
 PdfGraphics2D(
     PdfContentByte cb,
     float width,
     float height,
     FontMapper fontMapper,
     boolean onlyShapes,
     boolean convertImagesToJPEG,
     float quality) {
   super();
   dg2.setRenderingHint(
       RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   setRenderingHint(
       RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   // ssteward: no com.sun.image.codec.jpeg.JPEGCodec for libgcj
   convertImagesToJPEG = false;
   /* ssteward
          try {
              Class.forName("com.sun.image.codec.jpeg.JPEGCodec");
          }
          catch (Throwable t) {
              convertImagesToJPEG = false;
          }
   */
   this.convertImagesToJPEG = convertImagesToJPEG;
   this.jpegQuality = quality;
   this.onlyShapes = onlyShapes;
   this.transform = new AffineTransform();
   this.baseFonts = new HashMap();
   if (!onlyShapes) {
     this.fontMapper = fontMapper;
     if (this.fontMapper == null) this.fontMapper = new DefaultFontMapper();
   }
   this.kids = new ArrayList();
   paint = Color.black;
   background = Color.white;
   setFont(new Font("sanserif", Font.PLAIN, 12));
   this.cb = cb;
   cb.saveState();
   this.width = width;
   this.height = height;
   clip = new Area(new Rectangle2D.Float(0, 0, width, height));
   clip(clip);
   originalStroke = stroke = oldStroke = strokeOne;
   setStrokeDiff(stroke, null);
   cb.saveState();
 }
Exemplo n.º 3
0
 /** @see Graphics#create() */
 public Graphics create() {
   PdfGraphics2D g2 = new PdfGraphics2D();
   g2.rhints.putAll(this.rhints);
   g2.onlyShapes = this.onlyShapes;
   g2.transform = new AffineTransform(this.transform);
   g2.baseFonts = this.baseFonts;
   g2.fontMapper = this.fontMapper;
   g2.paint = this.paint;
   g2.fillGState = this.fillGState;
   g2.currentFillGState = this.currentFillGState;
   g2.strokeGState = this.strokeGState;
   g2.background = this.background;
   g2.mediaTracker = this.mediaTracker;
   g2.convertImagesToJPEG = this.convertImagesToJPEG;
   g2.jpegQuality = this.jpegQuality;
   g2.setFont(this.font);
   g2.cb = this.cb.getDuplicate();
   g2.cb.saveState();
   g2.width = this.width;
   g2.height = this.height;
   g2.followPath(new Area(new Rectangle2D.Float(0, 0, width, height)), CLIP);
   if (this.clip != null) g2.clip = new Area(this.clip);
   g2.composite = composite;
   g2.stroke = stroke;
   g2.originalStroke = originalStroke;
   g2.strokeOne = (BasicStroke) g2.transformStroke(g2.strokeOne);
   g2.oldStroke = g2.strokeOne;
   g2.setStrokeDiff(g2.oldStroke, null);
   g2.cb.saveState();
   if (g2.clip != null) g2.followPath(g2.clip, CLIP);
   g2.kid = true;
   if (this.kids == null) this.kids = new ArrayList();
   this.kids.add(new Integer(cb.getInternalBuffer().size()));
   this.kids.add(g2);
   return g2;
 }
Exemplo n.º 4
0
 /** Constructor for PDFGraphics2D. */
 PdfGraphics2D(
     PdfContentByte cb,
     float width,
     float height,
     FontMapper fontMapper,
     boolean onlyShapes,
     boolean convertImagesToJPEG,
     float quality) {
   super();
   dg2.setRenderingHint(
       RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   setRenderingHint(
       RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   setRenderingHint(HyperLinkKey.KEY_INSTANCE, HyperLinkKey.VALUE_HYPERLINKKEY_OFF);
   this.convertImagesToJPEG = convertImagesToJPEG;
   this.jpegQuality = quality;
   this.onlyShapes = onlyShapes;
   this.transform = new AffineTransform();
   this.baseFonts = new HashMap();
   if (!onlyShapes) {
     this.fontMapper = fontMapper;
     if (this.fontMapper == null) this.fontMapper = new DefaultFontMapper();
   }
   paint = Color.black;
   background = Color.white;
   setFont(new Font("sanserif", Font.PLAIN, 12));
   this.cb = cb;
   cb.saveState();
   this.width = width;
   this.height = height;
   clip = new Area(new Rectangle2D.Float(0, 0, width, height));
   clip(clip);
   originalStroke = stroke = oldStroke = strokeOne;
   setStrokeDiff(stroke, null);
   cb.saveState();
 }
Exemplo n.º 5
0
  private void followPath(Shape s, int drawType) {
    if (s == null) return;
    if (drawType == STROKE) {
      if (!(stroke instanceof BasicStroke)) {
        s = stroke.createStrokedShape(s);
        followPath(s, FILL);
        return;
      }
    }
    if (drawType == STROKE) {
      setStrokeDiff(stroke, oldStroke);
      oldStroke = stroke;
      setStrokePaint();
    } else if (drawType == FILL) setFillPaint();
    PathIterator points;
    int traces = 0;
    if (drawType == CLIP) points = s.getPathIterator(IDENTITY);
    else points = s.getPathIterator(transform);
    float[] coords = new float[6];
    while (!points.isDone()) {
      ++traces;
      int segtype = points.currentSegment(coords);
      normalizeY(coords);
      switch (segtype) {
        case PathIterator.SEG_CLOSE:
          cb.closePath();
          break;

        case PathIterator.SEG_CUBICTO:
          cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
          break;

        case PathIterator.SEG_LINETO:
          cb.lineTo(coords[0], coords[1]);
          break;

        case PathIterator.SEG_MOVETO:
          cb.moveTo(coords[0], coords[1]);
          break;

        case PathIterator.SEG_QUADTO:
          cb.curveTo(coords[0], coords[1], coords[2], coords[3]);
          break;
      }
      points.next();
    }
    switch (drawType) {
      case FILL:
        if (traces > 0) {
          if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) cb.eoFill();
          else cb.fill();
        }
        break;
      case STROKE:
        if (traces > 0) cb.stroke();
        break;
      default: // drawType==CLIP
        if (traces == 0) cb.rectangle(0, 0, 0, 0);
        if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) cb.eoClip();
        else cb.clip();
        cb.newPath();
    }
  }