Package java.awt.geom

Examples of java.awt.geom.Dimension2D


      );

    FormXObject normalAppearanceState = new FormXObject(document);
    {
      Rectangle2D widgetBox = widget.getBox();
      Dimension2D size = new Dimension(widgetBox.getWidth(),widgetBox.getHeight());
      normalAppearanceState.setSize(size);
      PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

      composer.beginLocalState();
      float lineWidth = 1;
      composer.setLineWidth(lineWidth);
      composer.setFillColor(getBackColor());
      composer.setStrokeColor(getForeColor());
      Rectangle2D frame = new Rectangle2D.Double(lineWidth/2,lineWidth/2,size.getWidth()-lineWidth,size.getHeight()-lineWidth);
      composer.drawRectangle(frame,5);
      composer.fillStroke();
      composer.end();

      composer.beginMarkedContent(PdfName.Tx);
      composer.setFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Helvetica,
          false,
          false
          ),
        getFontSize()
        );
      composer.showText(
        (String)field.getValue(),
        new Point2D.Double(0,size.getHeight()/2),
        AlignmentXEnum.Left,
        AlignmentYEnum.Middle,
        0
        );
      composer.end();
View Full Code Here


    }

    FormXObject normalAppearanceState = new FormXObject(document);
    {
      Rectangle2D widgetBox = widget.getBox();
      Dimension2D size = new Dimension(widgetBox.getWidth(),widgetBox.getHeight());
      normalAppearanceState.setSize(size);
      PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

      composer.beginLocalState();
      float lineWidth = 1;
      composer.setLineWidth(lineWidth);
      composer.setFillColor(getBackColor());
      composer.setStrokeColor(getForeColor());
      Rectangle2D frame = new Rectangle2D.Double(lineWidth/2,lineWidth/2,size.getWidth()-lineWidth,size.getHeight()-lineWidth);
      composer.drawRectangle(frame,5);
      composer.fillStroke();
      composer.end();

      composer.beginLocalState();
      composer.drawRectangle(frame,5);
      composer.clip(); // Ensures that the visible content is clipped within the rounded frame.

      composer.beginMarkedContent(PdfName.Tx);
      composer.setFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyEnum.Helvetica,
          false,
          false
          ),
        getFontSize()
        );
      double y = 3;
      for(ChoiceItem item : field.getItems())
      {
        composer.showText(
          item.getText(),
          new Point2D.Double(0,y)
          );
        y += getFontSize() * 1.175;
        if(y > size.getHeight())
          break;
      }
      composer.end();
      composer.end();

View Full Code Here

    Pages pages = document.getPages();

    // 2. Page rasterization.
    int pageIndex = promptPageChoice("Select the page to render", pages.size());
    Page page = pages.get(pageIndex);
    Dimension2D imageSize = page.getSize();
    Renderer renderer = new Renderer();
    BufferedImage image = renderer.render(page, imageSize);

    // 3. Save the page image!
    try
View Full Code Here

    )
  {
    // Add page!
    Page page = new Page(document);
    document.getPages().add(page);
    Dimension2D pageSize = page.getSize();

    PrimitiveComposer composer = new PrimitiveComposer(page);
    // Add the background template!
    composer.showXObject(template);
    // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!
    /*
      NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
      Flow-level typographic features are currently not supported: block-level typographic features
      are the foundations upon which flow-level typographic features will sit.
    */
    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.setHyphenation(true);

    Dimension breakSize = new Dimension(0,10);
    // Add the font to the document!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "TravelingTypewriter.otf"
      );

    Rectangle2D frame = new Rectangle2D.Double(
      20,
      150,
      (pageSize.getWidth() - 90 - 20) / 2,
      pageSize.getHeight() - 250
      );
    // NOTE: If you wanna see the block frame that constrains the text, uncomment this line:
    /*
    composer.setStrokeColor(
      new DeviceRGBColor(115f/255,164f/255,232f/255)
      );
    composer.drawRectangle(frame);
    composer.stroke();
    */

    // Showing the 'GNU' image...
    // Instantiate a jpeg image object!
    Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "gnu.jpg"); // Abstract image (entity).
    // Show the image!
    composer.showXObject(
      image.toXObject(document),
      new Point2D.Double(
        (pageSize.getWidth() - 90 - image.getWidth()) / 2 + 20,
        pageSize.getHeight() - 100 - image.getHeight()
        ),
      new Dimension(0,0)
      );

    // Showing the title...
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    composer.setFont(font,24);
    blockComposer.showText("The Free Software Definition");
    blockComposer.end();

    // Showing the copyright note...
    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight() + 32,
      blockComposer.getBoundBox().getWidth(),
      (pageSize.getHeight() - 100 - image.getHeight() - 10) - (blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight() + 32)
      );
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    composer.setFont(font,6);
    blockComposer.showText("Copyright 2004, 2005, 2006 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice is preserved.");

    // Showing the body...
    blockComposer.showBreak(breakSize);
    composer.setFont(font,8.25f);
    Rectangle2D[] frames = new Rectangle2D[]
      {
        new Rectangle2D.Double(
          blockComposer.getBoundBox().getX(),
          pageSize.getHeight() - 100 - image.getHeight() - 10,
          blockComposer.getBoundBox().getWidth()-image.getWidth()/2,
          image.getHeight() + 10
          ),
        new Rectangle2D.Double(
          20 + 20 + (pageSize.getWidth() - 90 - 20) / 2,
          150,
          (pageSize.getWidth() - 90 - 20) / 2,
          (pageSize.getHeight() - 100 - image.getHeight() - 10) - 150
          ),
        new Rectangle2D.Double(
          20 + 20 + (pageSize.getWidth() - 90 - 20) / 2 + image.getWidth()/2,
          pageSize.getHeight() - 100 - image.getHeight() - 10,
          blockComposer.getBoundBox().getWidth()-image.getWidth()/2,
          image.getHeight() + 10
          ),
        new Rectangle2D.Double(
          20,
          150,
          (pageSize.getWidth() - 90 - 20) / 2,
          (pageSize.getHeight() - 100) - 150
          ),
        new Rectangle2D.Double(
          20 + 20 + (pageSize.getWidth() - 90 - 20) / 2,
          150,
          (pageSize.getWidth() - 90 - 20) / 2,
          (pageSize.getHeight() - 100) - 150
          )
      };
    AlignmentYEnum[] alignmentYs = new AlignmentYEnum[]
      {
        AlignmentYEnum.Top,
View Full Code Here

    )
  {
    // Add welcome page to the document!
    Page page = new Page(document); // Instantiates the page inside the document context.
    document.getPages().add(page); // Puts the page in the pages collection.
    Dimension2D pageSize = page.getSize();

    PrimitiveComposer composer = new PrimitiveComposer(page);
    // Add the background template!
    composer.showXObject(template);
    // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!
    /*
      NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
      Flow-level typographic features are currently not supported: block-level typographic features
      are the foundations upon which flow-level typographic features will sit.
    */
    BlockComposer blockComposer = new BlockComposer(composer);

    Dimension breakSize = new Dimension(0,20); // Size of a paragraph break.
    // Instantiate the page body's font!
    Font font = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "lazyDog.ttf"
      );

    // Showing the page title...
    // Define the box frame to force the page title within!
    Rectangle2D frame = new Rectangle2D.Double(
      20,
      150,
      pageSize.getWidth() - 90,
      pageSize.getHeight() - 250
      );
    // Begin the block!
    blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Top);
    // Set the font to use!
    composer.setFont(font,56);
    // Set the text rendering mode (outline only)!
    composer.setTextRenderMode(TextRenderModeEnum.Stroke);
    // Show the page title!
    blockComposer.showText("Welcome");
    // End the block!
    blockComposer.end();

    // Showing the clown photo...
    // Instantiate a jpeg image object!
    Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "Clown.jpg"); // Abstract image (entity).

    Point2D imageLocation = new Point2D.Double(
      blockComposer.getBoundBox().getX() + blockComposer.getBoundBox().getWidth() - image.getWidth(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight() + 25
      );
    // Show the image!
    composer.showXObject(
      image.toXObject(document),
      imageLocation,
      new Dimension(0,0)
      );

    Rectangle2D descriptionFrame = new Rectangle2D.Double(
      imageLocation.getX(),
      imageLocation.getY() + image.getHeight() + 5,
      image.getWidth(),
      20
      );

    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      imageLocation.getY(),
      blockComposer.getBoundBox().getWidth() - image.getWidth() - 20,
      image.getHeight()
      );
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Middle);
    composer.setFont(font,30);
    blockComposer.showText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
    blockComposer.showBreak(AlignmentXEnum.Center);
    blockComposer.showText("Enjoy!");
    blockComposer.end();

    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY()+blockComposer.getBoundBox().getHeight(),
      pageSize.getWidth() - 90,
      pageSize.getHeight() - 100 - (blockComposer.getBoundBox().getY()+blockComposer.getBoundBox().getHeight())
      );
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    composer.setFont(font,14);
    blockComposer.showText("PS: As promised, since version 0.0.3 PDF Clown has supported");
    // Begin local state!
View Full Code Here

    // Create a template (form)!
    FormXObject template = new FormXObject(document);

    // Size.
    template.setSize(document.getPageSize());
    Dimension2D templateSize = template.getSize();

    // Get form content stream!
    PrimitiveComposer composer = new PrimitiveComposer(template);

    // Showing the header image inside the common content stream...
    // Instantiate a jpeg image object!
    Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "mountains.jpg"); // Abstract image (entity).
    // Show the image inside the common content stream!
    composer.showXObject(
      image.toXObject(document),
      new Point2D.Double(0,0),
      new Dimension(
        (int)templateSize.getWidth() - 50,
        125
        )
      );

    // Showing the 'PDFClown' label inside the common content stream...
    composer.beginLocalState();
    composer.setFillColor(
      new DeviceRGBColor(115f/255,164f/255,232f/255)
      );
    // Set the font to use!
    composer.setFont(
      new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Times,
        true,
        false
        ),
      120
      );
    // Show the text!
    composer.showText(
      "PDFClown",
      new Point2D.Double(
        0,
        templateSize.getHeight() - composer.getState().getFont().getAscent(composer.getState().getFontSize())
        )
      );

    // Drawing the side rectangle...
    composer.drawRectangle(
      new Rectangle2D.Double(
        templateSize.getWidth() - 50,
        0,
        50,
        templateSize.getHeight()
        )
      );
    composer.fill();
    composer.end();

    // Showing the side text inside the common content stream...
    composer.beginLocalState();
    composer.setFont(
      new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Helvetica,
        false,
        false
        ),
      8
      );
    composer.setFillColor(
      new DeviceRGBColor(1,1,1)
      );
    composer.beginLocalState();
    composer.rotate(
      90,
      new Point2D.Double(
        templateSize.getWidth() - 50,
        templateSize.getHeight() - 25
        )
      );
    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.begin(
      new Rectangle2D.Double(0,0,300,50),
View Full Code Here

  */
  @Override
  public double[] getMatrix(
    )
  {
    Dimension2D size = getSize();

    /*
      NOTE: Image-space-to-user-space matrix is [1/w 0 0 1/h 0 0],
      where w and h are the width and height of the image in samples [PDF:1.6:4.8.3].
    */
    return new double[]
      {
        1 / size.getWidth(), // a.
        0, // b.
        0, // c.
        1 / size.getHeight(), // d.
        0, // e.
        0 // f.
      };
  }
View Full Code Here

    Document document
    )
  {
    Page page = new Page(document);
    document.getPages().add(page);
    Dimension2D pageSize = page.getSize();

    PrimitiveComposer composer = new PrimitiveComposer(page);
    {
      BlockComposer blockComposer = new BlockComposer(composer);
      blockComposer.setHyphenation(true);
      blockComposer.begin(
        new Rectangle2D.Double(
          Margin,
          Margin,
          (float)pageSize.getWidth() - Margin * 2,
          (float)pageSize.getHeight() - Margin * 2
          ),
        AlignmentXEnum.Justify,
        AlignmentYEnum.Top
        );
      StandardType1Font bodyFont = new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Courier,
        true,
        false
        );
      composer.setFont(bodyFont,32);
      blockComposer.showText("Transformation sample"); blockComposer.showBreak();
      composer.setFont(bodyFont,16);
      blockComposer.showText("Showing the GNU logo placed on the page center, rotated by 25 degrees clockwise.");
      blockComposer.end();
    }
    // Showing the 'GNU' image...
    {
      // Instantiate a jpeg image object!
      Image image = Image.get(
        getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "gnu.jpg"
        ); // Abstract image (entity).
      // Show the image!
      composer.showXObject(
        image.toXObject(document),
        new Point2D.Double(
          (float)pageSize.getWidth() / 2,
          (float)pageSize.getHeight() / 2
          ),
        new Dimension(0,0),
        AlignmentXEnum.Center,
        AlignmentYEnum.Middle,
        -25
View Full Code Here

        /*
          NOTE: Images can be represented on a page either as
          external objects (XObject) or inline objects.
        */
        Dimension2D imageSize = null; // Image native size.
        if(objectWrapper instanceof ContentScanner.XObjectWrapper)
        {
          ContentScanner.XObjectWrapper xObjectWrapper = (ContentScanner.XObjectWrapper)objectWrapper;
          XObject xObject = xObjectWrapper.getXObject();
          // Is the external object an image?
          if(xObject instanceof ImageXObject)
          {
            System.out.print(
              "External Image '" + xObjectWrapper.getName() + "' (" + xObject.getBaseObject() + ")" // Image key and indirect reference.
              );
            imageSize = xObject.getSize(); // Image native size.
          }
        }
        else if(objectWrapper instanceof ContentScanner.InlineImageWrapper)
        {
          System.out.print("Inline Image");
          InlineImage inlineImage = ((ContentScanner.InlineImageWrapper)objectWrapper).getInlineImage();
          imageSize = inlineImage.getSize(); // Image native size.
        }

        if(imageSize != null)
        {
          Rectangle2D box = objectWrapper.getBox(); // Image position (location and size) on the page.
          System.out.println(
            " on page " + (page.getIndex() + 1) + " (" + page.getBaseObject() + ")" // Page index and indirect reference.
            );
          System.out.println("  Coordinates:");
          System.out.println("     x: " + Math.round(box.getX()));
          System.out.println("     y: " + Math.round(box.getY()));
          System.out.println("     width: " + Math.round(box.getWidth()) + " (native: " + Math.round(imageSize.getWidth()) + ")");
          System.out.println("     height: " + Math.round(box.getHeight()) + " (native: " + Math.round(imageSize.getHeight()) + ")");
        }
      }
    }
  }
View Full Code Here

    Document document
    )
  {
    Page page = new Page(document);
    document.getPages().add(page);
    Dimension2D pageSize = page.getSize();

    PrimitiveComposer composer = new PrimitiveComposer(page);
    {
      BlockComposer blockComposer = new BlockComposer(composer);
      blockComposer.setHyphenation(true);
      blockComposer.begin(
        new Rectangle2D.Double(
          Margin,
          Margin,
          (float)pageSize.getWidth() - Margin * 2,
          (float)pageSize.getHeight() - Margin * 2
          ),
        AlignmentXEnum.Justify,
        AlignmentYEnum.Top
        );
      StandardType1Font bodyFont = new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Courier,
        true,
        false
        );
      composer.setFont(bodyFont,32);
      blockComposer.showText("Inline image sample"); blockComposer.showBreak();
      composer.setFont(bodyFont,16);
      blockComposer.showText("Showing the GNU logo as an inline image within the page content stream.");
      blockComposer.end();
    }
    // Showing the 'GNU' image...
    {
      // Instantiate the image!
      Image image = Image.get(getInputPath() + java.io.File.separator + "images" + java.io.File.separator + "gnu.jpg");
      // Set the position of the image in the page!
      composer.applyMatrix(200,0,0,200,(pageSize.getWidth()-200)/2,(pageSize.getHeight()-200)/2);
      // Show the image!
      image.toInlineObject(composer); // Transforms the image entity into an inline image within the page.
    }
    composer.flush();
  }
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.