intarsys PDF library API

de.intarsys.pdf.cds
Class CDSRectangle

java.lang.Object
  extended by de.intarsys.pdf.cos.COSBasedObject
      extended by de.intarsys.pdf.cds.CDSBase
          extended by de.intarsys.pdf.cds.CDSRectangle
All Implemented Interfaces:
ICOSObjectListener, IAttributeSupport

public class CDSRectangle
extends CDSBase

The implementation of the pdf rectangle data type.

The specification of the data type is found in [PDF} chapter 3.8.3.

              A rectangle is defined by
                   [llx, lly, urx, ury ]
              where
                   llx = lower left x coordinate
                   lly = lower left y coordinate
                   urx = upper right x coordinate
                   ury = upper right y coordinate
 
                          urx
                           |
                           v
                     +-----+  <-ury
                     |     |
              lly -> +-----+
                     ˆ
                     |
                    llx
 
 
 
An application should be prepared to get any two diagonally opposite corners in the rectangle specification. Use "normalize()" to ensure a rectangle that conforms to the above picture.


Nested Class Summary
 
Nested classes/interfaces inherited from class de.intarsys.pdf.cos.COSBasedObject
COSBasedObject.MetaClass
 
Field Summary
static float[] SIZE_A4
           
 
Fields inherited from class de.intarsys.pdf.cos.COSBasedObject
META
 
Constructor Summary
CDSRectangle()
          CDTRectangle constructor comment.
CDSRectangle(float[] rectArray)
          CDTRectangle constructor.
CDSRectangle(float llx, float lly, float urx, float ury)
          CDTRectangle constructor.
CDSRectangle(Rectangle2D rect)
           
 
Method Summary
 boolean contains(double x, double y)
          true if x/y lies within this.
 boolean contains(double x, double y, double epsilon)
          true if x/y lies within this, with a "uncertainty" of epsilon.
 CDSRectangle copy()
          Create a copy of the receiver
static CDSRectangle createFromCOS(COSArray array)
          Create a CDSRectangle from an array holding the rectangle coordinates.
 float getHeight()
          Return the height (an absolute value) of the rectangle.
 float getLowerLeftX()
          The lower left x coordinate.
 float getLowerLeftY()
          The lower left y coordinate.
 float getUpperRightX()
          The upper right x coordinate.
 float getUpperRightY()
          The upper rigth y coordinate.
 float getWidth()
          Get the width (an absolute value) of the rectangle.
 void invalidateCaches()
          Invalidate all local caches as the base object may have changed.
 void move(float dx, float dy)
          Move the rectangle by a relative offset.
 CDSRectangle moveTo(float x, float y)
          Move the rectangle to a new absolute position.
 CDSRectangle normalize()
          Adjust the corner coordinates so that lower left is really in the lower left (this means returns the smallest coordinate values).
 void resize(float dx, float dy)
          Resize the rectangle by moving the upper right corner.
 void resizeTo(float width, float height)
          Resize the rectangle to a new width and heigth.
 void setCorners(float llx, float lly, float urx, float ury)
          Set the corners of this.
 void setHeight(float height)
          Set the height of this.
 void setLowerLeftX(float num)
          Set the lower left x coordinate.
 void setLowerLeftY(float num)
          Set the lower left y coordinate.
 void setUpperRightX(float num)
          Set the upper right x coordinate.
 void setUpperRightY(float num)
          Set the upper right y coordinate.
 void setWidth(float width)
          Set the width of this.
 Rectangle2D toNormalizedRectangle()
          Construct a Rectangle2D object from the receiver.
 Rectangle2D toRectangle()
          Construct a Rectangle2D object from the receiver.
 
Methods inherited from class de.intarsys.pdf.cos.COSBasedObject
changed, cosGetArray, cosGetDict, cosGetDoc, cosGetField, cosGetObject, cosGetStream, cosHasField, cosRemoveField, cosSetField, getAttribute, getFieldBoolean, getFieldDate, getFieldFixed, getFieldFixedArray, getFieldInt, getFieldMLString, getFieldString, removeAttribute, setAttribute, setFieldBoolean, setFieldFixed, setFieldInt, setFieldMLString, setFieldName, setFieldObject, setFieldString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIZE_A4

public static final float[] SIZE_A4
Constructor Detail

CDSRectangle

public CDSRectangle()
CDTRectangle constructor comment.


CDSRectangle

public CDSRectangle(float llx,
                    float lly,
                    float urx,
                    float ury)
CDTRectangle constructor. Create a new rectangle with given size.

Parameters:
llx - the lower left x
lly - the lower left y
urx - the upper right x
ury - the upper right y

CDSRectangle

public CDSRectangle(float[] rectArray)
CDTRectangle constructor. Create a new rectangle with given array. The array must have 4 elements of type float.

Parameters:
rectArray - A four dimensional array defining llx,lly, urx, ury.
See Also:
CDSRectangle(float llx, float lly, float urx, float ury)

CDSRectangle

public CDSRectangle(Rectangle2D rect)
Method Detail

createFromCOS

public static CDSRectangle createFromCOS(COSArray array)
Create a CDSRectangle from an array holding the rectangle coordinates.

Parameters:
array - The base COSArray
Returns:
Create a CDSRectangle from array

contains

public boolean contains(double x,
                        double y)
true if x/y lies within this.

Parameters:
x - x coordinate to be checked.
y - y coordinate to be checked.
Returns:
true if x/y lies within this.

contains

public boolean contains(double x,
                        double y,
                        double epsilon)
true if x/y lies within this, with a "uncertainty" of epsilon.

Parameters:
x - x coordinate to be checked.
y - y coordinate to be checked.
epsilon - The allowed range of uncertainty
Returns:
true if x/y lies within this.

copy

public CDSRectangle copy()
Create a copy of the receiver

Returns:
a new copy of the receiver

getHeight

public float getHeight()
Return the height (an absolute value) of the rectangle.

Returns:
Return the height (an absolute value) of the rectangle.

getLowerLeftX

public float getLowerLeftX()
The lower left x coordinate.

Returns:
The lower left x coordinate.

getLowerLeftY

public float getLowerLeftY()
The lower left y coordinate.

Returns:
The lower left y coordinate.

getUpperRightX

public float getUpperRightX()
The upper right x coordinate.

Returns:
The upper right x coordinate.

getUpperRightY

public float getUpperRightY()
The upper rigth y coordinate.

Returns:
The upper right y coordinate.

getWidth

public float getWidth()
Get the width (an absolute value) of the rectangle.

Returns:
Get the width (an absolute value) of the rectangle.

invalidateCaches

public void invalidateCaches()
Description copied from class: COSBasedObject
Invalidate all local caches as the base object may have changed.

Overrides:
invalidateCaches in class COSBasedObject

move

public void move(float dx,
                 float dy)
Move the rectangle by a relative offset. The relationship of the opposite corners is preserved by this method.

Parameters:
dx - The offset by wich we move in x direction.
dy - The offset by wich we move in y direction.

moveTo

public CDSRectangle moveTo(float x,
                           float y)
Move the rectangle to a new absolute position. The relationship of the opposite corners is preserved by this method. The receiver is modified.

Parameters:
x - The new x position of the lower left corner.
y - The new y position of the lower left corner.
Returns:
this

normalize

public CDSRectangle normalize()
Adjust the corner coordinates so that lower left is really in the lower left (this means returns the smallest coordinate values).

This method changes this in place!

Returns:
this

resize

public void resize(float dx,
                   float dy)
Resize the rectangle by moving the upper right corner.

Parameters:
dx - The distance we move the upper right x coordinate.
dy - The distance we move the upper right y coordinate.

resizeTo

public void resizeTo(float width,
                     float height)
Resize the rectangle to a new width and heigth. The new width and heigth are defined relative to the lower left corner as signed values.

Parameters:
width - The new width of the rectangle.
height - The new height of the rectangle.

setCorners

public void setCorners(float llx,
                       float lly,
                       float urx,
                       float ury)
Set the corners of this.

Parameters:
llx - The lower left x coordinate
lly - The lower left y coordinate
urx - The upper right x coordinate
ury - The upper right y coordinate

setHeight

public void setHeight(float height)
Set the height of this.

Parameters:
height - THe new height

setLowerLeftX

public void setLowerLeftX(float num)
Set the lower left x coordinate.

Parameters:
num - The lower left x coordinate.

setLowerLeftY

public void setLowerLeftY(float num)
Set the lower left y coordinate.

Parameters:
num - The lower left y coordinate.

setUpperRightX

public void setUpperRightX(float num)
Set the upper right x coordinate.

Parameters:
num - The upper right x coordinate.

setUpperRightY

public void setUpperRightY(float num)
Set the upper right y coordinate.

Parameters:
num - The upper right y coordinate.

setWidth

public void setWidth(float width)
Set the width of this.

Parameters:
width - The new width.

toNormalizedRectangle

public Rectangle2D toNormalizedRectangle()
Construct a Rectangle2D object from the receiver. The rectangle will be normalized before construction.

Returns:
The Rectangle2D created from the receiver.

toRectangle

public Rectangle2D toRectangle()
Construct a Rectangle2D object from the receiver. The resulting rectangle is not normalized, that means it may return a negative width or height.

Returns:
The Rectangle2D created from the receiver.

intarsys PDF library API

Copyright © 2006 intarsys consulting GmbH. All Rights Reserved.