Package org.apache.fop.image

Examples of org.apache.fop.image.FopImage


    /** @see org.apache.fop.render.AbstractPathOrientedRenderer */
    protected void drawImage(String url, Rectangle2D pos) {
        endTextObject();
        url = ImageFactory.getURL(url);
        ImageFactory fact = userAgent.getFactory().getImageFactory();
        FopImage fopimage = fact.getImage(url, userAgent);
        if (fopimage == null) {
            return;
        }
        if (!fopimage.load(FopImage.DIMENSIONS)) {
            return;
        }
        float x = (float)pos.getX() / 1000f;
        x += currentIPPosition / 1000f;
        float y = (float)pos.getY() / 1000f;
        y += currentBPPosition / 1000f;
        float w = (float)pos.getWidth() / 1000f;
        float h = (float)pos.getHeight() / 1000f;
        try {
            String mime = fopimage.getMimeType();
            if ("text/xml".equals(mime)) {
                if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                    return;
                }
                Document doc = ((XMLImage) fopimage).getDocument();
                String ns = ((XMLImage) fopimage).getNameSpace();

                renderDocument(doc, ns, pos);
            } else if ("image/svg+xml".equals(mime)) {
                if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                    return;
                }
                Document doc = ((XMLImage) fopimage).getDocument();
                String ns = ((XMLImage) fopimage).getNameSpace();

View Full Code Here


            String url = eg.getURL();

            //set image data
            FOUserAgent userAgent = eg.getUserAgent();
            ImageFactory fact = userAgent.getFactory().getImageFactory();
            FopImage fopimage = fact.getImage(url, userAgent);
            if (fopimage == null) {
                log.error("Image could not be found: " + url);
                return;
            }
            fopimage.load(FopImage.ORIGINAL_DATA);

            byte[] rawData;
            if ("image/svg+xml".equals(fopimage.getMimeType())) {
                rawData = SVGConverter.convertToJPEG((XMLImage)fopimage);
            } else {
                rawData = fopimage.getRessourceBytes();
            }
            if (rawData == null) {
                log.warn(FONode.decorateWithContextInfo(
                        "Image could not be embedded: " + url, eg));
                return;
            }

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

            final RtfExternalGraphic newGraphic = c.getTextrun().newImage();
   
            //set URL
            newGraphic.setURL(url);
            newGraphic.setImageData(rawData);

            //set scaling
            if (eg.getScaling() == Constants.EN_UNIFORM) {
                newGraphic.setScaling ("uniform");
            }

            //get width
            int width = 0;
            if (eg.getWidth().getEnum() == Constants.EN_AUTO) {
                width = fopimage.getIntrinsicWidth();
            } else {
                width = eg.getWidth().getValue();
            }

            //get height
            int height = 0;
            if (eg.getWidth().getEnum() == Constants.EN_AUTO) {
                height = fopimage.getIntrinsicHeight();
            } else {
                height = eg.getHeight().getValue();
            }

            //get content-width
            int contentwidth = 0;
            if (eg.getContentWidth().getEnum()
                    == Constants.EN_AUTO) {
                contentwidth = fopimage.getIntrinsicWidth();
            } else if (eg.getContentWidth().getEnum()
                    == Constants.EN_SCALE_TO_FIT) {
                contentwidth = width;
            } else {
                //TODO: check, if the value is a percent value
                contentwidth = eg.getContentWidth().getValue();
            }

            //get content-width
            int contentheight = 0;
            if (eg.getContentHeight().getEnum()
                    == Constants.EN_AUTO) {

                contentheight = fopimage.getIntrinsicHeight();

            } else if (eg.getContentHeight().getEnum()
                    == Constants.EN_SCALE_TO_FIT) {

                contentheight = height;
View Full Code Here

            return;
        }

        url = ImageFactory.getURL(url);
        ImageFactory fact = userAgent.getFactory().getImageFactory();
        FopImage fopimage = fact.getImage(url, userAgent);
        if (fopimage == null) {
            return;
        }
        if (!fopimage.load(FopImage.DIMENSIONS)) {
            return;
        }
        String mime = fopimage.getMimeType();
        if ("text/xml".equals(mime)) {
            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                return;
            }
            Document doc = ((XMLImage) fopimage).getDocument();
            String ns = ((XMLImage) fopimage).getNameSpace();

            renderDocument(doc, ns, pos);
        } else if ("image/svg+xml".equals(mime)) {
            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                return;
            }
            Document doc = ((XMLImage) fopimage).getDocument();
            String ns = ((XMLImage) fopimage).getNameSpace();

            renderDocument(doc, ns, pos);
        } else if ("image/eps".equals(mime)) {
            FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
            int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
            fact.releaseImage(url, userAgent);
           
            float w = (float)pos.getWidth() / 1000f;
            float h = (float)pos.getHeight() / 1000f;
            placeImage((float) pos.getX() / 1000,
                       (float) pos.getY() / 1000, w, h, xobj);
        } else if ("image/jpeg".equals(mime) || "image/tiff".equals(mime)) {
            FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
            int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
            fact.releaseImage(url, userAgent);

            float w = (float)pos.getWidth() / 1000f;
            float h = (float)pos.getHeight() / 1000f;
            placeImage((float) pos.getX() / 1000,
                       (float) pos.getY() / 1000, w, h, xobj);
        } else {
            if (!fopimage.load(FopImage.BITMAP)) {
                return;
            }
            FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
            int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
            fact.releaseImage(url, userAgent);
View Full Code Here

                drawBackground(back, sx, sy, paddRectWidth, paddRectHeight);
            }

            // background image
            if (back.getFopImage() != null) {
                FopImage fopimage = back.getFopImage();
                if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
                    saveGraphicsState();
                    clipRect(sx, sy, paddRectWidth, paddRectHeight);
                    int horzCount = (int) ((paddRectWidth * 1000 / fopimage
                            .getIntrinsicWidth()) + 1.0f);
                    int vertCount = (int) ((paddRectHeight * 1000 / fopimage
                            .getIntrinsicHeight()) + 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;
                            pos = new Rectangle2D.Float(sx
                                    + (x * fopimage.getIntrinsicWidth()), sy
                                    + (y * fopimage.getIntrinsicHeight()),
                                    fopimage.getIntrinsicWidth(), fopimage
                                            .getIntrinsicHeight());
                            putImage(back.getURL(), pos); // TODO test
                        }
                    }
                    restoreGraphicsState();
View Full Code Here

        int x = currentIPPosition; // TODO + area.getXOffset();
        int y = currentBPPosition;
        String url = ImageFactory.getURL(pUrl);

        ImageFactory fact = userAgent.getFactory().getImageFactory();
        FopImage fopimage = fact.getImage(url, userAgent);

        if (fopimage == null) {
            return;
        }
        if (!fopimage.load(FopImage.DIMENSIONS)) {
            return;
        }
        int w = fopimage.getWidth();
        int h = fopimage.getHeight();
        String mime = fopimage.getMimeType();
        if ("text/xml".equals(mime)) {
            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                return;
            }
            Document doc = ((XMLImage) fopimage).getDocument();
            String ns = ((XMLImage) fopimage).getNameSpace();
            renderDocument(doc, ns, pos);

        } else if ("image/svg+xml".equals(mime)) {
            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                return;
            }
            Document doc = ((XMLImage) fopimage).getDocument();
            String ns = ((XMLImage) fopimage).getNameSpace();

            renderDocument(doc, ns, pos);
        } else if ("image/eps".equals(mime)) {
            log.warn("EPS images are not supported by this renderer");
        } else if ("image/jpeg".equals(mime)) {
            if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
                return;
            }

            // TODO Load JPEGs rather through fopimage.load(FopImage.BITMAP),
            // but JpegImage will need to be extended for that

            // url = url.substring(7);
            // url = "C:/eclipse/myWorkbenches/fop4/xml-fop/examples/fo" + url;
            java.awt.Image awtImage = new javax.swing.ImageIcon(url).getImage();

            state.getGraph().drawImage(awtImage,
                    (int)(x / 1000f), (int)(y / 1000f),
                    (int)(pos.getWidth() / 1000f), (int)(pos.getHeight() / 1000f), null);
        } else {
            if (!fopimage.load(FopImage.BITMAP)) {
                log.warn("Loading of bitmap failed: " + url);
                return;
            }

            byte[] raw = fopimage.getBitmaps();

            // TODO Hardcoded color and sample models, FIX ME!
            ColorModel cm = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
                    new int[] {8, 8, 8},
View Full Code Here

  int w = area.getContentWidth();
  int h = area.getHeight();

  this.currentYPosition -= h;

  FopImage img = area.getImage();

  int xObjectNum = this.pdfDoc.addImage(img);

  currentStream.add("ET\nq\n" + (((float) w) / 1000f) + " 0 0 " +
        (((float) h) / 1000f) + " " +
View Full Code Here

    }
   
  public void renderImage(String href, float x, float y, float width, float height)
  {
    try {
      FopImage img = FopImageFactory.Make(href);
      if(img != null) {
        int xObjectNum = this.pdfDoc.addImage(img);
        currentStream.add("q\n1 0 0 -1 " + 0
                  + " " + (y + height) + " cm\n" + width + " 0 0 " +
              height + " " +
View Full Code Here

  int w = area.getContentWidth();
  int h = area.getHeight();

  this.currentYPosition -= h*1000;

  FopImage img = area.getImage();

  int xObjectNum = this.pdfDoc.addImage(img);

  currentStream.add("ET\nq\n" + (img.getWidth()/1000f) + " 0 0 " +
        (img.getHeight()/1000f) + " " +
        ((x + img.getX())/1000f) + " " +
        (((y - h) - img.getY())/1000f) + " cm\n" +
        "/Im" + xObjectNum + " Do\nQ\nBT\n");
    }
View Full Code Here

                            float height) {
        try {
            if (href.indexOf(":") == -1) {
                href = "file:" + href;
            }
            FopImage img = FopImageFactory.Make(href);
            PDFNumber pdfNumber = new PDFNumber();
            if (img instanceof SVGImage) {
                SVGSVGElement svg =
                  ((SVGImage) img).getSVGDocument().getRootElement();
                currentStream.write("q\n" + pdfNumber.doubleOut(width /
View Full Code Here

            if (href.indexOf(":") == -1) {
                href = "file:" + href;
            }
            try {
                // this is really only to get a cached svg image
                FopImage img = FopImageFactory.Make(href);
                if (img instanceof SVGImage) {
                    SVGDocument doc = ((SVGImage) img).getSVGDocument();
                    Element ele = doc.getElementById(
                                    ref.substring(pos + 1, ref.length()));
                    if (ele instanceof SVGElement) {
View Full Code Here

TOP

Related Classes of org.apache.fop.image.FopImage

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.