1 17 18 19 20 package org.apache.fop.render.ps; 21 22 import java.awt.Dimension ; 23 import java.awt.geom.Rectangle2D ; 24 import java.io.IOException ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.fop.image.EPSImage; 29 import org.apache.fop.image.FopImage; 30 import org.apache.fop.image.JpegImage; 31 import org.apache.xmlgraphics.ps.PSGenerator; 32 33 36 public class PSImageUtils extends org.apache.xmlgraphics.ps.PSImageUtils { 37 38 39 protected static Log log = LogFactory.getLog(PSImageUtils.class); 40 41 51 public static void renderBitmapImage(FopImage img, 52 float x, float y, float w, float h, PSGenerator gen) 53 throws IOException { 54 if (img instanceof JpegImage) { 55 if (!img.load(FopImage.ORIGINAL_DATA)) { 56 gen.commentln("%JPEG image could not be processed: " + img); 57 return; 58 } 59 } else { 60 if (!img.load(FopImage.BITMAP)) { 61 gen.commentln("%Bitmap image could not be processed: " + img); 62 return; 63 } 64 } 65 byte[] imgmap; 66 if (img.getBitmapsSize() > 0) { 67 imgmap = img.getBitmaps(); 68 } else { 69 imgmap = img.getRessourceBytes(); 70 } 71 72 String imgName = img.getMimeType() + " " + img.getOriginalURI(); 73 Dimension imgDim = new Dimension (img.getWidth(), img.getHeight()); 74 Rectangle2D targetRect = new Rectangle2D.Double (x, y, w, h); 75 boolean isJPEG = (img instanceof JpegImage); 76 writeImage(imgmap, imgDim, imgName, targetRect, isJPEG, 77 img.getColorSpace(), gen); 78 } 79 80 public static void renderEPS(EPSImage img, 81 float x, float y, float w, float h, 82 PSGenerator gen) { 83 try { 84 if (!img.load(FopImage.ORIGINAL_DATA)) { 85 gen.commentln("%EPS image could not be processed: " + img); 86 return; 87 } 88 int[] bbox = img.getBBox(); 89 int bboxw = bbox[2] - bbox[0]; 90 int bboxh = bbox[3] - bbox[1]; 91 String name = img.getDocName(); 92 if (name == null || name.length() == 0) { 93 name = img.getOriginalURI(); 94 } 95 renderEPS(img.getEPSImage(), name, 96 x, y, w, h, 97 bbox[0], bbox[1], bboxw, bboxh, gen); 98 99 } catch (Exception e) { 100 log.error("PSRenderer.renderImageArea(): Error rendering bitmap (" 101 + e.getMessage() + ")", e); 102 } 103 } 104 105 } 106 | Popular Tags |