Examples of Dimension2D


Examples of java.awt.geom.Dimension2D

    document.setPageSize(PageFormat.getSize());

    // 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(
      SampleHelper.createTemplate(document)
      );

    // Wrap the content composer inside a block filter in order to achieve higher-level typographic control!
    BlockComposer blockComposer = new BlockComposer(composer);
    blockComposer.setHyphenation(true);

    Rectangle2D.Double frame = new Rectangle2D.Double(
      30,
      150,
      pageSize.getWidth() - 110,
      pageSize.getHeight() - 250
      );

    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    StandardType1Font titleFont = new StandardType1Font(
      document,
      StandardType1Font.FamilyEnum.Times,
      true,
      false
      );
    composer.setFont(titleFont,48);
    blockComposer.showText("Welcome"); blockComposer.showBreak();
    StandardType1Font bodyFont = new StandardType1Font(
      document,
      StandardType1Font.FamilyEnum.Times,
      false,
      false
      );
    composer.setFont(bodyFont,16);
    blockComposer.showText("This is an on-the-fly servlet-driven PDF sample document generated by PDF Clown for Java.");
    blockComposer.end();

    // Move past the closed block!
    frame.y = blockComposer.getBoundBox().getMaxY() + 30;
    frame.height -= (blockComposer.getBoundBox().getHeight() + 30);

    // Showing the posted image...
    // Instantiate a jpeg image object!
    Image image = null;
    try
    {
      image = Image.get(
        new Buffer(imageFileFormField.get())
        ); // Abstract image (entity).
    }
    catch(Exception e)
    {/* NOOP. */}
    if(image == null)
    {
      blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
      composer.setFont(bodyFont,12);
      composer.setFillColor(new DeviceRGBColor(1,0,0));
      blockComposer.showText("The file you uploaded wasn't a valid JPEG image!");
      blockComposer.end();

      // Move past the closed block!
      frame.y = blockComposer.getBoundBox().getMaxY() + 20;
      frame.height -= (blockComposer.getBoundBox().getHeight() + 20);
    }
    else
    {
      blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
      composer.setFont(bodyFont,12);
      blockComposer.showText("Here it is the image you uploaded: ");
      blockComposer.end();

      // Move past the closed block!
      frame.y = blockComposer.getBoundBox().getMaxY() + 20;
      frame.height -= (blockComposer.getBoundBox().getHeight() + 20);

      double width = image.getWidth(), height = image.getHeight();
      if(width > frame.getWidth())
      {
        height *= frame.getWidth() / width;
        width = frame.getWidth();
      }
      if(height > frame.getHeight() / 2)
      {
        width *= frame.getHeight() / 2 / height;
        height = frame.getHeight() / 2;
      }
      // Show the image!
      composer.showXObject(
        image.toXObject(document),
        new Point2D.Double(
          (pageSize.getWidth() - 90 - width) / 2 + 20,
          blockComposer.getBoundBox().getMaxY() + 20
          ),
        new Dimension(width,height)
        );
      // Move past the image closed block!
      frame.x = (pageSize.getWidth() - 90 - width) / 2 + 20;
      frame.y += (height + 7);
      frame.height -= (height + 7);
      frame.width = width;
    }

View Full Code Here

Examples of java.awt.geom.Dimension2D

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

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

    PrimitiveComposer composer = new PrimitiveComposer(template);

    Image image = null;
    try
    {
      // Instantiate a jpeg image object!
      image = Image.get(new java.io.File(((java.net.URL)SampleHelper.class.getResource("mountains.jpg")).toURI()).getPath()); // Abstract image (entity).
    }
    catch(Exception e)
    {/* NOOP. */}
    // 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();

    // Begin the graphics state!
    composer.beginLocalState();
    // Set the font to use!
    composer.setFont(
      new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Helvetica,
        false,
        false
        ),
      8
      );
    // Set the fill color to use!
    composer.setFillColor(
      DeviceRGBColor.White
      );
    composer.beginLocalState();
    composer.translate((float)templateSize.getWidth() - 20, 20);
    composer.rotate(90);
    composer.showText("Generated by PDF Clown on " + (new Date()));
    composer.translate(0,-8);
    composer.showText("For more info, visit http://www.pdfclown.org");
    composer.end();
View Full Code Here

Examples of java.awt.geom.Dimension2D

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

    PrimitiveComposer composer = new PrimitiveComposer(page);

    int x = Margin, y = Margin;
    StandardType1Font titleFont = new StandardType1Font(
      document,
      StandardType1Font.FamilyEnum.Times,
      true,
      true
      );
    StandardType1Font font = null;
    // Iterating through the standard Type 1 fonts...
    for(StandardType1Font.FamilyEnum fontFamily
      : EnumSet.allOf(StandardType1Font.FamilyEnum.class))
    {
      // Iterating through the font styles...
      for(int styleIndex = 0; styleIndex < 4; styleIndex++)
      {
        /*
          NOTE: Symbol and Zapf Dingbats are available just as regular fonts (no italic or bold variant).
        */
        if(styleIndex > 0
          && (fontFamily == StandardType1Font.FamilyEnum.Symbol
            || fontFamily == StandardType1Font.FamilyEnum.ZapfDingbats))
            break;

        boolean bold, italic;
        switch(styleIndex)
        {
          case 0: // Regular.
            bold = false;
            italic = false;
            break;
          case 1: // Bold.
            bold = true;
            italic = false;
            break;
          case 2: // Italic.
            bold = false;
            italic = true;
            break;
          case 3: // Bold italic.
            bold = true;
            italic = true;
            break;
          default:
            throw new RuntimeException("styleIndex " + styleIndex + " not supported.");
        }
        // Define the font used to show its character set!
        font = new StandardType1Font(
          document,
          fontFamily,
          bold,
          italic
          );

        if(y > pageSize.getHeight() - Margin)
        {
          composer.flush();

          page = new Page(document);
          document.getPages().add(page);
          pageSize = page.getSize();
          composer = new PrimitiveComposer(page);
          x = Margin; y = Margin;
        }

        if(styleIndex == 0)
        {
          composer.drawLine(
            new Point2D.Double(x,y),
            new Point2D.Double(pageSize.getWidth() - Margin,y)
            );
          composer.stroke();
          y += 5;
        }

        composer.setFont(
          titleFont,
          FontBaseSize * (styleIndex == 0 ? 1.5f : 1)
          );
        composer.showText(
          fontFamily.name() + (bold ? " bold" : "") + (italic ? " italic" : ""),
          new Point2D.Double(x,y)
          );

        y += 40;
        // Set the font used to show its character set!
        composer.setFont(font,FontBaseSize);
        // Iterating through the font characters...
        for(int charCode = 32; charCode < 256; charCode++)
        {
          if(y > pageSize.getHeight() - Margin)
          {
            composer.flush();

            page = new Page(document);
            document.getPages().add(page);
            pageSize = page.getSize();
            composer = new PrimitiveComposer(page);
            x = Margin; y = Margin;

            composer.setFont(titleFont,FontBaseSize);
            composer.showText(
              fontFamily.name() + " (continued)",
              new Point2D.Double(pageSize.getWidth() - Margin, y),
              AlignmentXEnum.Right,
              AlignmentYEnum.Top,
              0
              );
            composer.setFont(font,FontBaseSize);
            y += FontBaseSize * 2;
          }

          try
          {
            // Show the current character (using the current standard Type 1 font)!
            composer.showText(
              new String(new char[]{(char)charCode}),
              new Point2D.Double(x,y)
              );
            x += FontBaseSize;
            if(x > pageSize.getWidth() - Margin)
            {x = Margin; y += 30;}
          }
          catch(Exception e)
          { /* Ignore */ }
        }
View Full Code Here

Examples of java.awt.geom.Dimension2D

    // Adjusting default dimensions...
    /*
      NOTE: Zero-valued dimensions represent default proportional dimensions.
    */
    Dimension2D xObjectSize = xObject.getSize();
    if(size.getWidth() == 0)
    {
      if(size.getHeight() == 0)
      {size.setSize(xObjectSize);}
      else
      {size.setSize(size.getHeight() * xObjectSize.getWidth() / xObjectSize.getHeight(),size.getHeight());}
    }
    else if(size.getHeight() == 0)
    {size.setSize(size.getWidth(),size.getWidth() * xObjectSize.getHeight() / xObjectSize.getWidth());}

    // Scaling.
    double[] matrix = xObject.getMatrix();
    double scaleX, scaleY;
    scaleX = size.getWidth() / (xObjectSize.getWidth() * matrix[0]);
    scaleY = size.getHeight() / (xObjectSize.getHeight() * matrix[3]);

    // Alignment.
    float locationOffsetX, locationOffsetY;
    switch(alignmentX)
    {
View Full Code Here

Examples of java.awt.geom.Dimension2D

  {
    // Add a 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();

    // Create a content composer for the page!
    /*
      NOTE: There are several ways to add contents to a content stream:
      - adding content objects directly to the Contents collection;
      - adding content objects through a ContentScanner instance;
      - invoking basic drawing functions through a PrimitiveComposer instance;
      - invoking advanced static-positioning functions through a BlockComposer instance;
      - invoking advanced dynamic-positioning functions through a FlowComposer instance (currently not implemented yet).
    */
    PrimitiveComposer composer = new PrimitiveComposer(page);
    // Wrap the content composer within a block filter!
    /*
      NOTE: The block filter is a basic typesetter. It exposes higher-level graphical
      functionalities (horizontal/vertical alignment, indentation, paragraph composition etc.)
      leveraging the content composer primitives.
      It's important to note that this is just an intermediate abstraction layer of the typesetting
      stack: further abstract levels could sit upon it, allowing the convenient treatment of
      typographic entities like titles, paragraphs, columns, tables, headers, footers etc.
      When such further abstract levels are available, the final user (developer of consuming
      applications) won't care any more of the details you can see here in the following code lines
      (such as bothering to select the first-letter font...).
    */
    BlockComposer blockComposer = new BlockComposer(composer);

    composer.beginLocalState();

    // Define the block frame that will encompass our contents on the page canvas!
    Rectangle2D frame = new Rectangle2D.Double(
      Margin_X,
      Margin_Y,
      pageSize.getWidth() - Margin_X * 2,
      pageSize.getHeight() - Margin_Y * 2
      );
    // Begin the title block!
    blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Top);
    Font decorativeFont = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "Ruritania-Outline.ttf"
      );
    composer.setFont(decorativeFont,56);
    blockComposer.showText("Chapter 1");
    blockComposer.showBreak();
    composer.setFont(decorativeFont,32);
    blockComposer.showText("Down the Rabbit-Hole");
    // End the title block!
    blockComposer.end();

    // Update the block frame to begin after the title!
    frame = new Rectangle2D.Double(
      blockComposer.getBoundBox().getX(),
      blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight(),
      blockComposer.getBoundBox().getWidth(),
      pageSize.getHeight() - Margin_Y - (blockComposer.getBoundBox().getY() + blockComposer.getBoundBox().getHeight())
      );
    // Begin the body block!
    blockComposer.begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Bottom);
    Font bodyFont = Font.get(
      document,
      getInputPath() + java.io.File.separator + "fonts" + java.io.File.separator + "TravelingTypewriter.otf"
      );
    composer.setFont(bodyFont,14);
    composer.beginLocalState();
    composer.setFont(decorativeFont,28);
    blockComposer.showText("A");
    composer.end();
    blockComposer.showText("lice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'");
    // Define new-paragraph first-line offset!
    Dimension breakSize = new Dimension(24,8); // Indentation (24pt) and top margin (8pt).
    // Begin a new paragraph!
    blockComposer.showBreak(breakSize);
    blockComposer.showText("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.");
    // Begin a new paragraph!
    blockComposer.showBreak(breakSize);
    blockComposer.showText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.");
    // End the body block!
    blockComposer.end();

    composer.end();

    composer.beginLocalState();
    composer.rotate(
      90,
      new Point2D.Double(
        pageSize.getWidth() - 50,
        pageSize.getHeight() - 25
        )
      );
    blockComposer = new BlockComposer(composer);
    blockComposer.begin(
      new Rectangle2D.Double(0,0,300,50),
View Full Code Here

Examples of java.awt.geom.Dimension2D

    )
  {
    // 1. Create a new external form object to represent the watermark!
    FormXObject watermark = new FormXObject(document);
    // Size.
    Dimension2D size = document.getSize();
    watermark.setSize(size);

    // 2. Inserting the contents of the watermark...
    // 2.1. Create a content composer for the watermark!
    PrimitiveComposer composer = new PrimitiveComposer(watermark);
    // 2.2. Inserting the contents...
    // Set the font to use!
    composer.setFont(
      new StandardType1Font(
        document,
        StandardType1Font.FamilyEnum.Times,
        true,
        false
        ),
      120
      );
    // Set the color to fill the text characters!
    composer.setFillColor(
      new DeviceRGBColor(115f/255, 164f/255, 232f/255)
      );
    // Show the text!
    composer.showText(
      "PDFClown", // Text to show.
      new Point2D.Double(size.getWidth()/2d,size.getHeight()/2d), // Anchor location: page center.
      AlignmentXEnum.Center, // Horizontal placement (relative to the anchor): center.
      AlignmentYEnum.Middle, // Vertical placement (relative to the anchor): middle.
      50 // Rotation: 50-degree-counterclockwise.
      );
    // 2.3. Flush the contents into the watermark!
View Full Code Here

Examples of java.awt.geom.Dimension2D

//   appearance.getDown().put(PdfName.Yes,onState);
//   appearance.getRollover().put(PdfName.Off,offState);
//   appearance.getDown().put(PdfName.Off,offState);

      Rectangle2D widgetBox = widget.getBox();
      Dimension2D size = new Dimension(widgetBox.getWidth(),widgetBox.getHeight());
      Rectangle2D frame = new Rectangle2D.Double(0,0,size.getWidth(),size.getHeight());
      {
        onState.setSize(size);

        PrimitiveComposer composer = new PrimitiveComposer(onState);

        composer.beginLocalState();
        composer.setFillColor(getBackColor());
        composer.setStrokeColor(getForeColor());
        composer.drawRectangle(frame);
        composer.fillStroke();
        composer.end();

        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
        composer.setFillColor(getForeColor());
        composer.setFont(
          new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.ZapfDingbats,
            true,
            false
            ),
          (float)(size.getHeight() * 0.8)
          );
        blockComposer.showText(new String(new char[]{getCheckSymbol()}));
        blockComposer.end();

        composer.flush();
View Full Code Here

Examples of java.awt.geom.Dimension2D

//   appearance.getDown().put(new PdfName(...),onState);
//   appearance.getRollover().put(PdfName.Off,offState);
//   appearance.getDown().put(PdfName.Off,offState);

      Rectangle2D widgetBox = widget.getBox();
      Dimension2D size = new Dimension(widgetBox.getWidth(),widgetBox.getHeight());
      Rectangle2D frame = new Rectangle2D.Double(1,1,size.getWidth()-2,size.getHeight()-2);
      {
        onState.setSize(size);

        PrimitiveComposer composer = new PrimitiveComposer(onState);

        composer.beginLocalState();
        composer.setFillColor(getBackColor());
        composer.setStrokeColor(getForeColor());
        composer.drawEllipse(frame);
        composer.fillStroke();
        composer.end();

        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
        composer.setFillColor(getForeColor());
        composer.setFont(
          new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.ZapfDingbats,
            true,
            false
            ),
          (float)(size.getHeight() * 0.8)
          );
        blockComposer.showText(new String(new char[]{getRadioSymbol()}));
        blockComposer.end();

        composer.flush();
View Full Code Here

Examples of java.awt.geom.Dimension2D

    {widget.setAppearance(appearance = new Appearance(document));}

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

      String caption = (String)field.getValue();
      if(caption != null)
      {
        BlockComposer blockComposer = new BlockComposer(composer);
        blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
        composer.setFillColor(getForeColor());
        composer.setFont(
          new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            true,
            false
            ),
          (float)(size.getHeight() * 0.5)
          );
        blockComposer.showText(caption);
        blockComposer.end();
      }

View Full Code Here

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
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.