diff options
author | Keiron Liddle <keiron@apache.org> | 2002-06-28 10:09:07 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-06-28 10:09:07 +0000 |
commit | 73d16e990b458dfbd9db7d68085da601c49d9c42 (patch) | |
tree | 776879d5a2a26abec2228cacf6ff0781db239256 /src/org/apache/fop/svg | |
parent | 00dd98af348dcae07fa4f0ea8838ccb2603e7d94 (diff) | |
download | xmlgraphics-fop-73d16e990b458dfbd9db7d68085da601c49d9c42.tar.gz xmlgraphics-fop-73d16e990b458dfbd9db7d68085da601c49d9c42.zip |
handles pattern resources better
made stream filters externally configured
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194934 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/svg')
-rw-r--r-- | src/org/apache/fop/svg/PDFDocumentGraphics2D.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 91 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTextElementBridge.java | 4 |
3 files changed, 62 insertions, 39 deletions
diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java index 355837630..628817b77 100644 --- a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -37,6 +37,7 @@ import org.apache.batik.ext.awt.g2d.GraphicContext; public class PDFDocumentGraphics2D extends PDFGraphics2D { OutputStream stream; + PDFPage currentPage; PDFStream pdfStream; int width; int height; @@ -69,7 +70,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { standalone = true; this.pdfDoc = new PDFDocument(); this.pdfDoc.setProducer("FOP SVG Renderer"); - pdfStream = this.pdfDoc.makeStream(); + pdfStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER); graphicsState = new PDFState(); @@ -87,6 +88,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { PDFResources pdfResources = this.pdfDoc.getResources(); currentPage = this.pdfDoc.makePage(pdfResources, width, height); + resourceContext = currentPage; currentStream.write("1 0 0 -1 0 " + height + " cm\n"); } @@ -156,7 +158,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { currentPage.setContents(pdfStream); this.pdfDoc.addPage(currentPage); if (fontInfo != null) { - FontSetup.addToResources(this.pdfDoc, fontInfo); + FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo); } pdfDoc.outputHeader(stream); this.pdfDoc.output(stream); diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 91c7389e6..db48aa2a4 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -58,7 +58,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * the PDF Document being created */ protected PDFDocument pdfDoc; - protected PDFPage currentPage; + protected PDFResourceContext resourceContext; /** * the current state of the pdf graphics @@ -113,10 +113,10 @@ public class PDFGraphics2D extends AbstractGraphics2D { * existing document. */ public PDFGraphics2D(boolean textAsShapes, FontState fs, PDFDocument doc, - PDFPage page, String font, float size, int xpos, int ypos) { + PDFResourceContext page, String font, float size, int xpos, int ypos) { super(textAsShapes); pdfDoc = doc; - currentPage = page; + resourceContext = page; currentFontName = font; currentFontSize = size; currentYPosition = ypos; @@ -175,16 +175,17 @@ public class PDFGraphics2D extends AbstractGraphics2D { if(linkType != PDFLink.EXTERNAL) { String pdfdest = "/FitR " + dest; - currentPage.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, pdfdest)); + // TODO use page ref instead + resourceContext.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, pdfdest)); } else { - currentPage.addAnnotation(pdfDoc.makeLink(rect, + resourceContext.addAnnotation(pdfDoc.makeLink(rect, dest, linkType)); } } public void addJpegImage(JpegImage jpeg, float x, float y, float width, float height) { FopPDFImage fopimage = new FopPDFImage(jpeg); - int xObjectNum = this.pdfDoc.addImage(fopimage).getXNumber(); + int xObjectNum = this.pdfDoc.addImage(resourceContext, fopimage).getXNumber(); AffineTransform at = getTransform(); double[] matrix = new double[6]; @@ -316,7 +317,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { // if the mask is binary then we could convert it into a bitmask BitmapImage fopimg = new BitmapImage("TempImageMask:" + img.toString(), buf.getWidth(), buf.getHeight(), mask, null); fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY)); - PDFXObject xobj = pdfDoc.addImage(fopimg); + PDFXObject xobj = pdfDoc.addImage(resourceContext, fopimg); ref = xobj.referencePDF(); } else { mask = null; @@ -324,7 +325,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { BitmapImage fopimg = new BitmapImage("TempImage:" + img.toString(), buf.getWidth(), buf.getHeight(), result, ref); fopimg.setTransparent(new PDFColor(255, 255, 255)); - imageInfo.xObjectNum = pdfDoc.addImage(fopimg).getXNumber(); + imageInfo.xObjectNum = pdfDoc.addImage(resourceContext, fopimg).getXNumber(); imageInfos.put(img, imageInfo); } @@ -476,7 +477,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { if(c.getAlpha() != 255) { PDFGState gstate = pdfDoc.makeGState(); gstate.setAlpha(c.getAlpha() / 255f, false); - currentPage.addGState(gstate); + resourceContext.addGState(gstate); currentStream.write("/" + gstate.getName() + " gs\n"); } @@ -655,43 +656,63 @@ public class PDFGraphics2D extends AbstractGraphics2D { color1.getVector(), color2.getVector(), 1.0); PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); - PDFPattern myPat = this.pdfDoc.createGradient(false, aColorSpace, + PDFResources res = pdfDoc.makeResources(); + PDFPattern myPat = this.pdfDoc.createGradient(resourceContext, false, aColorSpace, someColors, null, theCoords); currentStream.write(myPat.getColorSpaceOut(fill)); } else if (paint instanceof RadialGradientPaint) { - System.err.println("Radial gradient paint not supported"); - RadialGradientPaint rgp = (RadialGradientPaint)paint; -/* + + float ar = rgp.getRadius(); + Point2D ac = rgp.getCenterPoint(); + Point2D af = rgp.getFocusPoint(); + ArrayList theCoords = new ArrayList(); - theCoords.add( new Double(currentXPosition / 1000f + acx)); - theCoords.add( new Double(currentYPosition / 1000f - acy)); + theCoords.add( new Double(currentXPosition + ac.getX())); + theCoords.add( new Double(currentYPosition - ac.getY())); theCoords.add(new Double(0)); - theCoords.add( new Double(currentXPosition / 1000f + afx)); // Fx - theCoords.add(new Double(currentYPosition / 1000f - afy)); // Fy + theCoords.add( new Double(currentXPosition + af.getX())); // Fx + theCoords.add(new Double(currentYPosition - af.getY())); // Fy theCoords.add(new Double(ar)); - float lastoffset = 0; - PDFColor color = new PDFColor(0, 0, 0); - color = new PDFColor(red, green, blue); + Color[] cols = rgp.getColors(); + ArrayList someColors = new ArrayList(); + for(int count = 0; count < cols.length; count++) { + someColors.add(new PDFColor(cols[count].getRed(), cols[count].getGreen(), cols[count].getBlue())); + } - float offset = stop.getOffset().getBaseVal(); -// create bounds from last to offset + float[] fractions = rgp.getFractions(); + ArrayList theBounds = new ArrayList(); + float lastoffset = 0; + for(int count = 0; count < fractions.length; count++) { + float offset = fractions[count]; + // create bounds from last to offset lastoffset = offset; - someColors.add(color); } - PDFPattern myPat = pdfDoc.createGradient(true, aColorSpace, + PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB); + PDFPattern myPat = pdfDoc.createGradient(resourceContext, true, colSpace, someColors, theBounds, theCoords); currentStream.write(myPat.getColorSpaceOut(fill)); -*/ + } else if (paint instanceof PatternPaint) { PatternPaint pp = (PatternPaint)paint; Rectangle2D rect = pp.getPatternRect(); - PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontState, - pdfDoc, currentPage, + FontInfo fi = new FontInfo(); + FontSetup.setup(fi); + FontState fs = null; + try { + fs = new FontState(fi, "sans-serif", "normal", + "normal", 1, 0); + } catch (org.apache.fop.apps.FOPException fope) { + fope.printStackTrace(); + } + PDFResources res = pdfDoc.makeResources(); + PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res); + PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fs, + pdfDoc, context, currentFontName, currentFontSize, currentYPosition, currentXPosition); pattGraphic.gc = (GraphicContext)this.gc.clone(); @@ -722,10 +743,12 @@ public class PDFGraphics2D extends AbstractGraphics2D { translate.add(new Double(0)); translate.add(new Double(0)); translate.add(new Double(1)); - translate.add(new Double(rect.getX())); - translate.add(new Double(rect.getY())); - // TODO handle PDFResources - PDFPattern myPat = pdfDoc.makePattern(1, null, 1, 1, bbox, + translate.add(new Double(0/*rect.getX()*/)); + translate.add(new Double(0/*rect.getY()*/)); + + FontSetup.addToResources(pdfDoc, res, fi); + + PDFPattern myPat = pdfDoc.makePattern(resourceContext, 1, res, 1, 1, bbox, rect.getWidth(), rect.getHeight(), translate, null, pattStream.getBuffer()); @@ -916,11 +939,11 @@ public class PDFGraphics2D extends AbstractGraphics2D { c = getBackground(); applyColor(c, false); - if(salpha != 255 || c.getAlpha() != 255) { + if(salpha != 255/* || c.getAlpha() != 255*/) { PDFGState gstate = pdfDoc.makeGState(); gstate.setAlpha(salpha / 255f, true); //gstate.setAlpha(c.getAlpha() / 255f, false); - currentPage.addGState(gstate); + resourceContext.addGState(gstate); currentStream.write("/" + gstate.getName() + " gs\n"); } @@ -1150,7 +1173,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { if(c.getAlpha() != 255) { PDFGState gstate = pdfDoc.makeGState(); gstate.setAlpha(c.getAlpha() / 255f, true); - currentPage.addGState(gstate); + resourceContext.addGState(gstate); currentStream.write("/" + gstate.getName() + " gs\n"); } diff --git a/src/org/apache/fop/svg/PDFTextElementBridge.java b/src/org/apache/fop/svg/PDFTextElementBridge.java index 933165b97..fc2fd9fdd 100644 --- a/src/org/apache/fop/svg/PDFTextElementBridge.java +++ b/src/org/apache/fop/svg/PDFTextElementBridge.java @@ -60,9 +60,7 @@ public class PDFTextElementBridge extends SVGTextElementBridge { private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) { // Font size, in user space units. float fs = TextUtilities.convertFontSize(element).floatValue(); - /*if(((int)fs) != fs) { - return false; - }*/ + // PDF cannot display fonts over 36pt if(fs > 36) { return false; } |