You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2002/06/20 14:20:47 UTC

cvs commit: xml-fop/src/org/apache/fop/svg PDFGraphics2D.java

keiron      2002/06/20 05:20:47

  Modified:    src/org/apache/fop/pdf PDFDocument.java PDFPage.java
                        PDFPattern.java PDFResources.java
               src/org/apache/fop/svg PDFGraphics2D.java
  Added:       src/org/apache/fop/pdf PDFGState.java
  Log:
  implemented some basic transparency, needs optimization
  
  Revision  Changes    Path
  1.40      +10 -1     xml-fop/src/org/apache/fop/pdf/PDFDocument.java
  
  Index: PDFDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- PDFDocument.java	20 Jun 2002 09:14:15 -0000	1.39
  +++ PDFDocument.java	20 Jun 2002 12:20:46 -0000	1.40
  @@ -920,6 +920,15 @@
           return array;
       }
   
  +    /**
  +     * make an ExtGState for extra graphics options
  +     */
  +    public PDFGState makeGState() {
  +
  +        PDFGState gstate = new PDFGState(++this.objectcount);
  +        this.objects.add(gstate);
  +        return gstate;
  +    }
   
       public int addImage(FopImage img) {
           // check if already created
  
  
  
  1.15      +5 -1      xml-fop/src/org/apache/fop/pdf/PDFPage.java
  
  Index: PDFPage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPage.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PDFPage.java	18 Jun 2002 13:42:56 -0000	1.14
  +++ PDFPage.java	20 Jun 2002 12:20:46 -0000	1.15
  @@ -132,6 +132,10 @@
           this.annotList.addAnnot(annot);
       }
   
  +    public void addGState(PDFGState gstate) {
  +        this.resources.addGState(gstate);
  +    }
  +
       public void addShading(PDFShading shading) {
           this.resources.addShading(shading);
       }
  
  
  
  1.10      +3 -3      xml-fop/src/org/apache/fop/pdf/PDFPattern.java
  
  Index: PDFPattern.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPattern.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PDFPattern.java	2 Nov 2001 11:06:07 -0000	1.9
  +++ PDFPattern.java	20 Jun 2002 12:20:46 -0000	1.10
  @@ -81,8 +81,8 @@
        * String representing the extended Graphics state.
        * Probably will never be used like this.
        */
  -    protected StringBuffer extGState =
  -        null;                                                           // eventually, need a PDFExtGSState object... but not now.
  +    protected StringBuffer extGState = null;
  +    // eventually, need a PDFExtGSState object... but not now.
   
       /**
        * ArrayList of Doubles representing the Transformation matrix.
  
  
  
  1.12      +21 -5     xml-fop/src/org/apache/fop/pdf/PDFResources.java
  
  Index: PDFResources.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFResources.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PDFResources.java	2 Nov 2001 11:06:07 -0000	1.11
  +++ PDFResources.java	20 Jun 2002 12:20:46 -0000	1.12
  @@ -29,6 +29,7 @@
       protected ArrayList xObjects = null;
       protected ArrayList patterns = new ArrayList();
       protected ArrayList shadings = new ArrayList();
  +    protected ArrayList gstates = new ArrayList();
   
       /**
        * create a /Resources object.
  @@ -51,6 +52,10 @@
           this.fonts.put(font.getName(), font);
       }
   
  +    public void addGState(PDFGState gs) {
  +        this.gstates.add(gs);
  +    }
  +
       public void addShading(PDFShading theShading) {
           this.shadings.add(theShading);
       }
  @@ -100,7 +105,7 @@
                            + currentShading.referencePDF() + " ");    // \n ??????
               }
   
  -            p.append(">> \n");
  +            p.append(">>\n");
           }
           // "free" the memory. Sorta.
           currentShading = null;
  @@ -124,19 +129,30 @@
           // "free" the memory. Sorta.
           currentPattern = null;
   
  -        p.append("/ProcSet [ /PDF /ImageC /Text ] ");
  +        p.append("/ProcSet [ /PDF /ImageC /Text ]\n");
   
           if (!this.xObjects.isEmpty()) {
               p = p.append("/XObject <<");
               for (int i = 1; i <= this.xObjects.size(); i++) {
                   p = p.append("/Im" + i + " "
                                + ((PDFXObject)this.xObjects.get(i - 1)).referencePDF()
  -                             + " \n");
  +                             + "\n");
  +            }
  +            p = p.append(" >>\n");
  +        }
  +
  +        if (!this.gstates.isEmpty()) {
  +            p = p.append("/ExtGState <<");
  +            for (int i = 0; i < this.gstates.size(); i++) {
  +                PDFGState gs = (PDFGState)this.gstates.get(i);
  +                p = p.append("/" + gs.getName() + " "
  +                             + gs.referencePDF()
  +                             + "\n");
               }
               p = p.append(" >>\n");
           }
   
  -        p = p.append(">> \nendobj\n");
  +        p = p.append(">>\nendobj\n");
   
           return p.toString().getBytes();
       }
  
  
  
  1.1                  xml-fop/src/org/apache/fop/pdf/PDFGState.java
  
  Index: PDFGState.java
  ===================================================================
  /*
   * $Id: PDFGState.java,v 1.1 2002/06/20 12:20:46 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.pdf;
  
  /**
   * class representing a /ExtGState object.
   *
   */
  public class PDFGState extends PDFObject {
      float alphaFill = 1;
      float alphaStroke = 1;
  
      /**
       * create a /ExtGState object.
       *
       * @param number the object's number
       * @param pageReference the pageReference represented by this object
       */
      public PDFGState(int number) {
  
          /* generic creation of object */
          super(number);
  
      }
  
      public String getName() {
          return "GS" + this.number;
      }
  
      public void setAlpha(float val, boolean fill) {
          if(fill) {
              alphaFill = val;
          } else {
              alphaStroke = val;
          }
      }
  
      /**
       * represent the object in PDF
       *
       * @return the PDF string
       */
      public byte[] toPDF() {
          StringBuffer sb = new StringBuffer(this.number + " " + this.generation
                                + " obj\n<<\n/Type /ExtGState\n");
          if(alphaFill != 1) {
              sb.append("/ca " + alphaFill + "\n");
          }
          if(alphaStroke != 1) {
              sb.append("/CA " + alphaStroke + "\n");
          }
          sb.append(">>\nendobj\n");
          return sb.toString().getBytes();
      }
  
      /*
       * example
       * 29 0 obj
       * <<
       * /Type /ExtGState
       * /ca 0.5
       * >>
       * endobj
       */
  }
  
  
  
  1.30      +20 -3     xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java
  
  Index: PDFGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PDFGraphics2D.java	20 Jun 2002 09:14:16 -0000	1.29
  +++ PDFGraphics2D.java	20 Jun 2002 12:20:46 -0000	1.30
  @@ -536,7 +536,8 @@
   
           Shape imclip = getClip();
           boolean newClip = graphicsState.checkClip(imclip);
  -        boolean newTransform = graphicsState.checkTransform(trans);
  +        boolean newTransform = graphicsState.checkTransform(trans)
  +                               && !trans.isIdentity();
   
           if(newClip || newTransform) { 
               currentStream.write("q\n");
  @@ -553,6 +554,14 @@
                               + PDFNumber.doubleOut(tranvals[5], 5) + " cm\n");
               }
           }
  +
  +        if(c.getAlpha() != 255) {
  +            PDFGState gstate = pdfDoc.makeGState();
  +            gstate.setAlpha(c.getAlpha() / 255f, false);
  +            currentPage.addGState(gstate);
  +            currentStream.write("/" + gstate.getName() + " gs\n");
  +        }
  +
           applyColor(c, false);
   
           applyPaint(getPaint(), false);
  @@ -1134,6 +1143,14 @@
               writeClip(imclip);
               graphicsState.setClip(imclip);
           }
  +
  +        if(c.getAlpha() != 255) {
  +            PDFGState gstate = pdfDoc.makeGState();
  +            gstate.setAlpha(c.getAlpha() / 255f, true);
  +            currentPage.addGState(gstate);
  +            currentStream.write("/" + gstate.getName() + " gs\n");
  +        }
  +
           c = getColor();
           if(graphicsState.setColor(c)) {
               applyColor(c, true);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org