Class: HexaPDF::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/rectangle.rb

Overview

Implementation of the PDF rectangle data structure.

Rectangles are used for describing page and bounding boxes. They are represented by arrays of four numbers specifying the (x,y) coordinates of any diagonally opposite corners.

This class simplifies the usage of rectangles by automatically normalizing the coordinates so that they are in the order:

[llx, lly, urx, ury]

where llx is the lower-left x-coordinate, lly is the lower-left y-coordinate, urx is the upper-right x-coordinate and ury is the upper-right y-coordinate.

See: PDF1.7 s7.9.5

Constant Summary

Constants inherited from Object

Object::NOT_DUPLICATABLE_CLASSES

Instance Attribute Summary

Attributes inherited from Object

#data, #document, #must_be_indirect

Instance Method Summary collapse

Methods inherited from Object

#<=>, #==, deep_copy, #deep_copy, #document?, #eql?, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, #must_be_indirect?, #null?, #oid, #oid=, #type, #validate, #value, #value=

Constructor Details

This class inherits a constructor from HexaPDF::Object

Instance Method Details

#bottomObject

Returns the y-coordinate of the lower-left corner.



65
66
67
# File 'lib/hexapdf/rectangle.rb', line 65

def bottom
  value[1]
end

#heightObject

Returns the height of the rectangle.



80
81
82
# File 'lib/hexapdf/rectangle.rb', line 80

def height
  value[3] - value[1]
end

#leftObject

Returns the x-coordinate of the lower-left corner.



55
56
57
# File 'lib/hexapdf/rectangle.rb', line 55

def left
  value[0]
end

#rightObject

Returns the x-coordinate of the upper-right corner.



60
61
62
# File 'lib/hexapdf/rectangle.rb', line 60

def right
  value[2]
end

#topObject

Returns the y-coordinate of the upper-right corner.



70
71
72
# File 'lib/hexapdf/rectangle.rb', line 70

def top
  value[3]
end

#widthObject

Returns the width of the rectangle.



75
76
77
# File 'lib/hexapdf/rectangle.rb', line 75

def width
  value[2] - value[0]
end