diff options
author | Keiron Liddle <keiron@apache.org> | 2002-06-20 12:20:46 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-06-20 12:20:46 +0000 |
commit | 5aac7ca831a83a2f144c07c32198b50ac6270891 (patch) | |
tree | a20efbe891b8fca2dfe58e7ab42fffcfe0b513dd | |
parent | 7043c9829a66de30102b9a4ea839cc1633aa1db1 (diff) | |
download | xmlgraphics-fop-5aac7ca831a83a2f144c07c32198b50ac6270891.tar.gz xmlgraphics-fop-5aac7ca831a83a2f144c07c32198b50ac6270891.zip |
implemented some basic transparency, needs optimization
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194903 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/org/apache/fop/pdf/PDFDocument.java | 9 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFGState.java | 70 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFPage.java | 4 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFPattern.java | 4 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFResources.java | 24 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 19 |
6 files changed, 123 insertions, 7 deletions
diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 3954793d0..b2547e975 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -920,6 +920,15 @@ public class PDFDocument { 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 diff --git a/src/org/apache/fop/pdf/PDFGState.java b/src/org/apache/fop/pdf/PDFGState.java new file mode 100644 index 000000000..cf8d32c2a --- /dev/null +++ b/src/org/apache/fop/pdf/PDFGState.java @@ -0,0 +1,70 @@ +/* + * $Id$ + * 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 + */ +} diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index f0fcfad8c..739abe955 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -132,6 +132,10 @@ public class PDFPage extends PDFObject { this.annotList.addAnnot(annot); } + public void addGState(PDFGState gstate) { + this.resources.addGState(gstate); + } + public void addShading(PDFShading shading) { this.resources.addShading(shading); } diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java index a6342525d..412c923bd 100644 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ b/src/org/apache/fop/pdf/PDFPattern.java @@ -81,8 +81,8 @@ public class PDFPattern extends PDFPathPaint { * 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. diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java index 0b4a19cae..34b5d82b9 100644 --- a/src/org/apache/fop/pdf/PDFResources.java +++ b/src/org/apache/fop/pdf/PDFResources.java @@ -29,6 +29,7 @@ public class PDFResources extends PDFObject { 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 @@ public class PDFResources extends PDFObject { 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 @@ public class PDFResources extends PDFObject { + currentShading.referencePDF() + " "); // \n ?????? } - p.append(">> \n"); + p.append(">>\n"); } // "free" the memory. Sorta. currentShading = null; @@ -124,19 +129,30 @@ public class PDFResources extends PDFObject { // "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(); } diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 3d5b65f39..4295656d0 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -536,7 +536,8 @@ public class PDFGraphics2D extends AbstractGraphics2D { 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 @@ public class PDFGraphics2D extends AbstractGraphics2D { + 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 @@ public class PDFGraphics2D extends AbstractGraphics2D { 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); |