Examples of ImageSize


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

    public void testLoadImage() throws Exception {
        ImageContext context = MockImageContext.newSafeInstance();
        ImageSessionContext session = new MockImageSessionContext(context);
        // This image file is NOT a valid tif! It is the directory table ONLY.
        ImageInfo info = new ImageInfo("dirOnly.tif", MimeConstants.MIME_TIFF);
        ImageSize size = new ImageSize();
        // Size data can be retrieve by parsing the directory table in the TIFF
        size.setSizeInPixels(1728, 2266);
        size.setResolution(203, 192);
        size.calcSizeFromPixels();
        info.setSize(size);

        sut = new ImageLoaderRawCCITTFax();
        ImageRawCCITTFax rawImage = (ImageRawCCITTFax) sut.loadImage(info, null, session);
        assertEquals(2, rawImage.getCompression());
View Full Code Here

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

                        "Subimage {0} does not exist.", new Object[] {new Integer(pageIndex)});
                throw new SubImageNotFoundException(errorMessage);
            }
            int width = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_WIDTH);
            int height = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH);
            ImageSize size = new ImageSize();
            size.setSizeInPixels(width, height);
            int unit = 2; //inch is default
            if (dir.isTagPresent(TIFFImageDecoder.TIFF_RESOLUTION_UNIT)) {
                unit = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_RESOLUTION_UNIT);
            }
            if (unit == 2 || unit == 3) {
                float xRes;
                float yRes;
                TIFFField fldx = dir.getField(TIFFImageDecoder.TIFF_X_RESOLUTION);
                TIFFField fldy = dir.getField(TIFFImageDecoder.TIFF_Y_RESOLUTION);
                if (fldx == null || fldy == null) {
                    unit = 2;
                    xRes = context.getSourceResolution();
                    yRes = xRes;
                } else {
                    xRes = fldx.getAsFloat(0);
                    yRes = fldy.getAsFloat(0);
                }
                if (xRes == 0 || yRes == 0) {
                    //Some TIFFs may report 0 here which would lead to problems
                    size.setResolution(context.getSourceResolution());
                } else if (unit == 2) {
                    size.setResolution(xRes, yRes); //Inch
                } else {
                    size.setResolution(
                            UnitConv.in2mm(xRes) / 10,
                            UnitConv.in2mm(yRes) / 10); //Centimeters
                }
            } else {
                size.setResolution(context.getSourceResolution());
            }
            size.calcSizeFromPixels();
            if (log.isTraceEnabled()) {
                log.trace("TIFF image detected: " + size);
            }

            info = new ImageInfo(uri, MimeConstants.MIME_TIFF);
            info.setSize(size);

            TIFFField fld;

            fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
            if (fld != null) {
                int compression = fld.getAsInt(0);
                if (log.isTraceEnabled()) {
                    log.trace("TIFF compression: " + compression);
                }
                info.getCustomObjects().put("TIFF_COMPRESSION", new Integer(compression));
            }

            fld = dir.getField(TIFFImageDecoder.TIFF_TILE_WIDTH);
            if (fld != null) {
                if (log.isTraceEnabled()) {
                    log.trace("TIFF is tiled");
                }
                info.getCustomObjects().put("TIFF_TILED", Boolean.TRUE);
            }

            int stripCount;
            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
            if (fld == null) {
                stripCount = 1;
            } else {
                stripCount = (int)Math.ceil(size.getHeightPx() / (double)fld.getAsLong(0));
            }
            if (log.isTraceEnabled()) {
                log.trace("TIFF has " + stripCount + " strips.");
            }
            info.getCustomObjects().put("TIFF_STRIP_COUNT", new Integer(stripCount));
View Full Code Here

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

   * @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;

View Full Code Here

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

    displayImageInfo(ii);
  }
 
    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) + "\"");
   
  }
View Full Code Here

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

    public static CxCy scale(ImageInfo imageInfo, PageDimensions page) {
     
      double writableWidthTwips = page.getWritableWidthTwips();        
      log.debug("writableWidthTwips: " + writableWidthTwips);
     
        ImageSize size = imageInfo.getSize();
       
        Dimension2D dPt = size.getDimensionPt();
      double imageWidthTwips = dPt.getWidth() * 20;
      log.debug("imageWidthTwips: " + imageWidthTwips);
     
      long cx;
      long cy;
View Full Code Here

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

    private static double toEmu(double widthPx, double dpi) {
      return widthPx * EMU_RATIO / dpi;
    }

        public static CxCy scale(ImageInfo imageInfo, double xEmu, double yEmu) {
            ImageSize size = imageInfo.getSize();
            double iwEmu = toEmu(size.getWidthPx(), size.getDpiHorizontal());
            double ihEmu = toEmu(size.getHeightPx(), size.getDpiVertical());
       
            return scaleToFit(iwEmu, ihEmu, xEmu, yEmu);
        }
View Full Code Here

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

            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();
View Full Code Here

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

            int widthMpt = (int)Math.round(px2mpt(width, context.getSourceResolution()));
            int heightMpt = (int)Math.round(px2mpt(height, context.getSourceResolution()));

            ImageInfo info = new ImageInfo(uri, MimeConstants.MIME_SVG);
            ImageSize size = new ImageSize();
            size.setSizeInMillipoints(widthMpt, heightMpt);
            //Set the resolution to that of the FOUserAgent
            size.setResolution(context.getSourceResolution());
            size.calcPixelsFromSize();
            info.setSize(size);

            //The whole image had to be loaded for this, so keep it
            ImageXMLDOM xmlImage = new ImageXMLDOM(info,
                    doc, SVGDOMImplementation.SVG_NAMESPACE_URI);
View Full Code Here

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

            if (back.getColor() != null) {
                updateColor(back.getColor(), true);
                fillRect(sx, sy, paddRectWidth, paddRectHeight);
            }
            if (back.getImageInfo() != null) {
                ImageSize imageSize = back.getImageInfo().getSize();
                saveGraphicsState();
                clipRect(sx, sy, paddRectWidth, paddRectHeight);
                int horzCount = (int)((paddRectWidth
                        * 1000 / imageSize.getWidthMpt()) + 1.0f);
                int vertCount = (int)((paddRectHeight
                        * 1000 / imageSize.getHeightMpt()) + 1.0f);
                if (back.getRepeat() == EN_NOREPEAT) {
                    horzCount = 1;
                    vertCount = 1;
                } else if (back.getRepeat() == EN_REPEATX) {
                    vertCount = 1;
                } else if (back.getRepeat() == EN_REPEATY) {
                    horzCount = 1;
                }
                //change from points to millipoints
                sx *= 1000;
                sy *= 1000;
                if (horzCount == 1) {
                    sx += back.getHoriz();
                }
                if (vertCount == 1) {
                    sy += back.getVertical();
                }
                for (int x = 0; x < horzCount; x++) {
                    for (int y = 0; y < vertCount; y++) {
                        // place once
                        Rectangle2D pos;
                        // Image positions are relative to the currentIP/BP
                        pos = new Rectangle2D.Float(sx - currentIPPosition
                                                        + (x * imageSize.getWidthMpt()),
                                                    sy - currentBPPosition
                                                        + (y * imageSize.getHeightMpt()),
                                                        imageSize.getWidthMpt(),
                                                        imageSize.getHeightMpt());
                        drawImage(back.getURL(), pos);
                    }
                }
               
                restoreGraphicsState();
View Full Code Here

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

                fillRect(sx, sy, paddRectWidth, paddRectHeight);
            }
   
            // background image
            if (back.getImageInfo() != null) {
                ImageSize imageSize = back.getImageInfo().getSize();
                saveGraphicsState();
                clipRect(sx, sy, paddRectWidth, paddRectHeight);
                int horzCount = (int) ((paddRectWidth * 1000 / imageSize.getWidthMpt()) + 1.0f);
                int vertCount = (int) ((paddRectHeight * 1000 / imageSize.getHeightMpt()) + 1.0f);
                if (back.getRepeat() == EN_NOREPEAT) {
                    horzCount = 1;
                    vertCount = 1;
                } else if (back.getRepeat() == EN_REPEATX) {
                    vertCount = 1;
                } else if (back.getRepeat() == EN_REPEATY) {
                    horzCount = 1;
                }
                // change from points to millipoints
                sx *= 1000;
                sy *= 1000;
                if (horzCount == 1) {
                    sx += back.getHoriz();
                }
                if (vertCount == 1) {
                    sy += back.getVertical();
                }
                for (int x = 0; x < horzCount; x++) {
                    for (int y = 0; y < vertCount; y++) {
                        // place once
                        Rectangle2D pos;
                        // Image positions are relative to the currentIP/BP
                        pos = new Rectangle2D.Float(
                                sx - currentIPPosition
                                    + (x * imageSize.getWidthMpt()),
                                sy - currentBPPosition
                                    + (y * imageSize.getHeightMpt()),
                                imageSize.getWidthMpt(),
                                imageSize.getHeightMpt());
                        drawImage(back.getURL(), pos, null);
                    }
                }
                restoreGraphicsState();
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.