public class

Rect

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.Rect

Class Overview

Rect is a utility class used to manipulate PDF rectangle objects (refer to section 3.8.3 of the PDF Reference Manual). Rect can be associated with a SDF/Cos rectangle array using Rect(Obj*) constructor or later using Rect::Attach(Obj*) or Rect::Update(Obj*) methods. Rect keeps a local cache for rectangle points so it is necessary to call Rect::Update() method if the changes to the Rect should be saved in the attached Cos/SDF array.

Note: - Although rectangles are conventionally specified by their lower-left and upperright corners, it is acceptable to specify any two diagonally opposite corners.

Summary

Public Constructors
Rect()
Instantiate Rect with size 0.
Rect(Obj rect)
Create a Rect and initialize it using given Cos/SDF rectangle Array object.
Rect(double x1, double y1, double x2, double y2)
Create a Rect and initialize it using specified parameters.
Rect(DoubleRectangle2D r)
Instantiates a new rect from java Rectangle object
Public Methods
static Rect __Create(long impl)
long __GetHandle()
void attach(Obj rect)
Attach the Cos/SDF object to the Rect.
boolean contains(double x, double y)
Determines if the specified point is contained within the rectangular region defined by this Rectangle.
void destroy()
Frees the native memory of the object.
boolean equals(Object other)
double[] get()
Get the rectangle coordinates
double getHeight()
Get the height of rectangle
DoubleRectangle2D getRectangle()
Converts the rectangle to java.awt.geom.Rectangle2D
double getWidth()
Get the width of rectangle
double getX1()
Get the x coordinate of the lower-left point
double getX2()
Get the x coordinate of the upper-right point
double getY1()
Get the y coordinate of the lower-left point
double getY2()
Get the y coordinate of the upper-right point
int hashCode()
void inflate(double amount)
Expands the rectangle by the specified amount, in all directions.
void inflate(double x, double y)
Expands the rectangle by the specified amount in specifed direction
boolean intersectRect(Rect rect1, Rect rect2)
check if two rectangles intersect

Note: The intersection is the largest rectangle contained in both existing rectangles.

void normalize()
Normalizes the rectagle to the one with lower-left and upper-right corners.
void set(DoubleRectangle2D r)
Set the coordinates of the rectangle from jave Rectangle2D object
void set(double x1, double y1, double x2, double y2)
Set the coordinates of the rectangle.
void setX1(double x1)
Set the x coordinate of the lower-left point
void setX2(double x2)
Set the x coordinate of the upper-right point
void setY1(double y1)
Set the y coordinate of the lower-left point
void setY2(double y2)
Set the y coordinate of the upper-right point`
boolean update(Obj rect)
Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.
boolean update()
Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Rect ()

Instantiate Rect with size 0.

public Rect (Obj rect)

Create a Rect and initialize it using given Cos/SDF rectangle Array object. The rect is attached to this object.

Parameters
rect the rect

public Rect (double x1, double y1, double x2, double y2)

Create a Rect and initialize it using specified parameters. The rect is not attached to any Cos/SDF object.

Parameters
x1 x coordinate of the lower-left point
y1 y coordinate of the lower-left point
x2 x coordinate of the upper-right point
y2 y coordinate of the upper-right point

public Rect (DoubleRectangle2D r)

Instantiates a new rect from java Rectangle object

Parameters
r the rectangle object

Public Methods

public static Rect __Create (long impl)

public long __GetHandle ()

public void attach (Obj rect)

Attach the Cos/SDF object to the Rect.

Parameters
rect - underlying Cos/SDF object. Must be an SDF::Array with four SDF::Number elements.

public boolean contains (double x, double y)

Determines if the specified point is contained within the rectangular region defined by this Rectangle.

Parameters
x x coordinate of the point
y y coordinate of the point
Returns
  • true is the point is in the rectangle, false otherwise.

public void destroy ()

Frees the native memory of the object. This can be explicitly called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public boolean equals (Object other)

public double[] get ()

Get the rectangle coordinates

Returns
  • Rectangle coordinates in an array of doubles.

public double getHeight ()

Get the height of rectangle

Returns
  • rectangle's height

public DoubleRectangle2D getRectangle ()

Converts the rectangle to java.awt.geom.Rectangle2D

Returns
  • the rectangle from this object.

public double getWidth ()

Get the width of rectangle

Returns
  • rectangle's width

public double getX1 ()

Get the x coordinate of the lower-left point

Returns
  • x coordinate of the lower-left point

public double getX2 ()

Get the x coordinate of the upper-right point

Returns
  • x coordinate of the upper-right point

public double getY1 ()

Get the y coordinate of the lower-left point

Returns
  • y coordinate of the lower-left point

public double getY2 ()

Get the y coordinate of the upper-right point

Returns
  • y coordinate of the upper-right point

public int hashCode ()

public void inflate (double amount)

Expands the rectangle by the specified amount, in all directions.

Parameters
amount the amount to expand

public void inflate (double x, double y)

Expands the rectangle by the specified amount in specifed direction

Parameters
x Specifies the amount to increase the rectangle's Left (x1) and Right (x2) properties.
y Specifies the amount to increase the rectangle's Top (y1) and Bottom (y1) properties.

public boolean intersectRect (Rect rect1, Rect rect2)

check if two rectangles intersect

Note: The intersection is the largest rectangle contained in both existing rectangles.

Parameters
rect1 - A Rect object that contains a source rectangle.
rect2 - A Rect object that contains a source rectangle.
Returns
  • true if the intersection is not empty; false if the intersection is empty.

public void normalize ()

Normalizes the rectagle to the one with lower-left and upper-right corners.

Note: Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners.

public void set (DoubleRectangle2D r)

Set the coordinates of the rectangle from jave Rectangle2D object

Parameters
r the rectangle object

public void set (double x1, double y1, double x2, double y2)

Set the coordinates of the rectangle.

Parameters
x1 x coordinate of the lower-left point
y1 y coordinate of the lower-left point
x2 x coordinate of the upper-right point
y2 y coordinate of the upper-right point

public void setX1 (double x1)

Set the x coordinate of the lower-left point

Parameters
x1 x coordinate of the lower-left point

public void setX2 (double x2)

Set the x coordinate of the upper-right point

Parameters
x2 x coordinate of the upper-right point

public void setY1 (double y1)

Set the y coordinate of the lower-left point

Parameters
y1 y coordinate of the lower-left point

public void setY2 (double y2)

Set the y coordinate of the upper-right point`

Parameters
y2 y coordinate of the upper-right point`

public boolean update (Obj rect)

Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.

Parameters
rect - an SDF array that should be updated and attached to this Rect. If parameter rect is NULL or is omitted, update is performed on previously attached Cos/SDF rectangle.
Returns
  • true if the attached Cos/SDF rectangle array was successfully updated, false otherwise.

public boolean update ()

Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.

Returns
  • true if the attached Cos/SDF rectangle array was successfully updated, false otherwise.