Package java.awt.geom

Examples of java.awt.geom.Dimension2D


   * @param attrs the attributes.
   * @throws SAXException if there is a parsing error.
   */
  protected void startParsing(final Attributes attrs) throws SAXException
  {
    final Dimension2D pageSize = DoubleDimensionConverter.getObject(attrs.getValue(getUri(), "pageSize"));
    final double topBorder = Double.parseDouble(attrs.getValue(getUri(), "topBorder"));
    final double leftBorder = Double.parseDouble(attrs.getValue(getUri(), "leftBorder"));
    final double bottomBorder = Double.parseDouble(attrs.getValue(getUri(), "bottomBorder"));
    final double rightBorder = Double.parseDouble(attrs.getValue(getUri(), "rightBorder"));

    final Paper paper = PageFormatFactory.getInstance().createPaper(pageSize.getWidth(), pageSize.getHeight());
    PageFormatFactory.getInstance().setBorders(paper, topBorder, leftBorder, bottomBorder, rightBorder);

    pageFormat = new PageFormat();
    pageFormat.setPaper(paper);

View Full Code Here


   *
   * @return The object.
   */
  public Object createObject()
  {
    final Dimension2D dim = new FloatDimension();

    final float width = getFloatParameter("width");
    final float height = getFloatParameter("height");
    dim.setSize(width, height);
    return dim;
  }
View Full Code Here

    if (!(o instanceof Dimension2D))
    {
      throw new ObjectFactoryException("The given object is no java.awt.geom.Dimension2D.");
    }

    final Dimension2D dim = (Dimension2D) o;
    final float width = (float) dim.getWidth();
    final float height = (float) dim.getHeight();

    setParameter("width", new Float(width));
    setParameter("height", new Float(height));
  }
View Full Code Here

    }

    final String minSizeText = result1.getProperty("minimumSize");
    if (minSizeText != null)
    {
      final Dimension2D size = (Dimension2D) new DoubleDimensionConverter().convertFromString(minSizeText, getLocator());
      getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(size.getWidth()));
      getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(size.getHeight()));
    }

    final String prefSizeText = result1.getProperty("preferredSize");
    if (prefSizeText != null)
    {
      final Dimension2D size = (Dimension2D) new DoubleDimensionConverter().convertFromString(prefSizeText, getLocator());
      getStyle().setStyleProperty(ElementStyleKeys.WIDTH, new Float(size.getWidth()));
      getStyle().setStyleProperty(ElementStyleKeys.HEIGHT, new Float(size.getHeight()));
    }

    final String maxSizeText = result1.getProperty("maximumSize");
    if (maxSizeText != null)
    {
      final Dimension2D size = (Dimension2D) new DoubleDimensionConverter().convertFromString(maxSizeText, getLocator());
      getStyle().setStyleProperty(ElementStyleKeys.MAX_WIDTH, new Float(size.getWidth()));
      getStyle().setStyleProperty(ElementStyleKeys.MAX_HEIGHT, new Float(size.getHeight()));
    }

    final String bgColorText = result1.getProperty("background");
    if (bgColorText != null)
    {
View Full Code Here

   *
   * @return The object.
   */
  public Object createObject()
  {
    final Dimension2D dim = new Dimension();

    final float width = getFloatParameter("width");
    final float height = getFloatParameter("height");
    dim.setSize(width, height);
    return dim;
  }
View Full Code Here

            }
           
            int normalWidth = availableImageWidth;
            int normalHeight = availableImageHeight;

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

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

            int minWidth = Math.min(normalWidth, availableImageWidth);
            int minHeight = Math.min(normalHeight, availableImageHeight);

            BufferedImage bi =
              new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB);

            Graphics2D g = bi.createGraphics();
            if (printImage.getModeValue() == ModeEnum.OPAQUE)
            {
              g.setColor(printImage.getBackcolor());
              g.fillRect(0, 0, minWidth, minHeight);
            }
            renderer.render(
              g,
              new java.awt.Rectangle(
                (xoffset > 0 ? 0 : xoffset),
                (yoffset > 0 ? 0 : yoffset),
                normalWidth,
                normalHeight
                )
              );
            g.dispose();

            xoffset = (xoffset < 0 ? 0 : xoffset);
            yoffset = (yoffset < 0 ? 0 : yoffset);

            //awtImage = bi.getSubimage(0, 0, minWidth, minHeight);

            //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
            image = com.lowagie.text.Image.getInstance(bi, null);

            break;
          }
          case FILL_FRAME :
          {
            if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer))
            {
              image = (com.lowagie.text.Image)loadedImagesMap.get(renderer);
            }
            else
            {
              try
              {
                image = com.lowagie.text.Image.getInstance(renderer.getImageData());
                imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
              }
              catch(Exception e)
              {
                JRImageRenderer tmpRenderer =
                  JRImageRenderer.getOnErrorRendererForImage(
                    JRImageRenderer.getInstance(renderer.getImageData()),
                    printImage.getOnErrorTypeValue()
                    );
                if (tmpRenderer == null)
                {
                  break;
                }
                java.awt.Image awtImage = tmpRenderer.getImage();
                image = com.lowagie.text.Image.getInstance(awtImage, null);
              }

              if (printImage.isUsingCache())
              {
                loadedImagesMap.put(renderer, image);
              }
            }

            image.scaleAbsolute(availableImageWidth, availableImageHeight);
            break;
          }
          case RETAIN_SHAPE :
          default :
          {
            if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer))
            {
              image = (com.lowagie.text.Image)loadedImagesMap.get(renderer);
            }
            else
            {
              try
              {
                image = com.lowagie.text.Image.getInstance(renderer.getImageData());
                imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
              }
              catch(Exception e)
              {
                JRImageRenderer tmpRenderer =
                  JRImageRenderer.getOnErrorRendererForImage(
                    JRImageRenderer.getInstance(renderer.getImageData()),
                    printImage.getOnErrorTypeValue()
                    );
                if (tmpRenderer == null)
                {
                  break;
                }
                java.awt.Image awtImage = tmpRenderer.getImage();
                image = com.lowagie.text.Image.getInstance(awtImage, null);
              }

              if (printImage.isUsingCache())
              {
                loadedImagesMap.put(renderer, image);
              }
            }

            image.scaleToFit(availableImageWidth, availableImageHeight);

            xoffset = (int)(xalignFactor * (availableImageWidth - image.getPlainWidth()));
            yoffset = (int)(yalignFactor * (availableImageHeight - image.getPlainHeight()));

            xoffset = (xoffset < 0 ? 0 : xoffset);
            yoffset = (yoffset < 0 ? 0 : yoffset);

            break;
          }
        }

        if (image != null)
        {
          chunk = new Chunk(image, 0, 0);

          scaledWidth = image.getScaledWidth();
          scaledHeight = image.getScaledHeight();
        }
      }
      else
      {
        double normalWidth = availableImageWidth;
        double normalHeight = availableImageHeight;

        double displayWidth = availableImageWidth;
        double displayHeight = availableImageHeight;

        double ratioX = 1f;
        double ratioY = 1f;
       
        Rectangle2D clip = null;

        Dimension2D dimension = renderer.getDimension();
        if (dimension != null)
        {
          normalWidth = dimension.getWidth();
          normalHeight = dimension.getHeight();
          displayWidth = normalWidth;
          displayHeight = normalHeight;
         
          float xalignFactor = getXAlignFactor(printImage);
          float yalignFactor = getYAlignFactor(printImage);
View Full Code Here

          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();
            }
          }

          if (availableImageHeight > 0)
          {
View Full Code Here

  /**
   *
   */
  public Dimension2D getDimension()
  {
    Dimension2D imageDimension = null;
    try
    {
      // use original dimension if possible
      imageDimension = renderer.getDimension();
    }
View Full Code Here

  /**
   *
   */
  public byte[] getImageData() throws JRException
  {
    Dimension2D dimension = getDimension();
    if (dimension != null)
    {
      byte imageType = getImageType();
      BufferedImage bi =
        new BufferedImage(
          (int)dimension.getWidth(),
          (int)dimension.getHeight(),
          // avoid creating JPEG images with transparency that would result
          // in invalid image files for some viewers (browsers)
          (imageType == JRRenderable.IMAGE_TYPE_GIF || imageType == JRRenderable.IMAGE_TYPE_PNG
            ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB
          );

      Graphics2D g = createGraphics(bi);
      Color backcolor = getBackcolor();
      if (backcolor != null)
      {
        g.setColor(backcolor);
        g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight());
      }
      render(g, new Rectangle((int)dimension.getWidth(), (int)dimension.getHeight()));
      g.dispose();
     
      return JRImageLoader.loadImageDataFromAWTImage(bi, getImageType());
    }
    return null;
View Full Code Here

          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();
            }
          }
   
          if (imageHeight > 0)
          {
View Full Code Here

TOP

Related Classes of java.awt.geom.Dimension2D

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.