Package net.sf.jasperreports.engine

Examples of net.sf.jasperreports.engine.JRRenderable


      for(Iterator it = imagesToProcess.iterator(); it.hasNext();)
      {
        JRPrintElementIndex imageIndex = (JRPrintElementIndex)it.next();

        JRPrintImage image = getImage(jasperPrintList, imageIndex);
        JRRenderable renderer = image.getRenderer();
        if (renderer.getType() == JRRenderable.TYPE_SVG)
        {
          renderer =
            new JRWrappingSvgRenderer(
              renderer,
              new Dimension(image.getWidth(), image.getHeight()),
              ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
              );
        }

        oasisZip.addEntry(//FIXMEODT optimize with a different implementation of entry
          new FileBufferedZipEntry(
            "Pictures/" + getImageName(imageIndex),
            renderer.getImageData()
            )
          );
      }
    }
View Full Code Here


      availableImageWidth = availableImageWidth < 0 ? 0 : availableImageWidth;

      int availableImageHeight = element.getHeight() - topPadding - bottomPadding;
      availableImageHeight = availableImageHeight < 0 ? 0 : availableImageHeight;

      JRRenderable renderer = element.getRenderer();

      if (
        renderer != null &&
        availableImageWidth > 0 &&
        availableImageHeight > 0
        )
      {
        if (renderer.getType() == JRRenderable.TYPE_IMAGE)
        {
          // Image renderers are all asked for their image data and dimension at some point.
          // Better to test and replace the renderer now, in case of lazy load error.
          renderer = JRImageRenderer.getOnErrorRendererForImageData(renderer, element.getOnErrorTypeValue());
          if (renderer != null)
          {
            renderer = JRImageRenderer.getOnErrorRendererForDimension(renderer, element.getOnErrorTypeValue());
          }
        }
        else
        {
          renderer =
            new JRWrappingSvgRenderer(
              renderer,
              new Dimension(element.getWidth(), element.getHeight()),
              ModeEnum.OPAQUE == element.getModeValue() ? element.getBackcolor() : null
              );
        }
      }
      else
      {
        renderer = null;
      }

      if (renderer != null)
      {
        int normalWidth = availableImageWidth;
        int normalHeight = availableImageHeight;

        Dimension2D dimension = renderer.getDimension();
        if (dimension != null)
        {
          normalWidth = (int) dimension.getWidth();
          normalHeight = (int) dimension.getHeight();
        }

        float xalignFactor = 0f;
        switch (element.getHorizontalAlignmentValue())
        {
          case RIGHT:
          {
            xalignFactor = 1f;
            break;
          }
          case CENTER:
          {
            xalignFactor = 0.5f;
            break;
          }
          case LEFT:
          default:
          {
            xalignFactor = 0f;
            break;
          }
        }

        float yalignFactor = 0f;
        switch (element.getVerticalAlignmentValue())
        {
          case BOTTOM:
          {
            yalignFactor = 1f;
            break;
          }
          case MIDDLE:
          {
            yalignFactor = 0.5f;
            break;
          }
          case TOP:
          default:
          {
            yalignFactor = 0f;
            break;
          }
        }

        byte[] imageData = null;
        int topOffset = 0;
        int leftOffset = 0;
        int bottomOffset = 0;
        int rightOffset = 0;
       
        switch (element.getScaleImageValue())
        {
          case CLIP:
          {
            BufferedImage bi = new BufferedImage(availableImageWidth, availableImageHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D grx = bi.createGraphics();

            int xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
            int yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));

            Shape oldClipShape = grx.getClip();

            grx.clip(
              new Rectangle(
                0,
                0,
                availableImageWidth,
                availableImageHeight
                )
              );

            try
            {
              renderer.render(
                grx,
                new Rectangle(
                  xoffset,
                  yoffset,
                  normalWidth,
                  normalHeight
                  )
                );
            }
            finally
            {
              grx.setClip(oldClipShape);
            }

            topOffset = topPadding;
            leftOffset = leftPadding;
            bottomOffset = bottomPadding;
            rightOffset = rightPadding;

            imageData = JRImageLoader.loadImageDataFromAWTImage(bi, JRRenderable.IMAGE_TYPE_PNG);

            break;
          }
          case FILL_FRAME:
          {
            topOffset = topPadding;
            leftOffset = leftPadding;
            bottomOffset = bottomPadding;
            rightOffset = rightPadding;

            imageData = renderer.getImageData();

            break;
          }
          case RETAIN_SHAPE:
          default:
          {
            if (element.getHeight() > 0)
            {
              double ratio = (double) normalWidth / (double) normalHeight;

              if (ratio > (double) availableImageWidth / (double) availableImageHeight)
              {
                normalWidth = availableImageWidth;
                normalHeight = (int) (availableImageWidth / ratio);
              }
              else
              {
                normalWidth = (int) (availableImageHeight * ratio);
                normalHeight = availableImageHeight;
              }

              topOffset = topPadding + (int) (yalignFactor * (availableImageHeight - normalHeight));
              leftOffset = leftPadding + (int) (xalignFactor * (availableImageWidth - normalWidth));
              bottomOffset = bottomPadding + (int) ((1f - yalignFactor) * (availableImageHeight - normalHeight));
              rightOffset = rightPadding + (int) ((1f - xalignFactor) * (availableImageWidth - normalWidth));

              imageData = renderer.getImageData();
            }

            break;
          }
        }
View Full Code Here

            imagesDir.mkdir();
          }
 
          if (isPxImageLoaded)
          {
            JRRenderable pxRenderer =
              JRImageRenderer.getInstance("net/sf/jasperreports/engine/images/pixel.GIF");
            byte[] imageData = pxRenderer.getImageData();
 
            File imageFile = new File(imagesDir, "px");
            FileOutputStream fos = null;
 
            try
            {
              fos = new FileOutputStream(imageFile);
              fos.write(imageData, 0, imageData.length);
            }
            catch (IOException e)
            {
              throw new JRException("Error writing to image file : " + imageFile, e);
            }
            finally
            {
              if (fos != null)
              {
                try
                {
                  fos.close();
                }
                catch(IOException e)
                {
                }
              }
            }
          }
 
          for(Iterator it = imagesToProcess.iterator(); it.hasNext();)
          {
            JRPrintElementIndex imageIndex = (JRPrintElementIndex)it.next();
 
            JRPrintImage image = getImage(jasperPrintList, imageIndex);
            JRRenderable renderer = image.getRenderer();
            if (renderer.getType() == JRRenderable.TYPE_SVG)
            {
              renderer =
                new JRWrappingSvgRenderer(
                  renderer,
                  new Dimension(image.getWidth(), image.getHeight()),
                  ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
                  );
            }
 
            byte[] imageData = renderer.getImageData();
 
            File imageFile = new File(imagesDir, getImageName(imageIndex));
            FileOutputStream fos = null;
 
            try
View Full Code Here

      writer.write("<a name=\"");
      writer.write(image.getAnchorName());
      writer.write("\"/>");
    }
   
    JRRenderable renderer = image.getRenderer();
    JRRenderable originalRenderer = renderer;
    boolean imageMapRenderer = renderer != null
        && renderer instanceof JRImageMapRenderer
        && ((JRImageMapRenderer) renderer).hasImageAreaHyperlinks();

    boolean hasHyperlinks = false;

    if(renderer != null || isUsingImagesToAlign)
    {
      if (imageMapRenderer)
      {
        hasHyperlinks = true;
        hyperlinkStarted = false;
      }
      else
      {
        hasHyperlinks = startHyperlink(image);
      }
     
      writer.write("<img");
      String imagePath = null;
      String imageMapName = null;
      List imageMapAreas = null;
 
      ScaleImageEnum scaleImage = image.getScaleImageValue();
     
      if (renderer != null)
      {
        if (renderer.getType() == JRRenderable.TYPE_IMAGE && rendererToImagePathMap.containsKey(renderer.getId()))
        {
          imagePath = (String)rendererToImagePathMap.get(renderer.getId());
        }
        else
        {
          if (image.isLazy())
          {
            imagePath = ((JRImageRenderer)renderer).getImageLocation();
          }
          else
          {
            JRPrintElementIndex imageIndex = getElementIndex(gridCell);
            imagesToProcess.add(imageIndex);
 
            String imageName = getImageName(imageIndex);
            imagePath = imagesURI + imageName;
 
            //backward compatibility with the IMAGE_MAP parameter
            if (imageNameToImageDataMap != null)
            {
              if (renderer.getType() == JRRenderable.TYPE_SVG)
              {
                renderer =
                  new JRWrappingSvgRenderer(
                    renderer,
                    new Dimension(image.getWidth(), image.getHeight()),
                    ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
                    );
              }
              imageNameToImageDataMap.put(imageName, renderer.getImageData());
            }
            //END - backward compatibility with the IMAGE_MAP parameter
          }
 
          rendererToImagePathMap.put(renderer.getId(), imagePath);
        }
       
        if (imageMapRenderer)
        {
          Rectangle renderingArea = new Rectangle(image.getWidth(), image.getHeight());
         
          if (renderer.getType() == JRRenderable.TYPE_IMAGE)
          {
            imageMapName = (String) imageMaps.get(new Pair(renderer.getId(), renderingArea));
          }
 
          if (imageMapName == null)
          {
            imageMapName = "map_" + getElementIndex(gridCell).toString();
            imageMapAreas = ((JRImageMapRenderer) originalRenderer).getImageAreaHyperlinks(renderingArea);//FIXMECHART
           
            if (renderer.getType() == JRRenderable.TYPE_IMAGE)
            {
              imageMaps.put(new Pair(renderer.getId(), renderingArea), imageMapName);
            }
          }
        }
      }
      else     // ie:   if(isUsingImagesToAlign)
      {
        loadPxImage();
        imagePath = imagesURI + "px";
        scaleImage = ScaleImageEnum.FILL_FRAME;
      }
 
      writer.write(" src=\"");
      if (imagePath != null)
      {
        writer.write(imagePath);
      }
      writer.write("\"");
   
      int imageWidth = image.getWidth() - image.getLineBox().getLeftPadding().intValue() - image.getLineBox().getRightPadding().intValue();
      if (imageWidth < 0)
      {
        imageWidth = 0;
      }
   
      int imageHeight = image.getHeight() - image.getLineBox().getTopPadding().intValue() - image.getLineBox().getBottomPadding().intValue();
      if (imageHeight < 0)
      {
        imageHeight = 0;
      }
   
      switch (scaleImage)
      {
        case FILL_FRAME :
        {
          writer.write(" style=\"width: ");
          writer.write(toSizeUnit(imageWidth));
          writer.write("; height: ");
          writer.write(toSizeUnit(imageHeight));
          writer.write("\"");
   
          break;
        }
        case CLIP : //FIXMEIMAGE image clip could be achieved by cutting the image and preserving the image type
        case RETAIN_SHAPE :
        default :
        {
          double normalWidth = imageWidth;
          double normalHeight = imageHeight;
   
          if (!image.isLazy())
          {
            // Image load might fail.
            JRRenderable tmpRenderer =
              JRImageRenderer.getOnErrorRendererForDimension(renderer, image.getOnErrorTypeValue());
            Dimension2D dimension = tmpRenderer == null ? null : tmpRenderer.getDimension();
            // If renderer was replaced, ignore image dimension.
            if (tmpRenderer == renderer && dimension != null)
            {
              normalWidth = dimension.getWidth();
              normalHeight = dimension.getHeight();
View Full Code Here

  {
    isPxImageLoaded = true;
    //backward compatibility with the IMAGE_MAP parameter
    if (imageNameToImageDataMap != null && !imageNameToImageDataMap.containsKey("px"))
    {
      JRRenderable pxRenderer =
        JRImageRenderer.getInstance("net/sf/jasperreports/engine/images/pixel.GIF");
      rendererToImagePathMap.put(pxRenderer.getId(), imagesURI + "px");
      imageNameToImageDataMap.put("px", pxRenderer.getImageData());
    }
    //END - backward compatibility with the IMAGE_MAP parameter
  }
View Full Code Here

  {
    evaluateBarcode();
   
    BarcodeImageProducer imageProducer = BarcodeUtils.getImageProducer(
        componentElement);
    JRRenderable barcodeImage = imageProducer.createImage(
        componentElement,
        barcode, message, barcodeComponent.getOrientation());
    return barcodeImage;
  }
View Full Code Here

  {
    if (message != null)
    {
      BarcodeImageProducer imageProducer = BarcodeUtils.getImageProducer(
          fillContext.getComponentElement());
      JRRenderable barcodeImage = imageProducer.createImage(
          fillContext.getComponentElement(),
          barcode, message, barcodeComponent.getOrientation());
      image.setRenderer(barcodeImage);
    }
  }
View Full Code Here

      for(Iterator it = imagesToProcess.iterator(); it.hasNext();)
      {
        JRPrintElementIndex imageIndex = (JRPrintElementIndex)it.next();

        JRPrintImage image = getImage(jasperPrintList, imageIndex);
        JRRenderable renderer = image.getRenderer();
        if (renderer.getType() == JRRenderable.TYPE_SVG)
        {
          renderer =
            new JRWrappingSvgRenderer(
              renderer,
              new Dimension(image.getWidth(), image.getHeight()),
              ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
              );
        }

        String mimeType = JRTypeSniffer.getImageMimeType(renderer.getImageType());
        if (mimeType == null)
        {
          mimeType = JRRenderable.MIME_TYPE_JPEG;
        }
        String extension = mimeType.substring(mimeType.lastIndexOf('/') + 1);
       
        String imageName = IMAGE_NAME_PREFIX + imageIndex.toString() + "." + extension;
       
        pptxZip.addEntry(//FIXMEPPTX optimize with a different implementation of entry
          new FileBufferedZipEntry(
            "ppt/media/" + imageName,
            renderer.getImageData()
            )
          );
       
        //presentationRelsHelper.exportImage(imageName, extension);
      }
View Full Code Here

    availableImageWidth = availableImageWidth < 0 ? 0 : availableImageWidth;

    int availableImageHeight = image.getHeight() - topPadding - bottomPadding;
    availableImageHeight = availableImageHeight < 0 ? 0 : availableImageHeight;

    JRRenderable renderer = image.getRenderer();

    if (
      renderer != null &&
      availableImageWidth > 0 &&
      availableImageHeight > 0
      )
    {
      if (renderer.getType() == JRRenderable.TYPE_IMAGE)
      {
        // Non-lazy image renderers are all asked for their image data at some point.
        // Better to test and replace the renderer now, in case of lazy load error.
        renderer = JRImageRenderer.getOnErrorRendererForImageData(renderer, image.getOnErrorTypeValue());
      }
    }
    else
    {
      renderer = null;
    }

    if (renderer != null)
    {
      int width = availableImageWidth;
      int height = availableImageHeight;

      double normalWidth = availableImageWidth;
      double normalHeight = availableImageHeight;

      // Image load might fail.
      JRRenderable tmpRenderer =
        JRImageRenderer.getOnErrorRendererForDimension(renderer, image.getOnErrorTypeValue());
      Dimension2D dimension = tmpRenderer == null ? null : tmpRenderer.getDimension();
      // If renderer was replaced, ignore image dimension.
      if (tmpRenderer == renderer && dimension != null)
      {
        normalWidth = dimension.getWidth();
        normalHeight = dimension.getHeight();
View Full Code Here

    String imageName = request.getParameter(IMAGE_NAME_REQUEST_PARAMETER);
    if ("px".equals(imageName))
    {
      try
      {
        JRRenderable pxRenderer =
          JRImageRenderer.getInstance("net/sf/jasperreports/engine/images/pixel.GIF");
        imageData = pxRenderer.getImageData();
        imageMimeType = JRRenderable.MIME_TYPE_GIF;
      }
      catch (JRException e)
      {
        throw new ServletException(e);
      }
    }
    else
    {
      List jasperPrintList = BaseHttpServlet.getJasperPrintList(request);
     
      if (jasperPrintList == null)
      {
        throw new ServletException("No JasperPrint documents found on the HTTP session.");
      }
     
      JRPrintImage image = JRHtmlExporter.getImage(jasperPrintList, imageName);
     
      JRRenderable renderer = image.getRenderer();
      if (renderer.getType() == JRRenderable.TYPE_SVG)
      {
        renderer =
          new JRWrappingSvgRenderer(
            renderer,
            new Dimension(image.getWidth(), image.getHeight()),
            ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
            );
      }

      imageMimeType = JRTypeSniffer.getImageMimeType(renderer.getImageType());
     
      try
      {
        imageData = renderer.getImageData();
      }
      catch (JRException e)
      {
        throw new ServletException(e);
      }
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.JRRenderable

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.