public static void displayImageInfo(ImageInfo info) { ImageSize size = info.getSize(); Dimension2D dPt = size.getDimensionPt(); Dimension dPx = size.getDimensionPx(); log.debug(info.getOriginalURI() + " " + info.getMimeType() + " " + Math.round(dPx.getWidth()) + "x" + Math.round(dPx.getHeight())); log.debug("Resolution:" + Math.round(size.getDpiHorizontal()) + "x" + Math.round(size.getDpiVertical())); log.debug("Print size: " + Math.round(dPt.getWidth() / 72) + "\" x" + Math.round(dPt.getHeight() / 72) + "\""); }
/** * Create a <wp:inline> element suitable for this image, * which can be _embedded_ in w:p/w:r/w:drawing. * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document * @param cx Image width in twip * @param link true if this is to be linked not embedded * None of these things seem to be exposed in Word 2007's * user interface, but Word won't open the document if * any of the attributes these go in (except @ desc) aren't present! * @throws Exception */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, long cx, boolean link) throws Exception { ImageSize size = imageInfo.getSize(); Dimension2D dPt = size.getDimensionPt(); double imageWidthTwips = dPt.getWidth() * 20; log.debug("imageWidthTwips: " + imageWidthTwips); long cy; log.debug("Scaling image height to retain aspect ratio"); cy = UnitsOfMeasurement.twipToEMU(dPt.getHeight() * 20 * cx / imageWidthTwips); // Now convert cx to EMU cx = UnitsOfMeasurement.twipToEMU(cx); log.debug("cx=" + cx + "; cy=" + cy); return createImageInline(filenameHint, altText, id1, id2, cx, cy, link); }
public static void displayImageInfo(ImageInfo info) { ImageSize size = info.getSize(); Dimension2D dPt = size.getDimensionPt(); Dimension dPx = size.getDimensionPx(); log.debug(info.getOriginalURI() + " " + info.getMimeType() + " " + Math.round(dPx.getWidth()) + "x" + Math.round(dPx.getHeight())); log.debug("Resolution:" + Math.round(size.getDpiHorizontal()) + "x" + Math.round(size.getDpiVertical())); log.debug("Print size: " + Math.round(dPt.getWidth() / 72) + "\" x" + Math.round(dPt.getHeight() / 72) + "\""); }
/** * Create a <wp:inline> element suitable for this image, * which can be _embedded_ in w:p/w:r/w:drawing. * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document * @param cx Image width in twip * @param link true if this is to be linked not embedded * None of these things seem to be exposed in Word 2007's * user interface, but Word won't open the document if * any of the attributes these go in (except @ desc) aren't present! * @throws Exception */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, long cx, boolean link) throws Exception { ImageSize size = imageInfo.getSize(); Dimension2D dPt = size.getDimensionPt(); double imageWidthTwips = dPt.getWidth() * 20; log.debug("imageWidthTwips: " + imageWidthTwips); long cy; log.debug("Scaling image height to retain aspect ratio"); cy = UnitsOfMeasurement.twipToEMU(dPt.getHeight() * 20 * cx / imageWidthTwips); // Now convert cx to EMU cx = UnitsOfMeasurement.twipToEMU(cx); log.debug("cx=" + cx + "; cy=" + cy); return createImageInline(filenameHint, altText, id1, id2, cx, cy, link); }
/** {@inheritDoc} */ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { PSRenderingContext psContext = (PSRenderingContext)context; PSGenerator gen = psContext.getGenerator(); ImageRawEPS eps = (ImageRawEPS)image; float x = (float)pos.getX() / 1000f; float y = (float)pos.getY() / 1000f; float w = (float)pos.getWidth() / 1000f; float h = (float)pos.getHeight() / 1000f; ImageInfo info = image.getInfo(); Rectangle2D bbox = eps.getBoundingBox(); if (bbox == null) { bbox = new Rectangle2D.Double(); bbox.setFrame(new Point2D.Double(), info.getSize().getDimensionPt()); } InputStream in = eps.createInputStream(); try { String resourceName = info.getOriginalURI(); if (resourceName == null) { resourceName = "inline image"; } PSImageUtils.renderEPS(in, resourceName, new Rectangle2D.Float(x, y, w, h), bbox, gen); } finally { IOUtils.closeQuietly(in); } }
/** * Draws a form at a given location. * @param form the form resource * @param info the image info object representing the image in the form * @param rect the target rectangle (coordinates in millipoints) * @param generator the PostScript generator * @throws IOException if an I/O error occurs */ public static void drawForm(PSResource form, ImageInfo info, Rectangle rect, PSGenerator generator) throws IOException { Rectangle2D targetRect = new Rectangle2D.Double( rect.getMinX() / 1000.0, rect.getMinY() / 1000.0, rect.getWidth() / 1000.0, rect.getHeight() / 1000.0); generator.saveGraphicsState(); translateAndScale(generator, info.getSize().getDimensionPt(), targetRect); //The following %%IncludeResource marker is needed later by ResourceHandler! generator.writeDSCComment(DSCConstants.INCLUDE_RESOURCE, form); generator.getResourceTracker().notifyResourceUsageOnPage(form); generator.writeln(form.getName() + " execform"); generator.restoreGraphicsState(); }
/** {@inheritDoc} */ public void generateForm(RenderingContext context, Image image, PSImageFormResource form) throws IOException { PSRenderingContext psContext = (PSRenderingContext)context; PSGenerator gen = psContext.getGenerator(); ImageRendered imageRend = (ImageRendered)image; ImageInfo info = image.getInfo(); String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); RenderedImage ri = imageRend.getRenderedImage(); FormGenerator formGen = new ImageFormGenerator( form.getName(), imageDescription, info.getSize().getDimensionPt(), ri, false); formGen.generate(gen); }
private FormGenerator buildFormGenerator(int psLanguageLevel, final PSImageFormResource form, final ImageInfo info, final ImageGraphics2D imageG2D, final FontInfo fontInfo) { String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); final Dimension2D dimensionsPt = info.getSize().getDimensionPt(); final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt(); FormGenerator formGen;
/** {@inheritDoc} */ public void generateForm(RenderingContext context, Image image, PSImageFormResource form) throws IOException { PSRenderingContext psContext = (PSRenderingContext) context; PSGenerator gen = psContext.getGenerator(); ImageRawPNG png = (ImageRawPNG) image; ImageInfo info = image.getInfo(); String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); ImageEncoder encoder = new ImageEncoderPNG(png); FormGenerator formGen = new ImageFormGenerator(form.getName(), imageDescription, info.getSize() .getDimensionPt(), info.getSize().getDimensionPx(), encoder, png.getColorSpace(), false); formGen.generate(gen); }
/** {@inheritDoc} */ public void generateForm(RenderingContext context, Image image, PSImageFormResource form) throws IOException { PSRenderingContext psContext = (PSRenderingContext)context; PSGenerator gen = psContext.getGenerator(); ImageRawCCITTFax ccitt = (ImageRawCCITTFax)image; ImageInfo info = image.getInfo(); String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); ImageEncoder encoder = new ImageEncoderCCITTFax(ccitt); FormGenerator formGen = new ImageFormGenerator( form.getName(), imageDescription, info.getSize().getDimensionPt(), info.getSize().getDimensionPx(), encoder, ccitt.getColorSpace(), 1, false); formGen.generate(gen); }
/** {@inheritDoc} */ public void generateForm(RenderingContext context, Image image, PSImageFormResource form) throws IOException { PSRenderingContext psContext = (PSRenderingContext)context; PSGenerator gen = psContext.getGenerator(); ImageRawJPEG jpeg = (ImageRawJPEG)image; ImageInfo info = image.getInfo(); String imageDescription = info.getMimeType() + " " + info.getOriginalURI(); ImageEncoder encoder = new ImageEncoderJPEG(jpeg); FormGenerator formGen = new ImageFormGenerator( form.getName(), imageDescription, info.getSize().getDimensionPt(), info.getSize().getDimensionPx(), encoder, jpeg.getColorSpace(), jpeg.isInverted()); formGen.generate(gen); }