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 ss...@apache.org on 2015/02/10 14:22:49 UTC
svn commit: r1658711 - in /xmlgraphics/fop-pdf-images/trunk: lib/ lib/build/
src/java/META-INF/services/ src/java/org/apache/fop/render/pdf/pdfbox/
test/java/org/apache/fop/render/pdf/ test/resources/
Author: ssteiner
Date: Tue Feb 10 13:22:48 2015
New Revision: 1658711
URL: http://svn.apache.org/r1658711
Log:
FOP-2448: PDF to PS deduplication of images
Added:
xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.LICENCE.txt (with props)
xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.NOTICE.txt (with props)
xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.jar (with props)
xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.LICENSE.txt (with props)
xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.jar (with props)
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageLoaderFactoryImageRawData.java (with props)
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java (with props)
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderImageRawData.java (with props)
xmlgraphics/fop-pdf-images/trunk/test/resources/image.pdf (with props)
Modified:
xmlgraphics/fop-pdf-images/trunk/lib/fop.jar
xmlgraphics/fop-pdf-images/trunk/lib/xmlgraphics-commons-svn-trunk.jar
xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory
xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
Added: xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.LICENCE.txt
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.LICENCE.txt?rev=1658711&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.LICENCE.txt (added)
+++ xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.LICENCE.txt Tue Feb 10 13:22:48 2015
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2007 Mockito contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
Propchange: xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.LICENCE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.NOTICE.txt
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.NOTICE.txt?rev=1658711&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.NOTICE.txt (added)
+++ xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.NOTICE.txt Tue Feb 10 13:22:48 2015
@@ -0,0 +1,11 @@
+Mockito license - MIT.
+
+Libraries used:
+
+Cglib - Apache License 2.0
+ASM - BSD license
+
+Mockito all distribution:
+
+Objenesis - MIT license
+Hamcrest - BSD license
\ No newline at end of file
Propchange: xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.NOTICE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.jar?rev=1658711&view=auto
==============================================================================
Binary file - no diff available.
Propchange: xmlgraphics/fop-pdf-images/trunk/lib/build/mockito-core-1.8.5.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.LICENSE.txt
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.LICENSE.txt?rev=1658711&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.LICENSE.txt (added)
+++ xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.LICENSE.txt Tue Feb 10 13:22:48 2015
@@ -0,0 +1,18 @@
+Copyright (c) 2003-2008, Objenesis Team and all contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
Propchange: xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.jar?rev=1658711&view=auto
==============================================================================
Binary file - no diff available.
Propchange: xmlgraphics/fop-pdf-images/trunk/lib/build/objenesis-1.0.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: xmlgraphics/fop-pdf-images/trunk/lib/fop.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/fop.jar?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
Binary files - no diff available.
Modified: xmlgraphics/fop-pdf-images/trunk/lib/xmlgraphics-commons-svn-trunk.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/xmlgraphics-commons-svn-trunk.jar?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
Binary files - no diff available.
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory Tue Feb 10 13:22:48 2015
@@ -1 +1,2 @@
-org.apache.fop.render.pdf.pdfbox.ImageLoaderFactoryPDF
\ No newline at end of file
+org.apache.fop.render.pdf.pdfbox.ImageLoaderFactoryPDF
+org.apache.fop.render.pdf.pdfbox.ImageLoaderFactoryImageRawData
\ No newline at end of file
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImagePreloader Tue Feb 10 13:22:48 2015
@@ -1 +1,2 @@
-org.apache.fop.render.pdf.pdfbox.PreloaderPDF
\ No newline at end of file
+org.apache.fop.render.pdf.pdfbox.PreloaderPDF
+org.apache.fop.render.pdf.pdfbox.PreloaderImageRawData
\ No newline at end of file
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java Tue Feb 10 13:22:48 2015
@@ -37,7 +37,9 @@ import org.apache.xmlgraphics.image.load
import org.apache.xmlgraphics.image.loader.impl.AbstractImageConverter;
import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.ps.PSGenerator;
/**
* Image converter implementation to convert PDF pages into Java2D images.
@@ -80,7 +82,7 @@ public class ImageConverterPDF2G2D exten
return 1000; //Use only if no native embedding is possible
}
- private static class Graphics2DImagePainterPDF implements Graphics2DImagePainter {
+ private static class Graphics2DImagePainterPDF implements GeneralGraphics2DImagePainter {
private final PDPage page;
@@ -140,6 +142,10 @@ public class ImageConverterPDF2G2D exten
}
}
+ public Graphics2D getGraphics(boolean textAsShapes, PSGenerator gen) {
+ PSPDFGraphics2D graphics = new PSPDFGraphics2D(textAsShapes, gen);
+ return graphics;
+ }
}
}
Added: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageLoaderFactoryImageRawData.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageLoaderFactoryImageRawData.java?rev=1658711&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageLoaderFactoryImageRawData.java (added)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageLoaderFactoryImageRawData.java Tue Feb 10 13:22:48 2015
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pdf.pdfbox;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageLoaderFactory;
+import org.apache.xmlgraphics.image.loader.spi.ImageLoader;
+
+public class ImageLoaderFactoryImageRawData extends AbstractImageLoaderFactory {
+ public String[] getSupportedMIMETypes() {
+ String[] mimes = {"image/DataBufferInt"};
+ return mimes;
+ }
+
+ public ImageFlavor[] getSupportedFlavors(String s) {
+ ImageFlavor[] imageFlavors = {ImageFlavor.BUFFERED_IMAGE};
+ return imageFlavors;
+ }
+
+ public ImageLoader newImageLoader(ImageFlavor imageFlavor) {
+ return new RawImageLoader();
+ }
+
+ static class RawImageLoader implements ImageLoader {
+
+ public Image loadImage(ImageInfo imageInfo, Map map, ImageSessionContext imageSessionContext)
+ throws ImageException, IOException {
+ return imageInfo.getOriginalImage();
+ }
+
+ public Image loadImage(ImageInfo imageInfo, ImageSessionContext imageSessionContext)
+ throws ImageException, IOException {
+ return null;
+ }
+
+ public ImageFlavor getTargetFlavor() {
+ return ImageFlavor.BUFFERED_IMAGE;
+ }
+
+ public int getUsagePenalty() {
+ return 0;
+ }
+ }
+
+ public boolean isAvailable() {
+ return true;
+ }
+}
Propchange: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageLoaderFactoryImageRawData.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java Tue Feb 10 13:22:48 2015
@@ -49,8 +49,8 @@ public class PDFBoxImageHandler extends
ImagePDF.PDFBOX_IMAGE
};
- public void handleImage(RenderingContext context, Image image, Rectangle pos)
- throws IOException {
+ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
+ assert context instanceof PDFRenderingContext;
PDFRenderingContext pdfContext = (PDFRenderingContext)context;
PDFContentGenerator generator = pdfContext.getGenerator();
assert image instanceof ImagePDF;
Added: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java?rev=1658711&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java (added)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java Tue Feb 10 13:22:48 2015
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.pdf.pdfbox;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferInt;
+import java.awt.image.ImageObserver;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Arrays;
+
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.io.TempResourceURIGenerator;
+import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSResource;
+
+import org.apache.fop.render.ps.PSDocumentHandler;
+import org.apache.fop.render.ps.PSImageUtils;
+
+public class PSPDFGraphics2D extends PSGraphics2D {
+
+ public PSPDFGraphics2D(boolean textAsShapes) {
+ super(textAsShapes);
+ }
+
+ public PSPDFGraphics2D(PSGraphics2D g) {
+ super(g);
+ }
+
+ public PSPDFGraphics2D(boolean textAsShapes, PSGenerator gen) {
+ super(textAsShapes, gen);
+ }
+
+ @Override
+ public boolean drawImage(Image img, int x1, int y1, ImageObserver observer) {
+ PSGenerator tmp = gen;
+ if (gen instanceof PSDocumentHandler.FOPPSGenerator) {
+ PSDocumentHandler.FOPPSGenerator fopGen = (PSDocumentHandler.FOPPSGenerator)tmp;
+ PSDocumentHandler handler = fopGen.getHandler();
+ if (handler.getPSUtil().isOptimizeResources()) {
+ try {
+ final int width = img.getWidth(observer);
+ final int height = img.getHeight(observer);
+ if (width == -1 || height == -1) {
+ return false;
+ }
+ BufferedImage buf = getImage(width, height, img, observer);
+ if (buf == null) {
+ return false;
+ }
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataBufferInt db = (DataBufferInt) buf.getRaster().getDataBuffer();
+ DataOutputStream dos = new DataOutputStream(bos);
+ dos.writeInt(width);
+ dos.writeInt(height);
+ for (int i : db.getData()) {
+ dos.writeInt(i);
+ }
+ String format = DataBufferInt.class.getName();
+ int hash = Arrays.hashCode(bos.toByteArray());
+ URI uri = fopGen.getImages().get(hash);
+ if (uri == null) {
+ uri = new TempResourceURIGenerator("img" + hash + "." + format).generate();
+ fopGen.getImages().put(hash, uri);
+ BufferedOutputStream outputStream = fopGen.getTempStream(uri);
+ outputStream.write(bos.toByteArray());
+ outputStream.close();
+ }
+ PSResource form = handler.getFormForImage(uri.toASCIIString());
+ ImageInfo info = new ImageInfo(uri.toASCIIString(), "image/" + format);
+ ImageSize size = new ImageSize(width, height, handler.getUserAgent().getTargetResolution());
+ size.calcSizeFromPixels();
+ info.setSize(size);
+ float res = handler.getUserAgent().getSourceResolution() / 72;
+ Rectangle rect =
+ new Rectangle(0, 0, (int)(size.getWidthMpt() * res), (int)(size.getHeightMpt() * res));
+ gen.saveGraphicsState();
+ gen.concatMatrix(getTransform());
+ writeClip(getClip());
+ PSImageUtils.drawForm(form, info, rect, gen);
+ gen.restoreGraphicsState();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+ }
+ return super.drawImage(img, x1, y1, observer);
+ }
+
+ private BufferedImage getImage(int width, int height, Image img, ImageObserver observer) {
+ Dimension size = new Dimension(width, height);
+ BufferedImage buf = buildBufferedImage(size);
+ Graphics2D g = buf.createGraphics();
+ g.setComposite(AlphaComposite.SrcOver);
+ g.setBackground(new Color(1, 1, 1, 0));
+ g.fillRect(0, 0, width, height);
+ g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight()));
+ if (!g.drawImage(img, 0, 0, observer)) {
+ return null;
+ }
+ g.dispose();
+ return buf;
+ }
+}
Propchange: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderImageRawData.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderImageRawData.java?rev=1658711&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderImageRawData.java (added)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderImageRawData.java Tue Feb 10 13:22:48 2015
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.pdf.pdfbox;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferInt;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+
+import javax.xml.transform.Source;
+
+import org.apache.pdfbox.io.IOUtils;
+
+import org.apache.xmlgraphics.image.loader.ImageContext;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.ImageSource;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+
+public class PreloaderImageRawData extends AbstractImagePreloader {
+ public ImageInfo preloadImage(String s, Source source, ImageContext imageContext)
+ throws ImageException, IOException {
+ if (source instanceof ImageSource && s.contains(DataBufferInt.class.getName())) {
+ InputStream is = ((ImageSource)source).getInputStream();
+ byte[] input = IOUtils.toByteArray(is);
+ is.reset();
+ IntBuffer intBuf = ByteBuffer.wrap(input).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
+ int[] array = new int[intBuf.remaining()];
+ intBuf.get(array);
+ int width = array[0];
+ int height = array[1];
+ ImageInfo info = new ImageInfo(s, "image/DataBufferInt");
+ ImageSize size = new ImageSize(width, height, imageContext.getSourceResolution());
+ size.calcSizeFromPixels();
+ info.setSize(size);
+ BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ DataBufferInt db = (DataBufferInt) img.getRaster().getDataBuffer();
+ System.arraycopy(array, 2, db.getData(), 0, db.getData().length);
+ info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, new ImageRendered(info, img, null));
+ return info;
+ }
+ return null;
+ }
+}
Propchange: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderImageRawData.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1658711&r1=1658710&r2=1658711&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Tue Feb 10 13:22:48 2015
@@ -20,11 +20,16 @@ package org.apache.fop.render.pdf;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.awt.image.DataBufferInt;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -32,16 +37,14 @@ import java.util.Set;
import java.util.TreeSet;
import javax.imageio.ImageIO;
+import javax.imageio.stream.MemoryCacheImageInputStream;
-import org.apache.fop.pdf.PDFAnnotList;
-import org.apache.fop.pdf.PDFArray;
-import org.apache.fop.pdf.PDFGState;
-import org.apache.fop.render.pdf.pdfbox.FOPPDFMultiByteFont;
-import org.apache.fop.render.pdf.pdfbox.FOPPDFSingleByteFont;
-import org.apache.fop.render.pdf.pdfbox.ImagePDF;
-import org.apache.fop.render.pdf.pdfbox.PDFBoxImageHandler;
import org.junit.Test;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.commons.io.IOUtils;
import org.apache.fontbox.cff.CFFFont;
import org.apache.fontbox.cff.CFFParser;
@@ -53,20 +56,40 @@ import org.apache.pdfbox.pdmodel.PDDocum
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.xmlgraphics.image.loader.ImageException;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageSource;
import org.apache.xmlgraphics.image.loader.impl.DefaultImageContext;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontType;
import org.apache.fop.fonts.MultiByteFont;
import org.apache.fop.fonts.Typeface;
+import org.apache.fop.pdf.PDFAnnotList;
+import org.apache.fop.pdf.PDFArray;
import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFGState;
import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFResources;
+import org.apache.fop.render.pdf.pdfbox.FOPPDFMultiByteFont;
+import org.apache.fop.render.pdf.pdfbox.FOPPDFSingleByteFont;
+import org.apache.fop.render.pdf.pdfbox.ImageConverterPDF2G2D;
+import org.apache.fop.render.pdf.pdfbox.ImagePDF;
import org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter;
+import org.apache.fop.render.pdf.pdfbox.PDFBoxImageHandler;
+import org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D;
+import org.apache.fop.render.pdf.pdfbox.PreloaderImageRawData;
import org.apache.fop.render.pdf.pdfbox.PreloaderPDF;
+import org.apache.fop.render.ps.PSDocumentHandler;
+import org.apache.fop.render.ps.PSImageFormResource;
+import org.apache.fop.render.ps.PSRenderingUtil;
import junit.framework.Assert;
@@ -91,6 +114,7 @@ public class PDFBoxAdapterTestCase {
private static final String ROTATE = "test/resources/rotate.pdf";
private static final String SHADING = "test/resources/shading.pdf";
private static final String LINK = "test/resources/link.pdf";
+ private static final String IMAGE = "test/resources/image.pdf";
private PDFBoxAdapter getPDFBoxAdapter() {
PDFDocument doc = new PDFDocument("");
@@ -323,6 +347,69 @@ public class PDFBoxAdapterTestCase {
Assert.assertEquals(imageInfo.getMimeType(), "application/pdf");
}
+ @Test
+ public void testPSPDFGraphics2D() throws Exception {
+ ByteArrayOutputStream stream = pdfToPS(IMAGE);
+ Assert.assertTrue(stream.toString("UTF-8"),
+ stream.toString("UTF-8").contains("%%IncludeResource: form FOPForm:0\nFOPForm:0 execform"));
+ }
+
+ private ByteArrayOutputStream pdfToPS(String pdf) throws IOException, ImageException {
+ ImageConverterPDF2G2D i = new ImageConverterPDF2G2D();
+ ImageInfo imgi = new ImageInfo("a", "b");
+ PDDocument doc = PDDocument.load(pdf);
+ org.apache.xmlgraphics.image.loader.Image img = new ImagePDF(imgi, doc);
+ ImageGraphics2D ig = (ImageGraphics2D)i.convert(img, null);
+ GeneralGraphics2DImagePainter g = (GeneralGraphics2DImagePainter) ig.getGraphics2DImagePainter();
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ PSPDFGraphics2D g2d = (PSPDFGraphics2D) g.getGraphics(true, new FOPPSGeneratorImpl(stream));
+ Rectangle2D rect = new Rectangle2D.Float(0, 0, 100, 100);
+ GraphicContext gc = new GraphicContext();
+ g2d.setGraphicContext(gc);
+ ig.getGraphics2DImagePainter().paint(g2d, rect);
+ doc.close();
+ return stream;
+ }
+
+ @Test
+ public void testPreloaderImageRawData() throws IOException, ImageException {
+ PreloaderImageRawData p = new PreloaderImageRawData();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+ dos.writeInt(1);
+ dos.writeInt(1);
+ dos.writeInt(1);
+ InputStream is = new ByteArrayInputStream(bos.toByteArray());
+ ImageSource src = new ImageSource(new MemoryCacheImageInputStream(is), "", true);
+ ImageInfo img = p.preloadImage(DataBufferInt.class.getName(), src, new DefaultImageContext());
+ Assert.assertTrue(img.getOriginalImage() instanceof ImageRendered);
+ }
+
+ static class FOPPSGeneratorImpl extends PSGenerator implements PSDocumentHandler.FOPPSGenerator {
+ public FOPPSGeneratorImpl(OutputStream out) {
+ super(out);
+ }
+
+ public PSDocumentHandler getHandler() {
+ PSDocumentHandler handler = mock(PSDocumentHandler.class);
+ PSRenderingUtil util = mock(PSRenderingUtil.class);
+ when(util.isOptimizeResources()).thenReturn(true);
+ when(handler.getPSUtil()).thenReturn(util);
+ FOUserAgent mockedAgent = mock(FOUserAgent.class);
+ when(handler.getUserAgent()).thenReturn(mockedAgent);
+ when(mockedAgent.getTargetResolution()).thenReturn(72f);
+ when(handler.getFormForImage(any(String.class))).thenReturn(new PSImageFormResource(0, ""));
+ return handler;
+ }
+
+ public BufferedOutputStream getTempStream(URI uri) throws IOException {
+ return new BufferedOutputStream(new ByteArrayOutputStream());
+ }
+
+ public Map<Integer, URI> getImages() {
+ return new HashMap<Integer, URI>();
+ }
+ }
@Test
public void testPDFBoxImageHandler() throws Exception {
Added: xmlgraphics/fop-pdf-images/trunk/test/resources/image.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/resources/image.pdf?rev=1658711&view=auto
==============================================================================
Binary file - no diff available.
Propchange: xmlgraphics/fop-pdf-images/trunk/test/resources/image.pdf
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org