Package org.apache.xmlgraphics.image.loader

Examples of org.apache.xmlgraphics.image.loader.ImageInfo


            Part sourcePart, File imageFile) throws Exception {

        final byte[] locByte = new byte[1];

        //We are in the case that image is not load (no byte Array) so isLoad is false
        ImageInfo info = ensureFormatIsSupported(imageFile, locByte, false);

        ContentTypeManager ctm = opcPackage.getContentTypeManager();

        // Ensure the relationships part exists
        if (sourcePart.getRelationshipsPart() == null) {
            RelationshipsPart.createRelationshipsPartForPart(sourcePart);
        }

        String proposedRelId = sourcePart.getRelationshipsPart().getNextId();

        String ext = info.getMimeType().substring(info.getMimeType().indexOf("/") + 1);

        BinaryPartAbstractImage imagePart =
                (BinaryPartAbstractImage) ctm.newPartForContentType(
                info.getMimeType(),
                createImageName(opcPackage, sourcePart, proposedRelId, ext), null);

        log.debug("created part " + imagePart.getClass().getName()
                + " with name " + imagePart.getPartName().toString());
View Full Code Here


  private static ImageInfo ensureFormatIsSupported(URL url, File imageFile, byte[] bytes, boolean isLoad) throws Docx4JException {
   
    FileOutputStream fos;
    // ImageInfo can also tell us what sort of image it is 
   
    ImageInfo info = null;
    boolean imagePreloaderFound = true;
    try {
      try {
        info = getImageInfo(url);

        // Debug ... note that these figures
        // aren't necessarily accurate for EPS
        displayImageInfo(info);
      } catch (org.apache.xmlgraphics.image.loader.ImageException e) {
       
        // Assume: The file format is not supported. No ImagePreloader found for /tmp/img55623.img
        // There is no preloader for eg PDFs.
        // (To use an image natively, we do need a preloader)
        imagePreloaderFound = false;
                log.warn(e.getMessage());
      }
     
            if (imagePreloaderFound
                    && (info.getMimeType().equals(ContentTypes.IMAGE_TIFF)
          || info.getMimeType().equals(ContentTypes.IMAGE_EMF2) // ImageInfo
          || info.getMimeType().equals(ContentTypes.IMAGE_WMF)
          || info.getMimeType().equals(ContentTypes.IMAGE_PNG)
          || info.getMimeType().equals(ContentTypes.IMAGE_JPEG)
          || info.getMimeType().equals(ContentTypes.IMAGE_GIF)
//           || info.getMimeType().equals(ContentTypes.IMAGE_EPS)
                    || info.getMimeType().equals(ContentTypes.IMAGE_BMP))) {
          // TODO: add other supported formats
       
        // If its a format Word supports natively,
        // do nothing here
        log.debug(".. supported natively by Word");         
View Full Code Here

  public static BinaryPartAbstractImage createLinkedImagePart(OpcPackage opcPackage,
      Part sourcePart, URL url) throws Exception {
   
    log.debug("Incoming url for linked image: " + url.toString() );
   
        ImageInfo info = ensureFormatIsSupported(url, null, null, false); // final param doesn't matter in this case

    ContentTypeManager ctm = opcPackage.getContentTypeManager();
    String proposedRelId = sourcePart.getRelationshipsPart().getNextId();
    // In order to ensure unique part name,
    // idea is to use the relId, which ought to be unique
        String ext = info.getMimeType().substring(info.getMimeType().indexOf("/") + 1);
   
    BinaryPartAbstractImage imagePart =
                (BinaryPartAbstractImage) ctm.newPartForContentType(
        info.getMimeType(),
                createImageName(opcPackage, sourcePart, proposedRelId, ext), null);
   
    // NB: contents never populated
       
    log.debug("created part " + imagePart.getClass().getName()
View Full Code Here

    // than say a byte array, byte buffer, or input stream.

    ImageSessionContext sessionContext = new DefaultImageSessionContext(
        getImageManager().getImageContext(), null);

    ImageInfo info = getImageManager().getImageInfo(url.toString(), sessionContext);
   
    // Note that these figures do not appear to be reliable for EPS
    // eg ImageMagick 6.2.4 10/02/07 Q16
    // identify fig1.eps
    // reports:
View Full Code Here

    String uri = System.getProperty("user.dir") + "/sample-docs/metafile-samples/freehand_picture_saveas.wmf";
    System.out.println(uri);
   
    //String uri = "/tmp/img4448.img";
   
    ImageInfo ii = getImageInfo(new URL(uri));
   
    displayImageInfo(ii);
  }
View Full Code Here

            String uri = eg.getURL();

            //set image data
            FOUserAgent userAgent = eg.getUserAgent();
            ImageManager manager = userAgent.getFactory().getImageManager();
            ImageInfo info = manager.getImageInfo(uri, userAgent.getImageSessionContext());
            if (info == null) {
                log.error("Image could not be found: " + uri);
                return;
            }
View Full Code Here

        try {
            XMLObj child = ifo.getChildXMLObj();
            Document doc = child.getDOMDocument();
            String ns = child.getNamespaceURI();

            ImageInfo info = new ImageInfo(null, null);
            // Set the resolution to that of the FOUserAgent
            FOUserAgent ua = ifo.getUserAgent();
            ImageSize size = new ImageSize();
            size.setResolution(ua.getSourceResolution());

            // Set the image size to the size of the svg.
            Point2D csize = new Point2D.Float(-1, -1);
            Point2D intrinsicDimensions = child.getDimension(csize);
            size.setSizeInMillipoints(
                    (int)Math.round(intrinsicDimensions.getX() * 1000),
                    (int)Math.round(intrinsicDimensions.getY() * 1000));
            size.calcPixelsFromSize();
            info.setSize(size);

            ImageXMLDOM image = new ImageXMLDOM(info, doc, ns);

            FOUserAgent userAgent = ifo.getUserAgent();
            ImageManager manager = userAgent.getFactory().getImageManager();
View Full Code Here

     */
    private void putGraphic(AbstractGraphics abstractGraphic, Image image)
            throws IOException {
        byte[] rawData = null;

        final ImageInfo info = image.getInfo();

        if (image instanceof ImageRawStream) {
            ImageRawStream rawImage = (ImageRawStream)image;
            InputStream in = rawImage.createInputStream();
            try {
                rawData = IOUtils.toByteArray(in);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }

        if (rawData == null) {
            log.warn(FONode.decorateWithContextInfo("Image could not be embedded: "
                    + image, abstractGraphic));
            return;
        }

        //Set up percentage calculations
        this.percentManager.setDimension(abstractGraphic);
        PercentBaseContext pContext = new PercentBaseContext() {

            public int getBaseLength(int lengthBase, FObj fobj) {
                switch (lengthBase) {
                case LengthBase.IMAGE_INTRINSIC_WIDTH:
                    return info.getSize().getWidthMpt();
                case LengthBase.IMAGE_INTRINSIC_HEIGHT:
                    return info.getSize().getHeightMpt();
                default:
                    return percentManager.getBaseLength(lengthBase, fobj);
                }
            }

        };
        ImageLayout layout = new ImageLayout(abstractGraphic, pContext,
                image.getInfo().getSize().getDimensionMpt());

        final IRtfTextrunContainer c
            = (IRtfTextrunContainer)builderContext.getContainer(
                IRtfTextrunContainer.class, true, this);

        final RtfExternalGraphic rtfGraphic = c.getTextrun().newImage();

        //set URL
        if (info.getOriginalURI() != null) {
            rtfGraphic.setURL(info.getOriginalURI());
        }
        rtfGraphic.setImageData(rawData);

        FoUnitsConverter converter = FoUnitsConverter.getInstance();
        Dimension viewport = layout.getViewportSize();
View Full Code Here

    private boolean batikAvailable = true;

    /** {@inheritDoc} */
    public ImageInfo preloadImage(String uri, Source src, ImageContext context)
            throws IOException {
        ImageInfo info = null;
        if (batikAvailable) {
            try {
                Loader loader = new Loader();
                if (!loader.isSupportedSource(src)) {
                    return null;
View Full Code Here

                    in.mark(length + 1);
                    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
                            getParserName());
                    doc = factory.createSVGDocument(src.getSystemId(), in);
                }
                ImageInfo info = createImageInfo(uri, context, doc);

                return info;
            } catch (NoClassDefFoundError ncdfe) {
                if (in != null) {
                    try {
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.loader.ImageInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.